2015-12-25 22:42:14 +01:00
|
|
|
/*
|
2019-12-02 00:42:40 +01:00
|
|
|
This file is part of GNU Taler
|
2019-11-30 00:36:20 +01:00
|
|
|
(C) 2015-2019 GNUnet e.V.
|
2015-12-25 22:42:14 +01:00
|
|
|
|
2019-12-02 00:42:40 +01:00
|
|
|
GNU Taler is free software; you can redistribute it and/or modify it under the
|
2015-12-25 22:42:14 +01:00
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
2019-12-02 00:42:40 +01:00
|
|
|
GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
|
2015-12-25 22:42:14 +01:00
|
|
|
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
|
2019-12-02 00:42:40 +01:00
|
|
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
2015-12-25 22:42:14 +01:00
|
|
|
*/
|
|
|
|
|
2016-01-05 15:42:46 +01:00
|
|
|
/**
|
|
|
|
* High-level wallet operations that should be indepentent from the underlying
|
|
|
|
* browser extension interface.
|
|
|
|
*/
|
|
|
|
|
2017-05-24 16:52:00 +02:00
|
|
|
/**
|
|
|
|
* Imports.
|
|
|
|
*/
|
2021-05-12 16:18:32 +02:00
|
|
|
import {
|
|
|
|
BackupRecovery,
|
|
|
|
codecForAny,
|
2021-05-20 18:27:35 +02:00
|
|
|
codecForDeleteTransactionRequest,
|
2021-06-14 19:37:35 +02:00
|
|
|
codecForRetryTransactionRequest,
|
2021-05-20 16:24:41 +02:00
|
|
|
DeleteTransactionRequest,
|
2021-06-10 16:32:37 +02:00
|
|
|
durationFromSpec,
|
|
|
|
durationMax,
|
|
|
|
durationMin,
|
|
|
|
getDurationRemaining,
|
|
|
|
isTimestampExpired,
|
|
|
|
j2s,
|
2021-05-12 16:18:32 +02:00
|
|
|
TalerErrorCode,
|
2021-06-10 16:32:37 +02:00
|
|
|
Timestamp,
|
|
|
|
timestampMin,
|
2021-05-20 13:14:47 +02:00
|
|
|
WalletCurrencyInfo,
|
2021-05-12 16:18:32 +02:00
|
|
|
} from "@gnu-taler/taler-util";
|
2019-12-09 13:29:11 +01:00
|
|
|
import { CryptoWorkerFactory } from "./crypto/workers/cryptoApi";
|
2019-12-02 00:42:40 +01:00
|
|
|
import {
|
2021-02-08 15:38:34 +01:00
|
|
|
addBackupProvider,
|
|
|
|
AddBackupProviderRequest,
|
|
|
|
BackupInfo,
|
|
|
|
codecForAddBackupProviderRequest,
|
|
|
|
exportBackupEncrypted,
|
|
|
|
getBackupInfo,
|
|
|
|
getBackupRecovery,
|
|
|
|
importBackupEncrypted,
|
|
|
|
importBackupPlain,
|
|
|
|
loadBackupRecovery,
|
|
|
|
runBackupCycle,
|
|
|
|
} from "./operations/backup";
|
2021-03-10 12:00:30 +01:00
|
|
|
import { exportBackup } from "./operations/backup/export";
|
2021-02-08 15:38:34 +01:00
|
|
|
import { getBalances } from "./operations/balance";
|
|
|
|
import {
|
|
|
|
createDepositGroup,
|
|
|
|
processDepositGroup,
|
|
|
|
trackDepositGroup,
|
|
|
|
} from "./operations/deposits";
|
|
|
|
import {
|
|
|
|
makeErrorDetails,
|
|
|
|
OperationFailedAndReportedError,
|
|
|
|
OperationFailedError,
|
|
|
|
} from "./operations/errors";
|
|
|
|
import {
|
|
|
|
acceptExchangeTermsOfService,
|
2021-06-09 15:14:17 +02:00
|
|
|
getExchangeDetails,
|
2021-02-08 15:38:34 +01:00
|
|
|
getExchangePaytoUri,
|
|
|
|
updateExchangeFromUrl,
|
|
|
|
} from "./operations/exchanges";
|
2019-12-02 00:42:40 +01:00
|
|
|
import {
|
|
|
|
confirmPay,
|
2021-02-08 15:38:34 +01:00
|
|
|
preparePayForUri,
|
2019-12-03 00:52:15 +01:00
|
|
|
processDownloadProposal,
|
2019-12-06 00:24:34 +01:00
|
|
|
processPurchasePay,
|
2021-02-08 15:38:34 +01:00
|
|
|
refuseProposal,
|
2019-12-12 20:53:15 +01:00
|
|
|
} from "./operations/pay";
|
2021-02-08 15:38:34 +01:00
|
|
|
import { getPendingOperations } from "./operations/pending";
|
|
|
|
import { processRecoupGroup } from "./operations/recoup";
|
|
|
|
import {
|
|
|
|
autoRefresh,
|
|
|
|
createRefreshGroup,
|
|
|
|
processRefreshGroup,
|
|
|
|
} from "./operations/refresh";
|
|
|
|
import {
|
|
|
|
abortFailedPayWithRefund,
|
|
|
|
applyRefund,
|
|
|
|
processPurchaseQueryRefund,
|
|
|
|
} from "./operations/refund";
|
|
|
|
import {
|
|
|
|
createReserve,
|
|
|
|
createTalerWithdrawReserve,
|
|
|
|
forceQueryReserve,
|
|
|
|
getFundingPaytoUris,
|
|
|
|
processReserve,
|
|
|
|
} from "./operations/reserves";
|
|
|
|
import { InternalWalletState } from "./operations/state";
|
|
|
|
import {
|
|
|
|
runIntegrationTest,
|
|
|
|
testPay,
|
|
|
|
withdrawTestBalance,
|
|
|
|
} from "./operations/testing";
|
|
|
|
import { acceptTip, prepareTip, processTip } from "./operations/tip";
|
2021-06-14 19:37:35 +02:00
|
|
|
import { deleteTransaction, getTransactions, retryTransaction } from "./operations/transactions";
|
2021-02-08 15:38:34 +01:00
|
|
|
import {
|
|
|
|
getExchangeWithdrawalInfo,
|
|
|
|
getWithdrawalDetailsForUri,
|
|
|
|
processWithdrawGroup,
|
|
|
|
} from "./operations/withdraw";
|
2016-05-24 01:53:56 +02:00
|
|
|
import {
|
2021-05-20 13:14:47 +02:00
|
|
|
AuditorTrustRecord,
|
2017-05-28 01:10:54 +02:00
|
|
|
CoinRecord,
|
2021-02-08 15:38:34 +01:00
|
|
|
CoinSourceType,
|
2021-06-02 13:23:51 +02:00
|
|
|
ExchangeDetailsRecord,
|
2016-11-15 15:07:17 +01:00
|
|
|
ExchangeRecord,
|
2018-01-03 14:42:06 +01:00
|
|
|
ReserveRecord,
|
2019-11-21 23:09:43 +01:00
|
|
|
ReserveRecordStatus,
|
2021-06-09 15:14:17 +02:00
|
|
|
WalletStoresV1,
|
2021-03-17 17:56:37 +01:00
|
|
|
} from "./db.js";
|
|
|
|
import { NotificationType, WalletNotification } from "@gnu-taler/taler-util";
|
2021-02-08 15:38:34 +01:00
|
|
|
import {
|
|
|
|
PendingOperationInfo,
|
|
|
|
PendingOperationsResponse,
|
|
|
|
PendingOperationType,
|
2021-03-17 17:56:37 +01:00
|
|
|
} from "./pending-types.js";
|
|
|
|
import { CoinDumpJson } from "@gnu-taler/taler-util";
|
2021-02-08 15:38:34 +01:00
|
|
|
import {
|
|
|
|
codecForTransactionsRequest,
|
|
|
|
TransactionsRequest,
|
|
|
|
TransactionsResponse,
|
2021-03-17 17:56:37 +01:00
|
|
|
} from "@gnu-taler/taler-util";
|
2018-01-03 14:42:06 +01:00
|
|
|
import {
|
2020-07-16 19:22:56 +02:00
|
|
|
AcceptManualWithdrawalResult,
|
2021-02-08 15:38:34 +01:00
|
|
|
AcceptWithdrawalResponse,
|
|
|
|
ApplyRefundResponse,
|
2020-07-28 19:47:12 +02:00
|
|
|
BalancesResponse,
|
2021-02-08 15:38:34 +01:00
|
|
|
BenchmarkResult,
|
|
|
|
codecForAbortPayWithRefundRequest,
|
|
|
|
codecForAcceptBankIntegratedWithdrawalRequest,
|
2020-08-14 09:36:42 +02:00
|
|
|
codecForAcceptExchangeTosRequest,
|
2021-02-08 15:38:34 +01:00
|
|
|
codecForAcceptManualWithdrawalRequet,
|
|
|
|
codecForAcceptTipRequest,
|
|
|
|
codecForAddExchangeRequest,
|
2020-08-14 09:36:42 +02:00
|
|
|
codecForApplyRefundRequest,
|
|
|
|
codecForConfirmPayRequest,
|
2021-02-08 15:38:34 +01:00
|
|
|
codecForCreateDepositGroupRequest,
|
2020-09-03 22:50:20 +02:00
|
|
|
codecForForceExchangeUpdateRequest,
|
|
|
|
codecForForceRefreshRequest,
|
2021-02-08 15:38:34 +01:00
|
|
|
codecForGetExchangeTosRequest,
|
|
|
|
codecForGetWithdrawalDetailsForAmountRequest,
|
|
|
|
codecForGetWithdrawalDetailsForUri,
|
|
|
|
codecForIntegrationTestArgs,
|
|
|
|
codecForPreparePayRequest,
|
2020-09-08 14:10:47 +02:00
|
|
|
codecForPrepareTipRequest,
|
2021-02-08 15:38:34 +01:00
|
|
|
codecForSetCoinSuspendedRequest,
|
|
|
|
codecForTestPayArgs,
|
|
|
|
codecForTrackDepositGroupRequest,
|
|
|
|
codecForWithdrawTestBalance,
|
|
|
|
ConfirmPayResult,
|
|
|
|
CoreApiResponse,
|
2021-01-18 23:35:41 +01:00
|
|
|
CreateDepositGroupRequest,
|
|
|
|
CreateDepositGroupResponse,
|
2021-02-08 15:38:34 +01:00
|
|
|
ExchangeListItem,
|
|
|
|
ExchangesListRespose,
|
|
|
|
GetExchangeTosResult,
|
|
|
|
IntegrationTestArgs,
|
|
|
|
ManualWithdrawalDetails,
|
|
|
|
PreparePayResult,
|
|
|
|
PrepareTipResult,
|
|
|
|
RecoveryLoadRequest,
|
|
|
|
RefreshReason,
|
|
|
|
ReturnCoinsRequest,
|
|
|
|
TestPayArgs,
|
2021-01-18 23:35:41 +01:00
|
|
|
TrackDepositGroupRequest,
|
|
|
|
TrackDepositGroupResponse,
|
2021-02-08 15:38:34 +01:00
|
|
|
WithdrawTestBalanceRequest,
|
|
|
|
WithdrawUriInfoResponse,
|
2021-03-17 17:56:37 +01:00
|
|
|
} from "@gnu-taler/taler-util";
|
|
|
|
import { AmountJson, Amounts } from "@gnu-taler/taler-util";
|
2019-12-02 00:42:40 +01:00
|
|
|
import { assertUnreachable } from "./util/assertUnreachable";
|
2019-12-05 19:38:19 +01:00
|
|
|
import { AsyncOpMemoSingle } from "./util/asyncMemo";
|
2021-02-08 15:38:34 +01:00
|
|
|
import { HttpRequestLibrary } from "./util/http";
|
2021-06-08 20:58:13 +02:00
|
|
|
import { Logger } from "@gnu-taler/taler-util";
|
2021-02-08 15:38:34 +01:00
|
|
|
import { AsyncCondition } from "./util/promiseUtils";
|
|
|
|
import { TimerGroup } from "./util/timer";
|
2021-05-20 13:14:47 +02:00
|
|
|
import { getExchangeTrust } from "./operations/currencies.js";
|
2021-06-09 15:14:17 +02:00
|
|
|
import { DbAccess } from "./util/query.js";
|
2021-06-14 11:21:29 +02:00
|
|
|
import { setWalletDeviceId } from "./operations/backup/state.js";
|
2017-12-12 21:54:14 +01:00
|
|
|
|
2021-05-20 13:14:47 +02:00
|
|
|
const builtinAuditors: AuditorTrustRecord[] = [
|
2017-03-24 16:59:23 +01:00
|
|
|
{
|
2021-05-20 13:14:47 +02:00
|
|
|
currency: "KUDOS",
|
|
|
|
auditorPub: "BW9DC48PHQY4NH011SHHX36DZZ3Q22Y6X7FZ1VD1CMZ2PTFZ6PN0",
|
|
|
|
auditorBaseUrl: "https://auditor.demo.taler.net/",
|
|
|
|
uids: ["5P25XF8TVQP9AW6VYGY2KV47WT5Y3ZXFSJAA570GJPX5SVJXKBVG"],
|
2017-03-24 16:59:23 +01:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2019-11-21 23:09:43 +01:00
|
|
|
const logger = new Logger("wallet.ts");
|
|
|
|
|
2017-05-28 16:27:34 +02:00
|
|
|
/**
|
|
|
|
* The platform-independent wallet implementation.
|
|
|
|
*/
|
2016-01-10 20:07:42 +01:00
|
|
|
export class Wallet {
|
2019-12-02 00:42:40 +01:00
|
|
|
private ws: InternalWalletState;
|
2019-12-02 17:35:47 +01:00
|
|
|
private timerGroup: TimerGroup = new TimerGroup();
|
|
|
|
private latch = new AsyncCondition();
|
2020-04-06 17:45:41 +02:00
|
|
|
private stopped = false;
|
2019-12-05 19:38:19 +01:00
|
|
|
private memoRunRetryLoop = new AsyncOpMemoSingle<void>();
|
2019-12-02 00:42:40 +01:00
|
|
|
|
2021-06-09 15:14:17 +02:00
|
|
|
get db(): DbAccess<typeof WalletStoresV1> {
|
2019-12-02 00:42:40 +01:00
|
|
|
return this.ws.db;
|
|
|
|
}
|
|
|
|
|
2019-06-26 15:30:32 +02:00
|
|
|
constructor(
|
2021-06-09 15:14:17 +02:00
|
|
|
db: DbAccess<typeof WalletStoresV1>,
|
2019-06-26 15:30:32 +02:00
|
|
|
http: HttpRequestLibrary,
|
2019-08-15 19:10:23 +02:00
|
|
|
cryptoWorkerFactory: CryptoWorkerFactory,
|
2019-06-26 15:30:32 +02:00
|
|
|
) {
|
2019-12-05 19:38:19 +01:00
|
|
|
this.ws = new InternalWalletState(db, http, cryptoWorkerFactory);
|
2019-12-02 00:42:40 +01:00
|
|
|
}
|
|
|
|
|
2020-04-07 10:07:32 +02:00
|
|
|
getExchangePaytoUri(
|
|
|
|
exchangeBaseUrl: string,
|
|
|
|
supportedTargetTypes: string[],
|
|
|
|
): Promise<string> {
|
2019-12-02 00:42:40 +01:00
|
|
|
return getExchangePaytoUri(this.ws, exchangeBaseUrl, supportedTargetTypes);
|
|
|
|
}
|
|
|
|
|
2020-07-11 09:56:07 +02:00
|
|
|
async getWithdrawalDetailsForAmount(
|
2019-12-09 19:59:08 +01:00
|
|
|
exchangeBaseUrl: string,
|
|
|
|
amount: AmountJson,
|
2020-07-11 09:56:07 +02:00
|
|
|
): Promise<ManualWithdrawalDetails> {
|
2020-07-16 19:22:56 +02:00
|
|
|
const wi = await getExchangeWithdrawalInfo(
|
|
|
|
this.ws,
|
|
|
|
exchangeBaseUrl,
|
|
|
|
amount,
|
|
|
|
);
|
2021-06-02 13:23:51 +02:00
|
|
|
const paytoUris = wi.exchangeDetails.wireInfo.accounts.map(
|
2020-07-16 19:22:56 +02:00
|
|
|
(x) => x.payto_uri,
|
|
|
|
);
|
2020-07-11 09:56:07 +02:00
|
|
|
if (!paytoUris) {
|
|
|
|
throw Error("exchange is in invalid state");
|
|
|
|
}
|
|
|
|
return {
|
2020-07-28 20:08:50 +02:00
|
|
|
amountRaw: Amounts.stringify(amount),
|
|
|
|
amountEffective: Amounts.stringify(wi.selectedDenoms.totalCoinValue),
|
2020-07-11 09:56:07 +02:00
|
|
|
paytoUris,
|
|
|
|
tosAccepted: wi.termsOfServiceAccepted,
|
|
|
|
};
|
2019-11-20 19:48:43 +01:00
|
|
|
}
|
2017-06-05 02:00:03 +02:00
|
|
|
|
2019-12-05 19:38:19 +01:00
|
|
|
addNotificationListener(f: (n: WalletNotification) => void): void {
|
|
|
|
this.ws.addNotificationListener(f);
|
|
|
|
}
|
|
|
|
|
2019-11-21 23:09:43 +01:00
|
|
|
/**
|
2019-11-30 00:36:20 +01:00
|
|
|
* Execute one operation based on the pending operation info record.
|
2019-11-21 23:09:43 +01:00
|
|
|
*/
|
2019-11-30 00:36:20 +01:00
|
|
|
async processOnePendingOperation(
|
|
|
|
pending: PendingOperationInfo,
|
2020-04-06 17:45:41 +02:00
|
|
|
forceNow = false,
|
2019-11-30 00:36:20 +01:00
|
|
|
): Promise<void> {
|
2020-07-23 15:54:00 +02:00
|
|
|
logger.trace(`running pending ${JSON.stringify(pending, undefined, 2)}`);
|
2019-11-30 00:36:20 +01:00
|
|
|
switch (pending.type) {
|
2019-12-15 16:59:00 +01:00
|
|
|
case PendingOperationType.ExchangeUpdate:
|
2019-12-07 22:02:11 +01:00
|
|
|
await updateExchangeFromUrl(this.ws, pending.exchangeBaseUrl, forceNow);
|
2019-11-30 00:36:20 +01:00
|
|
|
break;
|
2019-12-15 16:59:00 +01:00
|
|
|
case PendingOperationType.Refresh:
|
2019-12-16 12:53:22 +01:00
|
|
|
await processRefreshGroup(this.ws, pending.refreshGroupId, forceNow);
|
2019-11-30 00:36:20 +01:00
|
|
|
break;
|
2019-12-15 16:59:00 +01:00
|
|
|
case PendingOperationType.Reserve:
|
2019-12-05 19:38:19 +01:00
|
|
|
await processReserve(this.ws, pending.reservePub, forceNow);
|
2019-11-30 00:36:20 +01:00
|
|
|
break;
|
2019-12-15 16:59:00 +01:00
|
|
|
case PendingOperationType.Withdraw:
|
2020-04-02 17:03:01 +02:00
|
|
|
await processWithdrawGroup(
|
2019-12-09 19:59:08 +01:00
|
|
|
this.ws,
|
2020-04-02 17:03:01 +02:00
|
|
|
pending.withdrawalGroupId,
|
2019-12-09 19:59:08 +01:00
|
|
|
forceNow,
|
|
|
|
);
|
2019-11-30 00:36:20 +01:00
|
|
|
break;
|
2019-12-16 12:53:22 +01:00
|
|
|
case PendingOperationType.ProposalDownload:
|
2019-12-07 22:02:11 +01:00
|
|
|
await processDownloadProposal(this.ws, pending.proposalId, forceNow);
|
2019-12-03 00:52:15 +01:00
|
|
|
break;
|
2019-12-15 16:59:00 +01:00
|
|
|
case PendingOperationType.TipPickup:
|
2019-12-07 22:02:11 +01:00
|
|
|
await processTip(this.ws, pending.tipId, forceNow);
|
2019-12-02 17:35:47 +01:00
|
|
|
break;
|
2019-12-15 16:59:00 +01:00
|
|
|
case PendingOperationType.Pay:
|
2019-12-07 22:02:11 +01:00
|
|
|
await processPurchasePay(this.ws, pending.proposalId, forceNow);
|
2019-12-06 00:24:34 +01:00
|
|
|
break;
|
2019-12-15 16:59:00 +01:00
|
|
|
case PendingOperationType.RefundQuery:
|
2019-12-07 22:02:11 +01:00
|
|
|
await processPurchaseQueryRefund(this.ws, pending.proposalId, forceNow);
|
2019-12-06 00:24:34 +01:00
|
|
|
break;
|
2020-03-11 20:14:28 +01:00
|
|
|
case PendingOperationType.Recoup:
|
|
|
|
await processRecoupGroup(this.ws, pending.recoupGroupId, forceNow);
|
|
|
|
break;
|
2020-09-03 13:59:09 +02:00
|
|
|
case PendingOperationType.ExchangeCheckRefresh:
|
2020-09-03 22:50:20 +02:00
|
|
|
await autoRefresh(this.ws, pending.exchangeBaseUrl);
|
2020-09-03 13:59:09 +02:00
|
|
|
break;
|
2021-01-18 23:35:41 +01:00
|
|
|
case PendingOperationType.Deposit:
|
|
|
|
await processDepositGroup(this.ws, pending.depositGroupId);
|
|
|
|
break;
|
2019-11-30 00:36:20 +01:00
|
|
|
default:
|
|
|
|
assertUnreachable(pending);
|
2019-11-21 23:09:43 +01:00
|
|
|
}
|
2019-11-30 00:36:20 +01:00
|
|
|
}
|
2019-11-21 23:09:43 +01:00
|
|
|
|
2019-11-30 00:36:20 +01:00
|
|
|
/**
|
|
|
|
* Process pending operations.
|
|
|
|
*/
|
2020-04-06 17:45:41 +02:00
|
|
|
public async runPending(forceNow = false): Promise<void> {
|
2021-06-10 16:32:37 +02:00
|
|
|
const pendingOpsResponse = await this.getPendingOperations();
|
2019-11-30 00:36:20 +01:00
|
|
|
for (const p of pendingOpsResponse.pendingOperations) {
|
2021-06-10 16:32:37 +02:00
|
|
|
if (!forceNow && !isTimestampExpired(p.timestampDue)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-11-30 00:36:20 +01:00
|
|
|
try {
|
2019-12-03 14:40:05 +01:00
|
|
|
await this.processOnePendingOperation(p, forceNow);
|
2019-11-30 00:36:20 +01:00
|
|
|
} catch (e) {
|
2020-03-12 14:55:38 +01:00
|
|
|
if (e instanceof OperationFailedAndReportedError) {
|
2020-03-24 10:55:04 +01:00
|
|
|
console.error(
|
|
|
|
"Operation failed:",
|
|
|
|
JSON.stringify(e.operationError, undefined, 2),
|
|
|
|
);
|
2020-03-12 14:55:38 +01:00
|
|
|
} else {
|
|
|
|
console.error(e);
|
|
|
|
}
|
2019-11-30 00:36:20 +01:00
|
|
|
}
|
2019-11-21 23:09:43 +01:00
|
|
|
}
|
2019-11-20 19:48:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-05 19:38:19 +01:00
|
|
|
* Run the wallet until there are no more pending operations that give
|
|
|
|
* liveness left. The wallet will be in a stopped state when this function
|
|
|
|
* returns without resolving to an exception.
|
2019-11-20 19:48:43 +01:00
|
|
|
*/
|
2020-09-01 14:30:46 +02:00
|
|
|
public async runUntilDone(
|
|
|
|
req: {
|
|
|
|
maxRetries?: number;
|
|
|
|
} = {},
|
|
|
|
): Promise<void> {
|
2020-05-11 14:49:43 +02:00
|
|
|
let done = false;
|
2020-12-16 17:59:04 +01:00
|
|
|
const p = new Promise<void>((resolve, reject) => {
|
2020-09-01 14:30:46 +02:00
|
|
|
// Monitor for conditions that means we're done or we
|
|
|
|
// should quit with an error (due to exceeded retries).
|
2020-03-24 10:55:04 +01:00
|
|
|
this.addNotificationListener((n) => {
|
2020-05-11 14:49:43 +02:00
|
|
|
if (done) {
|
|
|
|
return;
|
|
|
|
}
|
2020-01-18 23:32:03 +01:00
|
|
|
if (
|
|
|
|
n.type === NotificationType.WaitingForRetry &&
|
|
|
|
n.numGivingLiveness == 0
|
|
|
|
) {
|
2020-05-11 14:49:43 +02:00
|
|
|
done = true;
|
|
|
|
logger.trace("no liveness-giving operations left");
|
2020-01-18 23:32:03 +01:00
|
|
|
resolve();
|
|
|
|
}
|
2020-09-01 14:30:46 +02:00
|
|
|
const maxRetries = req.maxRetries;
|
|
|
|
if (!maxRetries) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-10 16:32:37 +02:00
|
|
|
this.getPendingOperations()
|
2020-09-01 14:30:46 +02:00
|
|
|
.then((pending) => {
|
|
|
|
for (const p of pending.pendingOperations) {
|
|
|
|
if (p.retryInfo && p.retryInfo.retryCounter > maxRetries) {
|
|
|
|
console.warn(
|
|
|
|
`stopping, as ${maxRetries} retries are exceeded in an operation of type ${p.type}`,
|
|
|
|
);
|
|
|
|
this.stop();
|
|
|
|
done = true;
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
logger.error(e);
|
|
|
|
reject(e);
|
|
|
|
});
|
2020-01-18 23:32:03 +01:00
|
|
|
});
|
2020-09-01 14:30:46 +02:00
|
|
|
// Run this asynchronously
|
2020-03-24 10:55:04 +01:00
|
|
|
this.runRetryLoop().catch((e) => {
|
2020-08-14 12:23:50 +02:00
|
|
|
logger.error("exception in wallet retry loop");
|
2020-01-18 23:32:03 +01:00
|
|
|
reject(e);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
await p;
|
|
|
|
}
|
|
|
|
|
2019-11-21 23:09:43 +01:00
|
|
|
/**
|
2019-12-05 19:38:19 +01:00
|
|
|
* Process pending operations and wait for scheduled operations in
|
|
|
|
* a loop until the wallet is stopped explicitly.
|
2019-11-21 23:09:43 +01:00
|
|
|
*/
|
2019-12-05 19:38:19 +01:00
|
|
|
public async runRetryLoop(): Promise<void> {
|
|
|
|
// Make sure we only run one main loop at a time.
|
|
|
|
return this.memoRunRetryLoop.memo(async () => {
|
|
|
|
try {
|
|
|
|
await this.runRetryLoopImpl();
|
|
|
|
} catch (e) {
|
|
|
|
console.error("error during retry loop execution", e);
|
|
|
|
throw e;
|
2019-11-30 00:36:20 +01:00
|
|
|
}
|
2019-12-05 19:38:19 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private async runRetryLoopImpl(): Promise<void> {
|
2021-06-10 16:32:37 +02:00
|
|
|
for (let iteration = 0; !this.stopped; iteration++) {
|
|
|
|
const pending = await this.getPendingOperations();
|
|
|
|
logger.trace(`pending operations: ${j2s(pending)}`);
|
|
|
|
let numGivingLiveness = 0;
|
|
|
|
let numDue = 0;
|
|
|
|
let minDue: Timestamp = { t_ms: "never" };
|
2020-09-03 17:08:26 +02:00
|
|
|
for (const p of pending.pendingOperations) {
|
2021-06-10 16:32:37 +02:00
|
|
|
minDue = timestampMin(minDue, p.timestampDue);
|
|
|
|
if (isTimestampExpired(p.timestampDue)) {
|
|
|
|
numDue++;
|
|
|
|
}
|
2020-09-03 17:08:26 +02:00
|
|
|
if (p.givesLifeness) {
|
2021-06-10 16:32:37 +02:00
|
|
|
numGivingLiveness++;
|
2020-09-03 17:08:26 +02:00
|
|
|
}
|
|
|
|
}
|
2020-09-03 22:50:20 +02:00
|
|
|
// Make sure that we run tasks that don't give lifeness at least
|
|
|
|
// one time.
|
2021-06-10 16:32:37 +02:00
|
|
|
if (iteration !== 0 && numDue === 0) {
|
|
|
|
// We've executed pending, due operations at least one.
|
|
|
|
// Now we don't have any more operations available,
|
|
|
|
// and need to wait.
|
|
|
|
|
|
|
|
// Wait for at most 5 seconds to the next check.
|
|
|
|
const dt = durationMin(
|
|
|
|
durationFromSpec({
|
|
|
|
seconds: 5,
|
|
|
|
}),
|
|
|
|
getDurationRemaining(minDue),
|
|
|
|
);
|
|
|
|
logger.trace(`waiting for at most ${dt.d_ms} ms`)
|
2019-12-06 11:01:39 +01:00
|
|
|
const timeout = this.timerGroup.resolveAfter(dt);
|
2019-12-05 19:38:19 +01:00
|
|
|
this.ws.notify({
|
|
|
|
type: NotificationType.WaitingForRetry,
|
|
|
|
numGivingLiveness,
|
2021-06-10 16:32:37 +02:00
|
|
|
numPending: pending.pendingOperations.length,
|
2019-12-05 19:38:19 +01:00
|
|
|
});
|
2021-06-10 16:32:37 +02:00
|
|
|
// Wait until either the timeout, or we are notified (via the latch)
|
|
|
|
// that more work might be available.
|
2019-12-05 19:38:19 +01:00
|
|
|
await Promise.race([timeout, this.latch.wait()]);
|
|
|
|
} else {
|
2020-09-03 22:50:20 +02:00
|
|
|
logger.trace(
|
|
|
|
`running ${pending.pendingOperations.length} pending operations`,
|
|
|
|
);
|
2019-12-05 19:38:19 +01:00
|
|
|
for (const p of pending.pendingOperations) {
|
2021-06-10 16:32:37 +02:00
|
|
|
if (!isTimestampExpired(p.timestampDue)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-12-05 19:38:19 +01:00
|
|
|
try {
|
|
|
|
await this.processOnePendingOperation(p);
|
|
|
|
} catch (e) {
|
2020-07-20 12:50:32 +02:00
|
|
|
if (e instanceof OperationFailedAndReportedError) {
|
|
|
|
logger.warn("operation processed resulted in reported error");
|
|
|
|
} else {
|
2020-09-01 14:30:46 +02:00
|
|
|
logger.error("Uncaught exception", e);
|
2020-07-20 12:50:32 +02:00
|
|
|
this.ws.notify({
|
|
|
|
type: NotificationType.InternalError,
|
|
|
|
message: "uncaught exception",
|
|
|
|
exception: e,
|
2020-07-22 10:52:03 +02:00
|
|
|
});
|
2020-07-20 12:50:32 +02:00
|
|
|
}
|
2019-12-05 19:38:19 +01:00
|
|
|
}
|
2020-07-20 12:50:32 +02:00
|
|
|
this.ws.notify({
|
|
|
|
type: NotificationType.PendingOperationProcessed,
|
2020-07-22 10:52:03 +02:00
|
|
|
});
|
2019-12-05 19:38:19 +01:00
|
|
|
}
|
2019-11-21 23:09:43 +01:00
|
|
|
}
|
|
|
|
}
|
2019-12-05 19:38:19 +01:00
|
|
|
logger.trace("exiting wallet retry loop");
|
2016-05-24 01:18:23 +02:00
|
|
|
}
|
|
|
|
|
2019-11-20 19:48:43 +01:00
|
|
|
/**
|
|
|
|
* Insert the hard-coded defaults for exchanges, coins and
|
|
|
|
* auditors into the database, unless these defaults have
|
|
|
|
* already been applied.
|
|
|
|
*/
|
2020-04-06 20:02:01 +02:00
|
|
|
async fillDefaults(): Promise<void> {
|
2021-06-09 15:14:17 +02:00
|
|
|
await this.db
|
|
|
|
.mktx((x) => ({ config: x.config, auditorTrustStore: x.auditorTrust }))
|
|
|
|
.runReadWrite(async (tx) => {
|
2019-11-20 19:48:43 +01:00
|
|
|
let applied = false;
|
2021-06-09 15:14:17 +02:00
|
|
|
await tx.config.iter().forEach((x) => {
|
2019-11-20 19:48:43 +01:00
|
|
|
if (x.key == "currencyDefaultsApplied" && x.value == true) {
|
|
|
|
applied = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (!applied) {
|
2021-05-20 13:14:47 +02:00
|
|
|
for (const c of builtinAuditors) {
|
2021-06-09 15:14:17 +02:00
|
|
|
await tx.auditorTrustStore.put(c);
|
2019-11-20 19:48:43 +01:00
|
|
|
}
|
|
|
|
}
|
2021-06-09 15:14:17 +02:00
|
|
|
});
|
2017-03-24 16:59:23 +01:00
|
|
|
}
|
|
|
|
|
2019-09-06 09:48:00 +02:00
|
|
|
/**
|
|
|
|
* Check if a payment for the given taler://pay/ URI is possible.
|
2019-09-06 11:06:28 +02:00
|
|
|
*
|
2019-09-06 09:48:00 +02:00
|
|
|
* If the payment is possible, the signature are already generated but not
|
|
|
|
* yet send to the merchant.
|
|
|
|
*/
|
2019-12-20 01:25:22 +01:00
|
|
|
async preparePayForUri(talerPayUri: string): Promise<PreparePayResult> {
|
|
|
|
return preparePayForUri(this.ws, talerPayUri);
|
2018-01-17 03:49:54 +01:00
|
|
|
}
|
|
|
|
|
2016-02-10 02:03:31 +01:00
|
|
|
/**
|
2018-01-29 16:41:17 +01:00
|
|
|
* Add a contract to the wallet and sign coins, and send them.
|
2016-02-10 02:03:31 +01:00
|
|
|
*/
|
2019-06-26 15:30:32 +02:00
|
|
|
async confirmPay(
|
2019-11-30 00:36:20 +01:00
|
|
|
proposalId: string,
|
2019-08-24 18:42:00 +02:00
|
|
|
sessionIdOverride: string | undefined,
|
2019-06-26 15:30:32 +02:00
|
|
|
): Promise<ConfirmPayResult> {
|
2019-12-02 17:35:47 +01:00
|
|
|
try {
|
|
|
|
return await confirmPay(this.ws, proposalId, sessionIdOverride);
|
|
|
|
} finally {
|
|
|
|
this.latch.trigger();
|
|
|
|
}
|
2019-12-02 00:42:40 +01:00
|
|
|
}
|
2019-11-30 00:36:20 +01:00
|
|
|
|
2016-02-09 21:56:06 +01:00
|
|
|
/**
|
2021-04-27 23:42:25 +02:00
|
|
|
* First fetch information required to withdraw from the reserve,
|
2016-02-09 21:56:06 +01:00
|
|
|
* then deplete the reserve, withdrawing coins until it is empty.
|
2019-11-21 23:09:43 +01:00
|
|
|
*
|
|
|
|
* The returned promise resolves once the reserve is set to the
|
|
|
|
* state DORMANT.
|
2016-02-09 21:56:06 +01:00
|
|
|
*/
|
2019-08-01 23:21:15 +02:00
|
|
|
async processReserve(reservePub: string): Promise<void> {
|
2019-12-02 17:35:47 +01:00
|
|
|
try {
|
|
|
|
return await processReserve(this.ws, reservePub);
|
|
|
|
} finally {
|
|
|
|
this.latch.trigger();
|
|
|
|
}
|
2016-01-24 19:57:09 +01:00
|
|
|
}
|
|
|
|
|
2016-02-09 21:56:06 +01:00
|
|
|
/**
|
|
|
|
* Create a reserve, but do not flag it as confirmed yet.
|
2017-04-28 23:28:27 +02:00
|
|
|
*
|
|
|
|
* Adds the corresponding exchange as a trusted exchange if it is neither
|
|
|
|
* audited nor trusted already.
|
2016-02-09 21:56:06 +01:00
|
|
|
*/
|
2020-07-16 19:22:56 +02:00
|
|
|
async acceptManualWithdrawal(
|
|
|
|
exchangeBaseUrl: string,
|
|
|
|
amount: AmountJson,
|
|
|
|
): Promise<AcceptManualWithdrawalResult> {
|
2019-12-02 17:35:47 +01:00
|
|
|
try {
|
2020-07-16 19:22:56 +02:00
|
|
|
const resp = await createReserve(this.ws, {
|
|
|
|
amount,
|
|
|
|
exchange: exchangeBaseUrl,
|
|
|
|
});
|
2021-06-09 15:14:17 +02:00
|
|
|
const exchangePaytoUris = await this.db
|
|
|
|
.mktx((x) => ({
|
|
|
|
exchanges: x.exchanges,
|
|
|
|
exchangeDetails: x.exchangeDetails,
|
|
|
|
reserves: x.reserves,
|
|
|
|
}))
|
|
|
|
.runReadWrite((tx) => getFundingPaytoUris(tx, resp.reservePub));
|
2020-07-16 19:22:56 +02:00
|
|
|
return {
|
|
|
|
reservePub: resp.reservePub,
|
|
|
|
exchangePaytoUris,
|
|
|
|
};
|
2019-12-02 17:35:47 +01:00
|
|
|
} finally {
|
|
|
|
this.latch.trigger();
|
|
|
|
}
|
2019-12-02 00:42:40 +01:00
|
|
|
}
|
2016-09-28 18:54:48 +02:00
|
|
|
|
2016-01-06 15:39:22 +01:00
|
|
|
/**
|
2019-12-02 00:42:40 +01:00
|
|
|
* Check if and how an exchange is trusted and/or audited.
|
2016-01-06 15:39:22 +01:00
|
|
|
*/
|
2019-12-02 00:42:40 +01:00
|
|
|
async getExchangeTrust(
|
|
|
|
exchangeInfo: ExchangeRecord,
|
|
|
|
): Promise<{ isTrusted: boolean; isAudited: boolean }> {
|
|
|
|
return getExchangeTrust(this.ws, exchangeInfo);
|
2019-11-30 00:36:20 +01:00
|
|
|
}
|
|
|
|
|
2020-08-03 09:30:48 +02:00
|
|
|
async getWithdrawalDetailsForUri(
|
|
|
|
talerWithdrawUri: string,
|
|
|
|
): Promise<WithdrawUriInfoResponse> {
|
2020-07-28 10:52:35 +02:00
|
|
|
return getWithdrawalDetailsForUri(this.ws, talerWithdrawUri);
|
2016-01-06 15:39:22 +01:00
|
|
|
}
|
|
|
|
|
2021-05-20 16:24:41 +02:00
|
|
|
async deleteTransaction(req: DeleteTransactionRequest): Promise<void> {
|
|
|
|
return deleteTransaction(this.ws, req.transactionId);
|
|
|
|
}
|
|
|
|
|
2021-06-14 11:21:29 +02:00
|
|
|
async setDeviceId(newDeviceId: string): Promise<void> {
|
|
|
|
return setWalletDeviceId(this.ws, newDeviceId);
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:17:02 +01:00
|
|
|
/**
|
2019-12-02 00:42:40 +01:00
|
|
|
* Update or add exchange DB entry by fetching the /keys and /wire information.
|
2016-02-11 18:17:02 +01:00
|
|
|
*/
|
2019-12-02 00:42:40 +01:00
|
|
|
async updateExchangeFromUrl(
|
|
|
|
baseUrl: string,
|
2020-04-06 17:45:41 +02:00
|
|
|
force = false,
|
2021-06-02 13:23:51 +02:00
|
|
|
): Promise<{
|
|
|
|
exchange: ExchangeRecord;
|
|
|
|
exchangeDetails: ExchangeDetailsRecord;
|
|
|
|
}> {
|
2019-12-06 11:01:39 +01:00
|
|
|
try {
|
|
|
|
return updateExchangeFromUrl(this.ws, baseUrl, force);
|
|
|
|
} finally {
|
|
|
|
this.latch.trigger();
|
|
|
|
}
|
2016-11-16 01:59:39 +01:00
|
|
|
}
|
|
|
|
|
2020-07-11 10:32:17 +02:00
|
|
|
async getExchangeTos(exchangeBaseUrl: string): Promise<GetExchangeTosResult> {
|
2021-06-02 13:23:51 +02:00
|
|
|
const { exchange, exchangeDetails } = await this.updateExchangeFromUrl(
|
|
|
|
exchangeBaseUrl,
|
|
|
|
);
|
|
|
|
const tos = exchangeDetails.termsOfServiceText;
|
|
|
|
const currentEtag = exchangeDetails.termsOfServiceLastEtag;
|
2020-07-11 10:32:17 +02:00
|
|
|
if (!tos || !currentEtag) {
|
|
|
|
throw Error("exchange is in invalid state");
|
|
|
|
}
|
|
|
|
return {
|
2021-06-02 13:23:51 +02:00
|
|
|
acceptedEtag: exchangeDetails.termsOfServiceAcceptedEtag,
|
2020-07-11 10:32:17 +02:00
|
|
|
currentEtag,
|
|
|
|
tos,
|
2020-07-16 19:22:56 +02:00
|
|
|
};
|
2020-07-11 10:32:17 +02:00
|
|
|
}
|
|
|
|
|
2017-10-15 18:30:02 +02:00
|
|
|
/**
|
2019-12-02 00:42:40 +01:00
|
|
|
* Get detailed balance information, sliced by exchange and by currency.
|
2017-10-15 18:30:02 +02:00
|
|
|
*/
|
2020-07-28 19:47:12 +02:00
|
|
|
async getBalances(): Promise<BalancesResponse> {
|
2019-12-05 19:38:19 +01:00
|
|
|
return this.ws.memoGetBalance.memo(() => getBalances(this.ws));
|
2019-12-02 00:42:40 +01:00
|
|
|
}
|
2017-10-15 18:30:02 +02:00
|
|
|
|
2019-12-15 16:59:00 +01:00
|
|
|
async refresh(oldCoinPub: string): Promise<void> {
|
2019-12-06 11:01:39 +01:00
|
|
|
try {
|
2021-06-09 15:14:17 +02:00
|
|
|
const refreshGroupId = await this.db
|
|
|
|
.mktx((x) => ({
|
|
|
|
refreshGroups: x.refreshGroups,
|
|
|
|
denominations: x.denominations,
|
|
|
|
coins: x.coins,
|
|
|
|
}))
|
|
|
|
.runReadWrite(async (tx) => {
|
2019-12-16 12:53:22 +01:00
|
|
|
return await createRefreshGroup(
|
2020-07-23 14:05:17 +02:00
|
|
|
this.ws,
|
2019-12-16 12:53:22 +01:00
|
|
|
tx,
|
|
|
|
[{ coinPub: oldCoinPub }],
|
|
|
|
RefreshReason.Manual,
|
|
|
|
);
|
2021-06-09 15:14:17 +02:00
|
|
|
});
|
2019-12-15 16:59:00 +01:00
|
|
|
await processRefreshGroup(this.ws, refreshGroupId.refreshGroupId);
|
2019-12-06 11:01:39 +01:00
|
|
|
} catch (e) {
|
|
|
|
this.latch.trigger();
|
|
|
|
}
|
2017-10-15 18:30:02 +02:00
|
|
|
}
|
|
|
|
|
2021-06-10 16:32:37 +02:00
|
|
|
async getPendingOperations(): Promise<PendingOperationsResponse> {
|
|
|
|
return this.ws.memoGetPending.memo(() => getPendingOperations(this.ws));
|
2019-11-19 16:16:12 +01:00
|
|
|
}
|
|
|
|
|
2019-12-09 19:59:08 +01:00
|
|
|
async acceptExchangeTermsOfService(
|
|
|
|
exchangeBaseUrl: string,
|
|
|
|
etag: string | undefined,
|
2020-04-06 20:02:01 +02:00
|
|
|
): Promise<void> {
|
2019-12-09 19:59:08 +01:00
|
|
|
return acceptExchangeTermsOfService(this.ws, exchangeBaseUrl, etag);
|
|
|
|
}
|
|
|
|
|
2020-07-09 15:26:18 +02:00
|
|
|
async getExchanges(): Promise<ExchangesListRespose> {
|
2021-06-02 13:23:51 +02:00
|
|
|
const exchanges: ExchangeListItem[] = [];
|
2021-06-09 15:14:17 +02:00
|
|
|
await this.db
|
|
|
|
.mktx((x) => ({
|
|
|
|
exchanges: x.exchanges,
|
|
|
|
exchangeDetails: x.exchangeDetails,
|
|
|
|
}))
|
|
|
|
.runReadOnly(async (tx) => {
|
|
|
|
const exchangeRecords = await tx.exchanges.iter().toArray();
|
|
|
|
for (const r of exchangeRecords) {
|
|
|
|
const dp = r.detailsPointer;
|
|
|
|
if (!dp) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const { currency, masterPublicKey } = dp;
|
|
|
|
const exchangeDetails = await getExchangeDetails(tx, r.baseUrl);
|
|
|
|
if (!exchangeDetails) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
exchanges.push({
|
|
|
|
exchangeBaseUrl: r.baseUrl,
|
|
|
|
currency,
|
|
|
|
paytoUris: exchangeDetails.wireInfo.accounts.map(
|
|
|
|
(x) => x.payto_uri,
|
|
|
|
),
|
|
|
|
});
|
|
|
|
}
|
2020-07-09 15:26:18 +02:00
|
|
|
});
|
2021-06-02 13:23:51 +02:00
|
|
|
return { exchanges };
|
2020-07-09 15:26:18 +02:00
|
|
|
}
|
|
|
|
|
2021-05-20 13:14:47 +02:00
|
|
|
async getCurrencies(): Promise<WalletCurrencyInfo> {
|
2021-06-09 15:14:17 +02:00
|
|
|
return await this.ws.db
|
|
|
|
.mktx((x) => ({
|
|
|
|
auditorTrust: x.auditorTrust,
|
|
|
|
exchangeTrust: x.exchangeTrust,
|
|
|
|
}))
|
|
|
|
.runReadOnly(async (tx) => {
|
|
|
|
const trustedAuditors = await tx.auditorTrust.iter().toArray();
|
|
|
|
const trustedExchanges = await tx.exchangeTrust.iter().toArray();
|
|
|
|
return {
|
|
|
|
trustedAuditors: trustedAuditors.map((x) => ({
|
|
|
|
currency: x.currency,
|
|
|
|
auditorBaseUrl: x.auditorBaseUrl,
|
|
|
|
auditorPub: x.auditorPub,
|
|
|
|
})),
|
|
|
|
trustedExchanges: trustedExchanges.map((x) => ({
|
|
|
|
currency: x.currency,
|
|
|
|
exchangeBaseUrl: x.exchangeBaseUrl,
|
|
|
|
exchangeMasterPub: x.exchangeMasterPub,
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
});
|
2019-11-21 23:09:43 +01:00
|
|
|
}
|
|
|
|
|
2017-06-05 02:00:03 +02:00
|
|
|
/**
|
|
|
|
* Stop ongoing processing.
|
|
|
|
*/
|
2020-04-06 20:02:01 +02:00
|
|
|
stop(): void {
|
2019-12-02 17:35:47 +01:00
|
|
|
this.stopped = true;
|
|
|
|
this.timerGroup.stopCurrentAndFutureTimers();
|
2019-12-05 19:38:19 +01:00
|
|
|
this.ws.cryptoApi.stop();
|
2017-06-05 02:00:03 +02:00
|
|
|
}
|
2017-08-14 04:16:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Trigger paying coins back into the user's account.
|
|
|
|
*/
|
|
|
|
async returnCoins(req: ReturnCoinsRequest): Promise<void> {
|
2019-12-19 20:42:49 +01:00
|
|
|
throw Error("not implemented");
|
2018-01-29 16:41:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Accept a refund, return the contract hash for the contract
|
|
|
|
* that was involved in the refund.
|
|
|
|
*/
|
2020-12-14 16:45:15 +01:00
|
|
|
async applyRefund(talerRefundUri: string): Promise<ApplyRefundResponse> {
|
2019-12-02 00:42:40 +01:00
|
|
|
return applyRefund(this.ws, talerRefundUri);
|
2017-08-27 03:56:19 +02:00
|
|
|
}
|
|
|
|
|
2019-11-30 00:36:20 +01:00
|
|
|
async acceptTip(talerTipUri: string): Promise<void> {
|
2019-12-06 11:01:39 +01:00
|
|
|
try {
|
|
|
|
return acceptTip(this.ws, talerTipUri);
|
|
|
|
} catch (e) {
|
|
|
|
this.latch.trigger();
|
|
|
|
}
|
2017-11-30 04:07:36 +01:00
|
|
|
}
|
|
|
|
|
2020-09-08 14:10:47 +02:00
|
|
|
async prepareTip(talerTipUri: string): Promise<PrepareTipResult> {
|
|
|
|
return prepareTip(this.ws, talerTipUri);
|
2017-11-30 04:07:36 +01:00
|
|
|
}
|
2017-12-10 21:34:56 +01:00
|
|
|
|
2020-09-08 22:48:03 +02:00
|
|
|
async abortFailedPayWithRefund(proposalId: string): Promise<void> {
|
|
|
|
return abortFailedPayWithRefund(this.ws, proposalId);
|
2018-01-29 16:41:17 +01:00
|
|
|
}
|
|
|
|
|
2019-12-09 19:59:08 +01:00
|
|
|
/**
|
|
|
|
* Inform the wallet that the status of a reserve has changed (e.g. due to a
|
|
|
|
* confirmation from the bank.).
|
|
|
|
*/
|
2020-04-06 20:02:01 +02:00
|
|
|
public async handleNotifyReserve(): Promise<void> {
|
2021-06-09 15:14:17 +02:00
|
|
|
const reserves = await this.ws.db
|
|
|
|
.mktx((x) => ({
|
|
|
|
reserves: x.reserves,
|
|
|
|
}))
|
|
|
|
.runReadOnly(async (tx) => {
|
|
|
|
return tx.reserves.iter().toArray();
|
|
|
|
});
|
2019-11-30 00:36:20 +01:00
|
|
|
for (const r of reserves) {
|
|
|
|
if (r.reserveStatus === ReserveRecordStatus.WAIT_CONFIRM_BANK) {
|
|
|
|
try {
|
2019-12-02 00:42:40 +01:00
|
|
|
this.processReserve(r.reservePub);
|
2019-11-30 00:36:20 +01:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-10 21:34:56 +01:00
|
|
|
/**
|
|
|
|
* Remove unreferenced / expired data from the wallet's database
|
|
|
|
* based on the current system time.
|
|
|
|
*/
|
2020-04-06 20:02:01 +02:00
|
|
|
async collectGarbage(): Promise<void> {
|
2019-08-20 17:58:01 +02:00
|
|
|
// FIXME(#5845)
|
|
|
|
// We currently do not garbage-collect the wallet database. This might change
|
|
|
|
// after the feature has been properly re-designed, and we have come up with a
|
|
|
|
// strategy to test it.
|
2017-12-10 21:34:56 +01:00
|
|
|
}
|
2017-12-12 16:39:55 +01:00
|
|
|
|
2019-08-29 23:12:55 +02:00
|
|
|
async acceptWithdrawal(
|
2019-08-28 02:49:27 +02:00
|
|
|
talerWithdrawUri: string,
|
|
|
|
selectedExchange: string,
|
2019-08-29 23:12:55 +02:00
|
|
|
): Promise<AcceptWithdrawalResponse> {
|
2019-12-06 11:01:39 +01:00
|
|
|
try {
|
2020-03-06 15:09:55 +01:00
|
|
|
return createTalerWithdrawReserve(
|
|
|
|
this.ws,
|
|
|
|
talerWithdrawUri,
|
|
|
|
selectedExchange,
|
|
|
|
);
|
2019-12-06 11:01:39 +01:00
|
|
|
} finally {
|
|
|
|
this.latch.trigger();
|
|
|
|
}
|
2019-08-28 02:49:27 +02:00
|
|
|
}
|
|
|
|
|
2019-12-20 01:25:22 +01:00
|
|
|
async refuseProposal(proposalId: string): Promise<void> {
|
|
|
|
return refuseProposal(this.ws, proposalId);
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:13 +02:00
|
|
|
benchmarkCrypto(repetitions: number): Promise<BenchmarkResult> {
|
2019-12-05 19:38:19 +01:00
|
|
|
return this.ws.cryptoApi.benchmark(repetitions);
|
2018-09-20 02:56:13 +02:00
|
|
|
}
|
2020-03-24 10:55:04 +01:00
|
|
|
|
|
|
|
async setCoinSuspended(coinPub: string, suspended: boolean): Promise<void> {
|
2021-06-09 15:14:17 +02:00
|
|
|
await this.db
|
|
|
|
.mktx((x) => ({
|
|
|
|
coins: x.coins,
|
|
|
|
}))
|
|
|
|
.runReadWrite(async (tx) => {
|
|
|
|
const c = await tx.coins.get(coinPub);
|
|
|
|
if (!c) {
|
|
|
|
logger.warn(`coin ${coinPub} not found, won't suspend`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
c.suspended = suspended;
|
|
|
|
await tx.coins.put(c);
|
|
|
|
});
|
2020-03-24 10:55:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dump the public information of coins we have in an easy-to-process format.
|
|
|
|
*/
|
|
|
|
async dumpCoins(): Promise<CoinDumpJson> {
|
|
|
|
const coinsJson: CoinDumpJson = { coins: [] };
|
2021-06-09 15:14:17 +02:00
|
|
|
await this.ws.db
|
|
|
|
.mktx((x) => ({
|
|
|
|
coins: x.coins,
|
|
|
|
denominations: x.denominations,
|
|
|
|
withdrawalGroups: x.withdrawalGroups,
|
|
|
|
}))
|
|
|
|
.runReadOnly(async (tx) => {
|
|
|
|
const coins = await tx.coins.iter().toArray();
|
|
|
|
for (const c of coins) {
|
|
|
|
const denom = await tx.denominations.get([
|
|
|
|
c.exchangeBaseUrl,
|
|
|
|
c.denomPubHash,
|
|
|
|
]);
|
|
|
|
if (!denom) {
|
|
|
|
console.error("no denom session found for coin");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const cs = c.coinSource;
|
|
|
|
let refreshParentCoinPub: string | undefined;
|
|
|
|
if (cs.type == CoinSourceType.Refresh) {
|
|
|
|
refreshParentCoinPub = cs.oldCoinPub;
|
|
|
|
}
|
|
|
|
let withdrawalReservePub: string | undefined;
|
|
|
|
if (cs.type == CoinSourceType.Withdraw) {
|
|
|
|
const ws = await tx.withdrawalGroups.get(cs.withdrawalGroupId);
|
|
|
|
if (!ws) {
|
|
|
|
console.error("no withdrawal session found for coin");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
withdrawalReservePub = ws.reservePub;
|
|
|
|
}
|
|
|
|
coinsJson.coins.push({
|
|
|
|
coin_pub: c.coinPub,
|
|
|
|
denom_pub: c.denomPub,
|
|
|
|
denom_pub_hash: c.denomPubHash,
|
|
|
|
denom_value: Amounts.stringify(denom.value),
|
|
|
|
exchange_base_url: c.exchangeBaseUrl,
|
|
|
|
refresh_parent_coin_pub: refreshParentCoinPub,
|
|
|
|
remaining_value: Amounts.stringify(c.currentAmount),
|
|
|
|
withdrawal_reserve_pub: withdrawalReservePub,
|
|
|
|
coin_suspended: c.suspended,
|
|
|
|
});
|
2020-03-24 10:55:04 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return coinsJson;
|
|
|
|
}
|
2020-05-12 10:38:58 +02:00
|
|
|
|
2020-05-15 09:23:35 +02:00
|
|
|
async getTransactions(
|
|
|
|
request: TransactionsRequest,
|
|
|
|
): Promise<TransactionsResponse> {
|
2020-05-12 10:38:58 +02:00
|
|
|
return getTransactions(this.ws, request);
|
|
|
|
}
|
2020-08-01 10:22:08 +02:00
|
|
|
|
2020-09-01 14:30:46 +02:00
|
|
|
async withdrawTestBalance(req: WithdrawTestBalanceRequest): Promise<void> {
|
|
|
|
await withdrawTestBalance(
|
|
|
|
this.ws,
|
|
|
|
req.amount,
|
|
|
|
req.bankBaseUrl,
|
|
|
|
req.exchangeBaseUrl,
|
|
|
|
);
|
2020-08-01 10:22:08 +02:00
|
|
|
}
|
2020-08-14 09:36:42 +02:00
|
|
|
|
2021-06-09 15:14:17 +02:00
|
|
|
async updateReserve(reservePub: string): Promise<ReserveRecord | undefined> {
|
|
|
|
await forceQueryReserve(this.ws, reservePub);
|
|
|
|
return await this.ws.db
|
|
|
|
.mktx((x) => ({
|
|
|
|
reserves: x.reserves,
|
|
|
|
}))
|
|
|
|
.runReadOnly(async (tx) => {
|
|
|
|
return tx.reserves.get(reservePub);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async getCoins(): Promise<CoinRecord[]> {
|
|
|
|
return await this.db
|
|
|
|
.mktx((x) => ({
|
|
|
|
coins: x.coins,
|
|
|
|
}))
|
|
|
|
.runReadOnly(async (tx) => {
|
|
|
|
return tx.coins.iter().toArray();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async getReservesForExchange(
|
|
|
|
exchangeBaseUrl?: string,
|
|
|
|
): Promise<ReserveRecord[]> {
|
|
|
|
return await this.db
|
|
|
|
.mktx((x) => ({
|
|
|
|
reserves: x.reserves,
|
|
|
|
}))
|
|
|
|
.runReadOnly(async (tx) => {
|
|
|
|
if (exchangeBaseUrl) {
|
|
|
|
return await tx.reserves
|
|
|
|
.iter()
|
|
|
|
.filter((r) => r.exchangeBaseUrl === exchangeBaseUrl);
|
|
|
|
} else {
|
|
|
|
return await tx.reserves.iter().toArray();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async getReserve(reservePub: string): Promise<ReserveRecord | undefined> {
|
|
|
|
return await this.db
|
|
|
|
.mktx((x) => ({
|
|
|
|
reserves: x.reserves,
|
|
|
|
}))
|
|
|
|
.runReadOnly(async (tx) => {
|
|
|
|
return tx.reserves.get(reservePub);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-14 09:36:42 +02:00
|
|
|
async runIntegrationtest(args: IntegrationTestArgs): Promise<void> {
|
|
|
|
return runIntegrationTest(this.ws.http, this, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
async testPay(args: TestPayArgs) {
|
|
|
|
return testPay(this.ws.http, this, args);
|
|
|
|
}
|
|
|
|
|
2021-01-07 15:01:23 +01:00
|
|
|
async exportBackupPlain() {
|
|
|
|
return exportBackup(this.ws);
|
|
|
|
}
|
|
|
|
|
|
|
|
async importBackupPlain(backup: any) {
|
|
|
|
return importBackupPlain(this.ws, backup);
|
|
|
|
}
|
|
|
|
|
2021-01-07 18:56:09 +01:00
|
|
|
async exportBackupEncrypted() {
|
|
|
|
return exportBackupEncrypted(this.ws);
|
|
|
|
}
|
|
|
|
|
|
|
|
async importBackupEncrypted(backup: Uint8Array) {
|
|
|
|
return importBackupEncrypted(this.ws, backup);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getBackupRecovery(): Promise<BackupRecovery> {
|
|
|
|
return getBackupRecovery(this.ws);
|
|
|
|
}
|
|
|
|
|
2021-01-08 13:30:29 +01:00
|
|
|
async loadBackupRecovery(req: RecoveryLoadRequest): Promise<void> {
|
|
|
|
return loadBackupRecovery(this.ws, req);
|
|
|
|
}
|
|
|
|
|
2021-01-07 18:56:09 +01:00
|
|
|
async addBackupProvider(req: AddBackupProviderRequest): Promise<void> {
|
|
|
|
return addBackupProvider(this.ws, req);
|
|
|
|
}
|
|
|
|
|
2021-01-18 23:35:41 +01:00
|
|
|
async createDepositGroup(
|
|
|
|
req: CreateDepositGroupRequest,
|
|
|
|
): Promise<CreateDepositGroupResponse> {
|
|
|
|
return createDepositGroup(this.ws, req);
|
|
|
|
}
|
|
|
|
|
2021-01-07 18:56:09 +01:00
|
|
|
async runBackupCycle(): Promise<void> {
|
|
|
|
return runBackupCycle(this.ws);
|
|
|
|
}
|
|
|
|
|
2021-01-08 13:30:29 +01:00
|
|
|
async getBackupStatus(): Promise<BackupInfo> {
|
|
|
|
return getBackupInfo(this.ws);
|
|
|
|
}
|
2021-01-13 00:51:30 +01:00
|
|
|
|
2021-01-18 23:35:41 +01:00
|
|
|
async trackDepositGroup(
|
|
|
|
req: TrackDepositGroupRequest,
|
|
|
|
): Promise<TrackDepositGroupResponse> {
|
|
|
|
return trackDepositGroup(this.ws, req);
|
|
|
|
}
|
|
|
|
|
2020-08-14 09:36:42 +02:00
|
|
|
/**
|
|
|
|
* Implementation of the "wallet-core" API.
|
|
|
|
*/
|
|
|
|
private async dispatchRequestInternal(
|
|
|
|
operation: string,
|
|
|
|
payload: unknown,
|
|
|
|
): Promise<Record<string, any>> {
|
|
|
|
switch (operation) {
|
|
|
|
case "withdrawTestkudos": {
|
2020-08-14 12:23:50 +02:00
|
|
|
await this.withdrawTestBalance({
|
|
|
|
amount: "TESTKUDOS:10",
|
|
|
|
bankBaseUrl: "https://bank.test.taler.net/",
|
|
|
|
exchangeBaseUrl: "https://exchange.test.taler.net/",
|
|
|
|
});
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
case "withdrawTestBalance": {
|
|
|
|
const req = codecForWithdrawTestBalance().decode(payload);
|
|
|
|
await this.withdrawTestBalance(req);
|
2020-08-14 09:36:42 +02:00
|
|
|
return {};
|
|
|
|
}
|
2020-08-14 12:48:48 +02:00
|
|
|
case "runIntegrationTest": {
|
2020-08-14 09:36:42 +02:00
|
|
|
const req = codecForIntegrationTestArgs().decode(payload);
|
|
|
|
await this.runIntegrationtest(req);
|
2020-09-01 14:30:46 +02:00
|
|
|
return {};
|
2020-08-14 09:36:42 +02:00
|
|
|
}
|
|
|
|
case "testPay": {
|
2020-08-14 12:23:50 +02:00
|
|
|
const req = codecForTestPayArgs().decode(payload);
|
|
|
|
await this.testPay(req);
|
2020-09-01 14:30:46 +02:00
|
|
|
return {};
|
2020-08-14 09:36:42 +02:00
|
|
|
}
|
|
|
|
case "getTransactions": {
|
|
|
|
const req = codecForTransactionsRequest().decode(payload);
|
|
|
|
return await this.getTransactions(req);
|
|
|
|
}
|
|
|
|
case "addExchange": {
|
|
|
|
const req = codecForAddExchangeRequest().decode(payload);
|
|
|
|
await this.updateExchangeFromUrl(req.exchangeBaseUrl);
|
|
|
|
return {};
|
|
|
|
}
|
2020-09-03 22:50:20 +02:00
|
|
|
case "forceUpdateExchange": {
|
|
|
|
const req = codecForForceExchangeUpdateRequest().decode(payload);
|
|
|
|
await this.updateExchangeFromUrl(req.exchangeBaseUrl, true);
|
|
|
|
return {};
|
|
|
|
}
|
2020-08-14 09:36:42 +02:00
|
|
|
case "listExchanges": {
|
|
|
|
return await this.getExchanges();
|
|
|
|
}
|
|
|
|
case "getWithdrawalDetailsForUri": {
|
|
|
|
const req = codecForGetWithdrawalDetailsForUri().decode(payload);
|
|
|
|
return await this.getWithdrawalDetailsForUri(req.talerWithdrawUri);
|
|
|
|
}
|
|
|
|
case "acceptManualWithdrawal": {
|
|
|
|
const req = codecForAcceptManualWithdrawalRequet().decode(payload);
|
|
|
|
const res = await this.acceptManualWithdrawal(
|
|
|
|
req.exchangeBaseUrl,
|
|
|
|
Amounts.parseOrThrow(req.amount),
|
|
|
|
);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
case "getWithdrawalDetailsForAmount": {
|
|
|
|
const req = codecForGetWithdrawalDetailsForAmountRequest().decode(
|
|
|
|
payload,
|
|
|
|
);
|
|
|
|
return await this.getWithdrawalDetailsForAmount(
|
|
|
|
req.exchangeBaseUrl,
|
|
|
|
Amounts.parseOrThrow(req.amount),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
case "getBalances": {
|
|
|
|
return await this.getBalances();
|
|
|
|
}
|
|
|
|
case "getPendingOperations": {
|
|
|
|
return await this.getPendingOperations();
|
|
|
|
}
|
|
|
|
case "setExchangeTosAccepted": {
|
|
|
|
const req = codecForAcceptExchangeTosRequest().decode(payload);
|
2020-09-01 14:30:46 +02:00
|
|
|
await this.acceptExchangeTermsOfService(req.exchangeBaseUrl, req.etag);
|
2020-08-14 09:36:42 +02:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
case "applyRefund": {
|
|
|
|
const req = codecForApplyRefundRequest().decode(payload);
|
|
|
|
return await this.applyRefund(req.talerRefundUri);
|
|
|
|
}
|
|
|
|
case "acceptBankIntegratedWithdrawal": {
|
|
|
|
const req = codecForAcceptBankIntegratedWithdrawalRequest().decode(
|
|
|
|
payload,
|
|
|
|
);
|
|
|
|
return await this.acceptWithdrawal(
|
|
|
|
req.talerWithdrawUri,
|
|
|
|
req.exchangeBaseUrl,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
case "getExchangeTos": {
|
|
|
|
const req = codecForGetExchangeTosRequest().decode(payload);
|
|
|
|
return this.getExchangeTos(req.exchangeBaseUrl);
|
|
|
|
}
|
|
|
|
case "retryPendingNow": {
|
|
|
|
await this.runPending(true);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
case "preparePay": {
|
|
|
|
const req = codecForPreparePayRequest().decode(payload);
|
|
|
|
return await this.preparePayForUri(req.talerPayUri);
|
|
|
|
}
|
|
|
|
case "confirmPay": {
|
|
|
|
const req = codecForConfirmPayRequest().decode(payload);
|
|
|
|
return await this.confirmPay(req.proposalId, req.sessionId);
|
|
|
|
}
|
2020-09-08 22:48:03 +02:00
|
|
|
case "abortFailedPayWithRefund": {
|
|
|
|
const req = codecForAbortPayWithRefundRequest().decode(payload);
|
|
|
|
await this.abortFailedPayWithRefund(req.proposalId);
|
|
|
|
return {};
|
|
|
|
}
|
2020-09-03 22:50:20 +02:00
|
|
|
case "dumpCoins": {
|
|
|
|
return await this.dumpCoins();
|
|
|
|
}
|
|
|
|
case "setCoinSuspended": {
|
|
|
|
const req = codecForSetCoinSuspendedRequest().decode(payload);
|
|
|
|
await this.setCoinSuspended(req.coinPub, req.suspended);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
case "forceRefresh": {
|
|
|
|
const req = codecForForceRefreshRequest().decode(payload);
|
|
|
|
const coinPubs = req.coinPubList.map((x) => ({ coinPub: x }));
|
2021-06-09 15:14:17 +02:00
|
|
|
const refreshGroupId = await this.db
|
|
|
|
.mktx((x) => ({
|
|
|
|
refreshGroups: x.refreshGroups,
|
|
|
|
denominations: x.denominations,
|
|
|
|
coins: x.coins,
|
|
|
|
}))
|
|
|
|
.runReadWrite(async (tx) => {
|
2020-09-03 22:50:20 +02:00
|
|
|
return await createRefreshGroup(
|
|
|
|
this.ws,
|
|
|
|
tx,
|
|
|
|
coinPubs,
|
|
|
|
RefreshReason.Manual,
|
|
|
|
);
|
2021-06-09 15:14:17 +02:00
|
|
|
});
|
2020-09-03 22:50:20 +02:00
|
|
|
return {
|
|
|
|
refreshGroupId,
|
|
|
|
};
|
|
|
|
}
|
2020-09-08 14:10:47 +02:00
|
|
|
case "prepareTip": {
|
|
|
|
const req = codecForPrepareTipRequest().decode(payload);
|
|
|
|
return await this.prepareTip(req.talerTipUri);
|
|
|
|
}
|
|
|
|
case "acceptTip": {
|
|
|
|
const req = codecForAcceptTipRequest().decode(payload);
|
|
|
|
await this.acceptTip(req.walletTipId);
|
|
|
|
return {};
|
|
|
|
}
|
2020-12-02 14:55:04 +01:00
|
|
|
case "exportBackup": {
|
|
|
|
return exportBackup(this.ws);
|
|
|
|
}
|
|
|
|
case "addBackupProvider": {
|
|
|
|
const req = codecForAddBackupProviderRequest().decode(payload);
|
|
|
|
await addBackupProvider(this.ws, req);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
case "runBackupCycle": {
|
|
|
|
await runBackupCycle(this.ws);
|
|
|
|
return {};
|
|
|
|
}
|
2021-03-10 17:11:59 +01:00
|
|
|
case "exportBackupRecovery": {
|
|
|
|
const resp = await getBackupRecovery(this.ws);
|
|
|
|
return resp;
|
|
|
|
}
|
|
|
|
case "importBackupRecovery": {
|
|
|
|
const req = codecForAny().decode(payload);
|
|
|
|
await loadBackupRecovery(this.ws, req);
|
|
|
|
return {};
|
|
|
|
}
|
2021-03-03 21:20:05 +01:00
|
|
|
case "getBackupInfo": {
|
|
|
|
const resp = await getBackupInfo(this.ws);
|
|
|
|
return resp;
|
|
|
|
}
|
2021-01-18 23:35:41 +01:00
|
|
|
case "createDepositGroup": {
|
|
|
|
const req = codecForCreateDepositGroupRequest().decode(payload);
|
|
|
|
return await createDepositGroup(this.ws, req);
|
|
|
|
}
|
2021-05-20 18:27:35 +02:00
|
|
|
case "trackDepositGroup": {
|
2021-01-18 23:35:41 +01:00
|
|
|
const req = codecForTrackDepositGroupRequest().decode(payload);
|
|
|
|
return trackDepositGroup(this.ws, req);
|
2021-05-20 18:27:35 +02:00
|
|
|
}
|
|
|
|
case "deleteTransaction": {
|
|
|
|
const req = codecForDeleteTransactionRequest().decode(payload);
|
|
|
|
await deleteTransaction(this.ws, req.transactionId);
|
|
|
|
return {};
|
|
|
|
}
|
2021-06-14 19:37:35 +02:00
|
|
|
case "retryTransaction": {
|
|
|
|
const req = codecForRetryTransactionRequest().decode(payload);
|
|
|
|
await retryTransaction(this.ws, req.transactionId);
|
|
|
|
return {};
|
|
|
|
}
|
2020-08-14 09:36:42 +02:00
|
|
|
}
|
|
|
|
throw OperationFailedError.fromCode(
|
|
|
|
TalerErrorCode.WALLET_CORE_API_OPERATION_UNKNOWN,
|
|
|
|
"unknown operation",
|
|
|
|
{
|
|
|
|
operation,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a request to the wallet-core API.
|
|
|
|
*/
|
|
|
|
async handleCoreApiRequest(
|
|
|
|
operation: string,
|
|
|
|
id: string,
|
|
|
|
payload: unknown,
|
|
|
|
): Promise<CoreApiResponse> {
|
|
|
|
try {
|
|
|
|
const result = await this.dispatchRequestInternal(operation, payload);
|
|
|
|
return {
|
|
|
|
type: "response",
|
|
|
|
operation,
|
|
|
|
id,
|
|
|
|
result,
|
|
|
|
};
|
|
|
|
} catch (e) {
|
|
|
|
if (
|
|
|
|
e instanceof OperationFailedError ||
|
|
|
|
e instanceof OperationFailedAndReportedError
|
|
|
|
) {
|
|
|
|
return {
|
|
|
|
type: "error",
|
|
|
|
operation,
|
|
|
|
id,
|
|
|
|
error: e.operationError,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
type: "error",
|
|
|
|
operation,
|
|
|
|
id,
|
|
|
|
error: makeErrorDetails(
|
|
|
|
TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION,
|
|
|
|
`unexpected exception: ${e}`,
|
|
|
|
{},
|
|
|
|
),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-18 01:16:31 +02:00
|
|
|
}
|