aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-03-06 11:02:13 +0100
committerFlorian Dold <florian@dold.me>2024-03-06 11:02:13 +0100
commit541886750eb1bc32b9aa0323868dd24776baf0eb (patch)
tree39fd2c3eaf5a1f4b4d676f8f3568750be7763b17 /packages/taler-wallet-core
parentd10b46bffcef1599ba59538c69cc11499a852b4d (diff)
downloadwallet-core-541886750eb1bc32b9aa0323868dd24776baf0eb.tar.gz
wallet-core-541886750eb1bc32b9aa0323868dd24776baf0eb.tar.bz2
wallet-core-541886750eb1bc32b9aa0323868dd24776baf0eb.zip
taler-harness: test aborting refreshes
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r--packages/taler-wallet-core/src/index.ts2
-rw-r--r--packages/taler-wallet-core/src/pay-peer-pull-debit.ts50
-rw-r--r--packages/taler-wallet-core/src/refresh.ts85
3 files changed, 68 insertions, 69 deletions
diff --git a/packages/taler-wallet-core/src/index.ts b/packages/taler-wallet-core/src/index.ts
index fa984fc8f..fe2d3af15 100644
--- a/packages/taler-wallet-core/src/index.ts
+++ b/packages/taler-wallet-core/src/index.ts
@@ -32,6 +32,8 @@ export * from "./versions.js";
export * from "./wallet-api-types.js";
export * from "./wallet.js";
+export { parseTransactionIdentifier } from "./transactions.js";
+
export { createPairTimeline } from "./denominations.js";
// FIXME: Should these really be exported?!
diff --git a/packages/taler-wallet-core/src/pay-peer-pull-debit.ts b/packages/taler-wallet-core/src/pay-peer-pull-debit.ts
index 7348a30ce..2418f08da 100644
--- a/packages/taler-wallet-core/src/pay-peer-pull-debit.ts
+++ b/packages/taler-wallet-core/src/pay-peer-pull-debit.ts
@@ -26,7 +26,6 @@
import {
AcceptPeerPullPaymentResponse,
Amounts,
- CancellationToken,
CoinRefreshRequest,
ConfirmPeerPullDebitRequest,
ContractTermsUtil,
@@ -95,7 +94,7 @@ import {
notifyTransition,
parseTransactionIdentifier,
} from "./transactions.js";
-import { InternalWalletState, WalletExecutionContext } from "./wallet.js";
+import { WalletExecutionContext } from "./wallet.js";
const logger = new Logger("pay-peer-pull-debit.ts");
@@ -552,15 +551,9 @@ export async function processPeerPullDebit(
switch (peerPullInc.status) {
case PeerPullDebitRecordStatus.PendingDeposit:
- return await processPeerPullDebitPendingDeposit(
- wex,
- peerPullInc,
- );
+ return await processPeerPullDebitPendingDeposit(wex, peerPullInc);
case PeerPullDebitRecordStatus.AbortingRefresh:
- return await processPeerPullDebitAbortingRefresh(
- wex,
- peerPullInc,
- );
+ return await processPeerPullDebitAbortingRefresh(wex, peerPullInc);
}
return TaskRunResult.finished();
}
@@ -791,23 +784,26 @@ export async function preparePeerPullDebit(
coinSelRes.result.coins,
);
- await wex.db.runReadWriteTx(["peerPullDebit", "contractTerms"], async (tx) => {
- await tx.contractTerms.put({
- h: contractTermsHash,
- contractTermsRaw: contractTerms,
- }),
- await tx.peerPullDebit.add({
- peerPullDebitId,
- contractPriv: contractPriv,
- exchangeBaseUrl: exchangeBaseUrl,
- pursePub: pursePub,
- timestampCreated: timestampPreciseToDb(TalerPreciseTimestamp.now()),
- contractTermsHash,
- amount: contractTerms.amount,
- status: PeerPullDebitRecordStatus.DialogProposed,
- totalCostEstimated: Amounts.stringify(totalAmount),
- });
- });
+ await wex.db.runReadWriteTx(
+ ["peerPullDebit", "contractTerms"],
+ async (tx) => {
+ await tx.contractTerms.put({
+ h: contractTermsHash,
+ contractTermsRaw: contractTerms,
+ }),
+ await tx.peerPullDebit.add({
+ peerPullDebitId,
+ contractPriv: contractPriv,
+ exchangeBaseUrl: exchangeBaseUrl,
+ pursePub: pursePub,
+ timestampCreated: timestampPreciseToDb(TalerPreciseTimestamp.now()),
+ contractTermsHash,
+ amount: contractTerms.amount,
+ status: PeerPullDebitRecordStatus.DialogProposed,
+ totalCostEstimated: Amounts.stringify(totalAmount),
+ });
+ },
+ );
return {
amount: contractTerms.amount,
diff --git a/packages/taler-wallet-core/src/refresh.ts b/packages/taler-wallet-core/src/refresh.ts
index c6ece1536..9c272ad18 100644
--- a/packages/taler-wallet-core/src/refresh.ts
+++ b/packages/taler-wallet-core/src/refresh.ts
@@ -107,7 +107,7 @@ import { getCandidateWithdrawalDenomsTx } from "./withdraw.js";
const logger = new Logger("refresh.ts");
export class RefreshTransactionContext implements TransactionContext {
- public transactionId: TransactionIdStr;
+ readonly transactionId: TransactionIdStr;
readonly taskId: TaskIdStr;
constructor(
@@ -126,53 +126,54 @@ export class RefreshTransactionContext implements TransactionContext {
async deleteTransaction(): Promise<void> {
const refreshGroupId = this.refreshGroupId;
- const ws = this.wex;
- await ws.db.runReadWriteTx(["refreshGroups", "tombstones"], async (tx) => {
- const rg = await tx.refreshGroups.get(refreshGroupId);
- if (rg) {
- await tx.refreshGroups.delete(refreshGroupId);
- await tx.tombstones.put({
- id: TombstoneTag.DeleteRefreshGroup + ":" + refreshGroupId,
- });
- }
- });
+ await this.wex.db.runReadWriteTx(
+ ["refreshGroups", "tombstones"],
+ async (tx) => {
+ const rg = await tx.refreshGroups.get(refreshGroupId);
+ if (rg) {
+ await tx.refreshGroups.delete(refreshGroupId);
+ await tx.tombstones.put({
+ id: TombstoneTag.DeleteRefreshGroup + ":" + refreshGroupId,
+ });
+ }
+ },
+ );
}
async suspendTransaction(): Promise<void> {
const { wex, refreshGroupId, transactionId } = this;
- let res = await wex.db.runReadWriteTx(["refreshGroups"], async (tx) => {
- const dg = await tx.refreshGroups.get(refreshGroupId);
- if (!dg) {
- logger.warn(
- `can't suspend refresh group, refreshGroupId=${refreshGroupId} not found`,
- );
- return undefined;
- }
- const oldState = computeRefreshTransactionState(dg);
- switch (dg.operationStatus) {
- case RefreshOperationStatus.Finished:
+ let transitionInfo = await wex.db.runReadWriteTx(
+ ["refreshGroups"],
+ async (tx) => {
+ const dg = await tx.refreshGroups.get(refreshGroupId);
+ if (!dg) {
+ logger.warn(
+ `can't suspend refresh group, refreshGroupId=${refreshGroupId} not found`,
+ );
return undefined;
- case RefreshOperationStatus.Pending: {
- dg.operationStatus = RefreshOperationStatus.Suspended;
- await tx.refreshGroups.put(dg);
- return {
- oldTxState: oldState,
- newTxState: computeRefreshTransactionState(dg),
- };
}
- case RefreshOperationStatus.Suspended:
- return undefined;
- }
- return undefined;
- });
- if (res) {
- wex.ws.notify({
- type: NotificationType.TransactionStateTransition,
- transactionId,
- oldTxState: res.oldTxState,
- newTxState: res.newTxState,
- });
- }
+ const oldState = computeRefreshTransactionState(dg);
+ switch (dg.operationStatus) {
+ case RefreshOperationStatus.Finished:
+ case RefreshOperationStatus.Suspended:
+ case RefreshOperationStatus.Failed:
+ return undefined;
+ case RefreshOperationStatus.Pending: {
+ dg.operationStatus = RefreshOperationStatus.Suspended;
+ await tx.refreshGroups.put(dg);
+ break;
+ }
+ default:
+ assertUnreachable(dg.operationStatus);
+ }
+ return {
+ oldTxState: oldState,
+ newTxState: computeRefreshTransactionState(dg),
+ };
+ },
+ );
+ wex.taskScheduler.stopShepherdTask(this.taskId);
+ notifyTransition(wex, transactionId, transitionInfo);
}
async abortTransaction(): Promise<void> {