aboutsummaryrefslogtreecommitdiff
path: root/src/operations
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-03-30 16:09:32 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-03-30 16:09:32 +0530
commitaaf950e2ad5c07d4423f9822e3a0ae9f7b8d2bdf (patch)
tree9274139660f30c4857d80044eb4ac283aac1775a /src/operations
parent15e18440dbad55df19977a2eb7053681259afc18 (diff)
re-format with prettier v2, fix HTML
Diffstat (limited to 'src/operations')
-rw-r--r--src/operations/balance.ts33
-rw-r--r--src/operations/errors.ts21
-rw-r--r--src/operations/exchanges.ts16
-rw-r--r--src/operations/history.ts53
-rw-r--r--src/operations/pay.ts34
-rw-r--r--src/operations/pending.ts18
-rw-r--r--src/operations/refresh.ts20
-rw-r--r--src/operations/reserves.ts37
-rw-r--r--src/operations/state.ts5
-rw-r--r--src/operations/tip.ts23
-rw-r--r--src/operations/versions.ts6
-rw-r--r--src/operations/withdraw.ts66
12 files changed, 173 insertions, 159 deletions
diff --git a/src/operations/balance.ts b/src/operations/balance.ts
index 03d1b2a9f..8858e8b43 100644
--- a/src/operations/balance.ts
+++ b/src/operations/balance.ts
@@ -34,8 +34,7 @@ export async function getBalancesInsideTransaction(
ws: InternalWalletState,
tx: TransactionHandle,
): Promise<WalletBalance> {
-
- /**
+ /**
* Add amount to a balance field, both for
* the slicing by exchange and currency.
*/
@@ -74,7 +73,7 @@ export async function getBalancesInsideTransaction(
byExchange: {},
};
- await tx.iter(Stores.coins).forEach(c => {
+ await tx.iter(Stores.coins).forEach((c) => {
if (c.suspended) {
return;
}
@@ -82,7 +81,7 @@ export async function getBalancesInsideTransaction(
addTo(balanceStore, "available", c.currentAmount, c.exchangeBaseUrl);
}
});
- await tx.iter(Stores.refreshGroups).forEach(r => {
+ await tx.iter(Stores.refreshGroups).forEach((r) => {
// Don't count finished refreshes, since the refresh already resulted
// in coins being added to the wallet.
if (r.timestampFinished) {
@@ -107,7 +106,7 @@ export async function getBalancesInsideTransaction(
}
});
- await tx.iter(Stores.withdrawalSession).forEach(wds => {
+ await tx.iter(Stores.withdrawalSession).forEach((wds) => {
let w = wds.totalCoinValue;
for (let i = 0; i < wds.planchets.length; i++) {
if (wds.withdrawn[i]) {
@@ -120,7 +119,7 @@ export async function getBalancesInsideTransaction(
addTo(balanceStore, "pendingIncoming", w, wds.exchangeBaseUrl);
});
- await tx.iter(Stores.purchases).forEach(t => {
+ await tx.iter(Stores.purchases).forEach((t) => {
if (t.timestampFirstSuccessfulPay) {
return;
}
@@ -145,14 +144,16 @@ export async function getBalances(
): Promise<WalletBalance> {
logger.trace("starting to compute balance");
- return await ws.db.runWithReadTransaction([
- Stores.coins,
- Stores.refreshGroups,
- Stores.reserves,
- Stores.purchases,
- Stores.withdrawalSession,
- ],
- async tx => {
- return getBalancesInsideTransaction(ws, tx);
- });
+ return await ws.db.runWithReadTransaction(
+ [
+ Stores.coins,
+ Stores.refreshGroups,
+ Stores.reserves,
+ Stores.purchases,
+ Stores.withdrawalSession,
+ ],
+ async (tx) => {
+ return getBalancesInsideTransaction(ws, tx);
+ },
+ );
}
diff --git a/src/operations/errors.ts b/src/operations/errors.ts
index 751a57111..50e68993b 100644
--- a/src/operations/errors.ts
+++ b/src/operations/errors.ts
@@ -64,7 +64,6 @@ export async function scrutinizeTalerJsonResponse<T>(
resp: HttpResponse,
codec: Codec<T>,
): Promise<T> {
-
// FIXME: We should distinguish between different types of error status
// to react differently (throttle, report permanent failure)
@@ -82,7 +81,7 @@ export async function scrutinizeTalerJsonResponse<T>(
details: {
httpStatusCode: resp.status,
errorResponse: errorJson,
- }
+ },
});
} catch (e) {
const m = "could not parse response JSON";
@@ -91,7 +90,7 @@ export async function scrutinizeTalerJsonResponse<T>(
message: m,
details: {
status: resp.status,
- }
+ },
});
}
throw exc;
@@ -101,13 +100,13 @@ export async function scrutinizeTalerJsonResponse<T>(
json = await resp.json();
} catch (e) {
const m = "could not parse response JSON";
- throw new OperationFailedError({
- type: "network",
- message: m,
- details: {
- status: resp.status,
- }
- });
+ throw new OperationFailedError({
+ type: "network",
+ message: m,
+ details: {
+ status: resp.status,
+ },
+ });
}
return codec.decode(json);
}
@@ -138,7 +137,7 @@ export async function guardOperationException<T>(
type: "exception",
message: e.message,
details: {},
- }
+ };
await onOpError(opErr);
throw new OperationFailedAndReportedError(opErr);
}
diff --git a/src/operations/exchanges.ts b/src/operations/exchanges.ts
index f920a5a59..3aaf77468 100644
--- a/src/operations/exchanges.ts
+++ b/src/operations/exchanges.ts
@@ -193,7 +193,7 @@ async function updateExchangeWithKeys(
.currency;
const newDenominations = await Promise.all(
- exchangeKeysJson.denoms.map(d =>
+ exchangeKeysJson.denoms.map((d) =>
denominationRecordFromKeys(ws, baseUrl, d),
),
);
@@ -202,7 +202,7 @@ async function updateExchangeWithKeys(
await ws.db.runWithWriteTransaction(
[Stores.exchanges, Stores.denominations, Stores.recoupGroups, Stores.coins],
- async tx => {
+ async (tx) => {
const r = await tx.get(Stores.exchanges, baseUrl);
if (!r) {
console.warn(`exchange ${baseUrl} no longer present`);
@@ -275,7 +275,7 @@ async function updateExchangeWithKeys(
if (recoupGroupId) {
// Asynchronously start recoup. This doesn't need to finish
// for the exchange update to be considered finished.
- processRecoupGroup(ws, recoupGroupId).catch(e => {
+ processRecoupGroup(ws, recoupGroupId).catch((e) => {
console.log("error while recouping coins:", e);
});
}
@@ -294,7 +294,7 @@ async function updateExchangeFinalize(
}
await ws.db.runWithWriteTransaction(
[Stores.exchanges, Stores.exchangeUpdatedEvents],
- async tx => {
+ async (tx) => {
const r = await tx.get(Stores.exchanges, exchangeBaseUrl);
if (!r) {
return;
@@ -338,7 +338,7 @@ async function updateExchangeWithTermsOfService(
const tosText = await resp.text();
const tosEtag = resp.headers.get("etag") || undefined;
- await ws.db.runWithWriteTransaction([Stores.exchanges], async tx => {
+ await ws.db.runWithWriteTransaction([Stores.exchanges], async (tx) => {
const r = await tx.get(Stores.exchanges, exchangeBaseUrl);
if (!r) {
return;
@@ -358,7 +358,7 @@ export async function acceptExchangeTermsOfService(
exchangeBaseUrl: string,
etag: string | undefined,
) {
- await ws.db.runWithWriteTransaction([Stores.exchanges], async tx => {
+ await ws.db.runWithWriteTransaction([Stores.exchanges], async (tx) => {
const r = await tx.get(Stores.exchanges, exchangeBaseUrl);
if (!r) {
return;
@@ -438,7 +438,7 @@ async function updateExchangeWithWireInfo(
feesForType[wireMethod] = feeList;
}
- await ws.db.runWithWriteTransaction([Stores.exchanges], async tx => {
+ await ws.db.runWithWriteTransaction([Stores.exchanges], async (tx) => {
const r = await tx.get(Stores.exchanges, exchangeBaseUrl);
if (!r) {
return;
@@ -500,7 +500,7 @@ async function updateExchangeFromUrlImpl(
};
await ws.db.put(Stores.exchanges, newExchangeRecord);
} else {
- await ws.db.runWithWriteTransaction([Stores.exchanges], async t => {
+ await ws.db.runWithWriteTransaction([Stores.exchanges], async (t) => {
const rec = await t.get(Stores.exchanges, baseUrl);
if (!rec) {
return;
diff --git a/src/operations/history.ts b/src/operations/history.ts
index 65907de8d..1b4172526 100644
--- a/src/operations/history.ts
+++ b/src/operations/history.ts
@@ -47,7 +47,7 @@ import { timestampCmp } from "../util/time";
* Create an event ID from the type and the primary key for the event.
*/
function makeEventId(type: HistoryEventType, ...args: string[]) {
- return type + ";" + args.map(x => encodeURIComponent(x)).join(";");
+ return type + ";" + args.map((x) => encodeURIComponent(x)).join(";");
}
function getOrderShortInfo(
@@ -72,7 +72,7 @@ async function collectProposalHistory(
history: HistoryEvent[],
historyQuery?: HistoryQuery,
) {
- tx.iter(Stores.proposals).forEachAsync(async proposal => {
+ tx.iter(Stores.proposals).forEachAsync(async (proposal) => {
const status = proposal.proposalStatus;
switch (status) {
case ProposalStatus.ACCEPTED:
@@ -182,8 +182,8 @@ export async function getHistory(
Stores.reserveUpdatedEvents,
Stores.recoupGroups,
],
- async tx => {
- tx.iter(Stores.exchanges).forEach(exchange => {
+ async (tx) => {
+ tx.iter(Stores.exchanges).forEach((exchange) => {
history.push({
type: HistoryEventType.ExchangeAdded,
builtIn: false,
@@ -196,7 +196,7 @@ export async function getHistory(
});
});
- tx.iter(Stores.exchangeUpdatedEvents).forEach(eu => {
+ tx.iter(Stores.exchangeUpdatedEvents).forEach((eu) => {
history.push({
type: HistoryEventType.ExchangeUpdated,
eventId: makeEventId(
@@ -208,7 +208,7 @@ export async function getHistory(
});
});
- tx.iter(Stores.withdrawalSession).forEach(wsr => {
+ tx.iter(Stores.withdrawalSession).forEach((wsr) => {
if (wsr.timestampFinish) {
const cs: PlanchetRecord[] = [];
wsr.planchets.forEach((x) => {
@@ -226,7 +226,7 @@ export async function getHistory(
})),
};
}
-
+
history.push({
type: HistoryEventType.Withdrawn,
withdrawSessionId: wsr.withdrawSessionId,
@@ -246,7 +246,7 @@ export async function getHistory(
await collectProposalHistory(tx, history, historyQuery);
- await tx.iter(Stores.payEvents).forEachAsync(async pe => {
+ await tx.iter(Stores.payEvents).forEachAsync(async (pe) => {
const proposal = await tx.get(Stores.proposals, pe.proposalId);
if (!proposal) {
return;
@@ -262,7 +262,7 @@ export async function getHistory(
let verboseDetails: VerbosePayCoinDetails | undefined = undefined;
if (historyQuery?.extraDebug) {
const coins: {
- value: string,
+ value: string;
contribution: string;
denomPub: string;
}[] = [];
@@ -272,7 +272,10 @@ export async function getHistory(
// FIXME: what to do here??
continue;
}
- const d = await tx.get(Stores.denominations, [c.exchangeBaseUrl, c.denomPub]);
+ const d = await tx.get(Stores.denominations, [
+ c.exchangeBaseUrl,
+ c.denomPub,
+ ]);
if (!d) {
// FIXME: what to do here??
continue;
@@ -283,10 +286,12 @@ export async function getHistory(
value: Amounts.toString(d.value),
});
}
- verboseDetails = { coins };
+ verboseDetails = { coins };
}
const amountPaidWithFees = Amounts.sum(
- purchase.payReq.coins.map(x => Amounts.parseOrThrow(x.contribution)),
+ purchase.payReq.coins.map((x) =>
+ Amounts.parseOrThrow(x.contribution),
+ ),
).amount;
history.push({
type: HistoryEventType.PaymentSent,
@@ -301,7 +306,7 @@ export async function getHistory(
});
});
- await tx.iter(Stores.refreshGroups).forEachAsync(async rg => {
+ await tx.iter(Stores.refreshGroups).forEachAsync(async (rg) => {
if (!rg.timestampFinished) {
return;
}
@@ -340,7 +345,7 @@ export async function getHistory(
if (historyQuery?.extraDebug) {
const outputCoins: {
value: string;
- denomPub: string,
+ denomPub: string;
}[] = [];
for (const rs of rg.refreshSessionPerCoin) {
if (!rs) {
@@ -350,7 +355,10 @@ export async function getHistory(
if (!nd) {
continue;
}
- const d = await tx.get(Stores.denominations, [rs.exchangeBaseUrl, nd]);
+ const d = await tx.get(Stores.denominations, [
+ rs.exchangeBaseUrl,
+ nd,
+ ]);
if (!d) {
continue;
}
@@ -362,7 +370,7 @@ export async function getHistory(
}
verboseDetails = {
outputCoins: outputCoins,
- }
+ };
}
history.push({
type: HistoryEventType.Refreshed,
@@ -379,7 +387,7 @@ export async function getHistory(
});
});
- tx.iter(Stores.reserveUpdatedEvents).forEachAsync(async ru => {
+ tx.iter(Stores.reserveUpdatedEvents).forEachAsync(async (ru) => {
const reserve = await tx.get(Stores.reserves, ru.reservePub);
if (!reserve) {
return;
@@ -413,7 +421,7 @@ export async function getHistory(
});
});
- tx.iter(Stores.tips).forEach(tip => {
+ tx.iter(Stores.tips).forEach((tip) => {
if (tip.acceptedTimestamp) {
history.push({
type: HistoryEventType.TipAccepted,
@@ -425,7 +433,7 @@ export async function getHistory(
}
});
- tx.iter(Stores.refundEvents).forEachAsync(async re => {
+ tx.iter(Stores.refundEvents).forEachAsync(async (re) => {
const proposal = await tx.get(Stores.proposals, re.proposalId);
if (!proposal) {
return;
@@ -486,7 +494,7 @@ export async function getHistory(
});
});
- tx.iter(Stores.recoupGroups).forEach(rg => {
+ tx.iter(Stores.recoupGroups).forEach((rg) => {
if (rg.timestampFinished) {
let verboseDetails: any = undefined;
if (historyQuery?.extraDebug) {
@@ -498,7 +506,10 @@ export async function getHistory(
history.push({
type: HistoryEventType.FundsRecouped,
timestamp: rg.timestampFinished,
- eventId: makeEventId(HistoryEventType.FundsRecouped, rg.recoupGroupId),
+ eventId: makeEventId(
+ HistoryEventType.FundsRecouped,
+ rg.recoupGroupId,
+ ),
numCoinsRecouped: rg.coinPubs.length,
verboseDetails,
});
diff --git a/src/operations/pay.ts b/src/operations/pay.ts
index f3468ae46..9b9d2fa9f 100644
--- a/src/operations/pay.ts
+++ b/src/operations/pay.ts
@@ -127,7 +127,7 @@ export interface AvailableCoinInfo {
/**
* Compute the total cost of a payment to the customer.
- *
+ *
* This includes the amount taken by the merchant, fees (wire/deposit) contributed
* by the customer, refreshing fees, fees for withdraw-after-refresh and "trimmings"
* of coins that are too small to spend.
@@ -461,7 +461,7 @@ async function recordConfirmPay(
await ws.db.runWithWriteTransaction(
[Stores.coins, Stores.purchases, Stores.proposals, Stores.refreshGroups],
- async tx => {
+ async (tx) => {
const p = await tx.get(Stores.proposals, proposal.proposalId);
if (p) {
p.proposalStatus = ProposalStatus.ACCEPTED;
@@ -486,7 +486,9 @@ async function recordConfirmPay(
coin.currentAmount = remaining.amount;
await tx.put(Stores.coins, coin);
}
- const refreshCoinPubs = coinSelection.coinPubs.map(x => ({ coinPub: x }));
+ const refreshCoinPubs = coinSelection.coinPubs.map((x) => ({
+ coinPub: x,
+ }));
await createRefreshGroup(tx, refreshCoinPubs, RefreshReason.Pay);
},
);
@@ -560,7 +562,7 @@ export async function abortFailedPayment(
RefundReason.AbortRefund,
);
- await ws.db.runWithWriteTransaction([Stores.purchases], async tx => {
+ await ws.db.runWithWriteTransaction([Stores.purchases], async (tx) => {
const p = await tx.get(Stores.purchases, proposalId);
if (!p) {
return;
@@ -575,7 +577,7 @@ async function incrementProposalRetry(
proposalId: string,
err: OperationError | undefined,
): Promise<void> {
- await ws.db.runWithWriteTransaction([Stores.proposals], async tx => {
+ await ws.db.runWithWriteTransaction([Stores.proposals], async (tx) => {
const pr = await tx.get(Stores.proposals, proposalId);
if (!pr) {
return;
@@ -597,7 +599,7 @@ async function incrementPurchasePayRetry(
err: OperationError | undefined,
): Promise<void> {
console.log("incrementing purchase pay retry with error", err);
- await ws.db.runWithWriteTransaction([Stores.purchases], async tx => {
+ await ws.db.runWithWriteTransaction([Stores.purchases], async (tx) => {
const pr = await tx.get(Stores.purchases, proposalId);
if (!pr) {
return;
@@ -630,7 +632,7 @@ async function resetDownloadProposalRetry(
ws: InternalWalletState,
proposalId: string,
) {
- await ws.db.mutate(Stores.proposals, proposalId, x => {
+ await ws.db.mutate(Stores.proposals, proposalId, (x) => {
if (x.retryInfo.active) {
x.retryInfo = initRetryInfo();
}
@@ -685,7 +687,7 @@ async function processDownloadProposalImpl(
await ws.db.runWithWriteTransaction(
[Stores.proposals, Stores.purchases],
- async tx => {
+ async (tx) => {
const p = await tx.get(Stores.proposals, proposalId);
if (!p) {
return;
@@ -715,11 +717,11 @@ async function processDownloadProposalImpl(
payDeadline: parsedContractTerms.pay_deadline,
refundDeadline: parsedContractTerms.refund_deadline,
wireFeeAmortization: parsedContractTerms.wire_fee_amortization || 1,
- allowedAuditors: parsedContractTerms.auditors.map(x => ({
+ allowedAuditors: parsedContractTerms.auditors.map((x) => ({
auditorBaseUrl: x.url,
auditorPub: x.master_pub,
})),
- allowedExchanges: parsedContractTerms.exchanges.map(x => ({
+ allowedExchanges: parsedContractTerms.exchanges.map((x) => ({
exchangeBaseUrl: x.url,
exchangePub: x.master_pub,
})),
@@ -797,7 +799,7 @@ async function startDownloadProposal(
downloadSessionId: sessionId,
};
- await ws.db.runWithWriteTransaction([Stores.proposals], async tx => {
+ await ws.db.runWithWriteTransaction([Stores.proposals], async (tx) => {
const existingRecord = await tx.getIndexed(
Stores.proposals.urlAndOrderIdIndex,
[merchantBaseUrl, orderId],
@@ -878,7 +880,7 @@ export async function submitPay(
await ws.db.runWithWriteTransaction(
[Stores.purchases, Stores.payEvents],
- async tx => {
+ async (tx) => {
await tx.put(Stores.purchases, purchase);
const payEvent: PayEventRecord = {
proposalId,
@@ -984,7 +986,7 @@ export async function preparePayForUri(
console.log(
"automatically re-submitting payment with different session ID",
);
- await ws.db.runWithWriteTransaction([Stores.purchases], async tx => {
+ await ws.db.runWithWriteTransaction([Stores.purchases], async (tx) => {
const p = await tx.get(Stores.purchases, proposalId);
if (!p) {
return;
@@ -1035,7 +1037,7 @@ export async function confirmPay(
sessionIdOverride != purchase.lastSessionId
) {
logger.trace(`changing session ID to ${sessionIdOverride}`);
- await ws.db.mutate(Stores.purchases, purchase.proposalId, x => {
+ await ws.db.mutate(Stores.purchases, purchase.proposalId, (x) => {
x.lastSessionId = sessionIdOverride;
x.paymentSubmitPending = true;
return x;
@@ -1118,7 +1120,7 @@ async function resetPurchasePayRetry(
ws: InternalWalletState,
proposalId: string,
) {
- await ws.db.mutate(Stores.purchases, proposalId, x => {
+ await ws.db.mutate(Stores.purchases, proposalId, (x) => {
if (x.payRetryInfo.active) {
x.payRetryInfo = initRetryInfo();
}
@@ -1151,7 +1153,7 @@ export async function refuseProposal(
) {
const success = await ws.db.runWithWriteTransaction(
[Stores.proposals],
- async tx => {
+ async (tx) => {
const proposal = await tx.get(Stores.proposals, proposalId);
if (!proposal) {
logger.trace(`proposal ${proposalId} not found, won't refuse proposal`);
diff --git a/src/operations/pending.ts b/src/operations/pending.ts
index a628d6130..adf47b151 100644
--- a/src/operations/pending.ts
+++ b/src/operations/pending.ts
@@ -59,7 +59,7 @@ async function gatherExchangePending(
// FIXME: exchanges should also be updated regularly
return;
}
- await tx.iter(Stores.exchanges).forEach(e => {
+ await tx.iter(Stores.exchanges).forEach((e) => {
switch (e.updateStatus) {
case ExchangeUpdateStatus.Finished:
if (e.lastError) {
@@ -148,7 +148,7 @@ async function gatherReservePending(
onlyDue: boolean = false,
): Promise<void> {
// FIXME: this should be optimized by using an index for "onlyDue==true".
- await tx.iter(Stores.reserves).forEach(reserve => {
+ await tx.iter(Stores.reserves).forEach((reserve) => {
const reserveType = reserve.bankWithdrawStatusUrl ? "taler-bank" : "manual";
if (!reserve.retryInfo.active) {
return;
@@ -214,7 +214,7 @@ async function gatherRefreshPending(
resp: PendingOperationsResponse,
onlyDue: boolean = false,
): Promise<void> {
- await tx.iter(Stores.refreshGroups).forEach(r => {
+ await tx.iter(Stores.refreshGroups).forEach((r) => {
if (r.timestampFinished) {
return;
}
@@ -243,7 +243,7 @@ async function gatherWithdrawalPending(
resp: PendingOperationsResponse,
onlyDue: boolean = false,
): Promise<void> {
- await tx.iter(Stores.withdrawalSession).forEach(wsr => {
+ await tx.iter(Stores.withdrawalSession).forEach((wsr) => {
if (wsr.timestampFinish) {
return;
}
@@ -277,7 +277,7 @@ async function gatherProposalPending(
resp: PendingOperationsResponse,
onlyDue: boolean = false,
): Promise<void> {
- await tx.iter(Stores.proposals).forEach(proposal => {
+ await tx.iter(Stores.proposals).forEach((proposal) => {
if (proposal.proposalStatus == ProposalStatus.PROPOSED) {
if (onlyDue) {
return;
@@ -318,7 +318,7 @@ async function gatherTipPending(
resp: PendingOperationsResponse,
onlyDue: boolean = false,
): Promise<void> {
- await tx.iter(Stores.tips).forEach(tip => {
+ await tx.iter(Stores.tips).forEach((tip) => {
if (tip.pickedUp) {
return;
}
@@ -348,7 +348,7 @@ async function gatherPurchasePending(
resp: PendingOperationsResponse,
onlyDue: boolean = false,
): Promise<void> {
- await tx.iter(Stores.purchases).forEach(pr => {
+ await tx.iter(Stores.purchases).forEach((pr) => {
if (pr.paymentSubmitPending) {
resp.nextRetryDelay = updateRetryDelay(
resp.nextRetryDelay,
@@ -411,7 +411,7 @@ async function gatherRecoupPending(
resp: PendingOperationsResponse,
onlyDue: boolean = false,
): Promise<void> {
- await tx.iter(Stores.recoupGroups).forEach(rg => {
+ await tx.iter(Stores.recoupGroups).forEach((rg) => {
if (rg.timestampFinished) {
return;
}
@@ -450,7 +450,7 @@ export async function getPendingOperations(
Stores.purchases,
Stores.recoupGroups,
],
- async tx => {
+ async (tx) => {
const walletBalance = await getBalancesInsideTransaction(ws, tx);
const resp: PendingOperationsResponse = {
nextRetryDelay: { d_ms: Number.MAX_SAFE_INTEGER },
diff --git a/src/operations/refresh.ts b/src/operations/refresh.ts
index f196fc5e1..5628263ec 100644
--- a/src/operations/refresh.ts
+++ b/src/operations/refresh.ts
@@ -68,7 +68,7 @@ export function getTotalRefreshCost(
const withdrawDenoms = getWithdrawDenomList(withdrawAmount, denoms);
const resultingAmount = Amounts.add(
Amounts.getZero(withdrawAmount.currency),
- ...withdrawDenoms.map(d => d.value),
+ ...withdrawDenoms.map((d) => d.value),
).amount;
const totalCost = Amounts.sub(amountLeft, resultingAmount).amount;
logger.trace(
@@ -139,7 +139,7 @@ async function refreshCreateSession(
);
await ws.db.runWithWriteTransaction(
[Stores.coins, Stores.refreshGroups],
- async tx => {
+ async (tx) => {
const rg = await tx.get(Stores.refreshGroups, refreshGroupId);
if (!rg) {
return;
@@ -175,7 +175,7 @@ async function refreshCreateSession(
// coin in the same transaction.
await ws.db.runWithWriteTransaction(
[Stores.refreshGroups, Stores.coins],
- async tx => {
+ async (tx) => {
const c = await tx.get(Stores.coins, coin.coinPub);
if (!c) {
throw Error("coin not found, but marked for refresh");
@@ -274,7 +274,7 @@ async function refreshMelt(
refreshSession.norevealIndex = norevealIndex;
- await ws.db.mutate(Stores.refreshGroups, refreshGroupId, rg => {
+ await ws.db.mutate(Stores.refreshGroups, refreshGroupId, (rg) => {
const rs = rg.refreshSessionPerCoin[coinIndex];
if (!rs) {
return;
@@ -420,7 +420,7 @@ async function refreshReveal(
await ws.db.runWithWriteTransaction(
[Stores.coins, Stores.refreshGroups],
- async tx => {
+ async (tx) => {
const rg = await tx.get(Stores.refreshGroups, refreshGroupId);
if (!rg) {
console.log("no refresh session found");
@@ -464,7 +464,7 @@ async function incrementRefreshRetry(
refreshGroupId: string,
err: OperationError | undefined,
): Promise<void> {
- await ws.db.runWithWriteTransaction([Stores.refreshGroups], async tx => {
+ await ws.db.runWithWriteTransaction([Stores.refreshGroups], async (tx) => {
const r = await tx.get(Stores.refreshGroups, refreshGroupId);
if (!r) {
return;
@@ -499,7 +499,7 @@ async function resetRefreshGroupRetry(
ws: InternalWalletState,
refreshSessionId: string,
) {
- await ws.db.mutate(Stores.refreshGroups, refreshSessionId, x => {
+ await ws.db.mutate(Stores.refreshGroups, refreshSessionId, (x) => {
if (x.retryInfo.active) {
x.retryInfo = initRetryInfo();
}
@@ -578,13 +578,13 @@ export async function createRefreshGroup(
const refreshGroup: RefreshGroupRecord = {
timestampFinished: undefined,
- finishedPerCoin: oldCoinPubs.map(x => false),
+ finishedPerCoin: oldCoinPubs.map((x) => false),
lastError: undefined,
lastErrorPerCoin: {},
- oldCoinPubs: oldCoinPubs.map(x => x.coinPub),
+ oldCoinPubs: oldCoinPubs.map((x) => x.coinPub),
reason,
refreshGroupId,
- refreshSessionPerCoin: oldCoinPubs.map(x => undefined),
+ refreshSessionPerCoin: oldCoinPubs.map((x) => undefined),
retryInfo: initRetryInfo(),
};
diff --git a/src/operations/reserves.ts b/src/operations/reserves.ts
index c0e22b3c6..5cf189d3b 100644
--- a/src/operations/reserves.ts
+++ b/src/operations/reserves.ts
@@ -65,7 +65,7 @@ import { getTimestampNow } from "../util/time";
const logger = new Logger("reserves.ts");
async function resetReserveRetry(ws: InternalWalletState, reservePub: string) {
- await ws.db.mutate(Stores.reserves, reservePub, x => {
+ await ws.db.mutate(Stores.reserves, reservePub, (x) => {
if (x.retryInfo.active) {
x.retryInfo = initRetryInfo();
}
@@ -156,7 +156,7 @@ export async function createReserve(
const resp = await ws.db.runWithWriteTransaction(
[Stores.currencies, Stores.reserves, Stores.bankWithdrawUris],
- async tx => {
+ async (tx) => {
// Check if we have already created a reserve for that bankWithdrawStatusUrl
if (reserveRecord.bankWithdrawStatusUrl) {
const bwi = await tx.get(
@@ -194,7 +194,7 @@ export async function createReserve(
// Asynchronously process the reserve, but return
// to the caller already.
- processReserve(ws, resp.reservePub, true).catch(e => {
+ processReserve(ws, resp.reservePub, true).catch((e) => {
console.error("Processing reserve (after createReserve) failed:", e);
});
@@ -208,7 +208,7 @@ export async function forceQueryReserve(
ws: InternalWalletState,
reservePub: string,
): Promise<void> {
- await ws.db.runWithWriteTransaction([Stores.reserves], async tx => {
+ await ws.db.runWithWriteTransaction([Stores.reserves], async (tx) => {
const reserve = await tx.get(Stores.reserves, reservePub);
if (!reserve) {
return;
@@ -275,7 +275,7 @@ async function registerReserveWithBank(
reserve_pub: reservePub,
selected_exchange: reserve.exchangeWire,
});
- await ws.db.mutate(Stores.reserves, reservePub, r => {
+ await ws.db.mutate(Stores.reserves, reservePub, (r) => {
switch (r.reserveStatus) {
case ReserveRecordStatus.REGISTERING_BANK:
case ReserveRecordStatus.WAIT_CONFIRM_BANK:
@@ -349,7 +349,7 @@ async function processReserveBankStatusImpl(
}
if (status.transfer_done) {
- await ws.db.mutate(Stores.reserves, reservePub, r => {
+ await ws.db.mutate(Stores.reserves, reservePub, (r) => {
switch (r.reserveStatus) {
case ReserveRecordStatus.REGISTERING_BANK:
case ReserveRecordStatus.WAIT_CONFIRM_BANK:
@@ -365,7 +365,7 @@ async function processReserveBankStatusImpl(
});
await processReserveImpl(ws, reservePub, true);
} else {
- await ws.db.mutate(Stores.reserves, reservePub, r => {
+ await ws.db.mutate(Stores.reserves, reservePub, (r) => {
switch (r.reserveStatus) {
case ReserveRecordStatus.WAIT_CONFIRM_BANK:
break;
@@ -385,7 +385,7 @@ async function incrementReserveRetry(
reservePub: string,
err: OperationError | undefined,
): Promise<void> {
- await ws.db.runWithWriteTransaction([Stores.reserves], async tx => {
+ await ws.db.runWithWriteTransaction([Stores.reserves], async (tx) => {
const r = await tx.get(Stores.reserves, reservePub);
if (!r) {
return;
@@ -462,7 +462,7 @@ async function updateReserve(
const balance = Amounts.parseOrThrow(reserveInfo.balance);
await ws.db.runWithWriteTransaction(
[Stores.reserves, Stores.reserveUpdatedEvents],
- async tx => {
+ async (tx) => {
const r = await tx.get(Stores.reserves, reservePub);
if (!r) {
return;
@@ -501,8 +501,7 @@ async function updateReserve(
if (cmp == 0) {
// Nothing changed, go back to sleep!
r.reserveStatus = ReserveRecordStatus.DORMANT;
- }
- else if (cmp > 0) {
+ } else if (cmp > 0) {
const extra = Amounts.sub(balance, expectedBalance.amount).amount;
r.amountWithdrawRemaining = Amounts.add(
r.amountWithdrawRemaining,
@@ -591,7 +590,7 @@ export async function confirmReserve(
req: ConfirmReserveRequest,
): Promise<void> {
const now = getTimestampNow();
- await ws.db.mutate(Stores.reserves, req.reservePub, reserve => {
+ await ws.db.mutate(Stores.reserves, req.reservePub, (reserve) => {
if (reserve.reserveStatus !== ReserveRecordStatus.UNCONFIRMED) {
return;
}
@@ -603,7 +602,7 @@ export async function confirmReserve(
ws.notify({ type: NotificationType.ReserveUpdated });
- processReserve(ws, req.reservePub, true).catch(e => {
+ processReserve(ws, req.reservePub, true).catch((e) => {
console.log("processing reserve (after confirmReserve) failed:", e);
});
}
@@ -653,7 +652,7 @@ async function depleteReserve(
const withdrawalSessionId = encodeCrock(randomBytes(32));
- const totalCoinValue = Amounts.sum(denomsForWithdraw.map(x => x.value))
+ const totalCoinValue = Amounts.sum(denomsForWithdraw.map((x) => x.value))
.amount;
const withdrawalRecord: WithdrawalSessionRecord = {
@@ -665,9 +664,9 @@ async function depleteReserve(
},
rawWithdrawalAmount: withdrawAmount,
timestampStart: getTimestampNow(),
- denoms: denomsForWithdraw.map(x => x.denomPub),
- withdrawn: denomsForWithdraw.map(x => false),
- planchets: denomsForWithdraw.map(x => undefined),
+ denoms: denomsForWithdraw.map((x) => x.denomPub),
+ withdrawn: denomsForWithdraw.map((x) => false),
+ planchets: denomsForWithdraw.map((x) => undefined),
totalCoinValue,
retryInfo: initRetryInfo(),
lastErrorPerCoin: {},
@@ -675,7 +674,7 @@ async function depleteReserve(
};
const totalCoinWithdrawFee = Amounts.sum(
- denomsForWithdraw.map(x => x.feeWithdraw),
+ denomsForWithdraw.map((x) => x.feeWithdraw),
).amount;
const totalWithdrawAmount = Amounts.add(totalCoinValue, totalCoinWithdrawFee)
.amount;
@@ -706,7 +705,7 @@ async function depleteReserve(
const success = await ws.db.runWithWriteTransaction(
[Stores.withdrawalSession, Stores.reserves],
- async tx => {
+ async (tx) => {
const myReserve = await tx.get(Stores.reserves, reservePub);
if (!myReserve) {
return false;
diff --git a/src/operations/state.ts b/src/operations/state.ts
index ae32db2b3..f571fe93a 100644
--- a/src/operations/state.ts
+++ b/src/operations/state.ts
@@ -15,10 +15,7 @@
*/
import { HttpRequestLibrary } from "../util/http";
-import {
- NextUrlResult,
- WalletBalance,
-} from "../types/walletTypes";
+import { NextUrlResult, WalletBalance } from "../types/walletTypes";
import { CryptoApi, CryptoWorkerFactory } from "../crypto/workers/cryptoApi";
import { AsyncOpMemoMap, AsyncOpMemoSingle } from "../util/asyncMemo";
import { Logger } from "../util/logging";
diff --git a/src/operations/tip.ts b/src/operations/tip.ts
index fcdda0763..3636dd247 100644
--- a/src/operations/tip.ts
+++ b/src/operations/tip.ts
@@ -16,10 +16,7 @@
import { InternalWalletState } from "./state";
import { parseTipUri } from "../util/taleruri";
-import {
- TipStatus,
- OperationError,
-} from "../types/walletTypes";
+import { TipStatus, OperationError } from "../types/walletTypes";
import {
TipPickupGetResponse,
TipPlanchetDetail,
@@ -130,7 +127,7 @@ async function incrementTipRetry(
refreshSessionId: string,
err: OperationError | undefined,
): Promise<void> {
- await ws.db.runWithWriteTransaction([Stores.tips], async tx => {
+ await ws.db.runWithWriteTransaction([Stores.tips], async (tx) => {
const t = await tx.get(Stores.tips, refreshSessionId);
if (!t) {
return;
@@ -162,7 +159,7 @@ async function resetTipRetry(
ws: InternalWalletState,
tipId: string,
): Promise<void> {
- await ws.db.mutate(Stores.tips, tipId, x => {
+ await ws.db.mutate(Stores.tips, tipId, (x) => {
if (x.retryInfo.active) {
x.retryInfo = initRetryInfo();
}
@@ -197,10 +194,10 @@ async function processTipImpl(
);
const planchets = await Promise.all(
- denomsForWithdraw.map(d => ws.cryptoApi.createTipPlanchet(d)),
+ denomsForWithdraw.map((d) => ws.cryptoApi.createTipPlanchet(d)),
);
- await ws.db.mutate(Stores.tips, tipId, r => {
+ await ws.db.mutate(Stores.tips, tipId, (r) => {
if (!r.planchets) {
r.planchets = planchets;
}
@@ -220,7 +217,7 @@ async function processTipImpl(
console.log("got planchets for tip!");
// Planchets in the form that the merchant expects
- const planchetsDetail: TipPlanchetDetail[] = tipRecord.planchets.map(p => ({
+ const planchetsDetail: TipPlanchetDetail[] = tipRecord.planchets.map((p) => ({
coin_ev: p.coinEv,
denom_pub_hash: p.denomPubHash,
}));
@@ -269,7 +266,7 @@ async function processTipImpl(
const withdrawalSessionId = encodeCrock(getRandomBytes(32));
const withdrawalSession: WithdrawalSessionRecord = {
- denoms: planchets.map(x => x.denomPub),
+ denoms: planchets.map((x) => x.denomPub),
exchangeBaseUrl: tipRecord.exchangeUrl,
planchets: planchets,
source: {
@@ -279,8 +276,8 @@ async function processTipImpl(
timestampStart: getTimestampNow(),
withdrawSessionId: withdrawalSessionId,
rawWithdrawalAmount: tipRecord.amount,
- withdrawn: planchets.map(x => false),
- totalCoinValue: Amounts.sum(planchets.map(p => p.coinValue)).amount,
+ withdrawn: planchets.map((x) => false),
+ totalCoinValue: Amounts.sum(planchets.map((p) => p.coinValue)).amount,
lastErrorPerCoin: {},
retryInfo: initRetryInfo(),
timestampFinish: undefined,
@@ -289,7 +286,7 @@ async function processTipImpl(
await ws.db.runWithWriteTransaction(
[Stores.tips, Stores.withdrawalSession],
- async tx => {
+ async (tx) => {
const tr = await tx.get(Stores.tips, tipId);
if (!tr) {
return;
diff --git a/src/operations/versions.ts b/src/operations/versions.ts
index 6ac78f013..8b55bd4d5 100644
--- a/src/operations/versions.ts
+++ b/src/operations/versions.ts
@@ -26,7 +26,7 @@ export const WALLET_EXCHANGE_PROTOCOL_VERSION = "7:0:0";
* Cache breaker that is appended to queries such as /keys and /wire
* to break through caching, if it has been accidentally/badly configured
* by the exchange.
- *
- * This is only a temporary measure.
+ *
+ * This is only a temporary measure.
*/
-export const WALLET_CACHE_BREAKER_CLIENT_VERSION = "3"; \ No newline at end of file
+export const WALLET_CACHE_BREAKER_CLIENT_VERSION = "3";
diff --git a/src/operations/withdraw.ts b/src/operations/withdraw.ts
index 37993023e..4d8af9fc0 100644
--- a/src/operations/withdraw.ts
+++ b/src/operations/withdraw.ts
@@ -144,7 +144,7 @@ async function getPossibleDenoms(
): Promise<DenominationRecord[]> {
return await ws.db
.iterIndex(Stores.denominations.exchangeBaseUrlIndex, exchangeBaseUrl)
- .filter(d => {
+ .filter((d) => {
return (
(d.status === DenominationStatus.Unverified ||
d.status === DenominationStatus.VerifiedGood) &&
@@ -248,7 +248,7 @@ async function processPlanchet(
const success = await ws.db.runWithWriteTransaction(
[Stores.coins, Stores.withdrawalSession, Stores.reserves],
- async tx => {
+ async (tx) => {
const ws = await tx.get(Stores.withdrawalSession, withdrawalSessionId);
if (!ws) {
return false;
@@ -429,17 +429,20 @@ async function makePlanchet(
reservePub: r.reservePub,
withdrawSig: r.withdrawSig,
};
- await ws.db.runWithWriteTransaction([Stores.withdrawalSession], async tx => {
- const myWs = await tx.get(Stores.withdrawalSession, withdrawalSessionId);
- if (!myWs) {
- return;
- }
- if (myWs.planchets[coinIndex]) {
- return;
- }
- myWs.planchets[coinIndex] = newPlanchet;
- await tx.put(Stores.withdrawalSession, myWs);
- });
+ await ws.db.runWithWriteTransaction(
+ [Stores.withdrawalSession],
+ async (tx) => {
+ const myWs = await tx.get(Stores.withdrawalSession, withdrawalSessionId);
+ if (!myWs) {
+ return;
+ }
+ if (myWs.planchets[coinIndex]) {
+ return;
+ }
+ myWs.planchets[coinIndex] = newPlanchet;
+ await tx.put(Stores.withdrawalSession, myWs);
+ },
+ );
}
async function processWithdrawCoin(
@@ -483,19 +486,22 @@ async function incrementWithdrawalRetry(
withdrawalSessionId: string,
err: OperationError | undefined,
): Promise<void> {
- await ws.db.runWithWriteTransaction([Stores.withdrawalSession], async tx => {
- const wsr = await tx.get(Stores.withdrawalSession, withdrawalSessionId);
- if (!wsr) {
- return;
- }
- if (!wsr.retryInfo) {
- return;
- }
- wsr.retryInfo.retryCounter++;
- updateRetryInfoTimeout(wsr.retryInfo);
- wsr.lastError = err;
- await tx.put(Stores.withdrawalSession, wsr);
- });
+ await ws.db.runWithWriteTransaction(
+ [Stores.withdrawalSession],
+ async (tx) => {
+ const wsr = await tx.get(Stores.withdrawalSession, withdrawalSessionId);
+ if (!wsr) {
+ return;
+ }
+ if (!wsr.retryInfo) {
+ return;
+ }
+ wsr.retryInfo.retryCounter++;
+ updateRetryInfoTimeout(wsr.retryInfo);
+ wsr.lastError = err;
+ await tx.put(Stores.withdrawalSession, wsr);
+ },
+ );
ws.notify({ type: NotificationType.WithdrawOperationError });
}
@@ -516,7 +522,7 @@ async function resetWithdrawSessionRetry(
ws: InternalWalletState,
withdrawalSessionId: string,
) {
- await ws.db.mutate(Stores.withdrawalSession, withdrawalSessionId, x => {
+ await ws.db.mutate(Stores.withdrawalSession, withdrawalSessionId, (x) => {
if (x.retryInfo.active) {
x.retryInfo = initRetryInfo();
}
@@ -594,12 +600,14 @@ export async function getExchangeWithdrawalInfo(
const possibleDenoms = await ws.db
.iterIndex(Stores.denominations.exchangeBaseUrlIndex, baseUrl)
- .filter(d => d.isOffered);
+ .filter((d) => d.isOffered);
const trustedAuditorPubs = [];
const currencyRecord = await ws.db.get(Stores.currencies, amount.currency);
if (currencyRecord) {
- trustedAuditorPubs.push(...currencyRecord.auditors.map(a => a.auditorPub));
+ trustedAuditorPubs.push(
+ ...currencyRecord.auditors.map((a) => a.auditorPub),
+ );
}
let versionMatch;