diff options
Diffstat (limited to 'packages/taler-wallet-cli/src')
-rw-r--r-- | packages/taler-wallet-cli/src/index.ts | 67 |
1 files changed, 27 insertions, 40 deletions
diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts index 3fc86d0b5..f3b205211 100644 --- a/packages/taler-wallet-cli/src/index.ts +++ b/packages/taler-wallet-cli/src/index.ts @@ -53,6 +53,7 @@ import { import { createPlatformHttpLib } from "@gnu-taler/taler-util/http"; import { JsonMessage, runRpcServer } from "@gnu-taler/taler-util/twrpc"; import { + AccessStats, createNativeWalletHost, createNativeWalletHost2, Wallet, @@ -237,16 +238,21 @@ export interface WalletContext { ): Promise<T>; } +interface CreateWalletResult { + wallet: Wallet; + getStats: () => AccessStats; +} + async function createLocalWallet( walletCliArgs: WalletCliArgsType, notificationHandler?: (n: WalletNotification) => void, -): Promise<Wallet> { +): Promise<CreateWalletResult> { const dbPath = walletCliArgs.wallet.walletDbFile ?? defaultWalletDbPath; const myHttpLib = createPlatformHttpLib({ enableThrottling: walletCliArgs.wallet.noThrottle ? false : true, requireTls: walletCliArgs.wallet.noHttp, }); - const wallet = await createNativeWalletHost({ + const wh = await createNativeWalletHost2({ persistentStoragePath: dbPath !== ":memory:" ? dbPath : undefined, httpLib: myHttpLib, notifyHandler: (n) => { @@ -269,10 +275,10 @@ async function createLocalWallet( applyVerbose(walletCliArgs.wallet.verbose); try { - await wallet.handleCoreApiRequest("initWallet", "native-init", { + await wh.wallet.handleCoreApiRequest("initWallet", "native-init", { skipDefaults: walletCliArgs.wallet.skipDefaults, }); - return wallet; + return { wallet: wh.wallet, getStats: wh.getDbStats }; } catch (e) { const ed = getErrorDetailFromException(e); console.error("Operation failed: " + summarizeTalerErrorDetail(ed)); @@ -307,16 +313,20 @@ async function withWallet<T>( w.close(); return res; } else { - const w = await createLocalWallet(walletCliArgs, waiter.notify); + const wh = await createLocalWallet(walletCliArgs, waiter.notify); const ctx: WalletContext = { - client: w.client, + client: wh.wallet.client, waitForNotificationCond: waiter.waitForNotificationCond, makeCoreApiRequest(operation, payload) { - return w.handleCoreApiRequest(operation, "my-req", payload); + return wh.wallet.handleCoreApiRequest(operation, "my-req", payload); }, }; const result = await f(ctx); - w.stop(); + wh.wallet.stop(); + if (process.env.TALER_WALLET_DBSTATS) { + console.log("database stats:"); + console.log(j2s(wh.getStats())); + } return result; } } @@ -330,7 +340,8 @@ async function withLocalWallet<T>( walletCliArgs: WalletCliArgsType, f: (w: { client: WalletCoreApiClient; ws: Wallet }) => Promise<T>, ): Promise<T> { - const w = await createLocalWallet(walletCliArgs); + const wh = await createLocalWallet(walletCliArgs); + const w = wh.wallet; const res = await f({ client: w.client, ws: w }); w.stop(); return res; @@ -1030,8 +1041,7 @@ peerCli const resp = await wallet.client.call( WalletApiOperation.ConfirmPeerPullDebit, { - peerPullDebitId: - args.confirmIncomingPayPull.peerPullDebitId, + peerPullDebitId: args.confirmIncomingPayPull.peerPullDebitId, }, ); console.log(JSON.stringify(resp, undefined, 2)); @@ -1046,8 +1056,7 @@ peerCli const resp = await wallet.client.call( WalletApiOperation.ConfirmPeerPushCredit, { - peerPushCreditId: - args.confirmIncomingPayPush.peerPushCreditId, + peerPushCreditId: args.confirmIncomingPayPush.peerPushCreditId, }, ); console.log(JSON.stringify(resp, undefined, 2)); @@ -1174,7 +1183,8 @@ advancedCli }) .action(async (args) => { logger.info(`serving at ${args.serve.unixPath}`); - const w = await createLocalWallet(args); + const wh = await createLocalWallet(args); + const w = wh.wallet; w.runTaskLoop() .then((res) => { logger.warn("task loop exited unexpectedly"); @@ -1270,7 +1280,7 @@ advancedCli await wallet.client.call(WalletApiOperation.RunIntegrationTest, { amountToSpend: "TESTKUDOS:1", amountToWithdraw: "TESTKUDOS:3", - bankAccessApiBaseUrl: "http://localhost:8082/taler-bank-access/", + corebankApiBaseUrl: "http://localhost:8082/taler-bank-access/", exchangeBaseUrl: "http://localhost:8081/", merchantBaseUrl: "http://localhost:8083/", }); @@ -1281,29 +1291,6 @@ advancedCli }); advancedCli - .subcommand("withdrawFakebank", "withdraw-fakebank", { - help: "Withdraw via a fakebank.", - }) - .requiredOption("exchange", ["--exchange"], clk.STRING, { - help: "Base URL of the exchange to use", - }) - .requiredOption("amount", ["--amount"], clk.STRING, { - help: "Amount to withdraw (before fees).", - }) - .requiredOption("bank", ["--bank"], clk.STRING, { - help: "Base URL of the Taler fakebank service.", - }) - .action(async (args) => { - await withWallet(args, async (wallet) => { - await wallet.client.call(WalletApiOperation.WithdrawFakebank, { - amount: args.withdrawFakebank.amount, - bank: args.withdrawFakebank.bank, - exchange: args.withdrawFakebank.exchange, - }); - }); - }); - -advancedCli .subcommand("genSegwit", "gen-segwit") .requiredArgument("paytoUri", clk.STRING) .requiredArgument("reservePub", clk.STRING) @@ -1520,8 +1507,8 @@ testCli.subcommand("withdrawKudos", "withdraw-kudos").action(async (args) => { await withWallet(args, async (wallet) => { await wallet.client.call(WalletApiOperation.WithdrawTestBalance, { amount: "KUDOS:50", - bankAccessApiBaseUrl: - "https://bank.demo.taler.net/demobanks/default/access-api/", + corebankApiBaseUrl: + "https://bank.demo.taler.net/", exchangeBaseUrl: "https://exchange.demo.taler.net/", }); }); |