diff options
author | Sebastian <sebasjm@gmail.com> | 2022-05-04 16:11:12 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-05-04 16:26:53 -0300 |
commit | 4491118494c332c9ce0a0c4533804744d63701f2 (patch) | |
tree | 883cef2f190321bf07d0d1b53f5842e9c9c6ddbd /packages/taler-wallet-core | |
parent | f16d2e52d51b931d18abd9d87568be681339350f (diff) | |
download | wallet-core-4491118494c332c9ce0a0c4533804744d63701f2.tar.xz |
add restricted option to manual withdraw
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r-- | packages/taler-wallet-core/src/util/coinSelection.test.ts | 42 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 5 |
2 files changed, 47 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/util/coinSelection.test.ts b/packages/taler-wallet-core/src/util/coinSelection.test.ts index dc64a57dc..ca7b76eb5 100644 --- a/packages/taler-wallet-core/src/util/coinSelection.test.ts +++ b/packages/taler-wallet-core/src/util/coinSelection.test.ts @@ -43,6 +43,20 @@ function fakeAci(current: string, feeDeposit: string): AvailableCoinInfo { }; } +function fakeAciWithAgeRestriction(current: string, feeDeposit: string): AvailableCoinInfo { + return { + availableAmount: a(current), + coinPub: "foobar", + denomPub: { + cipher: DenomKeyType.Rsa, + rsa_public_key: "foobar", + age_mask: 2446657, + }, + feeDeposit: a(feeDeposit), + exchangeBaseUrl: "https://example.com/", + }; +} + test("it should be able to pay if merchant takes the fees", (t) => { const acis: AvailableCoinInfo[] = [ fakeAci("EUR:1.0", "EUR:0.1"), @@ -267,3 +281,31 @@ test("coin selection 9", (t) => { ); t.pass(); }); + + +test("it should be able to use unrestricted coins for age restricted contract", (t) => { + const acis: AvailableCoinInfo[] = [ + fakeAciWithAgeRestriction("EUR:1.0", "EUR:0.2"), + fakeAciWithAgeRestriction("EUR:0.2", "EUR:0.2"), + ]; + const res = selectPayCoins({ + candidates: { + candidateCoins: acis, + wireFeesPerExchange: {}, + }, + contractTermsAmount: a("EUR:1.2"), + depositFeeLimit: a("EUR:0.4"), + wireFeeLimit: a("EUR:0"), + wireFeeAmortization: 1, + requiredMinimumAge: 13 + }); + if (!res) { + t.fail(); + return; + } + t.true(res.coinContributions.length === 2); + t.true( + Amounts.cmp(Amounts.sum(res.coinContributions).amount, "EUR:1.2") === 0, + ); + t.pass(); +}); diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index fb61ae0dc..053a0763b 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -454,11 +454,14 @@ async function acceptManualWithdrawal( ws: InternalWalletState, exchangeBaseUrl: string, amount: AmountJson, + restrictAge?: number, + ): Promise<AcceptManualWithdrawalResult> { try { const resp = await createReserve(ws, { amount, exchange: exchangeBaseUrl, + restrictAge }); const exchangePaytoUris = await ws.db .mktx((x) => ({ @@ -690,6 +693,7 @@ async function dumpCoins(ws: InternalWalletState): Promise<CoinDumpJson> { remaining_value: Amounts.stringify(c.currentAmount), withdrawal_reserve_pub: withdrawalReservePub, coin_suspended: c.suspended, + ageCommitmentProof: c.ageCommitmentProof, }); } }); @@ -801,6 +805,7 @@ async function dispatchRequestInternal( ws, req.exchangeBaseUrl, Amounts.parseOrThrow(req.amount), + req.restrictAge ); return res; } |