diff options
Diffstat (limited to 'packages/taler-wallet-core/src/transactions.ts')
-rw-r--r-- | packages/taler-wallet-core/src/transactions.ts | 114 |
1 files changed, 69 insertions, 45 deletions
diff --git a/packages/taler-wallet-core/src/transactions.ts b/packages/taler-wallet-core/src/transactions.ts index 12a4a31b5..f36380033 100644 --- a/packages/taler-wallet-core/src/transactions.ts +++ b/packages/taler-wallet-core/src/transactions.ts @@ -252,6 +252,10 @@ export async function getTransactionById( ort, ); } + checkDbInvariant( + withdrawalGroupRecord.exchangeBaseUrl !== undefined, + "manual withdraw should have exchange url", + ); const exchangeDetails = await getExchangeWireDetailsInTx( tx, withdrawalGroupRecord.exchangeBaseUrl, @@ -589,6 +593,9 @@ function buildTransactionForPeerPullCredit( ); }); const txState = computePeerPullCreditTransactionState(pullCredit); + checkDbInvariant(wsr.instructedAmount !== undefined, "wg unitialized"); + checkDbInvariant(wsr.denomsSel !== undefined, "wg unitialized"); + checkDbInvariant(wsr.exchangeBaseUrl !== undefined, "wg unitialized"); return { type: TransactionType.PeerPullCredit, txState, @@ -654,13 +661,16 @@ function buildTransactionForPeerPushCredit( pushInc: PeerPushPaymentIncomingRecord, pushOrt: OperationRetryRecord | undefined, peerContractTerms: PeerContractTerms, - wsr: WithdrawalGroupRecord | undefined, + wg: WithdrawalGroupRecord | undefined, wsrOrt: OperationRetryRecord | undefined, ): Transaction { - if (wsr) { - if (wsr.wgInfo.withdrawalType !== WithdrawalRecordType.PeerPushCredit) { + if (wg) { + if (wg.wgInfo.withdrawalType !== WithdrawalRecordType.PeerPushCredit) { throw Error("invalid withdrawal group type for push payment credit"); } + checkDbInvariant(wg.instructedAmount !== undefined, "wg unitialized"); + checkDbInvariant(wg.denomsSel !== undefined, "wg unitialized"); + checkDbInvariant(wg.exchangeBaseUrl !== undefined, "wg unitialized"); const txState = computePeerPushCreditTransactionState(pushInc); return { @@ -668,15 +678,15 @@ function buildTransactionForPeerPushCredit( txState, txActions: computePeerPushCreditTransactionActions(pushInc), amountEffective: isUnsuccessfulTransaction(txState) - ? Amounts.stringify(Amounts.zeroOfAmount(wsr.instructedAmount)) - : Amounts.stringify(wsr.denomsSel.totalCoinValue), - amountRaw: Amounts.stringify(wsr.instructedAmount), - exchangeBaseUrl: wsr.exchangeBaseUrl, + ? Amounts.stringify(Amounts.zeroOfAmount(wg.instructedAmount)) + : Amounts.stringify(wg.denomsSel.totalCoinValue), + amountRaw: Amounts.stringify(wg.instructedAmount), + exchangeBaseUrl: wg.exchangeBaseUrl, info: { expiration: peerContractTerms.purse_expiration, summary: peerContractTerms.summary, }, - timestamp: timestampPreciseFromDb(wsr.timestampStart), + timestamp: timestampPreciseFromDb(wg.timestampStart), transactionId: constructTransactionIdentifier({ tag: TransactionType.PeerPushCredit, peerPushCreditId: pushInc.peerPushCreditId, @@ -712,37 +722,40 @@ function buildTransactionForPeerPushCredit( } function buildTransactionForBankIntegratedWithdraw( - wgRecord: WithdrawalGroupRecord, + wg: WithdrawalGroupRecord, ort?: OperationRetryRecord, ): TransactionWithdrawal { - if (wgRecord.wgInfo.withdrawalType !== WithdrawalRecordType.BankIntegrated) + if (wg.wgInfo.withdrawalType !== WithdrawalRecordType.BankIntegrated) throw Error(""); - const txState = computeWithdrawalTransactionStatus(wgRecord); + const txState = computeWithdrawalTransactionStatus(wg); + checkDbInvariant(wg.instructedAmount !== undefined, "wg unitialized"); + checkDbInvariant(wg.denomsSel !== undefined, "wg unitialized"); + checkDbInvariant(wg.exchangeBaseUrl !== undefined, "wg unitialized"); return { type: TransactionType.Withdrawal, txState, - txActions: computeWithdrawalTransactionActions(wgRecord), + txActions: computeWithdrawalTransactionActions(wg), amountEffective: isUnsuccessfulTransaction(txState) - ? Amounts.stringify(Amounts.zeroOfAmount(wgRecord.instructedAmount)) - : Amounts.stringify(wgRecord.denomsSel.totalCoinValue), - amountRaw: Amounts.stringify(wgRecord.instructedAmount), + ? Amounts.stringify(Amounts.zeroOfAmount(wg.instructedAmount)) + : Amounts.stringify(wg.denomsSel.totalCoinValue), + amountRaw: Amounts.stringify(wg.instructedAmount), withdrawalDetails: { type: WithdrawalType.TalerBankIntegrationApi, - confirmed: wgRecord.wgInfo.bankInfo.timestampBankConfirmed ? true : false, - exchangeCreditAccountDetails: wgRecord.wgInfo.exchangeCreditAccounts, - reservePub: wgRecord.reservePub, - bankConfirmationUrl: wgRecord.wgInfo.bankInfo.confirmUrl, + confirmed: wg.wgInfo.bankInfo.timestampBankConfirmed ? true : false, + exchangeCreditAccountDetails: wg.wgInfo.exchangeCreditAccounts, + reservePub: wg.reservePub, + bankConfirmationUrl: wg.wgInfo.bankInfo.confirmUrl, reserveIsReady: - wgRecord.status === WithdrawalGroupStatus.Done || - wgRecord.status === WithdrawalGroupStatus.PendingReady, + wg.status === WithdrawalGroupStatus.Done || + wg.status === WithdrawalGroupStatus.PendingReady, }, - kycUrl: wgRecord.kycUrl, - exchangeBaseUrl: wgRecord.exchangeBaseUrl, - timestamp: timestampPreciseFromDb(wgRecord.timestampStart), + kycUrl: wg.kycUrl, + exchangeBaseUrl: wg.exchangeBaseUrl, + timestamp: timestampPreciseFromDb(wg.timestampStart), transactionId: constructTransactionIdentifier({ tag: TransactionType.Withdrawal, - withdrawalGroupId: wgRecord.withdrawalGroupId, + withdrawalGroupId: wg.withdrawalGroupId, }), ...(ort?.lastError ? { error: ort.lastError } : {}), }; @@ -759,50 +772,50 @@ export function isUnsuccessfulTransaction(state: TransactionState): boolean { } function buildTransactionForManualWithdraw( - withdrawalGroup: WithdrawalGroupRecord, + wg: WithdrawalGroupRecord, exchangeDetails: ExchangeWireDetails, ort?: OperationRetryRecord, ): TransactionWithdrawal { - if (withdrawalGroup.wgInfo.withdrawalType !== WithdrawalRecordType.BankManual) + if (wg.wgInfo.withdrawalType !== WithdrawalRecordType.BankManual) throw Error(""); const plainPaytoUris = exchangeDetails.wireInfo?.accounts.map((x) => x.payto_uri) ?? []; + checkDbInvariant(wg.instructedAmount !== undefined, "wg unitialized"); + checkDbInvariant(wg.denomsSel !== undefined, "wg unitialized"); + checkDbInvariant(wg.exchangeBaseUrl !== undefined, "wg unitialized"); const exchangePaytoUris = augmentPaytoUrisForWithdrawal( plainPaytoUris, - withdrawalGroup.reservePub, - withdrawalGroup.instructedAmount, + wg.reservePub, + wg.instructedAmount, ); - const txState = computeWithdrawalTransactionStatus(withdrawalGroup); + const txState = computeWithdrawalTransactionStatus(wg); return { type: TransactionType.Withdrawal, txState, - txActions: computeWithdrawalTransactionActions(withdrawalGroup), + txActions: computeWithdrawalTransactionActions(wg), amountEffective: isUnsuccessfulTransaction(txState) - ? Amounts.stringify( - Amounts.zeroOfAmount(withdrawalGroup.instructedAmount), - ) - : Amounts.stringify(withdrawalGroup.denomsSel.totalCoinValue), - amountRaw: Amounts.stringify(withdrawalGroup.instructedAmount), + ? Amounts.stringify(Amounts.zeroOfAmount(wg.instructedAmount)) + : Amounts.stringify(wg.denomsSel.totalCoinValue), + amountRaw: Amounts.stringify(wg.instructedAmount), withdrawalDetails: { type: WithdrawalType.ManualTransfer, - reservePub: withdrawalGroup.reservePub, + reservePub: wg.reservePub, exchangePaytoUris, - exchangeCreditAccountDetails: - withdrawalGroup.wgInfo.exchangeCreditAccounts, + exchangeCreditAccountDetails: wg.wgInfo.exchangeCreditAccounts, reserveIsReady: - withdrawalGroup.status === WithdrawalGroupStatus.Done || - withdrawalGroup.status === WithdrawalGroupStatus.PendingReady, + wg.status === WithdrawalGroupStatus.Done || + wg.status === WithdrawalGroupStatus.PendingReady, }, - kycUrl: withdrawalGroup.kycUrl, - exchangeBaseUrl: withdrawalGroup.exchangeBaseUrl, - timestamp: timestampPreciseFromDb(withdrawalGroup.timestampStart), + kycUrl: wg.kycUrl, + exchangeBaseUrl: wg.exchangeBaseUrl, + timestamp: timestampPreciseFromDb(wg.timestampStart), transactionId: constructTransactionIdentifier({ tag: TransactionType.Withdrawal, - withdrawalGroupId: withdrawalGroup.withdrawalGroupId, + withdrawalGroupId: wg.withdrawalGroupId, }), ...(ort?.lastError ? { error: ort.lastError } : {}), }; @@ -1090,6 +1103,10 @@ export async function getWithdrawalTransactionByUri( ort, ); } + checkDbInvariant( + withdrawalGroupRecord.exchangeBaseUrl !== undefined, + "manual withdraw should have exchange url", + ); const exchangeDetails = await getExchangeWireDetailsInTx( tx, withdrawalGroupRecord.exchangeBaseUrl, @@ -1337,6 +1354,13 @@ export async function getTransactions( }); await iterRecordsForWithdrawal(tx, filter, async (wsr) => { + if ( + wsr.rawWithdrawalAmount === undefined || + wsr.exchangeBaseUrl == undefined + ) { + // skip prepared withdrawals which has not been confirmed + return; + } const exchangesInTx = [wsr.exchangeBaseUrl]; if ( shouldSkipCurrency( |