commit b31d095e7c8be6f08427aa547ba762a374cb4b81 parent 2c2cc1e7cdaba1890e99b8f1443029bac2ca4c1f Author: Florian Dold <dold@taler.net> Date: Tue, 24 Nov 2026 17:48:40 +0100 wallet-core: preserve stored amounts during database conversion Copying transaction metadata recalculated amounts on records already copied, so verification rejected wallets with older refunds. Copy the metadata on its own and compare missing legacy scopes as an empty list, the default in SQLite. Diffstat:
5 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/packages/taler-wallet-core/src/db/indexeddb/transaction.ts b/packages/taler-wallet-core/src/db/indexeddb/transaction.ts @@ -363,6 +363,10 @@ export class IdbWalletTransaction implements WalletDbTransaction { async upsertTransactionMeta(rec: WalletTransactionMeta): Promise<void> { await updateTransactionAmounts(this, rec.transactionId); + await this.upsertTransactionMetaOnly(rec); + } + + async upsertTransactionMetaOnly(rec: WalletTransactionMeta): Promise<void> { const tx = this.tx; await tx.transactionsMeta.put({ transactionId: rec.transactionId, diff --git a/packages/taler-wallet-core/src/db/migration/converter.ts b/packages/taler-wallet-core/src/db/migration/converter.ts @@ -528,7 +528,9 @@ const COPY_PLAN: CopyStep[][] = [ step( "transactionsMeta", (tx) => tx.listTransactionMetaByTimestamp({}), - (tx, r) => tx.upsertTransactionMeta(r), + (tx, r) => tx.upsertTransactionMetaOnly(r), + // Older IndexedDB rows omit legacyScopes. SQLite defaults it to []. + (r) => ({ ...r, legacyScopes: r.legacyScopes ?? [] }), ), ], [ diff --git a/packages/taler-wallet-core/src/db/sqlite/transaction.ts b/packages/taler-wallet-core/src/db/sqlite/transaction.ts @@ -2957,6 +2957,10 @@ export class SqliteWalletTransaction implements WalletDbTransaction { async upsertTransactionMeta(rec: WalletTransactionMeta): Promise<void> { await updateTransactionAmounts(this, rec.transactionId); + await this.upsertTransactionMetaOnly(rec); + } + + async upsertTransactionMetaOnly(rec: WalletTransactionMeta): Promise<void> { await this.ensureLocalTransactionIdentifier(rec.transactionId); await this.run( `INSERT INTO transactions_meta ( diff --git a/packages/taler-wallet-core/src/db/transaction.ts b/packages/taler-wallet-core/src/db/transaction.ts @@ -310,7 +310,7 @@ export interface WalletDbTransaction { getPurchase(proposalId: string): Promise<WalletPurchase | undefined>; /** - * Create or update the transaction metadata for a transaction. + * Refresh the operation's amounts and store its transaction metadata. * * The transactionsMeta store is a materialized view over the individual * transaction stores, used to list transactions efficiently. @@ -318,6 +318,12 @@ export interface WalletDbTransaction { upsertTransactionMeta(rec: WalletTransactionMeta): Promise<void>; /** + * Store transaction metadata without recalculating the operation's amounts. + * Backend conversion must preserve those amounts until the copy is verified. + */ + upsertTransactionMetaOnly(rec: WalletTransactionMeta): Promise<void>; + + /** * Look up the locally assigned identifiers for transaction IDs in one * batch. Backends without efficient local identifiers return an empty map. */ diff --git a/packages/taler-wallet-core/src/requests.test.ts b/packages/taler-wallet-core/src/requests.test.ts @@ -397,6 +397,17 @@ test("importDb request converts a foreign backend dump", async () => { amountEffective: "TESTKUDOS:1", }); }); + // Reproduce a dump that predates transactionAmounts and legacyScopes. + const raw = await source.rawAccess(); + await raw.runAllStoresReadWriteTx({}, (tx) => + tx.transactionsMeta.put({ + transactionId: "txn:refund:request-import-refund", + timestamp: timestampPreciseToDb({ t_s: 2 }), + status: RefundGroupStatus.Done, + exchanges: [], + currency: "TESTKUDOS", + }), + ); await target.runReadWriteTx((tx) => tx.upsertConfig({ key: ConfigRecordKey.TestLoopTx, value: 1 }), ); @@ -443,6 +454,10 @@ test("importDb request converts a foreign backend dump", async () => { tx.getRefundGroup("request-import-refund"), ); assert.strictEqual( + importedRefund?.transactionAmounts?.initial, + "TESTKUDOS:1", + ); + assert.strictEqual( importedRefund?.purchaseSnapshot?.paymentInfo?.merchant.name, "import merchant", );