wallet-core: address DB FIXME

This commit is contained in:
Florian Dold 2022-10-14 22:56:29 +02:00
parent b36807aa0f
commit 3a2b96f3c2
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 21 additions and 19 deletions

View File

@ -500,11 +500,6 @@ export interface ExchangeDetailsPointer {
updateClock: TalerProtocolTimestamp; updateClock: TalerProtocolTimestamp;
} }
export interface MergeReserveInfo {
reservePub: string;
reservePriv: string;
}
/** /**
* Exchange record as stored in the wallet's database. * 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 * Public key of the reserve that we're currently using for
* receiving P2P payments. * receiving P2P payments.
*
* FIXME: Make this a rowId of reserves!
*/ */
currentMergeReserveInfo?: MergeReserveInfo; currentMergeReserveRowId?: number;
} }
export enum PlanchetStatus { export enum PlanchetStatus {

View File

@ -64,10 +64,10 @@ import {
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { import {
CoinStatus, CoinStatus,
MergeReserveInfo,
WithdrawalGroupStatus, WithdrawalGroupStatus,
WalletStoresV1, WalletStoresV1,
WithdrawalRecordType, WithdrawalRecordType,
ReserveRecord,
} from "../db.js"; } from "../db.js";
import { InternalWalletState } from "../internal-wallet-state.js"; import { InternalWalletState } from "../internal-wallet-state.js";
import { readSuccessResponseJsonOrThrow } from "../util/http.js"; import { readSuccessResponseJsonOrThrow } from "../util/http.js";
@ -340,7 +340,10 @@ export async function initiatePeerToPeerPush(
exchangeBaseUrl: coinSelRes.exchangeBaseUrl, exchangeBaseUrl: coinSelRes.exchangeBaseUrl,
contractPriv: econtractResp.contractPriv, contractPriv: econtractResp.contractPriv,
}), }),
transactionId: makeTransactionId(TransactionType.PeerPushDebit, pursePair.pub), transactionId: makeTransactionId(
TransactionType.PeerPushDebit,
pursePair.pub,
),
}; };
} }
@ -448,28 +451,34 @@ async function getMergeReserveInfo(
req: { req: {
exchangeBaseUrl: string; exchangeBaseUrl: string;
}, },
): Promise<MergeReserveInfo> { ): Promise<ReserveRecord> {
// We have to eagerly create the key pair outside of the transaction, // We have to eagerly create the key pair outside of the transaction,
// due to the async crypto API. // due to the async crypto API.
const newReservePair = await ws.cryptoApi.createEddsaKeypair({}); const newReservePair = await ws.cryptoApi.createEddsaKeypair({});
const mergeReserveInfo: MergeReserveInfo = await ws.db const mergeReserveRecord: ReserveRecord = await ws.db
.mktx((x) => [x.exchanges, x.withdrawalGroups]) .mktx((x) => [x.exchanges, x.reserves, x.withdrawalGroups])
.runReadWrite(async (tx) => { .runReadWrite(async (tx) => {
const ex = await tx.exchanges.get(req.exchangeBaseUrl); const ex = await tx.exchanges.get(req.exchangeBaseUrl);
checkDbInvariant(!!ex); checkDbInvariant(!!ex);
if (ex.currentMergeReserveInfo) { if (ex.currentMergeReserveRowId != null) {
return ex.currentMergeReserveInfo; const reserve = await tx.reserves.get(ex.currentMergeReserveRowId);
checkDbInvariant(!!reserve);
return reserve;
} }
await tx.exchanges.put(ex); const reserve: ReserveRecord = {
ex.currentMergeReserveInfo = {
reservePriv: newReservePair.priv, reservePriv: newReservePair.priv,
reservePub: newReservePair.pub, 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( export async function acceptPeerPushPayment(