diff options
author | Florian Dold <florian@dold.me> | 2023-06-24 17:49:53 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-06-24 17:49:53 +0200 |
commit | 1f31ebc3cc4b116f4d762f974e803c7ef85ab51f (patch) | |
tree | 4f67a83803c21bec53fe1728cb5733c03bc43e8a /packages/taler-wallet-core/src/operations | |
parent | 4f30506dcacc587586381b1a8fa20c5442784e41 (diff) | |
download | wallet-core-1f31ebc3cc4b116f4d762f974e803c7ef85ab51f.tar.xz |
wallet-core: allow confirming peer-push-credit via txid
Diffstat (limited to 'packages/taler-wallet-core/src/operations')
-rw-r--r-- | packages/taler-wallet-core/src/operations/pay-peer-push-credit.ts | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/packages/taler-wallet-core/src/operations/pay-peer-push-credit.ts b/packages/taler-wallet-core/src/operations/pay-peer-push-credit.ts index 53a569a92..341dccb7a 100644 --- a/packages/taler-wallet-core/src/operations/pay-peer-push-credit.ts +++ b/packages/taler-wallet-core/src/operations/pay-peer-push-credit.ts @@ -71,6 +71,7 @@ import { TransitionInfo, constructTransactionIdentifier, notifyTransition, + parseTransactionIdentifier, stopLongpolling, } from "./transactions.js"; import { @@ -617,12 +618,27 @@ export async function confirmPeerPushCredit( req: ConfirmPeerPushCreditRequest, ): Promise<AcceptPeerPushPaymentResponse> { let peerInc: PeerPushPaymentIncomingRecord | undefined; + let peerPushPaymentIncomingId: string; + if (req.peerPushPaymentIncomingId) { + peerPushPaymentIncomingId = req.peerPushPaymentIncomingId; + } else if (req.transactionId) { + const parsedTx = parseTransactionIdentifier(req.transactionId); + if (!parsedTx) { + throw Error("invalid transaction ID"); + } + if (parsedTx.tag !== TransactionType.PeerPushCredit) { + throw Error("invalid transaction ID type"); + } + peerPushPaymentIncomingId = parsedTx.peerPushPaymentIncomingId; + } else { + throw Error("no transaction ID (or deprecated peerPushPaymentIncomingId) provided"); + } await ws.db .mktx((x) => [x.contractTerms, x.peerPushPaymentIncoming]) .runReadWrite(async (tx) => { peerInc = await tx.peerPushPaymentIncoming.get( - req.peerPushPaymentIncomingId, + peerPushPaymentIncomingId, ); if (!peerInc) { return; @@ -643,7 +659,7 @@ export async function confirmPeerPushCredit( const transactionId = constructTransactionIdentifier({ tag: TransactionType.PeerPushCredit, - peerPushPaymentIncomingId: req.peerPushPaymentIncomingId, + peerPushPaymentIncomingId, }); return { |