wallet-core: store contract terms in separate object store only

This commit is contained in:
Florian Dold 2023-09-08 11:45:31 +02:00
parent c660db82c1
commit 132ece8e53
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
5 changed files with 106 additions and 100 deletions

View File

@ -101,6 +101,14 @@ import { RetryInfo, TaskIdentifiers } from "./operations/common.js";
* @author Florian Dold <dold@taler.net> * @author Florian Dold <dold@taler.net>
*/ */
/**
FIXMEs:
- Contract terms can be quite large. We currently tend to read the
full contract terms from the DB quite often.
Instead, we should probably extract what we need into a separate object
store.
*/
/** /**
* Name of the Taler database. This is effectively the major * Name of the Taler database. This is effectively the major
* version of the DB schema. Whenever it changes, custom import logic * version of the DB schema. Whenever it changes, custom import logic
@ -166,47 +174,47 @@ export enum WithdrawalGroupStatus {
/** /**
* Reserve must be registered with the bank. * Reserve must be registered with the bank.
*/ */
PendingRegisteringBank = 0x0100_0000, PendingRegisteringBank = 0x0100_0001,
SuspendedRegisteringBank = 0x0110_0000, SuspendedRegisteringBank = 0x0110_0001,
/** /**
* We've registered reserve's information with the bank * We've registered reserve's information with the bank
* and are now waiting for the user to confirm the withdraw * and are now waiting for the user to confirm the withdraw
* with the bank (typically 2nd factor auth). * with the bank (typically 2nd factor auth).
*/ */
PendingWaitConfirmBank = 0x0100_0001, PendingWaitConfirmBank = 0x0100_0002,
SuspendedWaitConfirmBank = 0x0110_0001, SuspendedWaitConfirmBank = 0x0110_0002,
/** /**
* Querying reserve status with the exchange. * Querying reserve status with the exchange.
*/ */
PendingQueryingStatus = 0x0100_0002, PendingQueryingStatus = 0x0100_0003,
SuspendedQueryingStatus = 0x0110_0002, SuspendedQueryingStatus = 0x0110_0003,
/** /**
* Ready for withdrawal. * Ready for withdrawal.
*/ */
PendingReady = 0x0100_0003, PendingReady = 0x0100_0004,
SuspendedReady = 0x0110_0003, SuspendedReady = 0x0110_0004,
/** /**
* We are telling the bank that we don't want to complete * We are telling the bank that we don't want to complete
* the withdrawal! * the withdrawal!
*/ */
AbortingBank = 0x0103_0000, AbortingBank = 0x0103_0001,
SuspendedAbortingBank = 0x0113_0000, SuspendedAbortingBank = 0x0113_0001,
/** /**
* Exchange wants KYC info from the user. * Exchange wants KYC info from the user.
*/ */
PendingKyc = 0x0100_0004, PendingKyc = 0x0100_0005,
SuspendedKyc = 0x0110_004, SuspendedKyc = 0x0110_005,
/** /**
* Exchange is doing AML checks. * Exchange is doing AML checks.
*/ */
PendingAml = 0x0100_0005, PendingAml = 0x0100_0006,
SuspendedAml = 0x0100_0005, SuspendedAml = 0x0100_0006,
/** /**
* The corresponding withdraw record has been created. * The corresponding withdraw record has been created.
@ -218,9 +226,9 @@ export enum WithdrawalGroupStatus {
/** /**
* The bank aborted the withdrawal. * The bank aborted the withdrawal.
*/ */
FailedBankAborted = 0x0501_0000, FailedBankAborted = 0x0501_0001,
FailedAbortingBank = 0x0501_0001, FailedAbortingBank = 0x0501_0002,
/** /**
* Aborted in a state where we were supposed to * Aborted in a state where we were supposed to
@ -272,9 +280,9 @@ export interface ReserveBankInfo {
*/ */
export enum DenominationVerificationStatus { export enum DenominationVerificationStatus {
/** /**
* Verification was delayed. * Verification was delayed (pending).
*/ */
Unverified = 0x0500_0000, Unverified = 0x0100_0000,
/** /**
* Verified as valid. * Verified as valid.
@ -532,6 +540,7 @@ export enum ExchangeEntryDbRecordStatus {
Used = 3, Used = 3,
} }
// FIXME: Use status ranges for this as well?
export enum ExchangeEntryDbUpdateStatus { export enum ExchangeEntryDbUpdateStatus {
Initial = 1, Initial = 1,
InitialUpdate = 2, InitialUpdate = 2,
@ -612,9 +621,9 @@ export interface ExchangeEntryRecord {
} }
export enum PlanchetStatus { export enum PlanchetStatus {
Pending = 10 /* ACTIVE_START */, Pending = 0x0100_0000,
KycRequired = 11 /* ACTIVE_START + 1 */, KycRequired = 0x0100_0001,
WithdrawalDone = 50 /* DORMANT_START */, WithdrawalDone = 0x0500_000,
} }
/** /**
@ -1358,7 +1367,8 @@ export interface WgInfoBankManual {
export interface WgInfoBankPeerPull { export interface WgInfoBankPeerPull {
withdrawalType: WithdrawalRecordType.PeerPullCredit; withdrawalType: WithdrawalRecordType.PeerPullCredit;
contractTerms: any; // FIXME: include a transaction ID here?
/** /**
* Needed to quickly construct the taler:// URI for the counterparty * Needed to quickly construct the taler:// URI for the counterparty
* without a join. * without a join.
@ -1369,7 +1379,7 @@ export interface WgInfoBankPeerPull {
export interface WgInfoBankPeerPush { export interface WgInfoBankPeerPush {
withdrawalType: WithdrawalRecordType.PeerPushCredit; withdrawalType: WithdrawalRecordType.PeerPushCredit;
contractTerms: any; // FIXME: include a transaction ID here?
} }
export interface WgInfoBankRecoup { export interface WgInfoBankRecoup {
@ -1829,11 +1839,6 @@ export interface PeerPushDebitRecord {
*/ */
contractEncNonce: string; contractEncNonce: string;
/**
* FIXME: Put those in a different object store!
*/
contractTerms: PeerContractTerms;
purseExpiration: TalerProtocolTimestamp; purseExpiration: TalerProtocolTimestamp;
timestampCreated: TalerPreciseTimestamp; timestampCreated: TalerPreciseTimestamp;
@ -1861,7 +1866,7 @@ export enum PeerPullPaymentCreditStatus {
SuspendedCreatePurse = 0x0110_0000, SuspendedCreatePurse = 0x0110_0000,
SuspendedReady = 0x0110_0001, SuspendedReady = 0x0110_0001,
SuspendedMergeKycRequired = 0x0110_0002, SuspendedMergeKycRequired = 0x0110_0002,
SuspendedWithdrawing = 0x0113_0000, SuspendedWithdrawing = 0x0110_0000,
SuspendedAbortingDeletePurse = 0x0113_0000, SuspendedAbortingDeletePurse = 0x0113_0000,
@ -1878,6 +1883,7 @@ export interface PeerPullCreditRecord {
/** /**
* Amount requested. * Amount requested.
* FIXME: What type of instructed amount is i?
*/ */
amount: AmountString; amount: AmountString;
@ -1908,11 +1914,6 @@ export interface PeerPullCreditRecord {
contractEncNonce: string; contractEncNonce: string;
/**
* FIXME: Put in separate object store!
*/
contractTerms: PeerContractTerms;
mergeTimestamp: TalerPreciseTimestamp; mergeTimestamp: TalerPreciseTimestamp;
mergeReserveRowId: number; mergeReserveRowId: number;
@ -2529,8 +2530,7 @@ export const WalletStoresV1 = {
byWithdrawalGroupId: describeIndex( byWithdrawalGroupId: describeIndex(
"byWithdrawalGroupId", "byWithdrawalGroupId",
"withdrawalGroupId", "withdrawalGroupId",
{ {},
},
), ),
}, },
), ),
@ -2571,8 +2571,7 @@ export const WalletStoresV1 = {
}), }),
{ {
byProposalId: describeIndex("byProposalId", "proposalId"), byProposalId: describeIndex("byProposalId", "proposalId"),
byStatus: describeIndex("byStatus", "status", { byStatus: describeIndex("byStatus", "status", {}),
}),
}, },
), ),
refundItems: describeStore( refundItems: describeStore(

View File

@ -27,6 +27,7 @@ import {
InitiatePeerPullCreditResponse, InitiatePeerPullCreditResponse,
Logger, Logger,
NotificationType, NotificationType,
PeerContractTerms,
TalerErrorCode, TalerErrorCode,
TalerPreciseTimestamp, TalerPreciseTimestamp,
TalerProtocolTimestamp, TalerProtocolTimestamp,
@ -143,7 +144,6 @@ async function queryPurseForPeerPullCredit(
amount: Amounts.parseOrThrow(pullIni.amount), amount: Amounts.parseOrThrow(pullIni.amount),
wgInfo: { wgInfo: {
withdrawalType: WithdrawalRecordType.PeerPullCredit, withdrawalType: WithdrawalRecordType.PeerPullCredit,
contractTerms: pullIni.contractTerms,
contractPriv: pullIni.contractPriv, contractPriv: pullIni.contractPriv,
}, },
forcedWithdrawalGroupId: pullIni.withdrawalGroupId, forcedWithdrawalGroupId: pullIni.withdrawalGroupId,
@ -283,9 +283,7 @@ async function processPeerPullCreditAbortingDeletePurse(
if (!ppiRec) { if (!ppiRec) {
return undefined; return undefined;
} }
if ( if (ppiRec.status !== PeerPullPaymentCreditStatus.AbortingDeletePurse) {
ppiRec.status !== PeerPullPaymentCreditStatus.AbortingDeletePurse
) {
return undefined; return undefined;
} }
const oldTxState = computePeerPullCreditTransactionState(ppiRec); const oldTxState = computePeerPullCreditTransactionState(ppiRec);
@ -371,6 +369,18 @@ async function handlePeerPullCreditCreatePurse(
throw Error("merge reserve for peer pull payment not found in database"); throw Error("merge reserve for peer pull payment not found in database");
} }
const contractTermsRecord = await ws.db
.mktx((x) => [x.contractTerms])
.runReadOnly(async (tx) => {
return tx.contractTerms.get(pullIni.contractTermsHash);
});
if (!contractTermsRecord) {
throw Error("contract terms for peer pull payment not found in database");
}
const contractTerms: PeerContractTerms = contractTermsRecord.contractTermsRaw;
const reservePayto = talerPaytoFromExchangeReserve( const reservePayto = talerPaytoFromExchangeReserve(
pullIni.exchangeBaseUrl, pullIni.exchangeBaseUrl,
mergeReserve.reservePub, mergeReserve.reservePub,
@ -379,19 +389,19 @@ async function handlePeerPullCreditCreatePurse(
const econtractResp = await ws.cryptoApi.encryptContractForDeposit({ const econtractResp = await ws.cryptoApi.encryptContractForDeposit({
contractPriv: pullIni.contractPriv, contractPriv: pullIni.contractPriv,
contractPub: pullIni.contractPub, contractPub: pullIni.contractPub,
contractTerms: pullIni.contractTerms, contractTerms: contractTermsRecord,
pursePriv: pullIni.pursePriv, pursePriv: pullIni.pursePriv,
pursePub: pullIni.pursePub, pursePub: pullIni.pursePub,
nonce: pullIni.contractEncNonce, nonce: pullIni.contractEncNonce,
}); });
const purseExpiration = pullIni.contractTerms.purse_expiration; const purseExpiration = contractTerms.purse_expiration;
const sigRes = await ws.cryptoApi.signReservePurseCreate({ const sigRes = await ws.cryptoApi.signReservePurseCreate({
contractTermsHash: pullIni.contractTermsHash, contractTermsHash: pullIni.contractTermsHash,
flags: WalletAccountMergeFlags.CreateWithPurseFee, flags: WalletAccountMergeFlags.CreateWithPurseFee,
mergePriv: pullIni.mergePriv, mergePriv: pullIni.mergePriv,
mergeTimestamp: TalerPreciseTimestamp.round(pullIni.mergeTimestamp), mergeTimestamp: TalerPreciseTimestamp.round(pullIni.mergeTimestamp),
purseAmount: pullIni.contractTerms.amount, purseAmount: pullIni.amount,
purseExpiration: purseExpiration, purseExpiration: purseExpiration,
purseFee: purseFee, purseFee: purseFee,
pursePriv: pullIni.pursePriv, pursePriv: pullIni.pursePriv,
@ -410,7 +420,7 @@ async function handlePeerPullCreditCreatePurse(
purse_fee: purseFee, purse_fee: purseFee,
purse_pub: pullIni.pursePub, purse_pub: pullIni.pursePub,
purse_sig: sigRes.purseSig, purse_sig: sigRes.purseSig,
purse_value: pullIni.contractTerms.amount, purse_value: pullIni.amount,
reserve_sig: sigRes.accountSig, reserve_sig: sigRes.accountSig,
econtract: econtractResp.econtract, econtract: econtractResp.econtract,
}; };
@ -585,8 +595,7 @@ async function processPeerPullCreditKycRequired(
requirementRow: kycPending.requirement_row, requirementRow: kycPending.requirement_row,
}; };
peerInc.kycUrl = kycStatus.kyc_url; peerInc.kycUrl = kycStatus.kyc_url;
peerInc.status = peerInc.status = PeerPullPaymentCreditStatus.PendingMergeKycRequired;
PeerPullPaymentCreditStatus.PendingMergeKycRequired;
const newTxState = computePeerPullCreditTransactionState(peerInc); const newTxState = computePeerPullCreditTransactionState(peerInc);
await tx.peerPullCredit.put(peerInc); await tx.peerPullCredit.put(peerInc);
// We'll remove this eventually! New clients should rely on the // We'll remove this eventually! New clients should rely on the
@ -769,7 +778,6 @@ export async function initiatePeerPullPayment(
mergePriv: mergePair.priv, mergePriv: mergePair.priv,
mergePub: mergePair.pub, mergePub: mergePair.pub,
status: PeerPullPaymentCreditStatus.PendingCreatePurse, status: PeerPullPaymentCreditStatus.PendingCreatePurse,
contractTerms: contractTerms,
mergeTimestamp, mergeTimestamp,
contractEncNonce, contractEncNonce,
mergeReserveRowId: mergeReserveRowId, mergeReserveRowId: mergeReserveRowId,
@ -848,8 +856,7 @@ export async function suspendPeerPullCreditTransaction(
newStatus = PeerPullPaymentCreditStatus.SuspendedReady; newStatus = PeerPullPaymentCreditStatus.SuspendedReady;
break; break;
case PeerPullPaymentCreditStatus.AbortingDeletePurse: case PeerPullPaymentCreditStatus.AbortingDeletePurse:
newStatus = newStatus = PeerPullPaymentCreditStatus.SuspendedAbortingDeletePurse;
PeerPullPaymentCreditStatus.SuspendedAbortingDeletePurse;
break; break;
case PeerPullPaymentCreditStatus.Done: case PeerPullPaymentCreditStatus.Done:
case PeerPullPaymentCreditStatus.SuspendedCreatePurse: case PeerPullPaymentCreditStatus.SuspendedCreatePurse:

View File

@ -446,7 +446,6 @@ async function handlePendingMerge(
amount, amount,
wgInfo: { wgInfo: {
withdrawalType: WithdrawalRecordType.PeerPushCredit, withdrawalType: WithdrawalRecordType.PeerPushCredit,
contractTerms,
}, },
forcedWithdrawalGroupId: peerInc.withdrawalGroupId, forcedWithdrawalGroupId: peerInc.withdrawalGroupId,
exchangeBaseUrl: peerInc.exchangeBaseUrl, exchangeBaseUrl: peerInc.exchangeBaseUrl,

View File

@ -154,9 +154,7 @@ async function handlePurseCreationConflict(
await ws.db await ws.db
.mktx((x) => [x.peerPushDebit]) .mktx((x) => [x.peerPushDebit])
.runReadWrite(async (tx) => { .runReadWrite(async (tx) => {
const myPpi = await tx.peerPushDebit.get( const myPpi = await tx.peerPushDebit.get(peerPushInitiation.pursePub);
peerPushInitiation.pursePub,
);
if (!myPpi) { if (!myPpi) {
return; return;
} }
@ -182,10 +180,27 @@ async function processPeerPushDebitCreateReserve(
ws: InternalWalletState, ws: InternalWalletState,
peerPushInitiation: PeerPushDebitRecord, peerPushInitiation: PeerPushDebitRecord,
): Promise<TaskRunResult> { ): Promise<TaskRunResult> {
logger.info("processing peer-push-debit pending(create-reserve)");
const pursePub = peerPushInitiation.pursePub; const pursePub = peerPushInitiation.pursePub;
const purseExpiration = peerPushInitiation.purseExpiration; const purseExpiration = peerPushInitiation.purseExpiration;
const hContractTerms = peerPushInitiation.contractTermsHash; const hContractTerms = peerPushInitiation.contractTermsHash;
const transactionId = constructTransactionIdentifier({
tag: TransactionType.PeerPushDebit,
pursePub: pursePub,
});
logger.trace(`processing ${transactionId} pending(create-reserve)`);
const contractTermsRecord = await ws.db
.mktx((x) => [x.contractTerms])
.runReadOnly(async (tx) => {
return tx.contractTerms.get(hContractTerms);
});
if (!contractTermsRecord) {
throw Error(
`db invariant failed, contract terms for ${transactionId} missing`,
);
}
const purseSigResp = await ws.cryptoApi.signPurseCreation({ const purseSigResp = await ws.cryptoApi.signPurseCreation({
hContractTerms, hContractTerms,
@ -208,7 +223,7 @@ async function processPeerPushDebitCreateReserve(
}); });
const encryptContractRequest: EncryptContractRequest = { const encryptContractRequest: EncryptContractRequest = {
contractTerms: peerPushInitiation.contractTerms, contractTerms: contractTermsRecord.contractTermsRaw,
mergePriv: peerPushInitiation.mergePriv, mergePriv: peerPushInitiation.mergePriv,
pursePriv: peerPushInitiation.pursePriv, pursePriv: peerPushInitiation.pursePriv,
pursePub: peerPushInitiation.pursePub, pursePub: peerPushInitiation.pursePub,
@ -329,9 +344,7 @@ async function processPeerPushDebitAbortingDeletePurse(
if (!ppiRec) { if (!ppiRec) {
return undefined; return undefined;
} }
if ( if (ppiRec.status !== PeerPushDebitStatus.AbortingDeletePurse) {
ppiRec.status !== PeerPushDebitStatus.AbortingDeletePurse
) {
return undefined; return undefined;
} }
const currency = Amounts.currencyOf(ppiRec.amount); const currency = Amounts.currencyOf(ppiRec.amount);
@ -658,7 +671,6 @@ export async function initiatePeerPushDebit(
pursePub: pursePair.pub, pursePub: pursePair.pub,
timestampCreated: TalerPreciseTimestamp.now(), timestampCreated: TalerPreciseTimestamp.now(),
status: PeerPushDebitStatus.PendingCreatePurse, status: PeerPushDebitStatus.PendingCreatePurse,
contractTerms: contractTerms,
contractEncNonce, contractEncNonce,
coinSel: { coinSel: {
coinPubs: sel.coins.map((x) => x.coinPub), coinPubs: sel.coins.map((x) => x.coinPub),
@ -881,8 +893,7 @@ export async function suspendPeerPushDebitTransaction(
newStatus = PeerPushDebitStatus.SuspendedAbortingRefresh; newStatus = PeerPushDebitStatus.SuspendedAbortingRefresh;
break; break;
case PeerPushDebitStatus.AbortingDeletePurse: case PeerPushDebitStatus.AbortingDeletePurse:
newStatus = newStatus = PeerPushDebitStatus.SuspendedAbortingDeletePurse;
PeerPushDebitStatus.SuspendedAbortingDeletePurse;
break; break;
case PeerPushDebitStatus.PendingReady: case PeerPushDebitStatus.PendingReady:
newStatus = PeerPushDebitStatus.SuspendedReady; newStatus = PeerPushDebitStatus.SuspendedReady;

View File

@ -154,7 +154,18 @@ import {
resumePeerPushDebitTransaction, resumePeerPushDebitTransaction,
abortPeerPushDebitTransaction, abortPeerPushDebitTransaction,
} from "./pay-peer-push-debit.js"; } from "./pay-peer-push-debit.js";
import { iterRecordsForDeposit, iterRecordsForPeerPullDebit, iterRecordsForPeerPullInitiation, iterRecordsForPeerPushCredit, iterRecordsForPeerPushInitiation, iterRecordsForPurchase, iterRecordsForRefresh, iterRecordsForRefund, iterRecordsForReward, iterRecordsForWithdrawal } from "./pending.js"; import {
iterRecordsForDeposit,
iterRecordsForPeerPullDebit,
iterRecordsForPeerPullInitiation,
iterRecordsForPeerPushCredit,
iterRecordsForPeerPushInitiation,
iterRecordsForPurchase,
iterRecordsForRefresh,
iterRecordsForRefund,
iterRecordsForReward,
iterRecordsForWithdrawal,
} from "./pending.js";
const logger = new Logger("taler-wallet-core:transactions.ts"); const logger = new Logger("taler-wallet-core:transactions.ts");
@ -337,9 +348,7 @@ export async function getTransactionById(
return await ws.db return await ws.db
.mktx((x) => [x.peerPullDebit]) .mktx((x) => [x.peerPullDebit])
.runReadWrite(async (tx) => { .runReadWrite(async (tx) => {
const debit = await tx.peerPullDebit.get( const debit = await tx.peerPullDebit.get(parsedTx.peerPullDebitId);
parsedTx.peerPullDebitId,
);
if (!debit) throw Error("not found"); if (!debit) throw Error("not found");
return buildTransactionForPullPaymentDebit(debit); return buildTransactionForPullPaymentDebit(debit);
}); });
@ -349,9 +358,7 @@ export async function getTransactionById(
return await ws.db return await ws.db
.mktx((x) => [x.peerPushDebit, x.contractTerms]) .mktx((x) => [x.peerPushDebit, x.contractTerms])
.runReadWrite(async (tx) => { .runReadWrite(async (tx) => {
const debit = await tx.peerPushDebit.get( const debit = await tx.peerPushDebit.get(parsedTx.pursePub);
parsedTx.pursePub,
);
if (!debit) throw Error("not found"); if (!debit) throw Error("not found");
const ct = await tx.contractTerms.get(debit.contractTermsHash); const ct = await tx.contractTerms.get(debit.contractTermsHash);
checkDbInvariant(!!ct); checkDbInvariant(!!ct);
@ -372,9 +379,7 @@ export async function getTransactionById(
x.operationRetries, x.operationRetries,
]) ])
.runReadWrite(async (tx) => { .runReadWrite(async (tx) => {
const pushInc = await tx.peerPushCredit.get( const pushInc = await tx.peerPushCredit.get(peerPushCreditId);
peerPushCreditId,
);
if (!pushInc) throw Error("not found"); if (!pushInc) throw Error("not found");
const ct = await tx.contractTerms.get(pushInc.contractTermsHash); const ct = await tx.contractTerms.get(pushInc.contractTermsHash);
checkDbInvariant(!!ct); checkDbInvariant(!!ct);
@ -532,8 +537,8 @@ function buildTransactionForPeerPullCredit(
// Old transactions don't have it! // Old transactions don't have it!
timestamp: pullCredit.mergeTimestamp ?? TalerPreciseTimestamp.now(), timestamp: pullCredit.mergeTimestamp ?? TalerPreciseTimestamp.now(),
info: { info: {
expiration: wsr.wgInfo.contractTerms.purse_expiration, expiration: peerContractTerms.purse_expiration,
summary: wsr.wgInfo.contractTerms.summary, summary: peerContractTerms.summary,
}, },
talerUri: stringifyPayPullUri({ talerUri: stringifyPayPullUri({
exchangeBaseUrl: wsr.exchangeBaseUrl, exchangeBaseUrl: wsr.exchangeBaseUrl,
@ -600,8 +605,8 @@ function buildTransactionForPeerPushCredit(
amountRaw: Amounts.stringify(wsr.instructedAmount), amountRaw: Amounts.stringify(wsr.instructedAmount),
exchangeBaseUrl: wsr.exchangeBaseUrl, exchangeBaseUrl: wsr.exchangeBaseUrl,
info: { info: {
expiration: wsr.wgInfo.contractTerms.purse_expiration, expiration: peerContractTerms.purse_expiration,
summary: wsr.wgInfo.contractTerms.summary, summary: peerContractTerms.summary,
}, },
timestamp: wsr.timestampStart, timestamp: wsr.timestampStart,
transactionId: constructTransactionIdentifier({ transactionId: constructTransactionIdentifier({
@ -1033,7 +1038,7 @@ export async function getTransactions(
), ),
); );
}); });
await iterRecordsForPeerPullInitiation(tx, filter, async (pi) => { await iterRecordsForPeerPullInitiation(tx, filter, async (pi) => {
const currency = Amounts.currencyOf(pi.amount); const currency = Amounts.currencyOf(pi.amount);
if (shouldSkipCurrency(transactionsRequest, currency)) { if (shouldSkipCurrency(transactionsRequest, currency)) {
@ -1078,7 +1083,7 @@ export async function getTransactions(
); );
transactions.push(buildTransactionForRefund(refundGroup, contractData)); transactions.push(buildTransactionForRefund(refundGroup, contractData));
}); });
await iterRecordsForRefresh(tx, filter, async (rg) => { await iterRecordsForRefresh(tx, filter, async (rg) => {
if (shouldSkipCurrency(transactionsRequest, rg.currency)) { if (shouldSkipCurrency(transactionsRequest, rg.currency)) {
return; return;
@ -1099,7 +1104,7 @@ export async function getTransactions(
} }
}); });
await iterRecordsForWithdrawal(tx, filter ,async (wsr) => { await iterRecordsForWithdrawal(tx, filter, async (wsr) => {
if ( if (
shouldSkipCurrency( shouldSkipCurrency(
transactionsRequest, transactionsRequest,
@ -1643,15 +1648,9 @@ export async function deleteTransaction(
case TransactionType.PeerPushCredit: { case TransactionType.PeerPushCredit: {
const peerPushCreditId = parsedTx.peerPushCreditId; const peerPushCreditId = parsedTx.peerPushCreditId;
await ws.db await ws.db
.mktx((x) => [ .mktx((x) => [x.withdrawalGroups, x.peerPushCredit, x.tombstones])
x.withdrawalGroups,
x.peerPushCredit,
x.tombstones,
])
.runReadWrite(async (tx) => { .runReadWrite(async (tx) => {
const pushInc = await tx.peerPushCredit.get( const pushInc = await tx.peerPushCredit.get(peerPushCreditId);
peerPushCreditId,
);
if (!pushInc) { if (!pushInc) {
return; return;
} }
@ -1670,10 +1669,7 @@ export async function deleteTransaction(
} }
await tx.peerPushCredit.delete(peerPushCreditId); await tx.peerPushCredit.delete(peerPushCreditId);
await tx.tombstones.put({ await tx.tombstones.put({
id: id: TombstoneTag.DeletePeerPushCredit + ":" + peerPushCreditId,
TombstoneTag.DeletePeerPushCredit +
":" +
peerPushCreditId,
}); });
}); });
return; return;
@ -1682,11 +1678,7 @@ export async function deleteTransaction(
case TransactionType.PeerPullCredit: { case TransactionType.PeerPullCredit: {
const pursePub = parsedTx.pursePub; const pursePub = parsedTx.pursePub;
await ws.db await ws.db
.mktx((x) => [ .mktx((x) => [x.withdrawalGroups, x.peerPullCredit, x.tombstones])
x.withdrawalGroups,
x.peerPullCredit,
x.tombstones,
])
.runReadWrite(async (tx) => { .runReadWrite(async (tx) => {
const pullIni = await tx.peerPullCredit.get(pursePub); const pullIni = await tx.peerPullCredit.get(pursePub);
if (!pullIni) { if (!pullIni) {
@ -1813,9 +1805,7 @@ export async function deleteTransaction(
await ws.db await ws.db
.mktx((x) => [x.peerPullDebit, x.tombstones]) .mktx((x) => [x.peerPullDebit, x.tombstones])
.runReadWrite(async (tx) => { .runReadWrite(async (tx) => {
const debit = await tx.peerPullDebit.get( const debit = await tx.peerPullDebit.get(peerPullDebitId);
peerPullDebitId,
);
if (debit) { if (debit) {
await tx.peerPullDebit.delete(peerPullDebitId); await tx.peerPullDebit.delete(peerPullDebitId);
await tx.tombstones.put({ id: transactionId }); await tx.tombstones.put({ id: transactionId });