summaryrefslogtreecommitdiff
path: root/src/operations
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-07-16 22:52:56 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-07-16 22:52:56 +0530
commit85a095fa7d4d31e1e84e5e096fa28c59f3cd1918 (patch)
treebfad4a87f540c0ae1480fd2ab80911045f7f912e /src/operations
parentdd3a31f33dc54b475b204e15d8d0a5c5e2a70ee8 (diff)
downloadwallet-core-85a095fa7d4d31e1e84e5e096fa28c59f3cd1918.tar.gz
wallet-core-85a095fa7d4d31e1e84e5e096fa28c59f3cd1918.tar.bz2
wallet-core-85a095fa7d4d31e1e84e5e096fa28c59f3cd1918.zip
manual withdrawalv0.7.1-dev.8v0.7.1-dev.7
Diffstat (limited to 'src/operations')
-rw-r--r--src/operations/pending.ts14
-rw-r--r--src/operations/reserves.ts78
-rw-r--r--src/operations/transactions.ts19
3 files changed, 44 insertions, 67 deletions
diff --git a/src/operations/pending.ts b/src/operations/pending.ts
index cf9b306d6..e610d42ef 100644
--- a/src/operations/pending.ts
+++ b/src/operations/pending.ts
@@ -160,20 +160,6 @@ async function gatherReservePending(
case ReserveRecordStatus.DORMANT:
// nothing to report as pending
break;
- case ReserveRecordStatus.UNCONFIRMED:
- if (onlyDue) {
- break;
- }
- resp.pendingOperations.push({
- type: PendingOperationType.Reserve,
- givesLifeness: false,
- stage: reserve.reserveStatus,
- timestampCreated: reserve.timestampCreated,
- reserveType,
- reservePub: reserve.reservePub,
- retryInfo: reserve.retryInfo,
- });
- break;
case ReserveRecordStatus.WAIT_CONFIRM_BANK:
case ReserveRecordStatus.WITHDRAWING:
case ReserveRecordStatus.QUERYING_STATUS:
diff --git a/src/operations/reserves.ts b/src/operations/reserves.ts
index 965831704..7dd97decb 100644
--- a/src/operations/reserves.ts
+++ b/src/operations/reserves.ts
@@ -17,7 +17,6 @@
import {
CreateReserveRequest,
CreateReserveResponse,
- ConfirmReserveRequest,
OperationError,
AcceptWithdrawalResponse,
} from "../types/walletTypes";
@@ -66,6 +65,8 @@ import {
reconcileReserveHistory,
summarizeReserveHistory,
} from "../util/reserveHistoryUtil";
+import { TransactionHandle } from "../util/query";
+import { addPaytoQueryParams } from "../util/payto";
const logger = new Logger("reserves.ts");
@@ -99,14 +100,18 @@ export async function createReserve(
if (req.bankWithdrawStatusUrl) {
reserveStatus = ReserveRecordStatus.REGISTERING_BANK;
} else {
- reserveStatus = ReserveRecordStatus.UNCONFIRMED;
+ reserveStatus = ReserveRecordStatus.QUERYING_STATUS;
}
let bankInfo: ReserveBankInfo | undefined;
if (req.bankWithdrawStatusUrl) {
+ if (!req.exchangePaytoUri) {
+ throw Error("Exchange payto URI must be specified for a bank-integrated withdrawal");
+ }
bankInfo = {
statusUrl: req.bankWithdrawStatusUrl,
+ exchangePaytoUri: req.exchangePaytoUri,
};
}
@@ -129,10 +134,9 @@ export async function createReserve(
reservePriv: keypair.priv,
reservePub: keypair.pub,
senderWire: req.senderWire,
- timestampConfirmed: undefined,
+ timestampBankConfirmed: undefined,
timestampReserveInfoPosted: undefined,
bankInfo,
- exchangeWire: req.exchangeWire,
reserveStatus,
lastSuccessfulStatusQuery: undefined,
retryInfo: initRetryInfo(),
@@ -314,7 +318,7 @@ async function registerReserveWithBank(
// FIXME: parse bank response
await ws.http.postJson(bankStatusUrl, {
reserve_pub: reservePub,
- selected_exchange: reserve.exchangeWire,
+ selected_exchange: bankInfo.exchangePaytoUri,
});
await ws.db.mutate(Stores.reserves, reservePub, (r) => {
switch (r.reserveStatus) {
@@ -395,7 +399,7 @@ async function processReserveBankStatusImpl(
return;
}
const now = getTimestampNow();
- r.timestampConfirmed = now;
+ r.timestampBankConfirmed = now;
r.reserveStatus = ReserveRecordStatus.QUERYING_STATUS;
r.retryInfo = initRetryInfo();
return r;
@@ -461,10 +465,6 @@ async function updateReserve(
throw Error("reserve not in db");
}
- if (reserve.timestampConfirmed === undefined) {
- throw Error("reserve not confirmed yet");
- }
-
if (reserve.reserveStatus !== ReserveRecordStatus.QUERYING_STATUS) {
return;
}
@@ -590,9 +590,6 @@ async function processReserveImpl(
`Processing reserve ${reservePub} with status ${reserve.reserveStatus}`,
);
switch (reserve.reserveStatus) {
- case ReserveRecordStatus.UNCONFIRMED:
- // nothing to do
- break;
case ReserveRecordStatus.REGISTERING_BANK:
await processReserveBankStatus(ws, reservePub);
return await processReserveImpl(ws, reservePub, true);
@@ -615,28 +612,6 @@ async function processReserveImpl(
}
}
-export async function confirmReserve(
- ws: InternalWalletState,
- req: ConfirmReserveRequest,
-): Promise<void> {
- const now = getTimestampNow();
- await ws.db.mutate(Stores.reserves, req.reservePub, (reserve) => {
- if (reserve.reserveStatus !== ReserveRecordStatus.UNCONFIRMED) {
- return;
- }
- reserve.timestampConfirmed = now;
- reserve.reserveStatus = ReserveRecordStatus.QUERYING_STATUS;
- reserve.retryInfo = initRetryInfo();
- return reserve;
- });
-
- ws.notify({ type: NotificationType.ReserveUpdated });
-
- processReserve(ws, req.reservePub, true).catch((e) => {
- console.log("processing reserve (after confirmReserve) failed:", e);
- });
-}
-
/**
* Withdraw coins from a reserve until it is empty.
*
@@ -818,7 +793,7 @@ export async function createTalerWithdrawReserve(
bankWithdrawStatusUrl: withdrawInfo.extractedStatusUrl,
exchange: selectedExchange,
senderWire: withdrawInfo.senderWire,
- exchangeWire: exchangeWire,
+ exchangePaytoUri: exchangeWire,
});
// We do this here, as the reserve should be registered before we return,
// so that we can redirect the user to the bank's status page.
@@ -829,3 +804,34 @@ export async function createTalerWithdrawReserve(
confirmTransferUrl: withdrawInfo.confirmTransferUrl,
};
}
+
+/**
+ * Get payto URIs needed to fund a reserve.
+ */
+export async function getFundingPaytoUris(
+ tx: TransactionHandle,
+ reservePub: string,
+): Promise<string[]> {
+ const r = await tx.get(Stores.reserves, reservePub);
+ if (!r) {
+ logger.error(`reserve ${reservePub} not found (DB corrupted?)`);
+ return [];
+ }
+ const exchange = await tx.get(Stores.exchanges, r.exchangeBaseUrl);
+ if (!exchange) {
+ logger.error(`exchange ${r.exchangeBaseUrl} not found (DB corrupted?)`);
+ return [];
+ }
+ const plainPaytoUris =
+ exchange.wireInfo?.accounts.map((x) => x.payto_uri) ?? [];
+ if (!plainPaytoUris) {
+ logger.error(`exchange ${r.exchangeBaseUrl} has no wire info`);
+ return [];
+ }
+ return plainPaytoUris.map((x) =>
+ addPaytoQueryParams(x, {
+ amount: Amounts.stringify(r.instructedAmount),
+ message: `Taler Withdrawal ${r.reservePub}`,
+ }),
+ );
+}
diff --git a/src/operations/transactions.ts b/src/operations/transactions.ts
index bcf7a9e68..bdb68a3bb 100644
--- a/src/operations/transactions.ts
+++ b/src/operations/transactions.ts
@@ -35,9 +35,7 @@ import {
WithdrawalType,
WithdrawalDetails,
} from "../types/transactions";
-import { WithdrawalDetailsResponse } from "../types/walletTypes";
-import { Logger } from "../util/logging";
-import { addPaytoQueryParams } from "../util/payto";
+import { getFundingPaytoUris } from "./reserves";
/**
* Create an event ID from the type and the primary key for the event.
@@ -257,22 +255,9 @@ export async function getTransactions(
bankConfirmationUrl: r.bankInfo.confirmUrl,
}
} else {
- const exchange = await tx.get(Stores.exchanges, r.exchangeBaseUrl);
- if (!exchange) {
- // FIXME: report somehow
- return;
- }
- const plainPaytoUris = exchange.wireInfo?.accounts.map((x) => x.payto_uri) ?? [];
- if (!plainPaytoUris) {
- // FIXME: report somehow
- return;
- }
withdrawalDetails = {
type: WithdrawalType.ManualTransfer,
- exchangePaytoUris: plainPaytoUris.map((x) => addPaytoQueryParams(x, {
- amount: Amounts.stringify(r.instructedAmount),
- message: `Taler Withdrawal ${r.reservePub}`,
- })),
+ exchangePaytoUris: await getFundingPaytoUris(tx, r.reservePub),
};
}
transactions.push({