summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/pay-peer-push-debit.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-04-23 03:09:40 +0200
committerFlorian Dold <florian@dold.me>2024-04-23 03:09:40 +0200
commit1edc144b3595ae1ab6b8af7a43d26b811b2c2623 (patch)
treedb552f6b4a351eb1d0dae902f4d504031852bda7 /packages/taler-wallet-core/src/pay-peer-push-debit.ts
parent4b69853c347071acb73efcde9d4969cf06d0dfcc (diff)
downloadwallet-core-1edc144b3595ae1ab6b8af7a43d26b811b2c2623.tar.gz
wallet-core-1edc144b3595ae1ab6b8af7a43d26b811b2c2623.tar.bz2
wallet-core-1edc144b3595ae1ab6b8af7a43d26b811b2c2623.zip
wallet-core: pass options object to all transactions
Diffstat (limited to 'packages/taler-wallet-core/src/pay-peer-push-debit.ts')
-rw-r--r--packages/taler-wallet-core/src/pay-peer-push-debit.ts118
1 files changed, 65 insertions, 53 deletions
diff --git a/packages/taler-wallet-core/src/pay-peer-push-debit.ts b/packages/taler-wallet-core/src/pay-peer-push-debit.ts
index 63a02d7a7..6452407ff 100644
--- a/packages/taler-wallet-core/src/pay-peer-push-debit.ts
+++ b/packages/taler-wallet-core/src/pay-peer-push-debit.ts
@@ -104,19 +104,22 @@ export class PeerPushDebitTransactionContext implements TransactionContext {
async deleteTransaction(): Promise<void> {
const { wex, pursePub, transactionId } = this;
- await wex.db.runReadWriteTx(["peerPushDebit", "tombstones"], async (tx) => {
- const debit = await tx.peerPushDebit.get(pursePub);
- if (debit) {
- await tx.peerPushDebit.delete(pursePub);
- await tx.tombstones.put({ id: transactionId });
- }
- });
+ await wex.db.runReadWriteTx(
+ { storeNames: ["peerPushDebit", "tombstones"] },
+ async (tx) => {
+ const debit = await tx.peerPushDebit.get(pursePub);
+ if (debit) {
+ await tx.peerPushDebit.delete(pursePub);
+ await tx.tombstones.put({ id: transactionId });
+ }
+ },
+ );
}
async suspendTransaction(): Promise<void> {
const { wex, pursePub, transactionId, taskId: retryTag } = this;
const transitionInfo = await wex.db.runReadWriteTx(
- ["peerPushDebit"],
+ { storeNames: ["peerPushDebit"] },
async (tx) => {
const pushDebitRec = await tx.peerPushDebit.get(pursePub);
if (!pushDebitRec) {
@@ -174,7 +177,7 @@ export class PeerPushDebitTransactionContext implements TransactionContext {
async abortTransaction(): Promise<void> {
const { wex, pursePub, transactionId, taskId: retryTag } = this;
const transitionInfo = await wex.db.runReadWriteTx(
- ["peerPushDebit"],
+ { storeNames: ["peerPushDebit"] },
async (tx) => {
const pushDebitRec = await tx.peerPushDebit.get(pursePub);
if (!pushDebitRec) {
@@ -228,7 +231,7 @@ export class PeerPushDebitTransactionContext implements TransactionContext {
async resumeTransaction(): Promise<void> {
const { wex, pursePub, transactionId, taskId: retryTag } = this;
const transitionInfo = await wex.db.runReadWriteTx(
- ["peerPushDebit"],
+ { storeNames: ["peerPushDebit"] },
async (tx) => {
const pushDebitRec = await tx.peerPushDebit.get(pursePub);
if (!pushDebitRec) {
@@ -286,7 +289,7 @@ export class PeerPushDebitTransactionContext implements TransactionContext {
async failTransaction(): Promise<void> {
const { wex, pursePub, transactionId, taskId: retryTag } = this;
const transitionInfo = await wex.db.runReadWriteTx(
- ["peerPushDebit"],
+ { storeNames: ["peerPushDebit"] },
async (tx) => {
const pushDebitRec = await tx.peerPushDebit.get(pursePub);
if (!pushDebitRec) {
@@ -434,7 +437,7 @@ async function handlePurseCreationConflict(
assertUnreachable(coinSelRes);
}
- await wex.db.runReadWriteTx(["peerPushDebit"], async (tx) => {
+ await wex.db.runReadWriteTx({ storeNames: ["peerPushDebit"] }, async (tx) => {
const myPpi = await tx.peerPushDebit.get(peerPushInitiation.pursePub);
if (!myPpi) {
return;
@@ -470,7 +473,7 @@ async function processPeerPushDebitCreateReserve(
logger.trace(`processing ${transactionId} pending(create-reserve)`);
const contractTermsRecord = await wex.db.runReadOnlyTx(
- ["contractTerms"],
+ { storeNames: ["contractTerms"] },
async (tx) => {
return tx.contractTerms.get(hContractTerms);
},
@@ -503,16 +506,18 @@ async function processPeerPushDebitCreateReserve(
assertUnreachable(coinSelRes);
}
const transitionDone = await wex.db.runReadWriteTx(
- [
- "exchanges",
- "contractTerms",
- "coins",
- "coinAvailability",
- "denominations",
- "refreshGroups",
- "refreshSessions",
- "peerPushDebit",
- ],
+ {
+ storeNames: [
+ "exchanges",
+ "contractTerms",
+ "coins",
+ "coinAvailability",
+ "denominations",
+ "refreshGroups",
+ "refreshSessions",
+ "peerPushDebit",
+ ],
+ },
async (tx) => {
const ppi = await tx.peerPushDebit.get(pursePub);
if (!ppi) {
@@ -720,14 +725,16 @@ async function processPeerPushDebitAbortingDeletePurse(
logger.info(`deleted purse with response status ${resp.status}`);
const transitionInfo = await wex.db.runReadWriteTx(
- [
- "peerPushDebit",
- "refreshGroups",
- "refreshSessions",
- "denominations",
- "coinAvailability",
- "coins",
- ],
+ {
+ storeNames: [
+ "peerPushDebit",
+ "refreshGroups",
+ "refreshSessions",
+ "denominations",
+ "coinAvailability",
+ "coins",
+ ],
+ },
async (tx) => {
const ppiRec = await tx.peerPushDebit.get(pursePub);
if (!ppiRec) {
@@ -779,6 +786,7 @@ interface SimpleTransition {
stTo: PeerPushDebitStatus;
}
+// FIXME: This should be a transition on the peer push debit transaction context!
async function transitionPeerPushDebitTransaction(
wex: WalletExecutionContext,
pursePub: string,
@@ -789,7 +797,7 @@ async function transitionPeerPushDebitTransaction(
pursePub,
});
const transitionInfo = await wex.db.runReadWriteTx(
- ["peerPushDebit"],
+ { storeNames: ["peerPushDebit"] },
async (tx) => {
const ppiRec = await tx.peerPushDebit.get(pursePub);
if (!ppiRec) {
@@ -826,7 +834,7 @@ async function processPeerPushDebitAbortingRefreshDeleted(
await waitRefreshFinal(wex, peerPushInitiation.abortRefreshGroupId);
}
const transitionInfo = await wex.db.runReadWriteTx(
- ["refreshGroups", "peerPushDebit"],
+ { storeNames: ["refreshGroups", "peerPushDebit"] },
async (tx) => {
const refreshGroup = await tx.refreshGroups.get(abortRefreshGroupId);
let newOpState: PeerPushDebitStatus | undefined;
@@ -875,7 +883,7 @@ async function processPeerPushDebitAbortingRefreshExpired(
pursePub: peerPushInitiation.pursePub,
});
const transitionInfo = await wex.db.runReadWriteTx(
- ["peerPushDebit", "refreshGroups"],
+ { storeNames: ["peerPushDebit", "refreshGroups"] },
async (tx) => {
const refreshGroup = await tx.refreshGroups.get(abortRefreshGroupId);
let newOpState: PeerPushDebitStatus | undefined;
@@ -958,14 +966,16 @@ async function processPeerPushDebitReady(
} else if (resp.status === HttpStatusCode.Gone) {
logger.info(`purse ${pursePub} is gone, aborting peer-push-debit`);
const transitionInfo = await wex.db.runReadWriteTx(
- [
- "peerPushDebit",
- "refreshGroups",
- "refreshSessions",
- "denominations",
- "coinAvailability",
- "coins",
- ],
+ {
+ storeNames: [
+ "peerPushDebit",
+ "refreshGroups",
+ "refreshSessions",
+ "denominations",
+ "coinAvailability",
+ "coins",
+ ],
+ },
async (tx) => {
const ppiRec = await tx.peerPushDebit.get(pursePub);
if (!ppiRec) {
@@ -1019,7 +1029,7 @@ export async function processPeerPushDebit(
pursePub: string,
): Promise<TaskRunResult> {
const peerPushInitiation = await wex.db.runReadOnlyTx(
- ["peerPushDebit"],
+ { storeNames: ["peerPushDebit"] },
async (tx) => {
return tx.peerPushDebit.get(pursePub);
},
@@ -1118,16 +1128,18 @@ export async function initiatePeerPushDebit(
const contractEncNonce = encodeCrock(getRandomBytes(24));
const transitionInfo = await wex.db.runReadWriteTx(
- [
- "exchanges",
- "contractTerms",
- "coins",
- "coinAvailability",
- "denominations",
- "refreshGroups",
- "refreshSessions",
- "peerPushDebit",
- ],
+ {
+ storeNames: [
+ "exchanges",
+ "contractTerms",
+ "coins",
+ "coinAvailability",
+ "denominations",
+ "refreshGroups",
+ "refreshSessions",
+ "peerPushDebit",
+ ],
+ },
async (tx) => {
const ppi: PeerPushDebitRecord = {
amount: Amounts.stringify(instructedAmount),