diff options
author | Florian Dold <florian@dold.me> | 2023-09-08 12:54:31 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-09-08 12:54:37 +0200 |
commit | 2ae952cdfa8f38a650be8e4438c21bace2f24c19 (patch) | |
tree | 2d4b8ec564102f750eb5b1e593bc13a0bdda1d5e /packages/taler-wallet-core | |
parent | 50b0b324ae67bea01079d6e9a1d684795f5b430f (diff) | |
download | wallet-core-2ae952cdfa8f38a650be8e4438c21bace2f24c19.tar.xz |
wallet-core: remove redundant deposit status field in DB
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r-- | packages/taler-wallet-core/src/db.ts | 17 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/deposits.ts | 41 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/pending.ts | 21 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/transactions.ts | 10 |
4 files changed, 41 insertions, 48 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 359569055..3db7ae9b5 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -921,8 +921,11 @@ export enum RefreshOperationStatus { * Status of a single element of a deposit group. */ export enum DepositElementStatus { - Unknown = 0x0100_0000, - Accepted = 0x0100_0001, + DepositPending = 0x0100_0000, + /** + * Accepted, but tracking. + */ + Tracking = 0x0100_0001, KycRequired = 0x0100_0002, Wired = 0x0500_0000, RefundSuccess = 0x0503_0000, @@ -1723,10 +1726,8 @@ export interface DepositGroupRecord { /** * The counterparty effective deposit amount. - * - * FIXME: If possible, rename to counterpartyEffectiveDepositAmount. */ - effectiveDepositAmount: AmountString; + counterpartyEffectiveDepositAmount: AmountString; timestampCreated: TalerPreciseTimestamp; @@ -1734,11 +1735,7 @@ export interface DepositGroupRecord { operationStatus: DepositOperationStatus; - // FIXME: Duplication between this and transactionPerCoin! - depositedPerCoin: boolean[]; - - // FIXME: Improve name! - transactionPerCoin: DepositElementStatus[]; + statusPerCoin: DepositElementStatus[]; /** * When the deposit transaction was aborted and diff --git a/packages/taler-wallet-core/src/operations/deposits.ts b/packages/taler-wallet-core/src/operations/deposits.ts index a8ec859cf..3d78e938b 100644 --- a/packages/taler-wallet-core/src/operations/deposits.ts +++ b/packages/taler-wallet-core/src/operations/deposits.ts @@ -510,10 +510,10 @@ async function refundDepositGroup( ws: InternalWalletState, depositGroup: DepositGroupRecord, ): Promise<TaskRunResult> { - const newTxPerCoin = [...depositGroup.transactionPerCoin]; - logger.info(`status per coin: ${j2s(depositGroup.transactionPerCoin)}`); - for (let i = 0; i < depositGroup.transactionPerCoin.length; i++) { - const st = depositGroup.transactionPerCoin[i]; + const newTxPerCoin = [...depositGroup.statusPerCoin]; + logger.info(`status per coin: ${j2s(depositGroup.statusPerCoin)}`); + for (let i = 0; i < depositGroup.statusPerCoin.length; i++) { + const st = depositGroup.statusPerCoin[i]; switch (st) { case DepositElementStatus.RefundFailed: case DepositElementStatus.RefundSuccess: @@ -593,7 +593,7 @@ async function refundDepositGroup( if (!newDg) { return; } - newDg.transactionPerCoin = newTxPerCoin; + newDg.statusPerCoin = newTxPerCoin; const refreshCoins: CoinRefreshRequest[] = []; for (let i = 0; i < newTxPerCoin.length; i++) { refreshCoins.push({ @@ -766,7 +766,7 @@ async function processDepositGroupPendingTrack( cancellationToken?: CancellationToken, ): Promise<TaskRunResult> { const { depositGroupId } = depositGroup; - for (let i = 0; i < depositGroup.depositedPerCoin.length; i++) { + for (let i = 0; i < depositGroup.statusPerCoin.length; i++) { const coinPub = depositGroup.payCoinSelection.coinPubs[i]; // FIXME: Make the URL part of the coin selection? const exchangeBaseUrl = await ws.db @@ -785,7 +785,7 @@ async function processDepositGroupPendingTrack( } | undefined; - if (depositGroup.transactionPerCoin[i] !== DepositElementStatus.Wired) { + if (depositGroup.statusPerCoin[i] !== DepositElementStatus.Wired) { const track = await trackDeposit( ws, depositGroup, @@ -810,7 +810,7 @@ async function processDepositGroupPendingTrack( exchangeBaseUrl, ); } else { - updatedTxStatus = DepositElementStatus.Accepted; + updatedTxStatus = DepositElementStatus.Tracking; } } else if (track.type === "wired") { updatedTxStatus = DepositElementStatus.Wired; @@ -840,7 +840,7 @@ async function processDepositGroupPendingTrack( id: track.exchange_sig, }; } else { - updatedTxStatus = DepositElementStatus.Unknown; + updatedTxStatus = DepositElementStatus.DepositPending; } } @@ -853,7 +853,7 @@ async function processDepositGroupPendingTrack( return; } if (updatedTxStatus !== undefined) { - dg.transactionPerCoin[i] = updatedTxStatus; + dg.statusPerCoin[i] = updatedTxStatus; } if (newWiredCoin) { /** @@ -885,8 +885,8 @@ async function processDepositGroupPendingTrack( return undefined; } const oldTxState = computeDepositTransactionStatus(dg); - for (let i = 0; i < depositGroup.depositedPerCoin.length; i++) { - if (depositGroup.transactionPerCoin[i] !== DepositElementStatus.Wired) { + for (let i = 0; i < depositGroup.statusPerCoin.length; i++) { + if (depositGroup.statusPerCoin[i] !== DepositElementStatus.Wired) { allWired = false; break; } @@ -943,7 +943,7 @@ async function processDepositGroupPendingDeposit( for (let i = 0; i < depositPermissions.length; i++) { const perm = depositPermissions[i]; - if (depositGroup.depositedPerCoin[i]) { + if (depositGroup.statusPerCoin[i] !== DepositElementStatus.DepositPending) { continue; } @@ -980,8 +980,12 @@ async function processDepositGroupPendingDeposit( if (!dg) { return; } - dg.depositedPerCoin[i] = true; - await tx.depositGroups.put(dg); + const coinStatus = dg.statusPerCoin[i]; + switch (coinStatus) { + case DepositElementStatus.DepositPending: + dg.statusPerCoin[i] = DepositElementStatus.Tracking; + await tx.depositGroups.put(dg); + } }); } @@ -1373,16 +1377,15 @@ export async function createDepositGroup( noncePub: noncePair.pub, timestampCreated: AbsoluteTime.toPreciseTimestamp(now), timestampFinished: undefined, - transactionPerCoin: payCoinSel.coinSel.coinPubs.map( - () => DepositElementStatus.Unknown, + statusPerCoin: payCoinSel.coinSel.coinPubs.map( + () => DepositElementStatus.DepositPending, ), payCoinSelection: payCoinSel.coinSel, payCoinSelectionUid: encodeCrock(getRandomBytes(32)), - depositedPerCoin: payCoinSel.coinSel.coinPubs.map(() => false), merchantPriv: merchantPair.priv, merchantPub: merchantPair.pub, totalPayCost: Amounts.stringify(totalDepositCost), - effectiveDepositAmount: Amounts.stringify( + counterpartyEffectiveDepositAmount: Amounts.stringify( counterpartyEffectiveDepositAmount, ), wire: { diff --git a/packages/taler-wallet-core/src/operations/pending.ts b/packages/taler-wallet-core/src/operations/pending.ts index 207e6ffda..6115f848b 100644 --- a/packages/taler-wallet-core/src/operations/pending.ts +++ b/packages/taler-wallet-core/src/operations/pending.ts @@ -46,6 +46,7 @@ import { RefundGroupStatus, ExchangeEntryDbUpdateStatus, RefreshOperationStatus, + DepositElementStatus, } from "../db.js"; import { PendingOperationsResponse, @@ -277,8 +278,8 @@ async function gatherDepositPending( ): Promise<void> { await iterRecordsForDeposit(tx, { onlyState: "nonfinal" }, async (dg) => { let deposited = true; - for (const d of dg.depositedPerCoin) { - if (!d) { + for (const d of dg.statusPerCoin) { + if (d === DepositElementStatus.DepositPending) { deposited = false; } } @@ -480,9 +481,7 @@ export async function iterRecordsForPeerPullInitiation( PeerPullPaymentCreditStatus.PendingCreatePurse, PeerPullPaymentCreditStatus.AbortingDeletePurse, ); - await tx.peerPullCredit.indexes.byStatus - .iter(keyRange) - .forEachAsync(f); + await tx.peerPullCredit.indexes.byStatus.iter(keyRange).forEachAsync(f); } else { await tx.peerPullCredit.indexes.byStatus.iter().forEachAsync(f); } @@ -528,9 +527,7 @@ export async function iterRecordsForPeerPullDebit( PeerPullDebitRecordStatus.PendingDeposit, PeerPullDebitRecordStatus.AbortingRefresh, ); - await tx.peerPullDebit.indexes.byStatus - .iter(keyRange) - .forEachAsync(f); + await tx.peerPullDebit.indexes.byStatus.iter(keyRange).forEachAsync(f); } else { await tx.peerPullDebit.indexes.byStatus.iter().forEachAsync(f); } @@ -576,9 +573,7 @@ export async function iterRecordsForPeerPushInitiation( PeerPushDebitStatus.PendingCreatePurse, PeerPushDebitStatus.AbortingRefresh, ); - await tx.peerPushDebit.indexes.byStatus - .iter(keyRange) - .forEachAsync(f); + await tx.peerPushDebit.indexes.byStatus.iter(keyRange).forEachAsync(f); } else { await tx.peerPushDebit.indexes.byStatus.iter().forEachAsync(f); } @@ -624,9 +619,7 @@ export async function iterRecordsForPeerPushCredit( PeerPushCreditStatus.PendingMerge, PeerPushCreditStatus.PendingWithdrawing, ); - await tx.peerPushCredit.indexes.byStatus - .iter(keyRange) - .forEachAsync(f); + await tx.peerPushCredit.indexes.byStatus.iter(keyRange).forEachAsync(f); } else { await tx.peerPushCredit.indexes.byStatus.iter().forEachAsync(f); } diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts index 8db68e0f1..9d5ca9f1a 100644 --- a/packages/taler-wallet-core/src/operations/transactions.ts +++ b/packages/taler-wallet-core/src/operations/transactions.ts @@ -791,8 +791,8 @@ function buildTransactionForDeposit( ort?: OperationRetryRecord, ): Transaction { let deposited = true; - for (const d of dg.depositedPerCoin) { - if (!d) { + for (const d of dg.statusPerCoin) { + if (d == DepositElementStatus.DepositPending) { deposited = false; } } @@ -801,7 +801,7 @@ function buildTransactionForDeposit( type: TransactionType.Deposit, txState: computeDepositTransactionStatus(dg), txActions: computeDepositTransactionActions(dg), - amountRaw: Amounts.stringify(dg.effectiveDepositAmount), + amountRaw: Amounts.stringify(dg.counterpartyEffectiveDepositAmount), amountEffective: Amounts.stringify(dg.totalPayCost), timestamp: dg.timestampCreated, targetPaytoUri: dg.wire.payto_uri, @@ -812,11 +812,11 @@ function buildTransactionForDeposit( }), wireTransferProgress: (100 * - dg.transactionPerCoin.reduce( + dg.statusPerCoin.reduce( (prev, cur) => prev + (cur === DepositElementStatus.Wired ? 1 : 0), 0, )) / - dg.transactionPerCoin.length, + dg.statusPerCoin.length, depositGroupId: dg.depositGroupId, trackingState: Object.values(dg.trackingState ?? {}), deposited, |