From f57dc7bf7a1e3a14c67512ba67d92fa350c95c0e Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 10 Jun 2022 13:03:47 +0200 Subject: wallet-core: implement and test forced coin/denom selection --- packages/taler-util/src/walletTypes.ts | 80 +++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 15 deletions(-) (limited to 'packages/taler-util/src/walletTypes.ts') diff --git a/packages/taler-util/src/walletTypes.ts b/packages/taler-util/src/walletTypes.ts index 00a489861..2e5dd418d 100644 --- a/packages/taler-util/src/walletTypes.ts +++ b/packages/taler-util/src/walletTypes.ts @@ -33,7 +33,6 @@ import { codecForAmountString, } from "./amounts.js"; import { - AbsoluteTime, codecForTimestamp, TalerProtocolTimestamp, } from "./time.js"; @@ -231,6 +230,7 @@ export const codecForCreateReserveRequest = (): Codec => .property("exchangePaytoUri", codecForString()) .property("senderWire", codecOptional(codecForString())) .property("bankWithdrawStatusUrl", codecOptional(codecForString())) + .property("forcedDenomSel", codecForAny()) .build("CreateReserveRequest"); /** @@ -674,6 +674,7 @@ export interface TestPayArgs { merchantAuthToken?: string; amount: string; summary: string; + forcedCoinSel?: ForcedCoinSel; } export const codecForTestPayArgs = (): Codec => @@ -682,6 +683,7 @@ export const codecForTestPayArgs = (): Codec => .property("merchantAuthToken", codecOptional(codecForString())) .property("amount", codecForString()) .property("summary", codecForString()) + .property("forcedCoinSel", codecForAny()) .build("TestPayArgs"); export interface IntegrationTestArgs { @@ -738,7 +740,7 @@ export const codecForGetExchangeTosRequest = (): Codec => export interface AcceptManualWithdrawalRequest { exchangeBaseUrl: string; amount: string; - restrictAge?: number, + restrictAge?: number; } export const codecForAcceptManualWithdrawalRequet = @@ -803,10 +805,11 @@ export interface ApplyRefundFromPurchaseIdRequest { purchaseId: string; } -export const codecForApplyRefundFromPurchaseIdRequest = (): Codec => - buildCodecForObject() - .property("purchaseId", codecForString()) - .build("ApplyRefundFromPurchaseIdRequest"); +export const codecForApplyRefundFromPurchaseIdRequest = + (): Codec => + buildCodecForObject() + .property("purchaseId", codecForString()) + .build("ApplyRefundFromPurchaseIdRequest"); export interface GetWithdrawalDetailsForUriRequest { talerWithdrawUri: string; @@ -866,12 +869,14 @@ export const codecForPreparePayRequest = (): Codec => export interface ConfirmPayRequest { proposalId: string; sessionId?: string; + forcedCoinSel?: ForcedCoinSel; } export const codecForConfirmPayRequest = (): Codec => buildCodecForObject() .property("proposalId", codecForString()) .property("sessionId", codecOptional(codecForString())) + .property("forcedCoinSel", codecForAny()) .build("ConfirmPay"); export type CoreApiResponse = CoreApiResponseSuccess | CoreApiResponseError; @@ -903,6 +908,7 @@ export interface WithdrawTestBalanceRequest { amount: string; bankBaseUrl: string; exchangeBaseUrl: string; + forcedDenomSel?: ForcedDenomSel; } export const withdrawTestBalanceDefaults = { @@ -976,6 +982,7 @@ export const codecForWithdrawTestBalance = .property("amount", codecForString()) .property("bankBaseUrl", codecForString()) .property("exchangeBaseUrl", codecForString()) + .property("forcedDenomSel", codecForAny()) .build("WithdrawTestBalanceRequest"); export interface ApplyRefundResponse { @@ -1026,8 +1033,6 @@ export const codecForForceRefreshRequest = (): Codec => .property("coinPubList", codecForList(codecForString())) .build("ForceRefreshRequest"); - - export interface PrepareRefundRequest { talerRefundUri: string; } @@ -1084,14 +1089,12 @@ export const codecForGetFeeForDeposit = (): Codec => export interface PrepareDepositRequest { depositPaytoUri: string; amount: AmountString; - } -export const codecForPrepareDepositRequest = - (): Codec => - buildCodecForObject() - .property("amount", codecForAmountString()) - .property("depositPaytoUri", codecForString()) - .build("PrepareDepositRequest"); +export const codecForPrepareDepositRequest = (): Codec => + buildCodecForObject() + .property("amount", codecForAmountString()) + .property("depositPaytoUri", codecForString()) + .build("PrepareDepositRequest"); export interface PrepareDepositResponse { totalDepositCost: AmountJson; @@ -1203,6 +1206,7 @@ export const codecForWithdrawFakebankRequest = export interface ImportDb { dump: any; } + export const codecForImportDbRequest = (): Codec => buildCodecForObject() .property("dump", codecForAny()) @@ -1214,3 +1218,49 @@ export interface ForcedDenomSel { count: number; }[]; } + +/** + * Forced coin selection for deposits/payments. + */ +export interface ForcedCoinSel { + coins: { + value: AmountString; + contribution: AmountString; + }[]; +} + +export interface TestPayResult { + payCoinSelection: PayCoinSelection, +} + + +/** + * Result of selecting coins, contains the exchange, and selected + * coins with their denomination. + */ + export interface PayCoinSelection { + /** + * Amount requested by the merchant. + */ + paymentAmount: AmountJson; + + /** + * Public keys of the coins that were selected. + */ + coinPubs: string[]; + + /** + * Amount that each coin contributes. + */ + coinContributions: AmountJson[]; + + /** + * How much of the wire fees is the customer paying? + */ + customerWireFees: AmountJson; + + /** + * How much of the deposit fees is the customer paying? + */ + customerDepositFees: AmountJson; +} \ No newline at end of file -- cgit v1.2.3