taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit cbc5ad536599f62f7fdddaf912cca91699ded00e
parent 246905ec79c4432095c07413a26e58b7588aafd6
Author: Florian Dold <dold@taler.net>
Date:   Wed, 22 Jul 2026 17:28:13 +0200

wallet: rename the global currency add methods to upsert

Adding an entry that is already stored is meant to do nothing, so the name
now says so.  The wallet-core API operations keep their names, as clients use
them.

Diffstat:
Mpackages/taler-wallet-core/src/db-converter.ts | 4++--
Mpackages/taler-wallet-core/src/dbtx-cache-invalidation.test.ts | 2+-
Mpackages/taler-wallet-core/src/dbtx-indexeddb.ts | 13+++++++++++--
Mpackages/taler-wallet-core/src/dbtx-shared.ts | 4++--
Mpackages/taler-wallet-core/src/dbtx-sqlite.ts | 4++--
Mpackages/taler-wallet-core/src/dbtx.ts | 20++++++++++++++++----
Mpackages/taler-wallet-core/src/requests.ts | 4++--
7 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/packages/taler-wallet-core/src/db-converter.ts b/packages/taler-wallet-core/src/db-converter.ts @@ -165,13 +165,13 @@ const COPY_PLAN: CopyStep[][] = [ step( "globalCurrencyExchanges", (tx) => tx.listGlobalCurrencyExchanges(), - (tx, r) => tx.addGlobalCurrencyExchange(r), + (tx, r) => tx.upsertGlobalCurrencyExchange(r), stripId, ), step( "globalCurrencyAuditors", (tx) => tx.listGlobalCurrencyAuditors(), - (tx, r) => tx.addGlobalCurrencyAuditor(r), + (tx, r) => tx.upsertGlobalCurrencyAuditor(r), stripId, ), step( diff --git a/packages/taler-wallet-core/src/dbtx-cache-invalidation.test.ts b/packages/taler-wallet-core/src/dbtx-cache-invalidation.test.ts @@ -205,7 +205,7 @@ for (const makeRunner of runnerFactories) { await watchForCacheInvalidation( tx, writeFlag, - ).addGlobalCurrencyExchange({ + ).upsertGlobalCurrencyExchange({ currency: "TESTKUDOS", exchangeBaseUrl: "https://exchange.test/", exchangeMasterPub: encodeCrock(stringToBytes("master-pub-0000")), diff --git a/packages/taler-wallet-core/src/dbtx-indexeddb.ts b/packages/taler-wallet-core/src/dbtx-indexeddb.ts @@ -404,7 +404,7 @@ export class IdbWalletTransaction implements WalletDbTransaction { return await this.tx.globalCurrencyExchanges.getAll(); } - async addGlobalCurrencyExchange( + async upsertGlobalCurrencyExchange( rec: WalletGlobalCurrencyExchange, ): Promise<void> { await this.tx.globalCurrencyExchanges.put(rec); @@ -418,9 +418,18 @@ export class IdbWalletTransaction implements WalletDbTransaction { return await this.tx.globalCurrencyAuditors.getAll(); } - async addGlobalCurrencyAuditor( + async upsertGlobalCurrencyAuditor( rec: WalletGlobalCurrencyAuditor, ): Promise<void> { + // See upsertGlobalCurrencyExchange. + const existing = await this.getGlobalCurrencyAuditor( + rec.currency, + rec.auditorBaseUrl, + rec.auditorPub, + ); + if (existing) { + return; + } await this.tx.globalCurrencyAuditors.put(rec); } diff --git a/packages/taler-wallet-core/src/dbtx-shared.ts b/packages/taler-wallet-core/src/dbtx-shared.ts @@ -125,9 +125,9 @@ export const CACHE_INVALIDATING_METHODS: ReadonlySet<string> = new Set([ "deleteDenomination", // Cascades to denominations, so it invalidates the same caches. "deleteDenominationFamily", - "addGlobalCurrencyExchange", + "upsertGlobalCurrencyExchange", "deleteGlobalCurrencyExchange", - "addGlobalCurrencyAuditor", + "upsertGlobalCurrencyAuditor", "deleteGlobalCurrencyAuditor", ]); diff --git a/packages/taler-wallet-core/src/dbtx-sqlite.ts b/packages/taler-wallet-core/src/dbtx-sqlite.ts @@ -4252,7 +4252,7 @@ export class SqliteWalletTransaction implements WalletDbTransaction { })); } - async addGlobalCurrencyExchange( + async upsertGlobalCurrencyExchange( rec: WalletGlobalCurrencyExchange, ): Promise<void> { await this.run( @@ -4309,7 +4309,7 @@ export class SqliteWalletTransaction implements WalletDbTransaction { })); } - async addGlobalCurrencyAuditor( + async upsertGlobalCurrencyAuditor( rec: WalletGlobalCurrencyAuditor, ): Promise<void> { await this.run( diff --git a/packages/taler-wallet-core/src/dbtx.ts b/packages/taler-wallet-core/src/dbtx.ts @@ -321,8 +321,15 @@ export interface WalletDbTransaction { /** List every globally-trusted exchange entry. */ listGlobalCurrencyExchanges(): Promise<WalletGlobalCurrencyExchange[]>; - /** Add a globally-trusted exchange entry. The row id is generated. */ - addGlobalCurrencyExchange(rec: WalletGlobalCurrencyExchange): Promise<void>; + /** + * Add a globally-trusted exchange entry. The row id is generated. + * + * Entries are identified by (currency, exchange base URL, master public + * key), so adding one that is already stored does nothing. + */ + upsertGlobalCurrencyExchange( + rec: WalletGlobalCurrencyExchange, + ): Promise<void>; /** Remove a globally-trusted exchange entry by row id. */ deleteGlobalCurrencyExchange(id: number): Promise<void>; @@ -330,8 +337,13 @@ export interface WalletDbTransaction { /** List every globally-trusted auditor entry. */ listGlobalCurrencyAuditors(): Promise<WalletGlobalCurrencyAuditor[]>; - /** Add a globally-trusted auditor entry. The row id is generated. */ - addGlobalCurrencyAuditor(rec: WalletGlobalCurrencyAuditor): Promise<void>; + /** + * Add a globally-trusted auditor entry. The row id is generated. + * + * Entries are identified by (currency, auditor base URL, auditor public + * key), so adding one that is already stored does nothing. + */ + upsertGlobalCurrencyAuditor(rec: WalletGlobalCurrencyAuditor): Promise<void>; /** Remove a globally-trusted auditor entry by row id. */ deleteGlobalCurrencyAuditor(id: number): Promise<void>; diff --git a/packages/taler-wallet-core/src/requests.ts b/packages/taler-wallet-core/src/requests.ts @@ -1489,7 +1489,7 @@ export async function handleAddGlobalCurrencyExchange( source: infoRec.source, }); } - await tx.addGlobalCurrencyExchange({ + await tx.upsertGlobalCurrencyExchange({ currency: req.currency, exchangeBaseUrl: req.exchangeBaseUrl, exchangeMasterPub: req.exchangeMasterPub, @@ -1561,7 +1561,7 @@ async function handleAddGlobalCurrencyAuditor( if (existingRec) { return; } - await tx.addGlobalCurrencyAuditor({ + await tx.upsertGlobalCurrencyAuditor({ currency: req.currency, auditorBaseUrl: req.auditorBaseUrl, auditorPub: req.auditorPub,