summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-01-14 18:00:00 +0100
committerFlorian Dold <florian@dold.me>2021-01-14 18:00:00 +0100
commit19eb72e277de89600506c2c7d1f14487ebe6408e (patch)
tree70b4d15291ad319abc302b09fc7cc4cd11361fb9
parent6293de7bfa4d8a52091b251e2333e9710ce1b22a (diff)
downloadwallet-core-19eb72e277de89600506c2c7d1f14487ebe6408e.tar.gz
wallet-core-19eb72e277de89600506c2c7d1f14487ebe6408e.tar.bz2
wallet-core-19eb72e277de89600506c2c7d1f14487ebe6408e.zip
logging, cosmetic fixes
-rw-r--r--packages/taler-wallet-core/src/operations/exchanges.ts3
-rw-r--r--packages/taler-wallet-core/src/operations/reserves.ts6
-rw-r--r--packages/taler-wallet-core/src/operations/tip.ts4
-rw-r--r--packages/taler-wallet-core/src/operations/withdraw-test.ts15
-rw-r--r--packages/taler-wallet-core/src/operations/withdraw.ts30
-rw-r--r--packages/taler-wallet-core/src/types/dbTypes.ts6
6 files changed, 45 insertions, 19 deletions
diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts
index 7cc4fe101..1125645f1 100644
--- a/packages/taler-wallet-core/src/operations/exchanges.ts
+++ b/packages/taler-wallet-core/src/operations/exchanges.ts
@@ -31,7 +31,7 @@ import {
ExchangeUpdateReason,
MetaStores,
} from "../types/dbTypes";
-import { canonicalizeBaseUrl } from "../util/helpers";
+import { canonicalizeBaseUrl, j2s } from "../util/helpers";
import * as Amounts from "../util/amounts";
import { parsePaytoUri } from "../util/payto";
import {
@@ -145,6 +145,7 @@ async function updateExchangeWithKeys(
);
logger.info("received /keys response");
+ logger.trace(j2s(exchangeKeysJson));
if (exchangeKeysJson.denoms.length === 0) {
const opErr = makeErrorDetails(
diff --git a/packages/taler-wallet-core/src/operations/reserves.ts b/packages/taler-wallet-core/src/operations/reserves.ts
index 7c878668f..2be992bf2 100644
--- a/packages/taler-wallet-core/src/operations/reserves.ts
+++ b/packages/taler-wallet-core/src/operations/reserves.ts
@@ -50,7 +50,7 @@ import {
denomSelectionInfoToState,
updateWithdrawalDenoms,
selectWithdrawalDenominations,
- getPossibleWithdrawalDenoms,
+ getCandidateWithdrawalDenoms,
} from "./withdraw";
import {
guardOperationException,
@@ -135,7 +135,7 @@ export async function createReserve(
const initialWithdrawalGroupId = encodeCrock(getRandomBytes(32));
await updateWithdrawalDenoms(ws, canonExchange);
- const denoms = await getPossibleWithdrawalDenoms(ws, canonExchange);
+ const denoms = await getCandidateWithdrawalDenoms(ws, canonExchange);
const denomSelInfo = selectWithdrawalDenominations(req.amount, denoms);
const initialDenomSel = denomSelectionInfoToState(denomSelInfo);
@@ -528,7 +528,7 @@ async function updateReserve(
const currency = balance.currency;
await updateWithdrawalDenoms(ws, reserve.exchangeBaseUrl);
- const denoms = await getPossibleWithdrawalDenoms(ws, reserve.exchangeBaseUrl);
+ const denoms = await getCandidateWithdrawalDenoms(ws, reserve.exchangeBaseUrl);
const newWithdrawalGroup = await ws.db.runWithWriteTransaction(
[Stores.coins, Stores.planchets, Stores.withdrawalGroups, Stores.reserves],
diff --git a/packages/taler-wallet-core/src/operations/tip.ts b/packages/taler-wallet-core/src/operations/tip.ts
index 328fe2cfa..9242d70d5 100644
--- a/packages/taler-wallet-core/src/operations/tip.ts
+++ b/packages/taler-wallet-core/src/operations/tip.ts
@@ -34,7 +34,7 @@ import {
getExchangeWithdrawalInfo,
denomSelectionInfoToState,
updateWithdrawalDenoms,
- getPossibleWithdrawalDenoms,
+ getCandidateWithdrawalDenoms,
selectWithdrawalDenominations,
} from "./withdraw";
import { updateExchangeFromUrl } from "./exchanges";
@@ -95,7 +95,7 @@ export async function prepareTip(
const walletTipId = encodeCrock(getRandomBytes(32));
await updateWithdrawalDenoms(ws, tipPickupStatus.exchange_url);
- const denoms = await getPossibleWithdrawalDenoms(
+ const denoms = await getCandidateWithdrawalDenoms(
ws,
tipPickupStatus.exchange_url,
);
diff --git a/packages/taler-wallet-core/src/operations/withdraw-test.ts b/packages/taler-wallet-core/src/operations/withdraw-test.ts
index d21119c8c..806d8e82d 100644
--- a/packages/taler-wallet-core/src/operations/withdraw-test.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw-test.ts
@@ -17,6 +17,7 @@
import test from "ava";
import { selectWithdrawalDenominations } from "./withdraw";
import { Amounts } from "../util/amounts";
+import { DenominationRecord, DenominationStatus } from "../types/dbTypes";
test("withdrawal selection bug repro", (t) => {
const amount = {
@@ -25,7 +26,7 @@ test("withdrawal selection bug repro", (t) => {
value: 23,
};
- const denoms = [
+ const denoms: DenominationRecord[] = [
{
denomPub:
"040000XT67C8KBD6B75TTQ3SK8FWXMNQW4372T3BDDGPAMB9RFCA03638W8T3F71WFEFK9NP32VKYVNFXPYRWQ1N1HDKV5J0DFEKHBPJCYSWCBJDRNWD7G8BN8PT97FA9AMV75MYEK4X54D1HGJ207JSVJBGFCATSPNTEYNHEQF1F220W00TBZR1HNPDQFD56FG0DJQ9KGHM8EC33H6AY9YN9CNX5R3Z4TZ4Q23W47SBHB13H6W74FQJG1F50X38VRSC4SR8RWBAFB7S4K8D2H4NMRFSQT892A3T0BTBW7HM5C0H2CK6FRKG31F7W9WP1S29013K5CXYE55CT8TH6N8J9B780R42Y5S3ZB6J6E9H76XBPSGH4TGYSR2VZRB98J417KCQMZKX1BB67E7W5KVE37TC9SJ904002",
@@ -68,7 +69,7 @@ test("withdrawal selection bug repro", (t) => {
stampStart: {
t_ms: 1585229388000,
},
- status: 0,
+ status: DenominationStatus.Unverified,
value: {
currency: "KUDOS",
fraction: 0,
@@ -117,7 +118,7 @@ test("withdrawal selection bug repro", (t) => {
stampStart: {
t_ms: 1585229388000,
},
- status: 0,
+ status: DenominationStatus.Unverified,
value: {
currency: "KUDOS",
fraction: 0,
@@ -166,7 +167,7 @@ test("withdrawal selection bug repro", (t) => {
stampStart: {
t_ms: 1585229388000,
},
- status: 0,
+ status: DenominationStatus.Unverified,
value: {
currency: "KUDOS",
fraction: 0,
@@ -215,7 +216,7 @@ test("withdrawal selection bug repro", (t) => {
stampStart: {
t_ms: 1585229388000,
},
- status: 0,
+ status: DenominationStatus.Unverified,
value: {
currency: "KUDOS",
fraction: 0,
@@ -264,7 +265,7 @@ test("withdrawal selection bug repro", (t) => {
stampStart: {
t_ms: 1585229388000,
},
- status: 0,
+ status: DenominationStatus.Unverified,
value: {
currency: "KUDOS",
fraction: 10000000,
@@ -313,7 +314,7 @@ test("withdrawal selection bug repro", (t) => {
stampStart: {
t_ms: 1585229388000,
},
- status: 0,
+ status: DenominationStatus.Unverified,
value: {
currency: "KUDOS",
fraction: 0,
diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts
index d28bea1e1..ffcc5ade6 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.ts
@@ -67,6 +67,7 @@ import { TalerErrorCode } from "../TalerErrorCode";
import { encodeCrock } from "../crypto/talerCrypto";
import { updateRetryInfoTimeout, initRetryInfo } from "../util/retries";
import { compare } from "../util/libtoolVersion";
+import { j2s } from "../util/helpers";
const logger = new Logger("withdraw.ts");
@@ -207,7 +208,7 @@ export async function getBankWithdrawalInfo(
/**
* Return denominations that can potentially used for a withdrawal.
*/
-export async function getPossibleWithdrawalDenoms(
+export async function getCandidateWithdrawalDenoms(
ws: InternalWalletState,
exchangeBaseUrl: string,
): Promise<DenominationRecord[]> {
@@ -544,7 +545,7 @@ export async function updateWithdrawalDenoms(
logger.error("exchange details not available");
throw Error(`exchange ${exchangeBaseUrl} details not available`);
}
- const denominations = await getPossibleWithdrawalDenoms(ws, exchangeBaseUrl);
+ const denominations = await getCandidateWithdrawalDenoms(ws, exchangeBaseUrl);
for (const denom of denominations) {
if (denom.status === DenominationStatus.Unverified) {
const valid = await ws.cryptoApi.isValidDenom(
@@ -559,6 +560,29 @@ export async function updateWithdrawalDenoms(
await ws.db.put(Stores.denominations, denom);
}
}
+ // FIXME: This debug info should either be made conditional on some flag
+ // or put into some wallet-core API.
+ logger.trace("updated withdrawable denominations");
+ const nextDenominations = await getCandidateWithdrawalDenoms(
+ ws,
+ exchangeBaseUrl,
+ );
+ const now = getTimestampNow();
+ for (const denom of nextDenominations) {
+ const started = timestampCmp(now, denom.stampStart) >= 0;
+ const lastPossibleWithdraw = timestampSubtractDuraction(
+ denom.stampExpireWithdraw,
+ { d_ms: 50 * 1000 },
+ );
+ const remaining = getDurationRemaining(lastPossibleWithdraw, now);
+ logger.trace(
+ `Denom ${denom.denomPubHash} ${denom.status} revoked ${
+ denom.isRevoked
+ } offered ${denom.isOffered} remaining ${
+ (remaining.d_ms as number) / 1000
+ }sec started ${started}`,
+ );
+ }
}
async function incrementWithdrawalRetry(
@@ -725,7 +749,7 @@ export async function getExchangeWithdrawalInfo(
}
await updateWithdrawalDenoms(ws, baseUrl);
- const denoms = await getPossibleWithdrawalDenoms(ws, baseUrl);
+ const denoms = await getCandidateWithdrawalDenoms(ws, baseUrl);
const selectedDenoms = selectWithdrawalDenominations(amount, denoms);
const exchangeWireAccounts: string[] = [];
for (const account of exchangeWireInfo.accounts) {
diff --git a/packages/taler-wallet-core/src/types/dbTypes.ts b/packages/taler-wallet-core/src/types/dbTypes.ts
index 60752fd68..e0d137535 100644
--- a/packages/taler-wallet-core/src/types/dbTypes.ts
+++ b/packages/taler-wallet-core/src/types/dbTypes.ts
@@ -261,15 +261,15 @@ export enum DenominationStatus {
/**
* Verification was delayed.
*/
- Unverified,
+ Unverified = "unverified",
/**
* Verified as valid.
*/
- VerifiedGood,
+ VerifiedGood = "verified-good",
/**
* Verified as invalid.
*/
- VerifiedBad,
+ VerifiedBad = "verified-bad",
}
/**