diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-05-15 16:03:52 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-05-15 16:03:52 +0530 |
commit | 3eb88574bcf327672c34120becfb511eac4e06cd (patch) | |
tree | 9d54748adef52dc9a21c8ea97c7d034cd773277a /src/operations | |
parent | 35c83414f9e0af11012c1a2e00672d2a7c1856ae (diff) | |
download | wallet-core-3eb88574bcf327672c34120becfb511eac4e06cd.tar.xz |
address first batch of transaction list issues
Diffstat (limited to 'src/operations')
-rw-r--r-- | src/operations/pay.ts | 10 | ||||
-rw-r--r-- | src/operations/reserves.ts | 51 | ||||
-rw-r--r-- | src/operations/tip.ts | 16 | ||||
-rw-r--r-- | src/operations/transactions.ts | 55 | ||||
-rw-r--r-- | src/operations/withdraw.ts | 20 |
5 files changed, 65 insertions, 87 deletions
diff --git a/src/operations/pay.ts b/src/operations/pay.ts index 45caa9583..20d62dea2 100644 --- a/src/operations/pay.ts +++ b/src/operations/pay.ts @@ -137,11 +137,7 @@ export async function getTotalPaymentCost( ws: InternalWalletState, pcs: PayCoinSelection, ): Promise<PayCostInfo> { - const costs = [ - pcs.paymentAmount, - pcs.customerDepositFees, - pcs.customerWireFees, - ]; + const costs = []; for (let i = 0; i < pcs.coinPubs.length; i++) { const coin = await ws.db.get(Stores.coins, pcs.coinPubs[i]); if (!coin) { @@ -165,6 +161,7 @@ export async function getTotalPaymentCost( const amountLeft = Amounts.sub(denom.value, pcs.coinContributions[i]) .amount; const refreshCost = getTotalRefreshCost(allDenoms, denom, amountLeft); + costs.push(pcs.coinContributions[i]); costs.push(refreshCost); } return { @@ -670,6 +667,9 @@ async function processDownloadProposalImpl( wireMethod: parsedContractTerms.wire_method, wireInfoHash: parsedContractTerms.h_wire, maxDepositFee: Amounts.parseOrThrow(parsedContractTerms.max_fee), + merchant: parsedContractTerms.merchant, + products: parsedContractTerms.products, + summaryI18n: parsedContractTerms.summary_i18n, }, contractTermsRaw: JSON.stringify(proposalResp.contract_terms), }; diff --git a/src/operations/reserves.ts b/src/operations/reserves.ts index 347f6e894..3d45d8d5a 100644 --- a/src/operations/reserves.ts +++ b/src/operations/reserves.ts @@ -35,6 +35,7 @@ import { WalletReserveHistoryItemType, WithdrawalSourceType, ReserveHistoryRecord, + ReserveBankInfo, } from "../types/dbTypes"; import { Logger } from "../util/logging"; import { Amounts } from "../util/amounts"; @@ -48,9 +49,11 @@ import { assertUnreachable } from "../util/assertUnreachable"; import { encodeCrock, getRandomBytes } from "../crypto/talerCrypto"; import { randomBytes } from "../crypto/primitives/nacl-fast"; import { - getVerifiedWithdrawDenomList, + selectWithdrawalDenoms, processWithdrawGroup, getBankWithdrawalInfo, + denomSelectionInfoToState, + getWithdrawDenomList, } from "./withdraw"; import { guardOperationException, @@ -100,6 +103,20 @@ export async function createReserve( reserveStatus = ReserveRecordStatus.UNCONFIRMED; } + let bankInfo: ReserveBankInfo | undefined; + + if (req.bankWithdrawStatusUrl) { + const denomSelInfo = await selectWithdrawalDenoms(ws, canonExchange, req.amount); + const denomSel = denomSelectionInfoToState(denomSelInfo); + bankInfo = { + statusUrl: req.bankWithdrawStatusUrl, + amount: req.amount, + bankWithdrawalGroupId: encodeCrock(getRandomBytes(32)), + withdrawalStarted: false, + denomSel, + }; + } + const reserveRecord: ReserveRecord = { timestampCreated: now, exchangeBaseUrl: canonExchange, @@ -108,14 +125,7 @@ export async function createReserve( senderWire: req.senderWire, timestampConfirmed: undefined, timestampReserveInfoPosted: undefined, - bankInfo: req.bankWithdrawStatusUrl - ? { - statusUrl: req.bankWithdrawStatusUrl, - amount: req.amount, - bankWithdrawalGroupId: encodeCrock(getRandomBytes(32)), - withdrawalStarted: false, - } - : undefined, + bankInfo, exchangeWire: req.exchangeWire, reserveStatus, lastSuccessfulStatusQuery: undefined, @@ -286,10 +296,11 @@ async function registerReserveWithBank( default: return; } - const bankStatusUrl = reserve.bankInfo?.statusUrl; - if (!bankStatusUrl) { + const bankInfo = reserve.bankInfo; + if (!bankInfo) { return; } + const bankStatusUrl = bankInfo.statusUrl; console.log("making selection"); if (reserve.timestampReserveInfoPosted) { throw Error("bank claims that reserve info selection is not done"); @@ -309,6 +320,9 @@ async function registerReserveWithBank( } r.timestampReserveInfoPosted = getTimestampNow(); r.reserveStatus = ReserveRecordStatus.WAIT_CONFIRM_BANK; + if (!r.bankInfo) { + throw Error("invariant failed"); + } r.retryInfo = initRetryInfo(); return r; }); @@ -657,7 +671,7 @@ async function depleteReserve( logger.trace(`getting denom list`); - const denomsForWithdraw = await getVerifiedWithdrawDenomList( + const denomsForWithdraw = await selectWithdrawalDenoms( ws, reserve.exchangeBaseUrl, withdrawAmount, @@ -752,17 +766,8 @@ async function depleteReserve( retryInfo: initRetryInfo(), lastErrorPerCoin: {}, lastError: undefined, - denomsSel: { - totalCoinValue: denomsForWithdraw.totalCoinValue, - totalWithdrawCost: denomsForWithdraw.totalWithdrawCost, - selectedDenoms: denomsForWithdraw.selectedDenoms.map((x) => { - return { - count: x.count, - denomPubHash: x.denom.denomPubHash, - }; - }), - }, - }; + denomsSel: denomSelectionInfoToState(denomsForWithdraw), + }; await tx.put(Stores.reserves, newReserve); await tx.put(Stores.reserveHistory, newHist); diff --git a/src/operations/tip.ts b/src/operations/tip.ts index f584fc502..15d2339b5 100644 --- a/src/operations/tip.ts +++ b/src/operations/tip.ts @@ -34,8 +34,9 @@ import { } from "../types/dbTypes"; import { getExchangeWithdrawalInfo, - getVerifiedWithdrawDenomList, + selectWithdrawalDenoms, processWithdrawGroup, + denomSelectionInfoToState, } from "./withdraw"; import { updateExchangeFromUrl } from "./exchanges"; import { getRandomBytes, encodeCrock } from "../crypto/talerCrypto"; @@ -81,7 +82,7 @@ export async function getTipStatus( ); const tipId = encodeCrock(getRandomBytes(32)); - const selectedDenoms = await getVerifiedWithdrawDenomList( + const selectedDenoms = await selectWithdrawalDenoms( ws, tipPickupStatus.exchange_url, amount, @@ -107,16 +108,7 @@ export async function getTipStatus( ).amount, retryInfo: initRetryInfo(), lastError: undefined, - denomsSel: { - totalCoinValue: selectedDenoms.totalCoinValue, - totalWithdrawCost: selectedDenoms.totalWithdrawCost, - selectedDenoms: selectedDenoms.selectedDenoms.map((x) => { - return { - count: x.count, - denomPubHash: x.denom.denomPubHash, - }; - }), - }, + denomsSel: denomSelectionInfoToState(selectedDenoms), }; await ws.db.put(Stores.tips, tipRecord); } diff --git a/src/operations/transactions.ts b/src/operations/transactions.ts index 4cc6154b5..fd7679621 100644 --- a/src/operations/transactions.ts +++ b/src/operations/transactions.ts @@ -18,7 +18,7 @@ * Imports. */ import { InternalWalletState } from "./state"; -import { Stores, ReserveRecordStatus, PurchaseRecord, ProposalStatus } from "../types/dbTypes"; +import { Stores, ReserveRecordStatus, PurchaseRecord } from "../types/dbTypes"; import { Amounts, AmountJson } from "../util/amounts"; import { timestampCmp } from "../util/time"; import { @@ -131,10 +131,8 @@ export async function getTransactions( if (wsr.timestampFinish) { transactions.push({ type: TransactionType.Withdrawal, - amountEffective: Amounts.stringify( - wsr.denomsSel.totalWithdrawCost, - ), - amountRaw: Amounts.stringify(wsr.denomsSel.totalCoinValue), + amountEffective: Amounts.stringify(wsr.denomsSel.totalCoinValue), + amountRaw: Amounts.stringify(wsr.denomsSel.totalWithdrawCost), confirmed: true, exchangeBaseUrl: wsr.exchangeBaseUrl, pending: !wsr.timestampFinish, @@ -163,9 +161,9 @@ export async function getTransactions( transactions.push({ type: TransactionType.Withdrawal, confirmed: false, - amountRaw: Amounts.stringify(r.bankInfo.amount), - amountEffective: undefined, - exchangeBaseUrl: undefined, + amountRaw: Amounts.stringify(r.bankInfo.denomSel.totalWithdrawCost), + amountEffective: Amounts.stringify(r.bankInfo.denomSel.totalCoinValue), + exchangeBaseUrl: r.exchangeBaseUrl, pending: true, timestamp: r.timestampCreated, bankConfirmationUrl: r.bankInfo.confirmUrl, @@ -176,38 +174,6 @@ export async function getTransactions( }); }); - tx.iter(Stores.proposals).forEachAsync(async (proposal) => { - if (!proposal.download) { - return; - } - if (proposal.proposalStatus !== ProposalStatus.PROPOSED) { - return; - } - const dl = proposal.download; - const purchase = await tx.get(Stores.purchases, proposal.proposalId); - if (purchase) { - return; - } - - transactions.push({ - type: TransactionType.Payment, - amountRaw: Amounts.stringify(dl.contractData.amount), - amountEffective: undefined, - status: PaymentStatus.Offered, - pending: true, - timestamp: proposal.timestamp, - transactionId: makeEventId(TransactionType.Payment, proposal.proposalId), - info: { - fulfillmentUrl: dl.contractData.fulfillmentUrl, - merchant: {}, - orderId: dl.contractData.orderId, - products: [], - summary: dl.contractData.summary, - summary_i18n: {}, - }, - }); - }); - tx.iter(Stores.purchases).forEachAsync(async (pr) => { if ( transactionsRequest?.currency && @@ -231,11 +197,11 @@ export async function getTransactions( transactionId: makeEventId(TransactionType.Payment, pr.proposalId), info: { fulfillmentUrl: pr.contractData.fulfillmentUrl, - merchant: {}, + merchant: pr.contractData.merchant, orderId: pr.contractData.orderId, - products: [], + products: pr.contractData.products, summary: pr.contractData.summary, - summary_i18n: {}, + summary_i18n: pr.contractData.summaryI18n, }, }); @@ -258,7 +224,8 @@ export async function getTransactions( timestamp: rg.timestampQueried, transactionId: makeEventId( TransactionType.Refund, - `{rg.timestampQueried.t_ms}`, + pr.proposalId, + `${rg.timestampQueried.t_ms}`, ), refundedTransactionId: makeEventId( TransactionType.Payment, diff --git a/src/operations/withdraw.ts b/src/operations/withdraw.ts index 21c30d7af..14071be79 100644 --- a/src/operations/withdraw.ts +++ b/src/operations/withdraw.ts @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2019-2029 Taler Systems SA + (C) 2019-2020 Taler Systems SA GNU Taler is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -27,6 +27,7 @@ import { DenominationSelectionInfo, PlanchetRecord, WithdrawalSourceType, + DenomSelectionState, } from "../types/dbTypes"; import { BankWithdrawDetails, @@ -419,6 +420,19 @@ async function processPlanchet( } } +export function denomSelectionInfoToState(dsi: DenominationSelectionInfo): DenomSelectionState { + return { + selectedDenoms: dsi.selectedDenoms.map((x) => { + return { + count: x.count, + denomPubHash: x.denom.denomPubHash + }; + }), + totalCoinValue: dsi.totalCoinValue, + totalWithdrawCost: dsi.totalWithdrawCost, + } +} + /** * Get a list of denominations to withdraw from the given exchange for the * given amount, making sure that all denominations' signatures are verified. @@ -426,7 +440,7 @@ async function processPlanchet( * Writes to the DB in order to record the result from verifying * denominations. */ -export async function getVerifiedWithdrawDenomList( +export async function selectWithdrawalDenoms( ws: InternalWalletState, exchangeBaseUrl: string, amount: AmountJson, @@ -603,7 +617,7 @@ export async function getExchangeWithdrawalInfo( throw Error(`exchange ${exchangeInfo.baseUrl} wire details not available`); } - const selectedDenoms = await getVerifiedWithdrawDenomList( + const selectedDenoms = await selectWithdrawalDenoms( ws, baseUrl, amount, |