aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-wallet-core/src/backup/index.ts12
-rw-r--r--packages/taler-wallet-core/src/merchants.ts66
-rw-r--r--packages/taler-wallet-core/src/pay-merchant.ts30
-rw-r--r--packages/taler-wallet-core/src/pay-peer-pull-debit.ts39
-rw-r--r--packages/taler-wallet-core/src/recoup.ts14
-rw-r--r--packages/taler-wallet-core/src/shepherd.ts32
6 files changed, 76 insertions, 117 deletions
diff --git a/packages/taler-wallet-core/src/backup/index.ts b/packages/taler-wallet-core/src/backup/index.ts
index c9ab6c5d9..13bf95026 100644
--- a/packages/taler-wallet-core/src/backup/index.ts
+++ b/packages/taler-wallet-core/src/backup/index.ts
@@ -82,19 +82,19 @@ import {
WalletDbReadOnlyTransaction,
timestampOptionalPreciseFromDb,
timestampPreciseToDb,
-} from "../../db.js";
-import { InternalWalletState } from "../../internal-wallet-state.js";
+} from "../db.js";
+import { InternalWalletState } from "../internal-wallet-state.js";
import {
checkDbInvariant,
checkLogicInvariant,
-} from "../../util/invariants.js";
-import { addAttentionRequest, removeAttentionRequest } from "../../attention.js";
+} from "../util/invariants.js";
+import { addAttentionRequest, removeAttentionRequest } from "../attention.js";
import {
TaskIdentifiers,
TaskRunResult,
TaskRunResultType,
-} from "../../common.js";
-import { preparePayForUri } from "../../pay-merchant.js";
+} from "../common.js";
+import { preparePayForUri } from "../pay-merchant.js";
const logger = new Logger("operations/backup.ts");
diff --git a/packages/taler-wallet-core/src/merchants.ts b/packages/taler-wallet-core/src/merchants.ts
deleted file mode 100644
index 6400aad7d..000000000
--- a/packages/taler-wallet-core/src/merchants.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- This file is part of GNU Taler
- (C) 2021 Taler Systems S.A..
-
- GNU Taler is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-
-/**
- * Imports.
- */
-import {
- canonicalizeBaseUrl,
- Logger,
- URL,
- codecForMerchantConfigResponse,
- LibtoolVersion,
-} from "@gnu-taler/taler-util";
-import { InternalWalletState, MerchantInfo } from "./internal-wallet-state.js";
-import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http";
-
-const logger = new Logger("taler-wallet-core:merchants.ts");
-
-export async function getMerchantInfo(
- ws: InternalWalletState,
- merchantBaseUrl: string,
-): Promise<MerchantInfo> {
- const canonBaseUrl = canonicalizeBaseUrl(merchantBaseUrl);
-
- const existingInfo = ws.merchantInfoCache[canonBaseUrl];
- if (existingInfo) {
- return existingInfo;
- }
-
- const configUrl = new URL("config", canonBaseUrl);
- const resp = await ws.http.fetch(configUrl.href);
-
- const configResp = await readSuccessResponseJsonOrThrow(
- resp,
- codecForMerchantConfigResponse(),
- );
-
- logger.info(
- `merchant "${canonBaseUrl}" reports protocol ${configResp.version}"`,
- );
-
- const parsedVersion = LibtoolVersion.parseVersion(configResp.version);
- if (!parsedVersion) {
- throw Error("invalid merchant version");
- }
-
- const merchantInfo: MerchantInfo = {
- protocolVersionCurrent: parsedVersion.current,
- };
-
- ws.merchantInfoCache[canonBaseUrl] = merchantInfo;
- return merchantInfo;
-}
diff --git a/packages/taler-wallet-core/src/pay-merchant.ts b/packages/taler-wallet-core/src/pay-merchant.ts
index f294035e6..0bd851464 100644
--- a/packages/taler-wallet-core/src/pay-merchant.ts
+++ b/packages/taler-wallet-core/src/pay-merchant.ts
@@ -32,6 +32,7 @@ import {
Amounts,
AmountString,
AsyncFlag,
+ CancellationToken,
codecForAbortResponse,
codecForMerchantContractTerms,
codecForMerchantOrderRefundPickupResponse,
@@ -94,6 +95,17 @@ import {
readUnexpectedResponseDetails,
throwUnexpectedRequestError,
} from "@gnu-taler/taler-util/http";
+import {
+ constructTaskIdentifier,
+ DbRetryInfo,
+ spendCoins,
+ TaskIdentifiers,
+ TaskRunResult,
+ TaskRunResultType,
+ TombstoneTag,
+ TransactionContext,
+ TransitionResult,
+} from "./common.js";
import { EddsaKeypair } from "./crypto/cryptoImplementation.js";
import {
CoinRecord,
@@ -121,22 +133,8 @@ import {
EXCHANGE_COINS_LOCK,
InternalWalletState,
} from "./internal-wallet-state.js";
-import { assertUnreachable } from "./util/assertUnreachable.js";
-import { PreviousPayCoins, selectPayCoinsNew } from "./util/coinSelection.js";
-import { checkDbInvariant } from "./util/invariants.js";
import { DbReadWriteTransaction, StoreNames } from "./query.js";
import {
- constructTaskIdentifier,
- DbRetryInfo,
- spendCoins,
- TaskIdentifiers,
- TaskRunResult,
- TaskRunResultType,
- TombstoneTag,
- TransactionContext,
- TransitionResult,
-} from "./common.js";
-import {
calculateRefreshOutput,
createRefreshGroup,
getTotalRefreshCost,
@@ -146,6 +144,9 @@ import {
notifyTransition,
parseTransactionIdentifier,
} from "./transactions.js";
+import { assertUnreachable } from "./util/assertUnreachable.js";
+import { PreviousPayCoins, selectPayCoinsNew } from "./util/coinSelection.js";
+import { checkDbInvariant } from "./util/invariants.js";
/**
* Logger.
@@ -1935,6 +1936,7 @@ export async function confirmPay(
export async function processPurchase(
ws: InternalWalletState,
proposalId: string,
+ cancellationToken: CancellationToken,
): Promise<TaskRunResult> {
const purchase = await ws.db.runReadOnlyTx(["purchases"], async (tx) => {
return tx.purchases.get(proposalId);
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 f71fdcee7..62472c7f8 100644
--- a/packages/taler-wallet-core/src/pay-peer-pull-debit.ts
+++ b/packages/taler-wallet-core/src/pay-peer-pull-debit.ts
@@ -26,6 +26,7 @@
import {
AcceptPeerPullPaymentResponse,
Amounts,
+ CancellationToken,
CoinRefreshRequest,
ConfirmPeerPullDebitRequest,
ContractTermsUtil,
@@ -63,6 +64,14 @@ import {
readTalerErrorResponse,
} from "@gnu-taler/taler-util/http";
import {
+ TaskRunResult,
+ TaskRunResultType,
+ TransactionContext,
+ TransitionResult,
+ constructTaskIdentifier,
+ spendCoins,
+} from "./common.js";
+import {
DbReadWriteTransaction,
InternalWalletState,
PeerPullDebitRecordStatus,
@@ -75,17 +84,6 @@ import {
createRefreshGroup,
timestampPreciseToDb,
} from "./index.js";
-import { assertUnreachable } from "./util/assertUnreachable.js";
-import { PeerCoinRepair, selectPeerCoins } from "./util/coinSelection.js";
-import { checkLogicInvariant } from "./util/invariants.js";
-import {
- TaskRunResult,
- TaskRunResultType,
- TransactionContext,
- TransitionResult,
- constructTaskIdentifier,
- spendCoins,
-} from "./common.js";
import {
codecForExchangePurseStatus,
getTotalPeerPaymentCost,
@@ -96,6 +94,9 @@ import {
notifyTransition,
parseTransactionIdentifier,
} from "./transactions.js";
+import { assertUnreachable } from "./util/assertUnreachable.js";
+import { PeerCoinRepair, selectPeerCoins } from "./util/coinSelection.js";
+import { checkLogicInvariant } from "./util/invariants.js";
const logger = new Logger("pay-peer-pull-debit.ts");
@@ -413,6 +414,7 @@ async function handlePurseCreationConflict(
async function processPeerPullDebitPendingDeposit(
ws: InternalWalletState,
peerPullInc: PeerPullPaymentIncomingRecord,
+ cancellationToken: CancellationToken,
): Promise<TaskRunResult> {
const pursePub = peerPullInc.pursePub;
@@ -445,6 +447,7 @@ async function processPeerPullDebitPendingDeposit(
const httpResp = await ws.http.fetch(purseDepositUrl.href, {
method: "POST",
body: depositPayload,
+ cancellationToken,
});
const ctx = new PeerPullDebitTransactionContext(
@@ -489,6 +492,7 @@ async function processPeerPullDebitPendingDeposit(
async function processPeerPullDebitAbortingRefresh(
ws: InternalWalletState,
peerPullInc: PeerPullPaymentIncomingRecord,
+ _cancellationToken: CancellationToken,
): Promise<TaskRunResult> {
const peerPullDebitId = peerPullInc.peerPullDebitId;
const abortRefreshGroupId = peerPullInc.abortRefreshGroupId;
@@ -538,6 +542,7 @@ async function processPeerPullDebitAbortingRefresh(
export async function processPeerPullDebit(
ws: InternalWalletState,
peerPullDebitId: string,
+ cancellationToken: CancellationToken,
): Promise<TaskRunResult> {
const peerPullInc = await ws.db.runReadOnlyTx(
["peerPullDebit"],
@@ -551,9 +556,17 @@ export async function processPeerPullDebit(
switch (peerPullInc.status) {
case PeerPullDebitRecordStatus.PendingDeposit:
- return await processPeerPullDebitPendingDeposit(ws, peerPullInc);
+ return await processPeerPullDebitPendingDeposit(
+ ws,
+ peerPullInc,
+ cancellationToken,
+ );
case PeerPullDebitRecordStatus.AbortingRefresh:
- return await processPeerPullDebitAbortingRefresh(ws, peerPullInc);
+ return await processPeerPullDebitAbortingRefresh(
+ ws,
+ peerPullInc,
+ cancellationToken,
+ );
}
return TaskRunResult.finished();
}
diff --git a/packages/taler-wallet-core/src/recoup.ts b/packages/taler-wallet-core/src/recoup.ts
index a2ffa4132..02aa1e167 100644
--- a/packages/taler-wallet-core/src/recoup.ts
+++ b/packages/taler-wallet-core/src/recoup.ts
@@ -26,6 +26,7 @@
*/
import {
Amounts,
+ CancellationToken,
CoinStatus,
Logger,
RefreshReason,
@@ -40,6 +41,11 @@ import {
} from "@gnu-taler/taler-util";
import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http";
import {
+ TaskRunResult,
+ TransactionContext,
+ constructTaskIdentifier,
+} from "./common.js";
+import {
CoinRecord,
CoinSourceType,
RecoupGroupRecord,
@@ -53,14 +59,9 @@ import {
} from "./db.js";
import { InternalWalletState } from "./internal-wallet-state.js";
import { PendingTaskType } from "./pending-types.js";
-import { checkDbInvariant } from "./util/invariants.js";
-import {
- TaskRunResult,
- TransactionContext,
- constructTaskIdentifier,
-} from "./common.js";
import { createRefreshGroup } from "./refresh.js";
import { constructTransactionIdentifier } from "./transactions.js";
+import { checkDbInvariant } from "./util/invariants.js";
import { internalCreateWithdrawalGroup } from "./withdraw.js";
const logger = new Logger("operations/recoup.ts");
@@ -295,6 +296,7 @@ async function recoupRefreshCoin(
export async function processRecoupGroup(
ws: InternalWalletState,
recoupGroupId: string,
+ cancellationToken: CancellationToken,
): Promise<TaskRunResult> {
let recoupGroup = await ws.db.runReadOnlyTx(["recoupGroups"], async (tx) => {
return tx.recoupGroups.get(recoupGroupId);
diff --git a/packages/taler-wallet-core/src/shepherd.ts b/packages/taler-wallet-core/src/shepherd.ts
index 438b4cf84..462d51a0d 100644
--- a/packages/taler-wallet-core/src/shepherd.ts
+++ b/packages/taler-wallet-core/src/shepherd.ts
@@ -37,14 +37,6 @@ import {
j2s,
makeErrorDetail,
} from "@gnu-taler/taler-util";
-import { CryptoApiStoppedError } from "./crypto/workers/crypto-dispatcher.js";
-import {
- OPERATION_STATUS_ACTIVE_FIRST,
- OPERATION_STATUS_ACTIVE_LAST,
- WalletDbAllStoresReadOnlyTransaction,
- timestampAbsoluteFromDb,
-} from "./index.js";
-import { InternalWalletState } from "./internal-wallet-state.js";
import { processBackupForProvider } from "./backup/index.js";
import {
DbRetryInfo,
@@ -54,18 +46,26 @@ import {
getExchangeState,
parseTaskIdentifier,
} from "./common.js";
+import { CryptoApiStoppedError } from "./crypto/workers/crypto-dispatcher.js";
import { processDepositGroup } from "./deposits.js";
import { updateExchangeFromUrlHandler } from "./exchanges.js";
+import {
+ OPERATION_STATUS_ACTIVE_FIRST,
+ OPERATION_STATUS_ACTIVE_LAST,
+ WalletDbAllStoresReadOnlyTransaction,
+ timestampAbsoluteFromDb,
+} from "./index.js";
+import { InternalWalletState } from "./internal-wallet-state.js";
import { processPurchase } from "./pay-merchant.js";
import { processPeerPullCredit } from "./pay-peer-pull-credit.js";
import { processPeerPullDebit } from "./pay-peer-pull-debit.js";
import { processPeerPushCredit } from "./pay-peer-push-credit.js";
import { processPeerPushDebit } from "./pay-peer-push-debit.js";
+import { PendingTaskType, TaskId } from "./pending-types.js";
import { processRecoupGroup } from "./recoup.js";
import { processRefreshGroup } from "./refresh.js";
import { constructTransactionIdentifier } from "./transactions.js";
import { processWithdrawalGroup } from "./withdraw.js";
-import { PendingTaskType, TaskId } from "./pending-types.js";
const logger = new Logger("shepherd.ts");
@@ -518,9 +518,13 @@ async function callOperationHandlerForTaskId(
cancellationToken,
);
case PendingTaskType.Purchase:
- return await processPurchase(ws, pending.proposalId);
+ return await processPurchase(ws, pending.proposalId, cancellationToken);
case PendingTaskType.Recoup:
- return await processRecoupGroup(ws, pending.recoupGroupId);
+ return await processRecoupGroup(
+ ws,
+ pending.recoupGroupId,
+ cancellationToken,
+ );
case PendingTaskType.Deposit:
return await processDepositGroup(
ws,
@@ -542,7 +546,11 @@ async function callOperationHandlerForTaskId(
cancellationToken,
);
case PendingTaskType.PeerPullDebit:
- return await processPeerPullDebit(ws, pending.peerPullDebitId);
+ return await processPeerPullDebit(
+ ws,
+ pending.peerPullDebitId,
+ cancellationToken,
+ );
case PendingTaskType.PeerPushCredit:
return await processPeerPushCredit(
ws,