aboutsummaryrefslogtreecommitdiff
path: root/src/wallet-impl/pending.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-12-02 17:35:47 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-12-02 17:35:47 +0100
commitb5ee6b7b4ee506712f51e1b90e9256c4b0c0c603 (patch)
tree7d8bb4398ab52b58a5223d37e058eaea6c72f963 /src/wallet-impl/pending.ts
parente1369ff7e8fc02116b9c4261036f0e42e3423cf4 (diff)
downloadwallet-core-b5ee6b7b4ee506712f51e1b90e9256c4b0c0c603.tar.xz
pending operations WIP
Diffstat (limited to 'src/wallet-impl/pending.ts')
-rw-r--r--src/wallet-impl/pending.ts44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/wallet-impl/pending.ts b/src/wallet-impl/pending.ts
index a66571a34..dbc6672c7 100644
--- a/src/wallet-impl/pending.ts
+++ b/src/wallet-impl/pending.ts
@@ -14,18 +14,29 @@
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
- /**
- * Imports.
- */
-import { PendingOperationInfo, PendingOperationsResponse } from "../walletTypes";
+/**
+ * Imports.
+ */
+import {
+ PendingOperationInfo,
+ PendingOperationsResponse,
+ getTimestampNow,
+} from "../walletTypes";
import { oneShotIter } from "../util/query";
import { InternalWalletState } from "./state";
-import { Stores, ExchangeUpdateStatus, ReserveRecordStatus, CoinStatus, ProposalStatus } from "../dbTypes";
+import {
+ Stores,
+ ExchangeUpdateStatus,
+ ReserveRecordStatus,
+ CoinStatus,
+ ProposalStatus,
+} from "../dbTypes";
export async function getPendingOperations(
ws: InternalWalletState,
): Promise<PendingOperationsResponse> {
const pendingOperations: PendingOperationInfo[] = [];
+ let minRetryDurationMs = 5000;
const exchanges = await oneShotIter(ws.db, Stores.exchanges).toArray();
for (let e of exchanges) {
switch (e.updateStatus) {
@@ -92,9 +103,8 @@ export async function getPendingOperations(
}
}
await oneShotIter(ws.db, Stores.reserves).forEach(reserve => {
- const reserveType = reserve.bankWithdrawStatusUrl
- ? "taler-bank"
- : "manual";
+ const reserveType = reserve.bankWithdrawStatusUrl ? "taler-bank" : "manual";
+ const now = getTimestampNow();
switch (reserve.reserveStatus) {
case ReserveRecordStatus.DORMANT:
// nothing to report as pending
@@ -110,6 +120,11 @@ export async function getPendingOperations(
reserveType,
reservePub: reserve.reservePub,
});
+ if (reserve.created.t_ms < now.t_ms - 5000) {
+ minRetryDurationMs = 500;
+ } else if (reserve.created.t_ms < now.t_ms - 30000) {
+ minRetryDurationMs = 2000;
+ }
break;
case ReserveRecordStatus.WAIT_CONFIRM_BANK:
pendingOperations.push({
@@ -120,6 +135,11 @@ export async function getPendingOperations(
reservePub: reserve.reservePub,
bankWithdrawConfirmUrl: reserve.bankWithdrawConfirmUrl,
});
+ if (reserve.created.t_ms < now.t_ms - 5000) {
+ minRetryDurationMs = 500;
+ } else if (reserve.created.t_ms < now.t_ms - 30000) {
+ minRetryDurationMs = 2000;
+ }
break;
default:
pendingOperations.push({
@@ -164,10 +184,7 @@ export async function getPendingOperations(
});
await oneShotIter(ws.db, Stores.withdrawalSession).forEach(ws => {
- const numCoinsWithdrawn = ws.withdrawn.reduce(
- (a, x) => a + (x ? 1 : 0),
- 0,
- );
+ const numCoinsWithdrawn = ws.withdrawn.reduce((a, x) => a + (x ? 1 : 0), 0);
const numCoinsTotal = ws.withdrawn.length;
if (numCoinsWithdrawn < numCoinsTotal) {
pendingOperations.push({
@@ -204,5 +221,8 @@ export async function getPendingOperations(
return {
pendingOperations,
+ nextRetryDelay: {
+ d_ms: minRetryDurationMs,
+ },
};
}