diff options
author | Florian Dold <florian@dold.me> | 2022-10-14 22:56:29 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-10-14 22:56:29 +0200 |
commit | 3a2b96f3c2dcdf106c989713253a8b3679ae078e (patch) | |
tree | f3613d9a9ed6114db1dad169d325d9407192268c | |
parent | b36807aa0f673d074f295d004812ba18b2ab544d (diff) | |
download | wallet-core-3a2b96f3c2dcdf106c989713253a8b3679ae078e.tar.xz |
wallet-core: address DB FIXME
-rw-r--r-- | packages/taler-wallet-core/src/db.ts | 9 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/pay-peer.ts | 31 |
2 files changed, 21 insertions, 19 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 72dd0dc9c..002db9805 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -500,11 +500,6 @@ export interface ExchangeDetailsPointer { updateClock: TalerProtocolTimestamp; } -export interface MergeReserveInfo { - reservePub: string; - reservePriv: string; -} - /** * Exchange record as stored in the wallet's database. */ @@ -555,10 +550,8 @@ export interface ExchangeRecord { /** * Public key of the reserve that we're currently using for * receiving P2P payments. - * - * FIXME: Make this a rowId of reserves! */ - currentMergeReserveInfo?: MergeReserveInfo; + currentMergeReserveRowId?: number; } export enum PlanchetStatus { diff --git a/packages/taler-wallet-core/src/operations/pay-peer.ts b/packages/taler-wallet-core/src/operations/pay-peer.ts index 8bce887c0..ffc49c24c 100644 --- a/packages/taler-wallet-core/src/operations/pay-peer.ts +++ b/packages/taler-wallet-core/src/operations/pay-peer.ts @@ -64,10 +64,10 @@ import { } from "@gnu-taler/taler-util"; import { CoinStatus, - MergeReserveInfo, WithdrawalGroupStatus, WalletStoresV1, WithdrawalRecordType, + ReserveRecord, } from "../db.js"; import { InternalWalletState } from "../internal-wallet-state.js"; import { readSuccessResponseJsonOrThrow } from "../util/http.js"; @@ -340,7 +340,10 @@ export async function initiatePeerToPeerPush( exchangeBaseUrl: coinSelRes.exchangeBaseUrl, contractPriv: econtractResp.contractPriv, }), - transactionId: makeTransactionId(TransactionType.PeerPushDebit, pursePair.pub), + transactionId: makeTransactionId( + TransactionType.PeerPushDebit, + pursePair.pub, + ), }; } @@ -448,28 +451,34 @@ async function getMergeReserveInfo( req: { exchangeBaseUrl: string; }, -): Promise<MergeReserveInfo> { +): Promise<ReserveRecord> { // We have to eagerly create the key pair outside of the transaction, // due to the async crypto API. const newReservePair = await ws.cryptoApi.createEddsaKeypair({}); - const mergeReserveInfo: MergeReserveInfo = await ws.db - .mktx((x) => [x.exchanges, x.withdrawalGroups]) + const mergeReserveRecord: ReserveRecord = await ws.db + .mktx((x) => [x.exchanges, x.reserves, x.withdrawalGroups]) .runReadWrite(async (tx) => { const ex = await tx.exchanges.get(req.exchangeBaseUrl); checkDbInvariant(!!ex); - if (ex.currentMergeReserveInfo) { - return ex.currentMergeReserveInfo; + if (ex.currentMergeReserveRowId != null) { + const reserve = await tx.reserves.get(ex.currentMergeReserveRowId); + checkDbInvariant(!!reserve); + return reserve; } - await tx.exchanges.put(ex); - ex.currentMergeReserveInfo = { + const reserve: ReserveRecord = { reservePriv: newReservePair.priv, reservePub: newReservePair.pub, }; - return ex.currentMergeReserveInfo; + const insertResp = await tx.reserves.put(reserve); + checkDbInvariant(typeof insertResp.key === "number"); + reserve.rowId = insertResp.key; + ex.currentMergeReserveRowId = reserve.rowId; + await tx.exchanges.put(ex); + return reserve; }); - return mergeReserveInfo; + return mergeReserveRecord; } export async function acceptPeerPushPayment( |