aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-05-23 22:44:52 +0200
committerFlorian Dold <florian@dold.me>2024-05-23 22:44:52 +0200
commitec53ef04777cc1047079285538330de996e7e0f2 (patch)
treec068b786901c9491c1b9e46848fa9c362bb75ca1 /packages/taler-wallet-core
parent274b72f6ea4ac92e334b97a9cc427d64b2307217 (diff)
downloadwallet-core-ec53ef04777cc1047079285538330de996e7e0f2.tar.xz
Revert "wallet-core: implement acceptBankIntegratedWithdrawal via prepare/confirm step"
This reverts commit 274b72f6ea4ac92e334b97a9cc427d64b2307217.
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r--packages/taler-wallet-core/src/versions.ts2
-rw-r--r--packages/taler-wallet-core/src/withdraw.ts158
2 files changed, 97 insertions, 63 deletions
diff --git a/packages/taler-wallet-core/src/versions.ts b/packages/taler-wallet-core/src/versions.ts
index b89ff16f6..d33a23cdd 100644
--- a/packages/taler-wallet-core/src/versions.ts
+++ b/packages/taler-wallet-core/src/versions.ts
@@ -52,7 +52,7 @@ export const WALLET_BANK_CONVERSION_API_PROTOCOL_VERSION = "2:0:0";
/**
* Libtool version of the wallet-core API.
*/
-export const WALLET_CORE_API_PROTOCOL_VERSION = "6:0:0";
+export const WALLET_CORE_API_PROTOCOL_VERSION = "5:0:0";
/**
* Libtool rules:
diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts
index 7f43b4333..1dc4e0999 100644
--- a/packages/taler-wallet-core/src/withdraw.ts
+++ b/packages/taler-wallet-core/src/withdraw.ts
@@ -2953,7 +2953,6 @@ export async function prepareBankIntegratedWithdrawal(
},
},
reserveStatus: WithdrawalGroupStatus.DialogProposed,
- amount: info.amount == null ? undefined : Amounts.parseOrThrow(info.amount),
});
const withdrawalGroupId = withdrawalGroup.withdrawalGroupId;
@@ -3000,25 +2999,6 @@ export async function confirmWithdrawal(
const talerWithdrawUri = withdrawalGroup.wgInfo.bankInfo.talerWithdrawUri;
const confirmUrl = withdrawalGroup.wgInfo.bankInfo.confirmUrl;
- let amount: AmountString;
-
- if (withdrawalGroup.instructedAmount == null) {
- if (req.amount == null) {
- throw Error(
- "neither the withdrawal group nor the request specifies an amount",
- );
- }
- amount = req.amount;
- } else {
- if (
- req.amount != null &&
- Amounts.cmp(withdrawalGroup.instructedAmount, req.amount) != 0
- ) {
- throw Error("conflicting amount");
- }
- amount = withdrawalGroup.instructedAmount;
- }
-
/**
* The only reason this could be undefined is because it is an old wallet
* database before adding the wireType field was added
@@ -3044,7 +3024,7 @@ export async function confirmWithdrawal(
wex,
{
exchange,
- instructedAmount: Amounts.parseOrThrow(amount),
+ instructedAmount: Amounts.parseOrThrow(req.amount),
},
wex.cancellationToken,
);
@@ -3056,7 +3036,7 @@ export async function confirmWithdrawal(
const initalDenoms = await getInitialDenomsSelection(
wex,
req.exchangeBaseUrl,
- Amounts.parseOrThrow(amount),
+ Amounts.parseOrThrow(req.amount),
req.forcedDenomSel,
);
@@ -3067,7 +3047,7 @@ export async function confirmWithdrawal(
switch (rec.status) {
case WithdrawalGroupStatus.DialogProposed: {
rec.exchangeBaseUrl = req.exchangeBaseUrl;
- rec.instructedAmount = amount;
+ rec.instructedAmount = req.amount;
rec.denomsSel = initalDenoms;
rec.rawWithdrawalAmount = initalDenoms.totalWithdrawCost;
rec.effectiveWithdrawalAmount = initalDenoms.totalCoinValue;
@@ -3094,11 +3074,6 @@ export async function confirmWithdrawal(
}
});
- wex.ws.notify({
- type: NotificationType.BalanceChange,
- hintTransactionId: ctx.transactionId,
- });
-
await wex.taskScheduler.resetTaskRetries(ctx.taskId);
}
@@ -3122,54 +3097,113 @@ export async function acceptWithdrawalFromUri(
amount?: AmountLike;
},
): Promise<AcceptWithdrawalResponse> {
- const resp = await prepareBankIntegratedWithdrawal(wex, {
- talerWithdrawUri: req.talerWithdrawUri,
- selectedExchange: req.selectedExchange,
- });
+ const selectedExchange = req.selectedExchange;
+ logger.info(
+ `accepting withdrawal via ${req.talerWithdrawUri}, canonicalized selected exchange ${selectedExchange}`,
+ );
+ const existingWithdrawalGroup = await wex.db.runReadOnlyTx(
+ { storeNames: ["withdrawalGroups"] },
+ async (tx) => {
+ return await tx.withdrawalGroups.indexes.byTalerWithdrawUri.get(
+ req.talerWithdrawUri,
+ );
+ },
+ );
- const transactionId = resp.transactionId;
- if (!transactionId) {
- throw Error("internal error, no transaction ID");
+ if (existingWithdrawalGroup) {
+ let url: string | undefined;
+ if (
+ existingWithdrawalGroup.wgInfo.withdrawalType ===
+ WithdrawalRecordType.BankIntegrated
+ ) {
+ url = existingWithdrawalGroup.wgInfo.bankInfo.confirmUrl;
+ }
+ return {
+ reservePub: existingWithdrawalGroup.reservePub,
+ confirmTransferUrl: url,
+ transactionId: constructTransactionIdentifier({
+ tag: TransactionType.Withdrawal,
+ withdrawalGroupId: existingWithdrawalGroup.withdrawalGroupId,
+ }),
+ };
}
- await confirmWithdrawal(wex, {
- transactionId,
- amount: req.amount == null ? undefined : Amounts.stringify(req.amount),
+ const exchange = await fetchFreshExchange(wex, selectedExchange);
+ const withdrawInfo = await getBankWithdrawalInfo(
+ wex.http,
+ req.talerWithdrawUri,
+ );
+ const exchangePaytoUri = await getExchangePaytoUri(
+ wex,
+ selectedExchange,
+ withdrawInfo.wireTypes,
+ );
+
+ let amount: AmountJson;
+ if (withdrawInfo.amount == null) {
+ if (req.amount == null) {
+ throw Error(
+ "amount required, as withdrawal operation has flexible amount",
+ );
+ }
+ amount = Amounts.parseOrThrow(req.amount);
+ } else {
+ if (
+ req.amount != null &&
+ Amounts.cmp(req.amount, withdrawInfo.amount) != 0
+ ) {
+ throw Error(
+ "mismatched amount, amount is fixed by bank but client provided different amount",
+ );
+ }
+ amount = withdrawInfo.amount;
+ }
+
+ const withdrawalAccountList = await fetchWithdrawalAccountInfo(
+ wex,
+ {
+ exchange,
+ instructedAmount: amount,
+ },
+ CancellationToken.CONTINUE,
+ );
+
+ const withdrawalGroup = await internalCreateWithdrawalGroup(wex, {
+ amount,
exchangeBaseUrl: req.selectedExchange,
- forcedDenomSel: req.forcedDenomSel,
+ wgInfo: {
+ withdrawalType: WithdrawalRecordType.BankIntegrated,
+ exchangeCreditAccounts: withdrawalAccountList,
+ bankInfo: {
+ exchangePaytoUri,
+ talerWithdrawUri: req.talerWithdrawUri,
+ confirmUrl: withdrawInfo.confirmTransferUrl,
+ timestampBankConfirmed: undefined,
+ timestampReserveInfoPosted: undefined,
+ wireTypes: withdrawInfo.wireTypes,
+ },
+ },
restrictAge: req.restrictAge,
+ forcedDenomSel: req.forcedDenomSel,
+ reserveStatus: WithdrawalGroupStatus.PendingRegisteringBank,
});
- const parsedTx = parseTransactionIdentifier(transactionId);
- checkLogicInvariant(parsedTx?.tag === TransactionType.Withdrawal);
-
- const ctx = new WithdrawTransactionContext(wex, parsedTx.withdrawalGroupId);
+ const withdrawalGroupId = withdrawalGroup.withdrawalGroupId;
- await waitWithdrawalRegistered(wex, ctx);
+ const ctx = new WithdrawTransactionContext(wex, withdrawalGroupId);
- const withdrawalGroup = await wex.db.runReadOnlyTx(
- {
- storeNames: ["withdrawalGroups"],
- },
- async (tx) => {
- return tx.withdrawalGroups.get(parsedTx.withdrawalGroupId);
- },
- );
+ wex.ws.notify({
+ type: NotificationType.BalanceChange,
+ hintTransactionId: ctx.transactionId,
+ });
- if (!withdrawalGroup) {
- throw Error("withdrawal group does not exist anymore");
- }
+ wex.taskScheduler.startShepherdTask(ctx.taskId);
- if (
- withdrawalGroup.wgInfo.withdrawalType !==
- WithdrawalRecordType.BankIntegrated
- ) {
- throw Error("withdrawal group has unexpected withdrawal type");
- }
+ await waitWithdrawalRegistered(wex, ctx);
return {
reservePub: withdrawalGroup.reservePub,
- confirmTransferUrl: withdrawalGroup.wgInfo.bankInfo.confirmUrl,
+ confirmTransferUrl: withdrawInfo.confirmTransferUrl,
transactionId: ctx.transactionId,
};
}