diff options
author | Sebastian <sebasjm@gmail.com> | 2024-08-05 10:41:53 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-08-05 10:42:07 -0300 |
commit | 50d183195c94d0995aafd60f0fa3766f5f5ba256 (patch) | |
tree | 60f81a3e79c578fbeaa8637a69ee6aa1e2d743c9 /packages/taler-wallet-core | |
parent | d65ff9a6c3c7478838ef1421dd32363495e99cba (diff) | |
download | wallet-core-50d183195c94d0995aafd60f0fa3766f5f5ba256.tar.xz |
scope info in tx details
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r-- | packages/taler-wallet-core/src/deposits.ts | 10 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/exchanges.ts | 78 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/pay-merchant.ts | 14 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/pay-peer-pull-credit.ts | 4 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/pay-peer-pull-debit.ts | 2 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/pay-peer-push-credit.ts | 4 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/pay-peer-push-debit.ts | 2 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/refresh.ts | 2 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/withdraw.ts | 26 |
9 files changed, 132 insertions, 10 deletions
diff --git a/packages/taler-wallet-core/src/deposits.ts b/packages/taler-wallet-core/src/deposits.ts index 37c73607a..2c931fc39 100644 --- a/packages/taler-wallet-core/src/deposits.ts +++ b/packages/taler-wallet-core/src/deposits.ts @@ -43,6 +43,7 @@ import { PrepareDepositRequest, PrepareDepositResponse, RefreshReason, + ScopeInfo, SelectedProspectiveCoin, TalerError, TalerErrorCode, @@ -99,7 +100,13 @@ import { timestampProtocolFromDb, timestampProtocolToDb, } from "./db.js"; -import { getExchangeWireDetailsInTx, getExchangeWireFee } from "./exchanges.js"; +import { + getExchangeScopeInfo, + getExchangeScopeInfoOrUndefined, + getExchangeWireDetailsInTx, + getExchangeWireFee, + getScopeForAllExchanges, +} from "./exchanges.js"; import { extractContractData, generateDepositPermissions, @@ -193,6 +200,7 @@ export class DepositTransactionContext implements TransactionContext { return { type: TransactionType.Deposit, txState, + scopes: await getScopeForAllExchanges(tx, !dg.infoPerExchange? []: Object.keys(dg.infoPerExchange)), txActions: computeDepositTransactionActions(dg), amountRaw: Amounts.stringify(dg.counterpartyEffectiveDepositAmount), amountEffective: isUnsuccessfulTransaction(txState) diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts index 270cd6ded..5872d87bb 100644 --- a/packages/taler-wallet-core/src/exchanges.ts +++ b/packages/taler-wallet-core/src/exchanges.ts @@ -248,6 +248,83 @@ async function getExchangeRecordsInternal( return details; } +export async function getScopeForAllCoins( + tx: WalletDbReadOnlyTransaction< + [ + "exchanges", + "exchangeDetails", + "globalCurrencyExchanges", + "globalCurrencyAuditors", + ] + >, + exs: string[], +): Promise<ScopeInfo[]> { + const queries = exs.map((exchange) => { + return getExchangeScopeInfoOrUndefined(tx, exchange); + }); + const rs = await Promise.all(queries); + return rs.filter((d): d is ScopeInfo => d !== undefined); +} + +export async function getScopeForAllExchanges( + tx: WalletDbReadOnlyTransaction< + [ + "exchanges", + "exchangeDetails", + "globalCurrencyExchanges", + "globalCurrencyAuditors", + ] + >, + exs: string[], +): Promise<ScopeInfo[]> { + const queries = exs.map((exchange) => { + return getExchangeScopeInfoOrUndefined(tx, exchange); + }); + const rs = await Promise.all(queries); + return rs.filter((d): d is ScopeInfo => d !== undefined); +} + +export async function getCoinScopeInfoOrUndefined( + tx: WalletDbReadOnlyTransaction< + [ + "coins", + "exchanges", + "exchangeDetails", + "globalCurrencyExchanges", + "globalCurrencyAuditors", + ] + >, + coinPub: string, +): Promise<ScopeInfo | undefined> { + const coin = await tx.coins.get(coinPub); + if (!coin) { + return undefined; + } + const det = await getExchangeRecordsInternal(tx, coin.exchangeBaseUrl); + if (!det) { + return undefined; + } + return internalGetExchangeScopeInfo(tx, det); +} + +export async function getExchangeScopeInfoOrUndefined( + tx: WalletDbReadOnlyTransaction< + [ + "exchanges", + "exchangeDetails", + "globalCurrencyExchanges", + "globalCurrencyAuditors", + ] + >, + exchangeBaseUrl: string, +): Promise<ScopeInfo | undefined> { + const det = await getExchangeRecordsInternal(tx, exchangeBaseUrl); + if (!det) { + return undefined; + } + return internalGetExchangeScopeInfo(tx, det); +} + export async function getExchangeScopeInfo( tx: WalletDbReadOnlyTransaction< [ @@ -2154,6 +2231,7 @@ export class DenomLossTransactionContext implements TransactionContext { return { type: TransactionType.DenomLoss, txState, + scopes: await getScopeForAllExchanges(tx, [rec.exchangeBaseUrl]), txActions: [TransactionAction.Delete], amountRaw: Amounts.stringify(rec.amount), amountEffective: Amounts.stringify(rec.amount), diff --git a/packages/taler-wallet-core/src/pay-merchant.ts b/packages/taler-wallet-core/src/pay-merchant.ts index f74e47213..726abb1e7 100644 --- a/packages/taler-wallet-core/src/pay-merchant.ts +++ b/packages/taler-wallet-core/src/pay-merchant.ts @@ -161,6 +161,7 @@ import { getDenomInfo, WalletExecutionContext, } from "./wallet.js"; +import { getScopeForAllExchanges } from "./exchanges.js"; /** * Logger. @@ -276,6 +277,12 @@ export class PayMerchantTransactionContext implements TransactionContext { return { type: TransactionType.Payment, txState, + scopes: await getScopeForAllExchanges( + tx, + !purchaseRec.payInfo.payCoinSelection + ? [] + : purchaseRec.payInfo.payCoinSelection.coinPubs, + ), txActions: computePayMerchantTransactionActions(purchaseRec), amountRaw: Amounts.stringify(contractData.amount), amountEffective: isUnsuccessfulTransaction(txState) @@ -617,10 +624,17 @@ export class RefundTransactionContext implements TransactionContext { summary_i18n: maybeContractData.summaryI18n, }; } + const purchaseRecord = await tx.purchases.get(refundRecord.proposalId); const txState = computeRefundTransactionState(refundRecord); return { type: TransactionType.Refund, + scopes: await getScopeForAllExchanges( + tx, + !purchaseRecord || !purchaseRecord.payInfo?.payCoinSelection + ? [] + : purchaseRecord.payInfo.payCoinSelection.coinPubs, + ), amountEffective: isUnsuccessfulTransaction(txState) ? Amounts.stringify(Amounts.zeroOfAmount(refundRecord.amountEffective)) : refundRecord.amountEffective, diff --git a/packages/taler-wallet-core/src/pay-peer-pull-credit.ts b/packages/taler-wallet-core/src/pay-peer-pull-credit.ts index de180ccd5..7071010b8 100644 --- a/packages/taler-wallet-core/src/pay-peer-pull-credit.ts +++ b/packages/taler-wallet-core/src/pay-peer-pull-credit.ts @@ -83,7 +83,7 @@ import { timestampPreciseFromDb, timestampPreciseToDb, } from "./db.js"; -import { fetchFreshExchange } from "./exchanges.js"; +import { fetchFreshExchange, getScopeForAllExchanges } from "./exchanges.js"; import { codecForExchangePurseStatus, getMergeReserveInfo, @@ -194,6 +194,7 @@ export class PeerPullCreditTransactionContext implements TransactionContext { return { type: TransactionType.PeerPullCredit, txState, + scopes: await getScopeForAllExchanges(tx, [pullCredit.exchangeBaseUrl]), txActions: computePeerPullCreditTransactionActions(pullCredit), amountEffective: isUnsuccessfulTransaction(txState) ? Amounts.stringify(Amounts.zeroOfAmount(wsr.instructedAmount)) @@ -228,6 +229,7 @@ export class PeerPullCreditTransactionContext implements TransactionContext { return { type: TransactionType.PeerPullCredit, txState, + scopes: await getScopeForAllExchanges(tx, [pullCredit.exchangeBaseUrl]), txActions: computePeerPullCreditTransactionActions(pullCredit), amountEffective: isUnsuccessfulTransaction(txState) ? Amounts.stringify(Amounts.zeroOfAmount(peerContractTerms.amount)) diff --git a/packages/taler-wallet-core/src/pay-peer-pull-debit.ts b/packages/taler-wallet-core/src/pay-peer-pull-debit.ts index dca228547..09ecbeb94 100644 --- a/packages/taler-wallet-core/src/pay-peer-pull-debit.ts +++ b/packages/taler-wallet-core/src/pay-peer-pull-debit.ts @@ -103,6 +103,7 @@ import { parseTransactionIdentifier, } from "./transactions.js"; import { WalletExecutionContext } from "./wallet.js"; +import { getScopeForAllExchanges } from "./exchanges.js"; const logger = new Logger("pay-peer-pull-debit.ts"); @@ -166,6 +167,7 @@ export class PeerPullDebitTransactionContext implements TransactionContext { return { type: TransactionType.PeerPullDebit, txState, + scopes: await getScopeForAllExchanges(tx, [pi.exchangeBaseUrl]), txActions: computePeerPullDebitTransactionActions(pi), amountEffective: isUnsuccessfulTransaction(txState) ? Amounts.stringify(Amounts.zeroOfAmount(pi.amount)) diff --git a/packages/taler-wallet-core/src/pay-peer-push-credit.ts b/packages/taler-wallet-core/src/pay-peer-push-credit.ts index 5199dbde4..830e2bd1b 100644 --- a/packages/taler-wallet-core/src/pay-peer-push-credit.ts +++ b/packages/taler-wallet-core/src/pay-peer-push-credit.ts @@ -79,7 +79,7 @@ import { timestampPreciseFromDb, timestampPreciseToDb, } from "./db.js"; -import { fetchFreshExchange } from "./exchanges.js"; +import { fetchFreshExchange, getScopeForAllExchanges } from "./exchanges.js"; import { codecForExchangePurseStatus, getMergeReserveInfo, @@ -183,6 +183,7 @@ export class PeerPushCreditTransactionContext implements TransactionContext { return { type: TransactionType.PeerPushCredit, txState, + scopes: await getScopeForAllExchanges(tx, [pushInc.exchangeBaseUrl]), txActions: computePeerPushCreditTransactionActions(pushInc), amountEffective: isUnsuccessfulTransaction(txState) ? Amounts.stringify(Amounts.zeroOfAmount(wg.instructedAmount)) @@ -207,6 +208,7 @@ export class PeerPushCreditTransactionContext implements TransactionContext { return { type: TransactionType.PeerPushCredit, txState, + scopes: await getScopeForAllExchanges(tx, [pushInc.exchangeBaseUrl]), txActions: computePeerPushCreditTransactionActions(pushInc), amountEffective: isUnsuccessfulTransaction(txState) ? Amounts.stringify(Amounts.zeroOfAmount(peerContractTerms.amount)) diff --git a/packages/taler-wallet-core/src/pay-peer-push-debit.ts b/packages/taler-wallet-core/src/pay-peer-push-debit.ts index b30ff334d..4485976b9 100644 --- a/packages/taler-wallet-core/src/pay-peer-push-debit.ts +++ b/packages/taler-wallet-core/src/pay-peer-push-debit.ts @@ -93,6 +93,7 @@ import { notifyTransition, } from "./transactions.js"; import { WalletExecutionContext } from "./wallet.js"; +import { getScopeForAllExchanges } from "./exchanges.js"; const logger = new Logger("pay-peer-push-debit.ts"); @@ -167,6 +168,7 @@ export class PeerPushDebitTransactionContext implements TransactionContext { return { type: TransactionType.PeerPushDebit, txState, + scopes: await getScopeForAllExchanges(tx, [pushDebitRec.exchangeBaseUrl]), txActions: computePeerPushDebitTransactionActions(pushDebitRec), amountEffective: isUnsuccessfulTransaction(txState) ? Amounts.stringify(Amounts.zeroOfAmount(pushDebitRec.totalCost)) diff --git a/packages/taler-wallet-core/src/refresh.ts b/packages/taler-wallet-core/src/refresh.ts index a657ec445..b8bd3c0b7 100644 --- a/packages/taler-wallet-core/src/refresh.ts +++ b/packages/taler-wallet-core/src/refresh.ts @@ -122,6 +122,7 @@ import { WalletExecutionContext, } from "./wallet.js"; import { getCandidateWithdrawalDenomsTx } from "./withdraw.js"; +import { getScopeForAllExchanges } from "./exchanges.js"; const logger = new Logger("refresh.ts"); @@ -186,6 +187,7 @@ export class RefreshTransactionContext implements TransactionContext { return { type: TransactionType.Refresh, txState, + scopes: await getScopeForAllExchanges(tx, !refreshGroupRecord.infoPerExchange? []: Object.keys(refreshGroupRecord.infoPerExchange)), txActions: computeRefreshTransactionActions(refreshGroupRecord), refreshReason: refreshGroupRecord.reason, amountEffective: isUnsuccessfulTransaction(txState) diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts index 09348baf7..406772d5f 100644 --- a/packages/taler-wallet-core/src/withdraw.ts +++ b/packages/taler-wallet-core/src/withdraw.ts @@ -160,6 +160,7 @@ import { fetchFreshExchange, getExchangePaytoUri, getExchangeWireDetailsInTx, + getScopeForAllExchanges, listExchanges, lookupExchangeByUri, markExchangeUsed, @@ -182,6 +183,7 @@ const logger = new Logger("withdraw.ts"); function buildTransactionForBankIntegratedWithdraw( wg: WithdrawalGroupRecord, + scopes: ScopeInfo[], ort?: OperationRetryRecord, ): TransactionWithdrawal { if (wg.wgInfo.withdrawalType !== WithdrawalRecordType.BankIntegrated) { @@ -202,6 +204,7 @@ function buildTransactionForBankIntegratedWithdraw( return { type: TransactionType.Withdrawal, txState, + scopes, txActions: computeWithdrawalTransactionActions(wg), exchangeBaseUrl: wg.exchangeBaseUrl, amountEffective: @@ -237,6 +240,7 @@ function buildTransactionForBankIntegratedWithdraw( function buildTransactionForManualWithdraw( wg: WithdrawalGroupRecord, exchangeDetails: ExchangeWireDetails | undefined, + scopes: ScopeInfo[], ort?: OperationRetryRecord, ): TransactionWithdrawal { if (wg.wgInfo.withdrawalType !== WithdrawalRecordType.BankManual) @@ -259,6 +263,7 @@ function buildTransactionForManualWithdraw( return { type: TransactionType.Withdrawal, txState, + scopes, txActions: computeWithdrawalTransactionActions(wg), amountEffective: isUnsuccessfulTransaction(txState) ? Amounts.stringify(Amounts.zeroOfAmount(wg.instructedAmount)) @@ -318,6 +323,18 @@ export class WithdrawTransactionContext implements TransactionContext { if (!withdrawalGroupRecord) { return undefined; } + const exchangeDetails = + withdrawalGroupRecord.exchangeBaseUrl === undefined + ? undefined + : await getExchangeWireDetailsInTx( + tx, + withdrawalGroupRecord.exchangeBaseUrl, + ); + const scopes = await getScopeForAllExchanges( + tx, + !exchangeDetails ? [] : [exchangeDetails.exchangeBaseUrl], + ); + const ort = await tx.operationRetries.get(this.taskId); if ( withdrawalGroupRecord.wgInfo.withdrawalType === @@ -325,16 +342,10 @@ export class WithdrawTransactionContext implements TransactionContext { ) { return buildTransactionForBankIntegratedWithdraw( withdrawalGroupRecord, + scopes, ort, ); } - const exchangeDetails = - withdrawalGroupRecord.exchangeBaseUrl === undefined - ? undefined - : await getExchangeWireDetailsInTx( - tx, - withdrawalGroupRecord.exchangeBaseUrl, - ); if (!exchangeDetails) { logger.warn( `transaction ${this.transactionId} is a manual withdrawal, but no exchange wire details found`, @@ -343,6 +354,7 @@ export class WithdrawTransactionContext implements TransactionContext { return buildTransactionForManualWithdraw( withdrawalGroupRecord, exchangeDetails, + scopes, ort, ); } |