diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-04-02 20:33:01 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-04-02 20:33:01 +0530 |
commit | ef0acf06bfb7820a21c4719dba0d659f600be3c7 (patch) | |
tree | 216d34722240f682e5ee58632947fa75e9b4fcee /src/headless | |
parent | 1728e5011e16f226c6e3675aa196872af39f6c4e (diff) | |
download | wallet-core-ef0acf06bfb7820a21c4719dba0d659f600be3c7.tar.xz |
model reserve history in the exchange, improve reserve handling logic
Diffstat (limited to 'src/headless')
-rw-r--r-- | src/headless/helpers.ts | 6 | ||||
-rw-r--r-- | src/headless/integrationtest.ts | 38 | ||||
-rw-r--r-- | src/headless/taler-wallet-cli.ts | 32 |
3 files changed, 52 insertions, 24 deletions
diff --git a/src/headless/helpers.ts b/src/headless/helpers.ts index fb3d800d4..92452e78f 100644 --- a/src/headless/helpers.ts +++ b/src/headless/helpers.ts @@ -35,6 +35,7 @@ import { Database } from "../util/query"; import { NodeHttpLib } from "./NodeHttpLib"; import { Logger } from "../util/logging"; import { SynchronousCryptoWorkerFactory } from "../crypto/workers/synchronousWorker"; +import { WithdrawalSourceType } from "../types/dbTypes"; const logger = new Logger("helpers.ts"); @@ -165,8 +166,9 @@ export async function withdrawTestBalance( }); myWallet.addNotificationListener((n) => { if ( - n.type === NotificationType.ReserveDepleted && - n.reservePub === reservePub + n.type === NotificationType.WithdrawGroupFinished && + n.withdrawalSource.type === WithdrawalSourceType.Reserve && + n.withdrawalSource.reservePub === reservePub ) { resolve(); } diff --git a/src/headless/integrationtest.ts b/src/headless/integrationtest.ts index 191e48ff6..6e45b76e2 100644 --- a/src/headless/integrationtest.ts +++ b/src/headless/integrationtest.ts @@ -22,9 +22,9 @@ import { getDefaultNodeWallet, withdrawTestBalance } from "./helpers"; import { MerchantBackendConnection } from "./merchant"; import { Logger } from "../util/logging"; import { NodeHttpLib } from "./NodeHttpLib"; -import * as Amounts from "../util/amounts"; import { Wallet } from "../wallet"; import { Configuration } from "../util/talerconfig"; +import { Amounts, AmountJson } from "../util/amounts"; const logger = new Logger("integrationtest.ts"); @@ -127,31 +127,31 @@ export async function runIntegrationTest(args: IntegrationTestArgs) { await myWallet.runUntilDone(); console.log("withdrawing test balance for refund"); - const withdrawAmountTwo: Amounts.AmountJson = { + const withdrawAmountTwo: AmountJson = { currency, value: 18, fraction: 0, }; - const spendAmountTwo: Amounts.AmountJson = { + const spendAmountTwo: AmountJson = { currency, value: 7, fraction: 0, }; - const refundAmount: Amounts.AmountJson = { + const refundAmount: AmountJson = { currency, value: 6, fraction: 0, }; - const spendAmountThree: Amounts.AmountJson = { + const spendAmountThree: AmountJson = { currency, value: 3, fraction: 0, }; await withdrawTestBalance( myWallet, - Amounts.toString(withdrawAmountTwo), + Amounts.stringify(withdrawAmountTwo), args.bankBaseUrl, args.exchangeBaseUrl, ); @@ -162,14 +162,14 @@ export async function runIntegrationTest(args: IntegrationTestArgs) { let { orderId: refundOrderId } = await makePayment( myWallet, myMerchant, - Amounts.toString(spendAmountTwo), + Amounts.stringify(spendAmountTwo), "order that will be refunded", ); const refundUri = await myMerchant.refund( refundOrderId, "test refund", - Amounts.toString(refundAmount), + Amounts.stringify(refundAmount), ); console.log("refund URI", refundUri); @@ -182,7 +182,7 @@ export async function runIntegrationTest(args: IntegrationTestArgs) { await makePayment( myWallet, myMerchant, - Amounts.toString(spendAmountThree), + Amounts.stringify(spendAmountThree), "payment after refund", ); @@ -240,7 +240,7 @@ export async function runIntegrationTestBasic(cfg: Configuration) { logger.info("withdrawing test balance"); await withdrawTestBalance( myWallet, - Amounts.toString(parsedWithdrawAmount), + Amounts.stringify(parsedWithdrawAmount), bankBaseUrl, exchangeBaseUrl, ); @@ -258,7 +258,7 @@ export async function runIntegrationTestBasic(cfg: Configuration) { await makePayment( myWallet, myMerchant, - Amounts.toString(parsedSpendAmount), + Amounts.stringify(parsedSpendAmount), "hello world", ); @@ -266,24 +266,24 @@ export async function runIntegrationTestBasic(cfg: Configuration) { await myWallet.runUntilDone(); console.log("withdrawing test balance for refund"); - const withdrawAmountTwo: Amounts.AmountJson = { + const withdrawAmountTwo: AmountJson = { currency, value: 18, fraction: 0, }; - const spendAmountTwo: Amounts.AmountJson = { + const spendAmountTwo: AmountJson = { currency, value: 7, fraction: 0, }; - const refundAmount: Amounts.AmountJson = { + const refundAmount: AmountJson = { currency, value: 6, fraction: 0, }; - const spendAmountThree: Amounts.AmountJson = { + const spendAmountThree: AmountJson = { currency, value: 3, fraction: 0, @@ -291,7 +291,7 @@ export async function runIntegrationTestBasic(cfg: Configuration) { await withdrawTestBalance( myWallet, - Amounts.toString(withdrawAmountTwo), + Amounts.stringify(withdrawAmountTwo), bankBaseUrl, exchangeBaseUrl, ); @@ -302,14 +302,14 @@ export async function runIntegrationTestBasic(cfg: Configuration) { let { orderId: refundOrderId } = await makePayment( myWallet, myMerchant, - Amounts.toString(spendAmountTwo), + Amounts.stringify(spendAmountTwo), "order that will be refunded", ); const refundUri = await myMerchant.refund( refundOrderId, "test refund", - Amounts.toString(refundAmount), + Amounts.stringify(refundAmount), ); console.log("refund URI", refundUri); @@ -322,7 +322,7 @@ export async function runIntegrationTestBasic(cfg: Configuration) { await makePayment( myWallet, myMerchant, - Amounts.toString(spendAmountThree), + Amounts.stringify(spendAmountThree), "payment after refund", ); diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts index 45ab819a7..d183ef316 100644 --- a/src/headless/taler-wallet-cli.ts +++ b/src/headless/taler-wallet-cli.ts @@ -24,7 +24,7 @@ import qrcodeGenerator = require("qrcode-generator"); import * as clk from "./clk"; import { BridgeIDBFactory, MemoryBackend } from "idb-bridge"; import { Logger } from "../util/logging"; -import * as Amounts from "../util/amounts"; +import { Amounts } from "../util/amounts"; import { decodeCrock } from "../crypto/talerCrypto"; import { OperationFailedAndReportedError } from "../operations/errors"; import { Bank } from "./bank"; @@ -190,7 +190,7 @@ walletCli } else { const currencies = Object.keys(balance.byCurrency).sort(); for (const c of currencies) { - console.log(Amounts.toString(balance.byCurrency[c].available)); + console.log(Amounts.stringify(balance.byCurrency[c].available)); } } }); @@ -356,6 +356,32 @@ advancedCli fs.writeFileSync(1, decodeCrock(enc.trim())); }); +const reservesCli = advancedCli.subcommand("reserves", "reserves", { + help: "Manage reserves.", +}); + +reservesCli + .subcommand("list", "list", { + help: "List reserves.", + }) + .action(async (args) => { + await withWallet(args, async (wallet) => { + const reserves = await wallet.getReserves(); + console.log(JSON.stringify(reserves, undefined, 2)); + }); + }); + +reservesCli + .subcommand("update", "update", { + help: "Update reserve status via exchange.", + }) + .requiredArgument("reservePub", clk.STRING) + .action(async (args) => { + await withWallet(args, async (wallet) => { + await wallet.updateReserve(args.update.reservePub); + }); + }); + advancedCli .subcommand("payPrepare", "pay-prepare", { help: "Claim an order but don't pay yet.", @@ -464,7 +490,7 @@ advancedCli console.log(` exchange ${coin.exchangeBaseUrl}`); console.log(` denomPubHash ${coin.denomPubHash}`); console.log( - ` remaining amount ${Amounts.toString(coin.currentAmount)}`, + ` remaining amount ${Amounts.stringify(coin.currentAmount)}`, ); } }); |