diff options
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r-- | packages/taler-wallet-core/src/common.ts | 16 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/db.ts | 9 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/deposits.ts | 7 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/exchanges.ts | 5 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/pay-merchant.ts | 20 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/pay-peer-pull-debit.ts | 5 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/pay-peer-push-debit.ts | 14 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/recoup.ts | 5 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/refresh.ts | 29 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/testing.ts | 8 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 20 |
11 files changed, 101 insertions, 37 deletions
diff --git a/packages/taler-wallet-core/src/common.ts b/packages/taler-wallet-core/src/common.ts index 9f63c74d5..83f50c8e3 100644 --- a/packages/taler-wallet-core/src/common.ts +++ b/packages/taler-wallet-core/src/common.ts @@ -46,6 +46,7 @@ import { } from "@gnu-taler/taler-util"; import { BackupProviderRecord, + CoinHistoryRecord, CoinRecord, DbPreciseTimestamp, DepositGroupRecord, @@ -221,6 +222,21 @@ export async function spendCoins( coinAvailability.visibleCoinCount--; } } + let histEntry: CoinHistoryRecord | undefined = await tx.coinHistory.get( + coin.coinPub, + ); + if (!histEntry) { + histEntry = { + coinPub: coin.coinPub, + history: [], + }; + } + histEntry.history.push({ + type: "spend", + transactionId: csi.transactionId, + amount: Amounts.stringify(contrib), + }); + await tx.coinHistory.put(histEntry); await tx.coins.put(coin); await tx.coinAvailability.put(coinAvailability); } diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 7c2380e2d..3438cbdc7 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -905,7 +905,12 @@ export interface CoinRecord { ageCommitmentProof: AgeCommitmentProof | undefined; } -export type WalletCoinHistoryItem = +/** + * History item for a coin. + * + * DB-specific format, + */ +export type DbWalletCoinHistoryItem = | { type: "withdraw"; transactionId: TransactionIdStr; @@ -944,7 +949,7 @@ export interface CoinHistoryRecord { * We store this as an array in the object store, as the coin history * is pretty much always very small. */ - history: WalletCoinHistoryItem[]; + history: DbWalletCoinHistoryItem[]; } export enum RefreshCoinStatus { diff --git a/packages/taler-wallet-core/src/deposits.ts b/packages/taler-wallet-core/src/deposits.ts index e3d0b997e..6394fdc78 100644 --- a/packages/taler-wallet-core/src/deposits.ts +++ b/packages/taler-wallet-core/src/deposits.ts @@ -518,12 +518,13 @@ async function refundDepositGroup( const res = await wex.db.runReadWriteTx( { storeNames: [ + "coinAvailability", + "coinHistory", + "coins", + "denominations", "depositGroups", "refreshGroups", "refreshSessions", - "coins", - "denominations", - "coinAvailability", ], }, async (tx) => { diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts index 3bec30587..4043d3498 100644 --- a/packages/taler-wallet-core/src/exchanges.ts +++ b/packages/taler-wallet-core/src/exchanges.ts @@ -1693,12 +1693,13 @@ export async function updateExchangeFromUrlHandler( await wex.db.runReadWriteTx( { storeNames: [ + "coinAvailability", + "coinHistory", "coins", "denominations", - "coinAvailability", + "exchanges", "refreshGroups", "refreshSessions", - "exchanges", ], }, async (tx) => { diff --git a/packages/taler-wallet-core/src/pay-merchant.ts b/packages/taler-wallet-core/src/pay-merchant.ts index 118a338cc..28fb204dd 100644 --- a/packages/taler-wallet-core/src/pay-merchant.ts +++ b/packages/taler-wallet-core/src/pay-merchant.ts @@ -282,13 +282,14 @@ export class PayMerchantTransactionContext implements TransactionContext { const transitionInfo = await wex.db.runReadWriteTx( { storeNames: [ - "purchases", - "refreshGroups", - "refreshSessions", - "denominations", "coinAvailability", + "coinHistory", "coins", + "denominations", "operationRetries", + "purchases", + "refreshGroups", + "refreshSessions", ], }, async (tx) => { @@ -3407,16 +3408,17 @@ async function storeRefunds( const result = await wex.db.runReadWriteTx( { storeNames: [ + "coinAvailability", + "coinHistory", + "coins", "coins", "denominations", - "purchases", - "refundItems", - "refundGroups", "denominations", - "coins", - "coinAvailability", + "purchases", "refreshGroups", "refreshSessions", + "refundGroups", + "refundItems", ], }, async (tx) => { 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 bc154a45d..a1c6b46ce 100644 --- a/packages/taler-wallet-core/src/pay-peer-pull-debit.ts +++ b/packages/taler-wallet-core/src/pay-peer-pull-debit.ts @@ -237,11 +237,12 @@ export class PeerPullDebitTransactionContext implements TransactionContext { { extraStores: [ "coinAvailability", + "coinAvailability", + "coinHistory", + "coins", "denominations", "refreshGroups", "refreshSessions", - "coins", - "coinAvailability", ], }, async (pi, tx) => { 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 92d4b98ba..6603cc4f3 100644 --- a/packages/taler-wallet-core/src/pay-peer-push-debit.ts +++ b/packages/taler-wallet-core/src/pay-peer-push-debit.ts @@ -733,12 +733,13 @@ async function processPeerPushDebitAbortingDeletePurse( const transitionInfo = await wex.db.runReadWriteTx( { storeNames: [ + "coinAvailability", + "coinHistory", + "coins", + "denominations", "peerPushDebit", "refreshGroups", "refreshSessions", - "denominations", - "coinAvailability", - "coins", ], }, async (tx) => { @@ -974,12 +975,13 @@ async function processPeerPushDebitReady( const transitionInfo = await wex.db.runReadWriteTx( { storeNames: [ + "coinAvailability", + "coinHistory", + "coins", + "denominations", "peerPushDebit", "refreshGroups", "refreshSessions", - "denominations", - "coinAvailability", - "coins", ], }, async (tx) => { diff --git a/packages/taler-wallet-core/src/recoup.ts b/packages/taler-wallet-core/src/recoup.ts index 9adc5e2ad..56c819bf8 100644 --- a/packages/taler-wallet-core/src/recoup.ts +++ b/packages/taler-wallet-core/src/recoup.ts @@ -392,12 +392,13 @@ export async function processRecoupGroup( await wex.db.runReadWriteTx( { storeNames: [ - "recoupGroups", "coinAvailability", + "coinHistory", + "coins", "denominations", + "recoupGroups", "refreshGroups", "refreshSessions", - "coins", ], }, async (tx) => { diff --git a/packages/taler-wallet-core/src/refresh.ts b/packages/taler-wallet-core/src/refresh.ts index 01970f8bc..9a5058a4d 100644 --- a/packages/taler-wallet-core/src/refresh.ts +++ b/packages/taler-wallet-core/src/refresh.ts @@ -92,6 +92,7 @@ import { import { CryptoApiStoppedError } from "./crypto/workers/crypto-dispatcher.js"; import { CoinAvailabilityRecord, + CoinHistoryRecord, CoinRecord, CoinSourceType, DenominationRecord, @@ -1546,7 +1547,13 @@ export async function calculateRefreshOutput( async function applyRefreshToOldCoins( wex: WalletExecutionContext, tx: WalletDbReadWriteTransaction< - ["denominations", "coins", "refreshGroups", "coinAvailability"] + [ + "denominations", + "coins", + "coinHistory", + "refreshGroups", + "coinAvailability", + ] >, oldCoinPubs: CoinRefreshRequest[], refreshGroupId: string, @@ -1604,6 +1611,24 @@ async function applyRefreshToOldCoins( default: assertUnreachable(coin.status); } + let histEntry: CoinHistoryRecord | undefined = await tx.coinHistory.get( + coin.coinPub, + ); + if (!histEntry) { + histEntry = { + coinPub: coin.coinPub, + history: [], + }; + } + histEntry.history.push({ + type: "refresh", + transactionId: constructTransactionIdentifier({ + tag: TransactionType.Refresh, + refreshGroupId, + }), + amount: Amounts.stringify(ocp.amount), + }); + await tx.coinHistory.put(histEntry); await tx.coins.put(coin); } } @@ -1628,6 +1653,7 @@ export async function createRefreshGroup( [ "denominations", "coins", + "coinHistory", "refreshGroups", "refreshSessions", "coinAvailability", @@ -1785,6 +1811,7 @@ export async function forceRefresh( "refreshSessions", "denominations", "coins", + "coinHistory", ], }, async (tx) => { diff --git a/packages/taler-wallet-core/src/testing.ts b/packages/taler-wallet-core/src/testing.ts index 057ac50cd..6435595cb 100644 --- a/packages/taler-wallet-core/src/testing.ts +++ b/packages/taler-wallet-core/src/testing.ts @@ -58,7 +58,10 @@ import { import { getBalances } from "./balance.js"; import { genericWaitForState } from "./common.js"; import { createDepositGroup } from "./deposits.js"; -import { fetchFreshExchange } from "./exchanges.js"; +import { + acceptExchangeTermsOfService, + fetchFreshExchange, +} from "./exchanges.js"; import { confirmPay, preparePayForUri, @@ -122,6 +125,9 @@ export async function withdrawTestBalance( amount, ); + await fetchFreshExchange(wex, req.exchangeBaseUrl); + await acceptExchangeTermsOfService(wex, req.exchangeBaseUrl); + const acceptResp = await acceptWithdrawalFromUri(wex, { talerWithdrawUri: wresp.taler_withdraw_uri, selectedExchange: exchangeBaseUrl, diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index bc2011883..a58e3aff0 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -516,7 +516,7 @@ async function dumpCoins(wex: WalletExecutionContext): Promise<CoinDumpJson> { const coinsJson: CoinDumpJson = { coins: [] }; logger.info("dumping coins"); await wex.db.runReadOnlyTx( - { storeNames: ["coins", "denominations"] }, + { storeNames: ["coins", "coinHistory", "denominations"] }, async (tx) => { const coins = await tx.coins.iter().toArray(); for (const c of coins) { @@ -547,16 +547,18 @@ async function dumpCoins(wex: WalletExecutionContext): Promise<CoinDumpJson> { logger.warn("no denomination found for coin"); continue; } + const historyRec = await tx.coinHistory.get(c.coinPub); coinsJson.coins.push({ - coin_pub: c.coinPub, - denom_pub: denomInfo.denomPub, - denom_pub_hash: c.denomPubHash, - denom_value: denom.value, - exchange_base_url: c.exchangeBaseUrl, - refresh_parent_coin_pub: refreshParentCoinPub, - withdrawal_reserve_pub: withdrawalReservePub, - coin_status: c.status, + coinPub: c.coinPub, + denomPub: denomInfo.denomPub, + denomPubHash: c.denomPubHash, + denomValue: denom.value, + exchangeBaseUrl: c.exchangeBaseUrl, + refreshParentCoinPub: refreshParentCoinPub, + withdrawalReservePub: withdrawalReservePub, + coinStatus: c.status, ageCommitmentProof: c.ageCommitmentProof, + history: historyRec ? historyRec.history : [], }); } }, |