From 582b6ae5f4139cd1be8096dd59371430455bbeef Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 23 Feb 2023 16:07:14 +0100 Subject: wallet-core: report correct amountEffective in peer-pull-credit even before withdrawal is active --- .../src/crypto/workers/nodeThreadWorker.ts | 2 +- packages/taler-wallet-core/src/db.ts | 14 ++++++++++++++ packages/taler-wallet-core/src/operations/exchanges.ts | 1 + packages/taler-wallet-core/src/operations/pay-peer.ts | 8 ++++++++ packages/taler-wallet-core/src/operations/transactions.ts | 2 +- 5 files changed, 25 insertions(+), 2 deletions(-) (limited to 'packages/taler-wallet-core/src') diff --git a/packages/taler-wallet-core/src/crypto/workers/nodeThreadWorker.ts b/packages/taler-wallet-core/src/crypto/workers/nodeThreadWorker.ts index d9b4399d6..eaa0108bb 100644 --- a/packages/taler-wallet-core/src/crypto/workers/nodeThreadWorker.ts +++ b/packages/taler-wallet-core/src/crypto/workers/nodeThreadWorker.ts @@ -151,7 +151,7 @@ class NodeThreadCryptoWorker implements CryptoWorker { this.onmessage(v); } }); - this.nodeWorker.unref(); + //this.nodeWorker.unref(); } /** diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 630713ee3..a7bdda3ec 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -1795,6 +1795,8 @@ export interface PeerPullPaymentInitiationRecord { */ amount: AmountString; + estimatedAmountEffective: AmountString; + /** * Purse public key. Used as the primary key to look * up this record. @@ -2606,6 +2608,18 @@ export const walletDbFixups: FixupDescription[] = [ }); }, }, + { + name: "PeerPullPaymentInitiationRecord_estimatedAmountEffective_add", + async fn(tx): Promise { + await tx.peerPullPaymentInitiations.iter().forEachAsync(async (pi) => { + if (pi.estimatedAmountEffective) { + return; + } + pi.estimatedAmountEffective = pi.amount; + await tx.peerPullPaymentInitiations.put(pi); + }); + }, + }, { name: "PeerPushPaymentInitiationRecord_ALL_removeLegacyTx", async fn(tx): Promise { diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index 457344e06..8a98c8299 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -260,6 +260,7 @@ async function validateWireInfo( throw Error("exchange acct signature invalid"); } } + logger.trace("account validation done"); const feesForType: WireFeeMap = {}; for (const wireMethod of Object.keys(wireInfo.fees)) { const feeList: WireFee[] = []; diff --git a/packages/taler-wallet-core/src/operations/pay-peer.ts b/packages/taler-wallet-core/src/operations/pay-peer.ts index 6a04bce7c..05338b83e 100644 --- a/packages/taler-wallet-core/src/operations/pay-peer.ts +++ b/packages/taler-wallet-core/src/operations/pay-peer.ts @@ -1655,6 +1655,13 @@ export async function initiatePeerPullPayment( const mergeReserveRowId = mergeReserveInfo.rowId; checkDbInvariant(!!mergeReserveRowId); + const wi = await getExchangeWithdrawalInfo( + ws, + exchangeBaseUrl, + Amounts.parseOrThrow(req.partialContractTerms.amount), + undefined, + ); + await ws.db .mktx((x) => [x.peerPullPaymentInitiations, x.contractTerms]) .runReadWrite(async (tx) => { @@ -1673,6 +1680,7 @@ export async function initiatePeerPullPayment( contractPriv: contractKeyPair.priv, contractPub: contractKeyPair.pub, withdrawalGroupId, + estimatedAmountEffective: wi.withdrawalAmountEffective, }); await tx.contractTerms.put({ contractTermsRaw: contractTerms, diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts index 764115cef..54fe1320d 100644 --- a/packages/taler-wallet-core/src/operations/transactions.ts +++ b/packages/taler-wallet-core/src/operations/transactions.ts @@ -542,7 +542,7 @@ function buildTransactionForPeerPullCredit( return { type: TransactionType.PeerPullCredit, - amountEffective: Amounts.stringify(peerContractTerms.amount), + amountEffective: Amounts.stringify(pullCredit.amount), amountRaw: Amounts.stringify(peerContractTerms.amount), exchangeBaseUrl: pullCredit.exchangeBaseUrl, extendedStatus: ExtendedStatus.Pending, -- cgit v1.2.3