aboutsummaryrefslogtreecommitdiff
path: root/src/operations
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-04-07 13:37:32 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-04-07 13:37:32 +0530
commitfb2e2f89935240666de66e4b2c11125cb3b2943d (patch)
tree7b7e148e6cce7bf7639a5e35102f5269f5920ab5 /src/operations
parent1471aae8927c20d646cc2aa5ab0e20c1a7f2c0ca (diff)
downloadwallet-core-fb2e2f89935240666de66e4b2c11125cb3b2943d.tar.xz
more lint fixes
Diffstat (limited to 'src/operations')
-rw-r--r--src/operations/balance.ts4
-rw-r--r--src/operations/exchanges.ts3
-rw-r--r--src/operations/pending.ts26
-rw-r--r--src/operations/recoup.ts4
-rw-r--r--src/operations/refresh.ts13
-rw-r--r--src/operations/refund.ts2
-rw-r--r--src/operations/reserves.ts38
-rw-r--r--src/operations/state.ts2
-rw-r--r--src/operations/tip.ts7
-rw-r--r--src/operations/withdraw.ts20
10 files changed, 53 insertions, 66 deletions
diff --git a/src/operations/balance.ts b/src/operations/balance.ts
index 7c2d0e3fe..c369af193 100644
--- a/src/operations/balance.ts
+++ b/src/operations/balance.ts
@@ -18,9 +18,9 @@
* Imports.
*/
import { WalletBalance, WalletBalanceEntry } from "../types/walletTypes";
-import { Database, TransactionHandle } from "../util/query";
+import { TransactionHandle } from "../util/query";
import { InternalWalletState } from "./state";
-import { Stores, TipRecord, CoinStatus } from "../types/dbTypes";
+import { Stores, CoinStatus } from "../types/dbTypes";
import * as Amounts from "../util/amounts";
import { AmountJson } from "../util/amounts";
import { Logger } from "../util/logging";
diff --git a/src/operations/exchanges.ts b/src/operations/exchanges.ts
index 27fed0b6c..a9e5158e9 100644
--- a/src/operations/exchanges.ts
+++ b/src/operations/exchanges.ts
@@ -460,7 +460,8 @@ export async function updateExchangeFromUrl(
baseUrl: string,
forceNow = false,
): Promise<ExchangeRecord> {
- const onOpErr = (e: OperationError): Promise<void> => setExchangeError(ws, baseUrl, e);
+ const onOpErr = (e: OperationError): Promise<void> =>
+ setExchangeError(ws, baseUrl, e);
return await guardOperationException(
() => updateExchangeFromUrlImpl(ws, baseUrl, forceNow),
onOpErr,
diff --git a/src/operations/pending.ts b/src/operations/pending.ts
index cee929aa2..3e548a27f 100644
--- a/src/operations/pending.ts
+++ b/src/operations/pending.ts
@@ -37,7 +37,7 @@ import {
} from "../util/time";
import { TransactionHandle } from "../util/query";
import { InternalWalletState } from "./state";
-import { getBalances, getBalancesInsideTransaction } from "./balance";
+import { getBalancesInsideTransaction } from "./balance";
import { ReserveType } from "../types/history";
function updateRetryDelay(
@@ -286,13 +286,23 @@ async function gatherProposalPending(
if (onlyDue) {
return;
}
- resp.pendingOperations.push({
- type: PendingOperationType.ProposalChoice,
- givesLifeness: false,
- merchantBaseUrl: proposal.download!!.contractData.merchantBaseUrl,
- proposalId: proposal.proposalId,
- proposalTimestamp: proposal.timestamp,
- });
+ const dl = proposal.download;
+ if (!dl) {
+ resp.pendingOperations.push({
+ type: PendingOperationType.Bug,
+ message: "proposal is in invalid state",
+ details: {},
+ givesLifeness: false,
+ });
+ } else {
+ resp.pendingOperations.push({
+ type: PendingOperationType.ProposalChoice,
+ givesLifeness: false,
+ merchantBaseUrl: dl.contractData.merchantBaseUrl,
+ proposalId: proposal.proposalId,
+ proposalTimestamp: proposal.timestamp,
+ });
+ }
} else if (proposal.proposalStatus == ProposalStatus.DOWNLOADING) {
resp.nextRetryDelay = updateRetryDelay(
resp.nextRetryDelay,
diff --git a/src/operations/recoup.ts b/src/operations/recoup.ts
index 97bc39564..e1c2325d7 100644
--- a/src/operations/recoup.ts
+++ b/src/operations/recoup.ts
@@ -279,7 +279,7 @@ async function recoupRefreshCoin(
async function resetRecoupGroupRetry(
ws: InternalWalletState,
recoupGroupId: string,
-) {
+): Promise<void> {
await ws.db.mutate(Stores.recoupGroups, recoupGroupId, (x) => {
if (x.retryInfo.active) {
x.retryInfo = initRetryInfo();
@@ -294,7 +294,7 @@ export async function processRecoupGroup(
forceNow = false,
): Promise<void> {
await ws.memoProcessRecoup.memo(recoupGroupId, async () => {
- const onOpErr = (e: OperationError) =>
+ const onOpErr = (e: OperationError): Promise<void> =>
incrementRecoupRetry(ws, recoupGroupId, e);
return await guardOperationException(
async () => await processRecoupGroupImpl(ws, recoupGroupId, forceNow),
diff --git a/src/operations/refresh.ts b/src/operations/refresh.ts
index 23d192e0a..924769334 100644
--- a/src/operations/refresh.ts
+++ b/src/operations/refresh.ts
@@ -28,7 +28,7 @@ import {
CoinSourceType,
} from "../types/dbTypes";
import { amountToPretty } from "../util/helpers";
-import { Database, TransactionHandle } from "../util/query";
+import { TransactionHandle } from "../util/query";
import { InternalWalletState } from "./state";
import { Logger } from "../util/logging";
import { getWithdrawDenomList } from "./withdraw";
@@ -390,8 +390,7 @@ async function refreshReveal(
console.error("denom not found");
continue;
}
- const pc =
- refreshSession.planchetsForGammas[refreshSession.norevealIndex!][i];
+ const pc = refreshSession.planchetsForGammas[norevealIndex][i];
const denomSig = await ws.cryptoApi.rsaUnblind(
respJson.ev_sigs[i].ev_sig,
pc.blindingKey,
@@ -485,7 +484,7 @@ export async function processRefreshGroup(
forceNow = false,
): Promise<void> {
await ws.memoProcessRefresh.memo(refreshGroupId, async () => {
- const onOpErr = (e: OperationError) =>
+ const onOpErr = (e: OperationError): Promise<void> =>
incrementRefreshRetry(ws, refreshGroupId, e);
return await guardOperationException(
async () => await processRefreshGroupImpl(ws, refreshGroupId, forceNow),
@@ -497,7 +496,7 @@ export async function processRefreshGroup(
async function resetRefreshGroupRetry(
ws: InternalWalletState,
refreshSessionId: string,
-) {
+): Promise<void> {
await ws.db.mutate(Stores.refreshGroups, refreshSessionId, (x) => {
if (x.retryInfo.active) {
x.retryInfo = initRetryInfo();
@@ -510,7 +509,7 @@ async function processRefreshGroupImpl(
ws: InternalWalletState,
refreshGroupId: string,
forceNow: boolean,
-) {
+): Promise<void> {
if (forceNow) {
await resetRefreshGroupRetry(ws, refreshGroupId);
}
@@ -532,7 +531,7 @@ async function processRefreshSession(
ws: InternalWalletState,
refreshGroupId: string,
coinIndex: number,
-) {
+): Promise<void> {
logger.trace(
`processing refresh session for coin ${coinIndex} of group ${refreshGroupId}`,
);
diff --git a/src/operations/refund.ts b/src/operations/refund.ts
index af9a48895..8feb2baea 100644
--- a/src/operations/refund.ts
+++ b/src/operations/refund.ts
@@ -465,7 +465,7 @@ async function processPurchaseApplyRefundImpl(
// Avoid duplicates
const refreshCoinsMap: { [coinPub: string]: CoinPublicKey } = {};
- const modCoin = async (perm: MerchantRefundPermission) => {
+ const modCoin = async (perm: MerchantRefundPermission): Promise<void> => {
const c = await tx.get(Stores.coins, perm.coin_pub);
if (!c) {
console.warn("coin not found, can't apply refund");
diff --git a/src/operations/reserves.ts b/src/operations/reserves.ts
index 2ee1b358f..153ad6b88 100644
--- a/src/operations/reserves.ts
+++ b/src/operations/reserves.ts
@@ -44,10 +44,7 @@ import {
getExchangeTrust,
getExchangePaytoUri,
} from "./exchanges";
-import {
- WithdrawOperationStatusResponse,
- codecForWithdrawOperationStatusResponse,
-} from "../types/talerTypes";
+import { codecForWithdrawOperationStatusResponse } from "../types/talerTypes";
import { assertUnreachable } from "../util/assertUnreachable";
import { encodeCrock, getRandomBytes } from "../crypto/talerCrypto";
import { randomBytes } from "../crypto/primitives/nacl-fast";
@@ -71,7 +68,10 @@ import {
const logger = new Logger("reserves.ts");
-async function resetReserveRetry(ws: InternalWalletState, reservePub: string) {
+async function resetReserveRetry(
+ ws: InternalWalletState,
+ reservePub: string,
+): Promise<void> {
await ws.db.mutate(Stores.reserves, reservePub, (x) => {
if (x.retryInfo.active) {
x.retryInfo = initRetryInfo();
@@ -101,8 +101,6 @@ export async function createReserve(
reserveStatus = ReserveRecordStatus.UNCONFIRMED;
}
- const currency = req.amount.currency;
-
const reserveRecord: ReserveRecord = {
timestampCreated: now,
exchangeBaseUrl: canonExchange,
@@ -251,7 +249,7 @@ export async function processReserve(
forceNow = false,
): Promise<void> {
return ws.memoProcessReserve.memo(reservePub, async () => {
- const onOpError = (err: OperationError) =>
+ const onOpError = (err: OperationError): Promise<void> =>
incrementReserveRetry(ws, reservePub, err);
await guardOperationException(
() => processReserveImpl(ws, reservePub, forceNow),
@@ -280,7 +278,8 @@ async function registerReserveWithBank(
if (reserve.timestampReserveInfoPosted) {
throw Error("bank claims that reserve info selection is not done");
}
- const bankResp = await ws.http.postJson(bankStatusUrl, {
+ // FIXME: parse bank response
+ await ws.http.postJson(bankStatusUrl, {
reserve_pub: reservePub,
selected_exchange: reserve.exchangeWire,
});
@@ -305,7 +304,7 @@ export async function processReserveBankStatus(
ws: InternalWalletState,
reservePub: string,
): Promise<void> {
- const onOpError = (err: OperationError) =>
+ const onOpError = (err: OperationError): Promise<void> =>
incrementReserveRetry(ws, reservePub, err);
await guardOperationException(
() => processReserveBankStatusImpl(ws, reservePub),
@@ -330,20 +329,13 @@ async function processReserveBankStatusImpl(
return;
}
- let status: WithdrawOperationStatusResponse;
- try {
- const statusResp = await ws.http.get(bankStatusUrl);
- if (statusResp.status !== 200) {
- throw Error(
- `unexpected status ${statusResp.status} for bank status query`,
- );
- }
- status = codecForWithdrawOperationStatusResponse().decode(
- await statusResp.json(),
- );
- } catch (e) {
- throw e;
+ const statusResp = await ws.http.get(bankStatusUrl);
+ if (statusResp.status !== 200) {
+ throw Error(`unexpected status ${statusResp.status} for bank status query`);
}
+ const status = codecForWithdrawOperationStatusResponse().decode(
+ await statusResp.json(),
+ );
ws.notify({ type: NotificationType.Wildcard });
diff --git a/src/operations/state.ts b/src/operations/state.ts
index 246a71266..97d591244 100644
--- a/src/operations/state.ts
+++ b/src/operations/state.ts
@@ -49,7 +49,7 @@ export class InternalWalletState {
this.cryptoApi = new CryptoApi(cryptoWorkerFactory);
}
- public notify(n: WalletNotification) {
+ public notify(n: WalletNotification): void {
logger.trace("Notification", n);
for (const l of this.listeners) {
const nc = JSON.parse(JSON.stringify(n));
diff --git a/src/operations/tip.ts b/src/operations/tip.ts
index 1a88dbca3..6f492ea31 100644
--- a/src/operations/tip.ts
+++ b/src/operations/tip.ts
@@ -18,9 +18,7 @@ import { InternalWalletState } from "./state";
import { parseTipUri } from "../util/taleruri";
import { TipStatus, OperationError } from "../types/walletTypes";
import {
- TipPickupGetResponse,
TipPlanchetDetail,
- TipResponse,
codecForTipPickupGetResponse,
codecForTipResponse,
} from "../types/talerTypes";
@@ -149,7 +147,8 @@ export async function processTip(
tipId: string,
forceNow = false,
): Promise<void> {
- const onOpErr = (e: OperationError) => incrementTipRetry(ws, tipId, e);
+ const onOpErr = (e: OperationError): Promise<void> =>
+ incrementTipRetry(ws, tipId, e);
await guardOperationException(
() => processTipImpl(ws, tipId, forceNow),
onOpErr,
@@ -172,7 +171,7 @@ async function processTipImpl(
ws: InternalWalletState,
tipId: string,
forceNow: boolean,
-) {
+): Promise<void> {
if (forceNow) {
await resetTipRetry(ws, tipId);
}
diff --git a/src/operations/withdraw.ts b/src/operations/withdraw.ts
index 70ecf9aed..1f5bfd0b9 100644
--- a/src/operations/withdraw.ts
+++ b/src/operations/withdraw.ts
@@ -21,7 +21,6 @@ import {
DenominationStatus,
CoinStatus,
CoinRecord,
- PlanchetRecord,
initRetryInfo,
updateRetryInfoTimeout,
CoinSourceType,
@@ -52,14 +51,10 @@ import {
timestampCmp,
timestampSubtractDuraction,
} from "../util/time";
-import {
- summarizeReserveHistory,
- ReserveHistorySummary,
-} from "../util/reserveHistoryUtil";
const logger = new Logger("withdraw.ts");
-function isWithdrawableDenom(d: DenominationRecord) {
+function isWithdrawableDenom(d: DenominationRecord): boolean {
const now = getTimestampNow();
const started = timestampCmp(now, d.stampStart) >= 0;
const lastPossibleWithdraw = timestampSubtractDuraction(
@@ -175,8 +170,6 @@ async function processPlanchet(
if (withdrawalGroup.withdrawn[coinIdx]) {
return;
}
- if (withdrawalGroup.source.type === "reserve") {
- }
const planchet = withdrawalGroup.planchets[coinIdx];
if (!planchet) {
console.log("processPlanchet: planchet not found");
@@ -248,7 +241,6 @@ async function processPlanchet(
};
let withdrawalGroupFinished = false;
- let summary: ReserveHistorySummary | undefined = undefined;
const success = await ws.db.runWithWriteTransaction(
[Stores.coins, Stores.withdrawalGroups, Stores.reserves],
@@ -276,12 +268,6 @@ async function processPlanchet(
withdrawalGroupFinished = true;
}
await tx.put(Stores.withdrawalGroups, ws);
- if (!planchet.isFromTip) {
- const r = await tx.get(Stores.reserves, planchet.reservePub);
- if (r) {
- summary = summarizeReserveHistory(r.reserveTransactions, r.currency);
- }
- }
await tx.add(Stores.coins, coin);
return true;
},
@@ -396,7 +382,7 @@ export async function processWithdrawGroup(
withdrawalGroupId: string,
forceNow = false,
): Promise<void> {
- const onOpErr = (e: OperationError) =>
+ const onOpErr = (e: OperationError): Promise<void> =>
incrementWithdrawalRetry(ws, withdrawalGroupId, e);
await guardOperationException(
() => processWithdrawGroupImpl(ws, withdrawalGroupId, forceNow),
@@ -407,7 +393,7 @@ export async function processWithdrawGroup(
async function resetWithdrawalGroupRetry(
ws: InternalWalletState,
withdrawalGroupId: string,
-) {
+): Promise<void> {
await ws.db.mutate(Stores.withdrawalGroups, withdrawalGroupId, (x) => {
if (x.retryInfo.active) {
x.retryInfo = initRetryInfo();