make verbose details an option

This commit is contained in:
Florian Dold 2020-01-22 12:22:57 +01:00
parent 21194fa781
commit 14103aa075
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
4 changed files with 77 additions and 55 deletions

View File

@ -187,7 +187,7 @@ export async function runIntegrationTest(args: IntegrationTestArgs) {
await myWallet.runUntilDone(); await myWallet.runUntilDone();
const history = await myWallet.getHistory(); const history = await myWallet.getHistory({ verboseDetails: true });
console.log("history after integration test:", JSON.stringify(history, undefined, 2)); console.log("history after integration test:", JSON.stringify(history, undefined, 2));
} }

View File

@ -215,15 +215,16 @@ export async function getHistory(
cs.push(x); cs.push(x);
} }
}); });
const verboseDetails: VerboseWithdrawDetails = {
coins: cs.map((x) => ({ let verboseDetails: VerboseWithdrawDetails | undefined = undefined;
value: Amounts.toString(x.coinValue), if (historyQuery?.verboseDetails) {
denomPub: x.denomPub, verboseDetails = {
})), coins: cs.map((x) => ({
}; value: Amounts.toString(x.coinValue),
const coins = cs.map((x) => ({ denomPub: x.denomPub,
value: x.coinValue })),
})); };
}
history.push({ history.push({
type: HistoryEventType.Withdrawn, type: HistoryEventType.Withdrawn,
@ -257,29 +258,32 @@ export async function getHistory(
if (!orderShortInfo) { if (!orderShortInfo) {
return; return;
} }
const coins: { let verboseDetails: VerbosePayCoinDetails | undefined = undefined;
value: string, if (historyQuery?.verboseDetails) {
contribution: string; const coins: {
denomPub: string; value: string,
}[] = []; contribution: string;
for (const x of purchase.payReq.coins) { denomPub: string;
const c = await tx.get(Stores.coins, x.coin_pub); }[] = [];
if (!c) { for (const x of purchase.payReq.coins) {
// FIXME: what to do here?? const c = await tx.get(Stores.coins, x.coin_pub);
continue; if (!c) {
// FIXME: what to do here??
continue;
}
const d = await tx.get(Stores.denominations, [c.exchangeBaseUrl, c.denomPub]);
if (!d) {
// FIXME: what to do here??
continue;
}
coins.push({
contribution: x.contribution,
denomPub: c.denomPub,
value: Amounts.toString(d.value),
});
} }
const d = await tx.get(Stores.denominations, [c.exchangeBaseUrl, c.denomPub]); verboseDetails = { coins };
if (!d) {
// FIXME: what to do here??
continue;
}
coins.push({
contribution: x.contribution,
denomPub: c.denomPub,
value: Amounts.toString(d.value),
});
} }
const verboseDetails: VerbosePayCoinDetails = { coins };
const amountPaidWithFees = Amounts.sum( const amountPaidWithFees = Amounts.sum(
purchase.payReq.coins.map(x => Amounts.parseOrThrow(x.contribution)), purchase.payReq.coins.map(x => Amounts.parseOrThrow(x.contribution)),
).amount; ).amount;
@ -331,30 +335,33 @@ export async function getHistory(
} else { } else {
amountRefreshedEffective = Amounts.sum(amountsEffective).amount; amountRefreshedEffective = Amounts.sum(amountsEffective).amount;
} }
const outputCoins: { let verboseDetails: VerboseRefreshDetails | undefined = undefined;
value: string; if (historyQuery?.verboseDetails) {
denomPub: string, const outputCoins: {
}[] = []; value: string;
for (const rs of rg.refreshSessionPerCoin) { denomPub: string,
if (!rs) { }[] = [];
continue; for (const rs of rg.refreshSessionPerCoin) {
} if (!rs) {
for (const nd of rs.newDenoms) {
if (!nd) {
continue; continue;
} }
const d = await tx.get(Stores.denominations, [rs.exchangeBaseUrl, nd]); for (const nd of rs.newDenoms) {
if (!d) { if (!nd) {
continue; continue;
}
const d = await tx.get(Stores.denominations, [rs.exchangeBaseUrl, nd]);
if (!d) {
continue;
}
outputCoins.push({
denomPub: d.denomPub,
value: Amounts.toString(d.value),
});
} }
outputCoins.push({
denomPub: d.denomPub,
value: Amounts.toString(d.value),
});
} }
} verboseDetails = {
const verboseDetails: VerboseRefreshDetails = { outputCoins: outputCoins,
outputCoins: outputCoins, }
} }
history.push({ history.push({
type: HistoryEventType.Refreshed, type: HistoryEventType.Refreshed,

View File

@ -509,7 +509,7 @@ export interface HistoryPaymentSent {
*/ */
sessionId: string | undefined; sessionId: string | undefined;
verboseDetails: VerbosePayCoinDetails; verboseDetails?: VerbosePayCoinDetails;
} }
/** /**
@ -590,7 +590,7 @@ export interface HistoryRefreshedEvent {
*/ */
refreshGroupId: string; refreshGroupId: string;
verboseDetails: VerboseRefreshDetails; verboseDetails?: VerboseRefreshDetails;
} }
export interface VerboseWithdrawDetails { export interface VerboseWithdrawDetails {
@ -630,7 +630,10 @@ export interface HistoryWithdrawnEvent {
*/ */
amountWithdrawnEffective: string; amountWithdrawnEffective: string;
verboseDetails: VerboseWithdrawDetails; /**
* Verbose details of the operations, only generated when requested.
*/
verboseDetails?: VerboseWithdrawDetails;
} }
/** /**
@ -684,5 +687,9 @@ export type HistoryEvent = HistoryEventBase &
); );
export interface HistoryQuery { export interface HistoryQuery {
// TBD /**
* Output extra verbose details, intended for debugging
* and not for end users.
*/
verboseDetails?: boolean;
} }

View File

@ -60,6 +60,9 @@ export type PendingOperationInfo = PendingOperationInfoCommon &
| PendingWithdrawOperation | PendingWithdrawOperation
); );
/**
* The wallet is currently updating information about an exchange.
*/
export interface PendingExchangeUpdateOperation { export interface PendingExchangeUpdateOperation {
type: PendingOperationType.ExchangeUpdate; type: PendingOperationType.ExchangeUpdate;
stage: string; stage: string;
@ -68,6 +71,11 @@ export interface PendingExchangeUpdateOperation {
lastError: OperationError | undefined; lastError: OperationError | undefined;
} }
/**
* Some interal error happened in the wallet. This pending operation
* should *only* be reported for problems in the wallet, not when
* a problem with a merchant/exchange/etc. occurs.
*/
export interface PendingBugOperation { export interface PendingBugOperation {
type: PendingOperationType.Bug; type: PendingOperationType.Bug;
message: string; message: string;