aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/withdraw.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-05-20 12:48:44 -0300
committerSebastian <sebasjm@gmail.com>2024-05-20 12:48:44 -0300
commitabafae8a1bf5b8b22b09438eac1d2292b6f836f2 (patch)
tree9c41e2f19cb40dd112521087ddfc0d78d799b913 /packages/taler-wallet-core/src/withdraw.ts
parent184c3bcd2d7aabbc033b035fda34e86b3df2f98a (diff)
downloadwallet-core-abafae8a1bf5b8b22b09438eac1d2292b6f836f2.tar.xz
fix #8856 #8840
Diffstat (limited to 'packages/taler-wallet-core/src/withdraw.ts')
-rw-r--r--packages/taler-wallet-core/src/withdraw.ts123
1 files changed, 56 insertions, 67 deletions
diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts
index d14689b12..b95ab8548 100644
--- a/packages/taler-wallet-core/src/withdraw.ts
+++ b/packages/taler-wallet-core/src/withdraw.ts
@@ -235,10 +235,6 @@ async function updateWithdrawalTransaction(
wgRecord.wgInfo.withdrawalType === WithdrawalRecordType.BankManual
) {
checkDbInvariant(
- wgRecord.exchangeBaseUrl !== undefined,
- "manual withdrawal without exchange can't be created",
- );
- checkDbInvariant(
wgRecord.instructedAmount !== undefined,
"manual withdrawal without amount can't be created",
);
@@ -918,10 +914,6 @@ async function processPlanchetGenerate(
coinIdx: number,
): Promise<void> {
checkDbInvariant(
- withdrawalGroup.exchangeBaseUrl !== undefined,
- "can't process unitialized exchange",
- );
- checkDbInvariant(
withdrawalGroup.denomsSel !== undefined,
"can't process unitialized exchange",
);
@@ -1129,10 +1121,6 @@ async function processPlanchetExchangeBatchRequest(
logger.info(
`processing planchet exchange batch request ${withdrawalGroup.withdrawalGroupId}, start=${args.coinStartIndex}, len=${args.batchSize}`,
);
- checkDbInvariant(
- withdrawalGroup.exchangeBaseUrl !== undefined,
- "can't process unitialized exchange",
- );
const exchangeBaseUrl = withdrawalGroup.exchangeBaseUrl;
const batchReq: ExchangeBatchWithdrawRequest = { planchets: [] };
@@ -1268,10 +1256,6 @@ async function processPlanchetVerifyAndStoreCoin(
resp: ExchangeWithdrawResponse,
): Promise<void> {
const withdrawalGroup = wgContext.wgRecord;
- checkDbInvariant(
- withdrawalGroup.exchangeBaseUrl !== undefined,
- "can't process unitialized exchange",
- );
const exchangeBaseUrl = withdrawalGroup.exchangeBaseUrl;
logger.trace(`checking and storing planchet idx=${coinIdx}`);
@@ -1454,7 +1438,8 @@ export async function updateWithdrawalDenoms(
denom.verificationStatus === DenominationVerificationStatus.Unverified
) {
logger.trace(
- `Validating denomination (${current + 1}/${denominations.length
+ `Validating denomination (${current + 1}/${
+ denominations.length
}) signature of ${denom.denomPubHash}`,
);
let valid = false;
@@ -1520,10 +1505,6 @@ async function processQueryReserve(
return TaskRunResult.backoff();
}
checkDbInvariant(
- withdrawalGroup.exchangeBaseUrl !== undefined,
- "can't process unitialized exchange",
- );
- checkDbInvariant(
withdrawalGroup.denomsSel !== undefined,
"can't process unitialized exchange",
);
@@ -1576,8 +1557,10 @@ async function processQueryReserve(
) {
amountChanged = true;
}
- console.log(`amount change ${j2s(result.response)}`)
- console.log(`amount change ${j2s(withdrawalGroup.denomsSel.totalWithdrawCost)}`)
+ console.log(`amount change ${j2s(result.response)}`);
+ console.log(
+ `amount change ${j2s(withdrawalGroup.denomsSel.totalWithdrawCost)}`,
+ );
const exchangeBaseUrl = withdrawalGroup.exchangeBaseUrl;
const currency = Amounts.currencyOf(withdrawalGroup.instructedAmount);
@@ -1757,10 +1740,6 @@ async function redenominateWithdrawal(
return;
}
checkDbInvariant(
- wg.exchangeBaseUrl !== undefined,
- "can't process unitialized exchange",
- );
- checkDbInvariant(
wg.denomsSel !== undefined,
"can't process unitialized exchange",
);
@@ -1900,10 +1879,6 @@ async function processWithdrawalGroupPendingReady(
const ctx = new WithdrawTransactionContext(wex, withdrawalGroupId);
checkDbInvariant(
- withdrawalGroup.exchangeBaseUrl !== undefined,
- "can't process unitialized exchange",
- );
- checkDbInvariant(
withdrawalGroup.denomsSel !== undefined,
"can't process unitialized exchange",
);
@@ -2215,7 +2190,7 @@ export async function getExchangeWithdrawalInfo(
) {
logger.warn(
`wallet's support for exchange protocol version ${WALLET_EXCHANGE_PROTOCOL_VERSION} might be outdated ` +
- `(exchange has ${exchange.protocolVersionRange}), checking for updates`,
+ `(exchange has ${exchange.protocolVersionRange}), checking for updates`,
);
}
}
@@ -2333,10 +2308,6 @@ export async function getFundingPaytoUris(
const withdrawalGroup = await tx.withdrawalGroups.get(withdrawalGroupId);
checkDbInvariant(!!withdrawalGroup);
checkDbInvariant(
- withdrawalGroup.exchangeBaseUrl !== undefined,
- "can't get funding uri from uninitialized wg",
- );
- checkDbInvariant(
withdrawalGroup.instructedAmount !== undefined,
"can't get funding uri from uninitialized wg",
);
@@ -2684,7 +2655,7 @@ export async function internalPrepareCreateWithdrawalGroup(
args: {
reserveStatus: WithdrawalGroupStatus;
amount?: AmountJson;
- exchangeBaseUrl?: string;
+ exchangeBaseUrl: string;
forcedWithdrawalGroupId?: string;
forcedDenomSel?: ForcedDenomSel;
reserveKeyPair?: EddsaKeypair;
@@ -2725,19 +2696,11 @@ export async function internalPrepareCreateWithdrawalGroup(
let initialDenomSel: DenomSelectionState | undefined;
const denomSelUid = encodeCrock(getRandomBytes(16));
- const creationInfo =
- exchangeBaseUrl !== undefined && amount !== undefined
- ? {
- canonExchange: exchangeBaseUrl,
- amount,
- }
- : undefined;
-
- if (creationInfo) {
+ if (amount !== undefined) {
initialDenomSel = await getInitialDenomsSelection(
wex,
- creationInfo.canonExchange,
- creationInfo.amount,
+ exchangeBaseUrl,
+ amount,
args.forcedDenomSel,
);
}
@@ -2764,9 +2727,7 @@ export async function internalPrepareCreateWithdrawalGroup(
wgInfo: args.wgInfo,
};
- if (creationInfo) {
- await fetchFreshExchange(wex, creationInfo.canonExchange);
- }
+ await fetchFreshExchange(wex, exchangeBaseUrl);
const transactionId = constructTransactionIdentifier({
tag: TransactionType.Withdrawal,
@@ -2776,7 +2737,12 @@ export async function internalPrepareCreateWithdrawalGroup(
return {
withdrawalGroup,
transactionId,
- creationInfo,
+ creationInfo: !amount
+ ? undefined
+ : {
+ amount,
+ canonExchange: exchangeBaseUrl,
+ },
};
}
@@ -2871,8 +2837,8 @@ export async function internalCreateWithdrawalGroup(
wex: WalletExecutionContext,
args: {
reserveStatus: WithdrawalGroupStatus;
+ exchangeBaseUrl: string;
amount?: AmountJson;
- exchangeBaseUrl?: string;
forcedWithdrawalGroupId?: string;
forcedDenomSel?: ForcedDenomSel;
reserveKeyPair?: EddsaKeypair;
@@ -2917,6 +2883,7 @@ export async function prepareBankIntegratedWithdrawal(
wex: WalletExecutionContext,
req: {
talerWithdrawUri: string;
+ selectedExchange?: string;
},
): Promise<PrepareBankIntegratedWithdrawalResponse> {
const existingWithdrawalGroup = await wex.db.runReadOnlyTx(
@@ -2929,13 +2896,6 @@ export async function prepareBankIntegratedWithdrawal(
);
if (existingWithdrawalGroup) {
- let url: string | undefined;
- if (
- existingWithdrawalGroup.wgInfo.withdrawalType ===
- WithdrawalRecordType.BankIntegrated
- ) {
- url = existingWithdrawalGroup.wgInfo.bankInfo.confirmUrl;
- }
const info = await getWithdrawalDetailsForUri(wex, req.talerWithdrawUri);
return {
transactionId: constructTransactionIdentifier({
@@ -2945,6 +2905,18 @@ export async function prepareBankIntegratedWithdrawal(
info,
};
}
+ const withdrawInfo = await getBankWithdrawalInfo(
+ wex.http,
+ req.talerWithdrawUri,
+ );
+
+ const info = await getWithdrawalDetailsForUri(wex, req.talerWithdrawUri);
+
+ const exchangeBaseUrl =
+ req.selectedExchange ?? withdrawInfo.suggestedExchange;
+ if (!exchangeBaseUrl) {
+ return { info };
+ }
/**
* Withdrawal group without exchange and amount
@@ -2954,20 +2926,20 @@ export async function prepareBankIntegratedWithdrawal(
* same URI
*/
const withdrawalGroup = await internalCreateWithdrawalGroup(wex, {
+ exchangeBaseUrl,
wgInfo: {
withdrawalType: WithdrawalRecordType.BankIntegrated,
bankInfo: {
talerWithdrawUri: req.talerWithdrawUri,
- confirmUrl: undefined,
+ confirmUrl: withdrawInfo.confirmTransferUrl,
timestampBankConfirmed: undefined,
timestampReserveInfoPosted: undefined,
+ wireTypes: withdrawInfo.wireTypes,
},
},
reserveStatus: WithdrawalGroupStatus.DialogProposed,
});
- const info = await getWithdrawalDetailsForUri(wex, req.talerWithdrawUri);
-
const withdrawalGroupId = withdrawalGroup.withdrawalGroupId;
const ctx = new WithdrawTransactionContext(wex, withdrawalGroupId);
@@ -3010,19 +2982,34 @@ export async function confirmWithdrawal(
const exchange = await fetchFreshExchange(wex, selectedExchange);
const talerWithdrawUri = withdrawalGroup.wgInfo.bankInfo.talerWithdrawUri;
+ const confirmUrl = withdrawalGroup.wgInfo.bankInfo.confirmUrl;
+
+ /**
+ * The only reasong this to be undefined is because it is an old wallet
+ * database before adding the wireType field was added
+ */
+ let wtypes: string[];
+ if (withdrawalGroup.wgInfo.bankInfo.wireTypes === undefined) {
+ const withdrawInfo = await getBankWithdrawalInfo(
+ wex.http,
+ talerWithdrawUri,
+ );
+ wtypes = withdrawInfo.wireTypes;
+ } else {
+ wtypes = withdrawalGroup.wgInfo.bankInfo.wireTypes;
+ }
- const withdrawInfo = await getBankWithdrawalInfo(wex.http, talerWithdrawUri);
const exchangePaytoUri = await getExchangePaytoUri(
wex,
selectedExchange,
- withdrawInfo.wireTypes,
+ wtypes,
);
const withdrawalAccountList = await fetchWithdrawalAccountInfo(
wex,
{
exchange,
- instructedAmount: withdrawInfo.amount,
+ instructedAmount: Amounts.parseOrThrow(req.amount),
},
wex.cancellationToken,
);
@@ -3057,9 +3044,10 @@ export async function confirmWithdrawal(
bankInfo: {
exchangePaytoUri,
talerWithdrawUri,
- confirmUrl: withdrawInfo.confirmTransferUrl,
+ confirmUrl: confirmUrl,
timestampBankConfirmed: undefined,
timestampReserveInfoPosted: undefined,
+ wireTypes: wtypes,
},
};
@@ -3157,6 +3145,7 @@ export async function acceptWithdrawalFromUri(
confirmUrl: withdrawInfo.confirmTransferUrl,
timestampBankConfirmed: undefined,
timestampReserveInfoPosted: undefined,
+ wireTypes: withdrawInfo.wireTypes,
},
},
restrictAge: req.restrictAge,