2019-08-01 23:27:42 +02:00
|
|
|
/*
|
2019-12-16 21:10:57 +01:00
|
|
|
This file is part of GNU Taler
|
|
|
|
(C) 2019 Taler Systems S.A.
|
2019-08-01 23:27:42 +02:00
|
|
|
|
2019-12-16 21:10:57 +01:00
|
|
|
GNU Taler is free software; you can redistribute it and/or modify it under the
|
2019-08-01 23:27:42 +02:00
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
2019-12-16 21:10:57 +01:00
|
|
|
GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
|
2019-08-01 23:27:42 +02:00
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
2019-12-16 21:10:57 +01:00
|
|
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
2019-08-01 23:27:42 +02:00
|
|
|
*/
|
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* Imports.
|
|
|
|
*/
|
2020-04-06 17:35:51 +02:00
|
|
|
import os from "os";
|
|
|
|
import fs from "fs";
|
2021-03-17 17:56:37 +01:00
|
|
|
import * as clk from "./clk.js";
|
2020-12-03 14:15:40 +01:00
|
|
|
import { deepStrictEqual } from "assert";
|
2021-03-17 17:56:37 +01:00
|
|
|
import { getTestInfo, runTests } from "./integrationtests/testrunner.js";
|
2021-04-14 18:21:23 +02:00
|
|
|
import {
|
|
|
|
PreparePayResultType,
|
|
|
|
setDangerousTimetravel,
|
|
|
|
classifyTalerUri,
|
|
|
|
TalerUriType,
|
|
|
|
RecoveryMergeStrategy,
|
|
|
|
Amounts,
|
|
|
|
addPaytoQueryParams,
|
|
|
|
codecForList,
|
|
|
|
codecForString,
|
2021-06-08 20:58:13 +02:00
|
|
|
Logger,
|
2021-06-15 18:52:43 +02:00
|
|
|
WithdrawalType,
|
2021-04-14 18:21:23 +02:00
|
|
|
} from "@gnu-taler/taler-util";
|
|
|
|
import {
|
|
|
|
NodeHttpLib,
|
|
|
|
getDefaultNodeWallet,
|
|
|
|
OperationFailedAndReportedError,
|
|
|
|
OperationFailedError,
|
|
|
|
decodeCrock,
|
|
|
|
rsaBlind,
|
|
|
|
NodeThreadCryptoWorkerFactory,
|
|
|
|
CryptoApi,
|
|
|
|
walletCoreDebugFlags,
|
2021-06-15 18:52:43 +02:00
|
|
|
handleCoreApiRequest,
|
|
|
|
runPending,
|
|
|
|
runUntilDone,
|
|
|
|
getClientFromWalletState,
|
2021-06-15 19:01:05 +02:00
|
|
|
WalletApiOperation,
|
|
|
|
WalletCoreApiClient,
|
|
|
|
InternalWalletState,
|
2021-04-14 18:21:23 +02:00
|
|
|
} from "@gnu-taler/taler-wallet-core";
|
2020-08-05 21:00:36 +02:00
|
|
|
|
|
|
|
// This module also serves as the entry point for the crypto
|
|
|
|
// thread worker, and thus must expose these two handlers.
|
2021-02-03 14:35:29 +01:00
|
|
|
export {
|
|
|
|
handleWorkerError,
|
|
|
|
handleWorkerMessage,
|
|
|
|
} from "@gnu-taler/taler-wallet-core";
|
2020-02-24 18:40:36 +01:00
|
|
|
|
2019-11-21 23:09:43 +01:00
|
|
|
const logger = new Logger("taler-wallet-cli.ts");
|
2019-08-16 23:29:29 +02:00
|
|
|
|
2020-03-23 12:30:01 +01:00
|
|
|
const defaultWalletDbPath = os.homedir + "/" + ".talerwalletdb.json";
|
2019-08-16 23:29:29 +02:00
|
|
|
|
2019-11-30 00:36:20 +01:00
|
|
|
function assertUnreachable(x: never): never {
|
|
|
|
throw new Error("Didn't expect to get here");
|
|
|
|
}
|
|
|
|
|
2019-11-19 16:16:12 +01:00
|
|
|
async function doPay(
|
2021-06-15 18:52:43 +02:00
|
|
|
wallet: WalletCoreApiClient,
|
2019-11-19 16:16:12 +01:00
|
|
|
payUrl: string,
|
|
|
|
options: { alwaysYes: boolean } = { alwaysYes: true },
|
2020-04-07 10:07:32 +02:00
|
|
|
): Promise<void> {
|
2021-06-15 18:52:43 +02:00
|
|
|
const result = await wallet.call(WalletApiOperation.PreparePayForUri, {
|
|
|
|
talerPayUri: payUrl,
|
|
|
|
});
|
2020-08-12 09:11:00 +02:00
|
|
|
if (result.status === PreparePayResultType.InsufficientBalance) {
|
2020-07-29 19:40:41 +02:00
|
|
|
console.log("contract", result.contractTerms);
|
2019-11-19 16:16:12 +01:00
|
|
|
console.error("insufficient balance");
|
|
|
|
process.exit(1);
|
|
|
|
return;
|
|
|
|
}
|
2020-08-12 09:11:00 +02:00
|
|
|
if (result.status === PreparePayResultType.AlreadyConfirmed) {
|
2020-07-28 11:48:01 +02:00
|
|
|
if (result.paid) {
|
|
|
|
console.log("already paid!");
|
|
|
|
} else {
|
|
|
|
console.log("payment already in progress");
|
|
|
|
}
|
2020-08-03 09:30:48 +02:00
|
|
|
|
2019-11-19 16:16:12 +01:00
|
|
|
process.exit(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (result.status === "payment-possible") {
|
|
|
|
console.log("paying ...");
|
|
|
|
} else {
|
|
|
|
throw Error("not reached");
|
|
|
|
}
|
2020-07-29 19:40:41 +02:00
|
|
|
console.log("contract", result.contractTerms);
|
|
|
|
console.log("raw amount:", result.amountRaw);
|
|
|
|
console.log("effective amount:", result.amountEffective);
|
2019-11-19 16:16:12 +01:00
|
|
|
let pay;
|
|
|
|
if (options.alwaysYes) {
|
|
|
|
pay = true;
|
|
|
|
} else {
|
|
|
|
while (true) {
|
|
|
|
const yesNoResp = (await clk.prompt("Pay? [Y/n]")).toLowerCase();
|
|
|
|
if (yesNoResp === "" || yesNoResp === "y" || yesNoResp === "yes") {
|
|
|
|
pay = true;
|
|
|
|
break;
|
|
|
|
} else if (yesNoResp === "n" || yesNoResp === "no") {
|
|
|
|
pay = false;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
console.log("please answer y/n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pay) {
|
2021-06-15 18:52:43 +02:00
|
|
|
await wallet.call(WalletApiOperation.ConfirmPay, {
|
|
|
|
proposalId: result.proposalId,
|
|
|
|
});
|
2019-11-19 16:16:12 +01:00
|
|
|
} else {
|
|
|
|
console.log("not paying");
|
|
|
|
}
|
2019-08-20 17:58:01 +02:00
|
|
|
}
|
|
|
|
|
2020-04-07 10:07:32 +02:00
|
|
|
function applyVerbose(verbose: boolean): void {
|
2020-08-03 09:30:48 +02:00
|
|
|
// TODO
|
2019-08-18 23:06:27 +02:00
|
|
|
}
|
|
|
|
|
2020-04-07 10:07:32 +02:00
|
|
|
function printVersion(): void {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
2020-08-06 17:36:56 +02:00
|
|
|
const info = require("../package.json");
|
2019-11-30 00:36:20 +01:00
|
|
|
console.log(`${info.version}`);
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
2020-08-05 21:00:36 +02:00
|
|
|
export const walletCli = clk
|
2019-11-19 16:16:12 +01:00
|
|
|
.program("wallet", {
|
|
|
|
help: "Command line interface for the GNU Taler wallet.",
|
|
|
|
})
|
2020-03-23 12:30:01 +01:00
|
|
|
.maybeOption("walletDbFile", ["--wallet-db"], clk.STRING, {
|
2020-03-24 10:55:04 +01:00
|
|
|
help: "location of the wallet database file",
|
2020-03-23 12:30:01 +01:00
|
|
|
})
|
2020-03-23 13:17:35 +01:00
|
|
|
.maybeOption("timetravel", ["--timetravel"], clk.INT, {
|
|
|
|
help: "modify system time by given offset in microseconds",
|
|
|
|
onPresentHandler: (x) => {
|
|
|
|
// Convert microseconds to milliseconds and do timetravel
|
|
|
|
logger.info(`timetravelling ${x} microseconds`);
|
2020-08-12 09:11:00 +02:00
|
|
|
setDangerousTimetravel(x / 1000);
|
2020-03-23 13:17:35 +01:00
|
|
|
},
|
|
|
|
})
|
2019-11-19 16:16:12 +01:00
|
|
|
.maybeOption("inhibit", ["--inhibit"], clk.STRING, {
|
|
|
|
help:
|
|
|
|
"Inhibit running certain operations, useful for debugging and testing.",
|
|
|
|
})
|
2020-03-24 19:24:32 +01:00
|
|
|
.flag("noThrottle", ["--no-throttle"], {
|
2020-03-27 19:48:25 +01:00
|
|
|
help: "Don't do any request throttling.",
|
2020-03-24 19:24:32 +01:00
|
|
|
})
|
2019-11-30 00:36:20 +01:00
|
|
|
.flag("version", ["-v", "--version"], {
|
|
|
|
onPresentHandler: printVersion,
|
|
|
|
})
|
2019-11-19 16:16:12 +01:00
|
|
|
.flag("verbose", ["-V", "--verbose"], {
|
|
|
|
help: "Enable verbose output.",
|
|
|
|
});
|
|
|
|
|
2019-11-20 19:48:43 +01:00
|
|
|
type WalletCliArgsType = clk.GetArgType<typeof walletCli>;
|
|
|
|
|
|
|
|
async function withWallet<T>(
|
|
|
|
walletCliArgs: WalletCliArgsType,
|
2021-06-15 18:52:43 +02:00
|
|
|
f: (w: {
|
|
|
|
client: WalletCoreApiClient;
|
|
|
|
ws: InternalWalletState;
|
|
|
|
}) => Promise<T>,
|
2019-11-20 19:48:43 +01:00
|
|
|
): Promise<T> {
|
2020-03-23 12:30:01 +01:00
|
|
|
const dbPath = walletCliArgs.wallet.walletDbFile ?? defaultWalletDbPath;
|
2020-03-24 19:24:32 +01:00
|
|
|
const myHttpLib = new NodeHttpLib();
|
|
|
|
if (walletCliArgs.wallet.noThrottle) {
|
|
|
|
myHttpLib.setThrottling(false);
|
|
|
|
}
|
2019-11-20 19:48:43 +01:00
|
|
|
const wallet = await getDefaultNodeWallet({
|
2020-03-23 12:30:01 +01:00
|
|
|
persistentStoragePath: dbPath,
|
2020-03-24 19:24:32 +01:00
|
|
|
httpLib: myHttpLib,
|
2019-11-20 19:48:43 +01:00
|
|
|
});
|
2019-11-21 23:09:43 +01:00
|
|
|
applyVerbose(walletCliArgs.wallet.verbose);
|
2019-11-20 19:48:43 +01:00
|
|
|
try {
|
2021-06-15 18:52:43 +02:00
|
|
|
const w = {
|
|
|
|
ws: wallet,
|
|
|
|
client: await getClientFromWalletState(wallet),
|
|
|
|
};
|
|
|
|
const ret = await f(w);
|
2019-11-20 19:48:43 +01:00
|
|
|
return ret;
|
|
|
|
} catch (e) {
|
2020-07-23 20:52:46 +02:00
|
|
|
if (
|
|
|
|
e instanceof OperationFailedAndReportedError ||
|
|
|
|
e instanceof OperationFailedError
|
|
|
|
) {
|
2019-11-21 23:09:43 +01:00
|
|
|
console.error("Operation failed: " + e.message);
|
2020-07-23 20:52:46 +02:00
|
|
|
console.error(
|
|
|
|
"Error details:",
|
|
|
|
JSON.stringify(e.operationError, undefined, 2),
|
|
|
|
);
|
2019-11-21 23:09:43 +01:00
|
|
|
} else {
|
2019-12-05 22:17:01 +01:00
|
|
|
console.error("caught unhandled exception (bug?):", e);
|
2019-11-21 23:09:43 +01:00
|
|
|
}
|
2019-11-20 19:48:43 +01:00
|
|
|
process.exit(1);
|
|
|
|
} finally {
|
2021-06-10 10:00:36 +02:00
|
|
|
logger.info("operation with wallet finished, stopping");
|
2019-11-20 19:48:43 +01:00
|
|
|
wallet.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 16:16:12 +01:00
|
|
|
walletCli
|
2019-11-30 00:36:20 +01:00
|
|
|
.subcommand("balance", "balance", { help: "Show wallet balance." })
|
|
|
|
.flag("json", ["--json"], {
|
|
|
|
help: "Show raw JSON.",
|
|
|
|
})
|
2020-03-24 10:55:04 +01:00
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
const balance = await wallet.client.call(
|
|
|
|
WalletApiOperation.GetBalances,
|
|
|
|
{},
|
|
|
|
);
|
2020-07-28 19:47:12 +02:00
|
|
|
console.log(JSON.stringify(balance, undefined, 2));
|
2019-08-01 23:21:15 +02:00
|
|
|
});
|
2019-07-31 01:33:56 +02:00
|
|
|
});
|
|
|
|
|
2019-11-19 16:16:12 +01:00
|
|
|
walletCli
|
2020-07-23 15:54:00 +02:00
|
|
|
.subcommand("api", "api", { help: "Call the wallet-core API directly." })
|
2020-07-23 15:00:08 +02:00
|
|
|
.requiredArgument("operation", clk.STRING)
|
|
|
|
.requiredArgument("request", clk.STRING)
|
2020-03-24 10:55:04 +01:00
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2020-07-23 15:00:08 +02:00
|
|
|
let requestJson;
|
|
|
|
try {
|
2020-07-23 15:54:00 +02:00
|
|
|
requestJson = JSON.parse(args.api.request);
|
2020-07-23 15:00:08 +02:00
|
|
|
} catch (e) {
|
2020-07-23 15:54:00 +02:00
|
|
|
console.error("Invalid JSON");
|
2020-07-23 15:00:08 +02:00
|
|
|
process.exit(1);
|
2019-12-16 21:10:57 +01:00
|
|
|
}
|
2021-06-15 18:52:43 +02:00
|
|
|
const resp = await handleCoreApiRequest(
|
|
|
|
wallet.ws,
|
2020-07-23 15:00:08 +02:00
|
|
|
args.api.operation,
|
2020-07-23 15:54:00 +02:00
|
|
|
"reqid-1",
|
2020-07-23 15:00:08 +02:00
|
|
|
requestJson,
|
|
|
|
);
|
|
|
|
console.log(JSON.stringify(resp, undefined, 2));
|
2019-09-04 14:28:22 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-19 16:16:12 +01:00
|
|
|
walletCli
|
|
|
|
.subcommand("", "pending", { help: "Show pending operations." })
|
2020-03-24 10:55:04 +01:00
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
const pending = await wallet.client.call(
|
|
|
|
WalletApiOperation.GetPendingOperations,
|
|
|
|
{},
|
|
|
|
);
|
2019-11-20 19:48:43 +01:00
|
|
|
console.log(JSON.stringify(pending, undefined, 2));
|
2019-11-19 16:16:12 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-12 10:38:58 +02:00
|
|
|
walletCli
|
2020-05-15 13:28:15 +02:00
|
|
|
.subcommand("transactions", "transactions", { help: "Show transactions." })
|
|
|
|
.maybeOption("currency", ["--currency"], clk.STRING)
|
|
|
|
.maybeOption("search", ["--search"], clk.STRING)
|
2020-05-12 10:38:58 +02:00
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
const pending = await wallet.client.call(
|
|
|
|
WalletApiOperation.GetTransactions,
|
|
|
|
{
|
|
|
|
currency: args.transactions.currency,
|
|
|
|
search: args.transactions.search,
|
|
|
|
},
|
|
|
|
);
|
2020-05-12 10:38:58 +02:00
|
|
|
console.log(JSON.stringify(pending, undefined, 2));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-08-20 15:59:05 +02:00
|
|
|
async function asyncSleep(milliSeconds: number): Promise<void> {
|
2019-08-20 17:58:01 +02:00
|
|
|
return new Promise<void>((resolve, reject) => {
|
|
|
|
setTimeout(() => resolve(), milliSeconds);
|
2019-08-20 15:59:05 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-20 19:48:43 +01:00
|
|
|
walletCli
|
|
|
|
.subcommand("runPendingOpt", "run-pending", {
|
2019-11-21 23:09:43 +01:00
|
|
|
help: "Run pending operations.",
|
2019-11-20 19:48:43 +01:00
|
|
|
})
|
2020-03-12 14:55:38 +01:00
|
|
|
.flag("forceNow", ["-f", "--force-now"])
|
2020-03-24 10:55:04 +01:00
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
await runPending(wallet.ws, args.runPendingOpt.forceNow);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
walletCli
|
|
|
|
.subcommand("retryTransaction", "retry-transaction", {
|
|
|
|
help: "Retry a transaction.",
|
|
|
|
})
|
|
|
|
.requiredArgument("transactionId", clk.STRING)
|
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
|
|
|
await wallet.client.call(WalletApiOperation.RetryTransaction, {
|
|
|
|
transactionId: args.retryTransaction.transactionId,
|
|
|
|
});
|
2019-11-20 19:48:43 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-24 12:04:15 +01:00
|
|
|
walletCli
|
|
|
|
.subcommand("finishPendingOpt", "run-until-done", {
|
|
|
|
help: "Run until no more work is left.",
|
|
|
|
})
|
2020-09-01 14:30:46 +02:00
|
|
|
.maybeOption("maxRetries", ["--max-retries"], clk.INT)
|
2020-03-24 12:04:15 +01:00
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
await runUntilDone(wallet.ws, {
|
2020-09-01 14:30:46 +02:00
|
|
|
maxRetries: args.finishPendingOpt.maxRetries,
|
|
|
|
});
|
2021-06-15 18:52:43 +02:00
|
|
|
wallet.ws.stop();
|
2020-03-24 12:04:15 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-20 16:24:41 +02:00
|
|
|
walletCli
|
|
|
|
.subcommand("deleteTransaction", "delete-transaction", {
|
|
|
|
help: "Permanently delete a transaction from the transaction list.",
|
|
|
|
})
|
|
|
|
.requiredArgument("transactionId", clk.STRING, {
|
|
|
|
help: "Identifier of the transaction to delete",
|
|
|
|
})
|
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
await wallet.client.call(WalletApiOperation.DeleteTransaction, {
|
2021-05-20 16:24:41 +02:00
|
|
|
transactionId: args.deleteTransaction.transactionId,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-19 16:16:12 +01:00
|
|
|
walletCli
|
2019-11-21 23:09:43 +01:00
|
|
|
.subcommand("handleUri", "handle-uri", {
|
|
|
|
help: "Handle a taler:// URI.",
|
2019-11-19 16:16:12 +01:00
|
|
|
})
|
2019-11-21 23:09:43 +01:00
|
|
|
.requiredArgument("uri", clk.STRING)
|
|
|
|
.flag("autoYes", ["-y", "--yes"])
|
2020-03-24 10:55:04 +01:00
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2019-11-21 23:09:43 +01:00
|
|
|
const uri: string = args.handleUri.uri;
|
2020-08-12 09:11:00 +02:00
|
|
|
const uriType = classifyTalerUri(uri);
|
2019-12-06 12:47:28 +01:00
|
|
|
switch (uriType) {
|
2020-08-12 09:11:00 +02:00
|
|
|
case TalerUriType.TalerPay:
|
2021-06-15 18:52:43 +02:00
|
|
|
await doPay(wallet.client, uri, {
|
|
|
|
alwaysYes: args.handleUri.autoYes,
|
|
|
|
});
|
2019-12-06 12:47:28 +01:00
|
|
|
break;
|
2020-08-12 09:11:00 +02:00
|
|
|
case TalerUriType.TalerTip:
|
2019-12-06 12:47:28 +01:00
|
|
|
{
|
2021-06-15 18:52:43 +02:00
|
|
|
const res = await wallet.client.call(
|
|
|
|
WalletApiOperation.PrepareTip,
|
|
|
|
{
|
|
|
|
talerTipUri: uri,
|
|
|
|
},
|
|
|
|
);
|
2019-12-06 12:47:28 +01:00
|
|
|
console.log("tip status", res);
|
2021-06-15 18:52:43 +02:00
|
|
|
await wallet.client.call(WalletApiOperation.AcceptTip, {
|
|
|
|
walletTipId: res.walletTipId,
|
|
|
|
});
|
2019-12-06 12:47:28 +01:00
|
|
|
}
|
|
|
|
break;
|
2020-08-12 09:11:00 +02:00
|
|
|
case TalerUriType.TalerRefund:
|
2021-06-15 18:52:43 +02:00
|
|
|
await wallet.client.call(WalletApiOperation.ApplyRefund, {
|
|
|
|
talerRefundUri: uri,
|
|
|
|
});
|
2019-12-06 12:47:28 +01:00
|
|
|
break;
|
2020-08-12 09:11:00 +02:00
|
|
|
case TalerUriType.TalerWithdraw:
|
2019-12-06 12:47:28 +01:00
|
|
|
{
|
2021-06-15 18:52:43 +02:00
|
|
|
const withdrawInfo = await wallet.client.call(
|
|
|
|
WalletApiOperation.GetWithdrawalDetailsForUri,
|
|
|
|
{
|
|
|
|
talerWithdrawUri: uri,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
console.log("withdrawInfo", withdrawInfo);
|
2020-07-28 10:52:35 +02:00
|
|
|
const selectedExchange = withdrawInfo.defaultExchangeBaseUrl;
|
2019-12-06 12:47:28 +01:00
|
|
|
if (!selectedExchange) {
|
|
|
|
console.error("no suggested exchange!");
|
|
|
|
process.exit(1);
|
|
|
|
return;
|
|
|
|
}
|
2021-06-15 18:52:43 +02:00
|
|
|
const res = await wallet.client.call(
|
|
|
|
WalletApiOperation.AcceptBankIntegratedWithdrawal,
|
|
|
|
{
|
|
|
|
exchangeBaseUrl: selectedExchange,
|
|
|
|
talerWithdrawUri: uri,
|
|
|
|
},
|
|
|
|
);
|
2019-12-06 12:47:28 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log(`URI type (${uriType}) not handled`);
|
|
|
|
break;
|
2019-11-21 23:09:43 +01:00
|
|
|
}
|
2019-12-06 12:47:28 +01:00
|
|
|
return;
|
2019-11-21 23:09:43 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const exchangesCli = walletCli.subcommand("exchangesCmd", "exchanges", {
|
|
|
|
help: "Manage exchanges.",
|
|
|
|
});
|
|
|
|
|
|
|
|
exchangesCli
|
|
|
|
.subcommand("exchangesListCmd", "list", {
|
|
|
|
help: "List known exchanges.",
|
|
|
|
})
|
2020-03-24 10:55:04 +01:00
|
|
|
.action(async (args) => {
|
2019-11-21 23:09:43 +01:00
|
|
|
console.log("Listing exchanges ...");
|
2020-03-24 10:55:04 +01:00
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
const exchanges = await wallet.client.call(
|
|
|
|
WalletApiOperation.ListExchanges,
|
|
|
|
{},
|
|
|
|
);
|
2020-07-09 15:26:18 +02:00
|
|
|
console.log(JSON.stringify(exchanges, undefined, 2));
|
2019-11-21 23:09:43 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
exchangesCli
|
|
|
|
.subcommand("exchangesUpdateCmd", "update", {
|
|
|
|
help: "Update or add an exchange by base URL.",
|
|
|
|
})
|
|
|
|
.requiredArgument("url", clk.STRING, {
|
|
|
|
help: "Base URL of the exchange.",
|
|
|
|
})
|
|
|
|
.flag("force", ["-f", "--force"])
|
2020-03-24 10:55:04 +01:00
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
await wallet.client.call(WalletApiOperation.AddExchange, {
|
|
|
|
exchangeBaseUrl: args.exchangesUpdateCmd.url,
|
|
|
|
forceUpdate: args.exchangesUpdateCmd.force,
|
|
|
|
});
|
2019-11-21 23:09:43 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-09 15:26:18 +02:00
|
|
|
exchangesCli
|
|
|
|
.subcommand("exchangesAddCmd", "add", {
|
|
|
|
help: "Add an exchange by base URL.",
|
|
|
|
})
|
|
|
|
.requiredArgument("url", clk.STRING, {
|
|
|
|
help: "Base URL of the exchange.",
|
|
|
|
})
|
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
await wallet.client.call(WalletApiOperation.AddExchange, {
|
|
|
|
exchangeBaseUrl: args.exchangesAddCmd.url,
|
|
|
|
});
|
2020-07-09 15:26:18 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-11 10:32:17 +02:00
|
|
|
exchangesCli
|
|
|
|
.subcommand("exchangesAcceptTosCmd", "accept-tos", {
|
|
|
|
help: "Accept terms of service.",
|
|
|
|
})
|
|
|
|
.requiredArgument("url", clk.STRING, {
|
|
|
|
help: "Base URL of the exchange.",
|
|
|
|
})
|
|
|
|
.requiredArgument("etag", clk.STRING, {
|
|
|
|
help: "ToS version tag to accept",
|
|
|
|
})
|
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
await wallet.client.call(WalletApiOperation.SetExchangeTosAccepted, {
|
|
|
|
etag: args.exchangesAcceptTosCmd.etag,
|
|
|
|
exchangeBaseUrl: args.exchangesAcceptTosCmd.url,
|
|
|
|
});
|
2020-07-11 10:32:17 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-16 19:22:56 +02:00
|
|
|
exchangesCli
|
2020-07-11 10:32:17 +02:00
|
|
|
.subcommand("exchangesTosCmd", "tos", {
|
|
|
|
help: "Show terms of service.",
|
|
|
|
})
|
|
|
|
.requiredArgument("url", clk.STRING, {
|
|
|
|
help: "Base URL of the exchange.",
|
|
|
|
})
|
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
const tosResult = await wallet.client.call(
|
|
|
|
WalletApiOperation.GetExchangeTos,
|
|
|
|
{
|
|
|
|
exchangeBaseUrl: args.exchangesTosCmd.url,
|
|
|
|
},
|
|
|
|
);
|
2020-07-11 10:32:17 +02:00
|
|
|
console.log(JSON.stringify(tosResult, undefined, 2));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-07 15:01:23 +01:00
|
|
|
const backupCli = walletCli.subcommand("backupArgs", "backup", {
|
|
|
|
help: "Subcommands for backups",
|
|
|
|
});
|
|
|
|
|
2021-06-14 11:21:29 +02:00
|
|
|
backupCli
|
|
|
|
.subcommand("setDeviceId", "set-device-id")
|
|
|
|
.requiredArgument("deviceId", clk.STRING, {
|
|
|
|
help: "new device ID",
|
|
|
|
})
|
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
await wallet.client.call(WalletApiOperation.SetWalletDeviceId, {
|
|
|
|
walletDeviceId: args.setDeviceId.deviceId,
|
|
|
|
});
|
2021-06-14 11:21:29 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-07 15:01:23 +01:00
|
|
|
backupCli.subcommand("exportPlain", "export-plain").action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
const backup = await wallet.client.call(
|
|
|
|
WalletApiOperation.ExportBackupPlain,
|
|
|
|
{},
|
|
|
|
);
|
2021-01-07 15:01:23 +01:00
|
|
|
console.log(JSON.stringify(backup, undefined, 2));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-07 18:56:09 +01:00
|
|
|
backupCli.subcommand("recoverySave", "save-recovery").action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
const recoveryJson = await wallet.client.call(
|
|
|
|
WalletApiOperation.ExportBackupRecovery,
|
|
|
|
{},
|
|
|
|
);
|
2021-01-07 18:56:09 +01:00
|
|
|
console.log(JSON.stringify(recoveryJson, undefined, 2));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
backupCli.subcommand("run", "run").action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
await wallet.client.call(WalletApiOperation.RunBackupCycle, {});
|
2021-01-07 18:56:09 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-08 13:30:29 +01:00
|
|
|
backupCli.subcommand("status", "status").action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
const status = await wallet.client.call(
|
|
|
|
WalletApiOperation.GetBackupInfo,
|
|
|
|
{},
|
|
|
|
);
|
2021-01-08 13:30:29 +01:00
|
|
|
console.log(JSON.stringify(status, undefined, 2));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-07 18:56:09 +01:00
|
|
|
backupCli
|
|
|
|
.subcommand("recoveryLoad", "load-recovery")
|
2021-01-08 13:30:29 +01:00
|
|
|
.maybeOption("strategy", ["--strategy"], clk.STRING, {
|
|
|
|
help:
|
|
|
|
"Strategy for resolving a conflict with the existing wallet key ('theirs' or 'ours')",
|
|
|
|
})
|
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
|
|
|
const data = JSON.parse(await read(process.stdin));
|
|
|
|
let strategy: RecoveryMergeStrategy | undefined;
|
|
|
|
const stratStr = args.recoveryLoad.strategy;
|
|
|
|
if (stratStr) {
|
|
|
|
if (stratStr === "theirs") {
|
|
|
|
strategy = RecoveryMergeStrategy.Theirs;
|
|
|
|
} else if (stratStr === "ours") {
|
|
|
|
strategy = RecoveryMergeStrategy.Theirs;
|
|
|
|
} else {
|
|
|
|
throw Error("invalid recovery strategy");
|
|
|
|
}
|
|
|
|
}
|
2021-06-15 18:52:43 +02:00
|
|
|
await wallet.client.call(WalletApiOperation.ImportBackupRecovery, {
|
2021-01-08 13:30:29 +01:00
|
|
|
recovery: data,
|
|
|
|
strategy,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-01-07 18:56:09 +01:00
|
|
|
|
|
|
|
backupCli
|
|
|
|
.subcommand("addProvider", "add-provider")
|
|
|
|
.requiredArgument("url", clk.STRING)
|
2021-01-08 13:30:29 +01:00
|
|
|
.flag("activate", ["--activate"])
|
2021-01-07 18:56:09 +01:00
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
await wallet.client.call(WalletApiOperation.AddBackupProvider, {
|
2021-01-07 18:56:09 +01:00
|
|
|
backupProviderBaseUrl: args.addProvider.url,
|
2021-01-08 13:30:29 +01:00
|
|
|
activate: args.addProvider.activate,
|
2021-01-07 18:56:09 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-18 23:35:41 +01:00
|
|
|
const depositCli = walletCli.subcommand("depositArgs", "deposit", {
|
|
|
|
help: "Subcommands for depositing money to payto:// accounts",
|
|
|
|
});
|
|
|
|
|
|
|
|
depositCli
|
|
|
|
.subcommand("createDepositArgs", "create")
|
|
|
|
.requiredArgument("amount", clk.STRING)
|
|
|
|
.requiredArgument("targetPayto", clk.STRING)
|
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
const resp = await wallet.client.call(
|
|
|
|
WalletApiOperation.CreateDepositGroup,
|
|
|
|
{
|
|
|
|
amount: args.createDepositArgs.amount,
|
|
|
|
depositPaytoUri: args.createDepositArgs.targetPayto,
|
|
|
|
},
|
|
|
|
);
|
2021-01-18 23:35:41 +01:00
|
|
|
console.log(`Created deposit ${resp.depositGroupId}`);
|
2021-06-15 18:52:43 +02:00
|
|
|
await runPending(wallet.ws);
|
2021-01-18 23:35:41 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
depositCli
|
|
|
|
.subcommand("trackDepositArgs", "track")
|
|
|
|
.requiredArgument("depositGroupId", clk.STRING)
|
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
const resp = await wallet.client.call(
|
|
|
|
WalletApiOperation.TrackDepositGroup,
|
|
|
|
{
|
|
|
|
depositGroupId: args.trackDepositArgs.depositGroupId,
|
|
|
|
},
|
|
|
|
);
|
2021-01-18 23:35:41 +01:00
|
|
|
console.log(JSON.stringify(resp, undefined, 2));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-21 23:09:43 +01:00
|
|
|
const advancedCli = walletCli.subcommand("advancedArgs", "advanced", {
|
|
|
|
help:
|
|
|
|
"Subcommands for advanced operations (only use if you know what you're doing!).",
|
|
|
|
});
|
|
|
|
|
2020-07-09 15:26:18 +02:00
|
|
|
advancedCli
|
|
|
|
.subcommand("manualWithdrawalDetails", "manual-withdrawal-details", {
|
|
|
|
help: "Query withdrawal fees.",
|
|
|
|
})
|
|
|
|
.requiredArgument("exchange", clk.STRING)
|
|
|
|
.requiredArgument("amount", clk.STRING)
|
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
const details = await wallet.client.call(
|
|
|
|
WalletApiOperation.GetWithdrawalDetailsForAmount,
|
|
|
|
{
|
|
|
|
amount: args.manualWithdrawalDetails.amount,
|
|
|
|
exchangeBaseUrl: args.manualWithdrawalDetails.exchange,
|
|
|
|
},
|
2020-07-09 15:26:18 +02:00
|
|
|
);
|
|
|
|
console.log(JSON.stringify(details, undefined, 2));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-27 17:59:51 +01:00
|
|
|
advancedCli
|
|
|
|
.subcommand("decode", "decode", {
|
2019-11-30 00:36:20 +01:00
|
|
|
help: "Decode base32-crockford.",
|
2019-11-27 17:59:51 +01:00
|
|
|
})
|
2020-03-24 10:55:04 +01:00
|
|
|
.action((args) => {
|
2019-11-30 00:36:20 +01:00
|
|
|
const enc = fs.readFileSync(0, "utf8");
|
2020-08-12 09:11:00 +02:00
|
|
|
fs.writeFileSync(1, decodeCrock(enc.trim()));
|
2019-11-27 17:59:51 +01:00
|
|
|
});
|
|
|
|
|
2020-06-21 14:49:27 +02:00
|
|
|
advancedCli
|
2020-06-21 14:50:39 +02:00
|
|
|
.subcommand("withdrawManually", "withdraw-manually", {
|
|
|
|
help: "Withdraw manually from an exchange.",
|
|
|
|
})
|
|
|
|
.requiredOption("exchange", ["--exchange"], clk.STRING, {
|
|
|
|
help: "Base URL of the exchange.",
|
|
|
|
})
|
|
|
|
.requiredOption("amount", ["--amount"], clk.STRING, {
|
|
|
|
help: "Amount to withdraw",
|
|
|
|
})
|
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
const exchangeBaseUrl = args.withdrawManually.exchange;
|
|
|
|
const amount = args.withdrawManually.amount;
|
|
|
|
const d = await wallet.client.call(
|
|
|
|
WalletApiOperation.GetWithdrawalDetailsForAmount,
|
|
|
|
{
|
|
|
|
amount: args.withdrawManually.amount,
|
|
|
|
exchangeBaseUrl: exchangeBaseUrl,
|
|
|
|
},
|
2020-06-21 14:50:39 +02:00
|
|
|
);
|
2021-06-15 18:52:43 +02:00
|
|
|
const acct = d.paytoUris[0];
|
2020-06-21 14:50:39 +02:00
|
|
|
if (!acct) {
|
|
|
|
console.log("exchange has no accounts");
|
|
|
|
return;
|
|
|
|
}
|
2021-06-15 18:52:43 +02:00
|
|
|
const resp = await wallet.client.call(
|
|
|
|
WalletApiOperation.AcceptManualWithdrawal,
|
|
|
|
{
|
|
|
|
amount,
|
|
|
|
exchangeBaseUrl,
|
|
|
|
},
|
2020-07-16 19:22:56 +02:00
|
|
|
);
|
2021-06-15 18:52:43 +02:00
|
|
|
const reservePub = resp.reservePub;
|
|
|
|
const completePaytoUri = addPaytoQueryParams(acct, {
|
2020-06-21 14:50:39 +02:00
|
|
|
amount: args.withdrawManually.amount,
|
2021-06-15 18:52:43 +02:00
|
|
|
message: `Taler top-up ${reservePub}`,
|
2020-06-21 14:50:39 +02:00
|
|
|
});
|
2021-06-15 18:52:43 +02:00
|
|
|
console.log("Created reserve", reservePub);
|
2020-06-21 14:50:39 +02:00
|
|
|
console.log("Payto URI", completePaytoUri);
|
2020-06-21 14:49:27 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-12 16:18:32 +02:00
|
|
|
const currenciesCli = walletCli.subcommand("currencies", "currencies", {
|
|
|
|
help: "Manage currencies.",
|
|
|
|
});
|
|
|
|
|
|
|
|
currenciesCli
|
2021-05-20 16:24:41 +02:00
|
|
|
.subcommand("show", "show", { help: "Show currencies." })
|
2021-05-12 16:18:32 +02:00
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
const currencies = await wallet.client.call(
|
|
|
|
WalletApiOperation.ListCurrencies,
|
|
|
|
{},
|
|
|
|
);
|
2021-05-12 16:18:32 +02:00
|
|
|
console.log(JSON.stringify(currencies, undefined, 2));
|
|
|
|
});
|
2021-05-20 16:24:41 +02:00
|
|
|
});
|
2021-05-12 16:18:32 +02:00
|
|
|
|
2019-11-30 00:36:20 +01:00
|
|
|
advancedCli
|
|
|
|
.subcommand("payPrepare", "pay-prepare", {
|
|
|
|
help: "Claim an order but don't pay yet.",
|
|
|
|
})
|
|
|
|
.requiredArgument("url", clk.STRING)
|
2020-03-24 10:55:04 +01:00
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
const res = await wallet.client.call(
|
|
|
|
WalletApiOperation.PreparePayForUri,
|
|
|
|
{
|
|
|
|
talerPayUri: args.payPrepare.url,
|
|
|
|
},
|
|
|
|
);
|
2019-11-30 00:36:20 +01:00
|
|
|
switch (res.status) {
|
2020-08-12 09:11:00 +02:00
|
|
|
case PreparePayResultType.InsufficientBalance:
|
2019-11-30 00:36:20 +01:00
|
|
|
console.log("insufficient balance");
|
|
|
|
break;
|
2020-08-12 09:11:00 +02:00
|
|
|
case PreparePayResultType.AlreadyConfirmed:
|
2020-07-28 11:48:01 +02:00
|
|
|
if (res.paid) {
|
|
|
|
console.log("already paid!");
|
|
|
|
} else {
|
|
|
|
console.log("payment in progress");
|
|
|
|
}
|
2019-11-30 00:36:20 +01:00
|
|
|
break;
|
2020-08-12 09:11:00 +02:00
|
|
|
case PreparePayResultType.PaymentPossible:
|
2019-11-30 00:36:20 +01:00
|
|
|
console.log("payment possible");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assertUnreachable(res);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2019-11-27 17:59:51 +01:00
|
|
|
|
2020-07-20 10:42:35 +02:00
|
|
|
advancedCli
|
|
|
|
.subcommand("payConfirm", "pay-confirm", {
|
|
|
|
help: "Confirm payment proposed by a merchant.",
|
|
|
|
})
|
|
|
|
.requiredArgument("proposalId", clk.STRING)
|
|
|
|
.maybeOption("sessionIdOverride", ["--session-id"], clk.STRING)
|
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
await wallet.client.call(WalletApiOperation.ConfirmPay, {
|
|
|
|
proposalId: args.payConfirm.proposalId,
|
|
|
|
sessionId: args.payConfirm.sessionIdOverride,
|
|
|
|
});
|
2020-07-20 10:42:35 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-21 23:09:43 +01:00
|
|
|
advancedCli
|
|
|
|
.subcommand("refresh", "force-refresh", {
|
|
|
|
help: "Force a refresh on a coin.",
|
|
|
|
})
|
|
|
|
.requiredArgument("coinPub", clk.STRING)
|
2020-03-24 10:55:04 +01:00
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
await wallet.client.call(WalletApiOperation.ForceRefresh, {
|
|
|
|
coinPubList: [args.refresh.coinPub],
|
|
|
|
});
|
2019-11-21 23:09:43 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-24 10:55:04 +01:00
|
|
|
advancedCli
|
|
|
|
.subcommand("dumpCoins", "dump-coins", {
|
|
|
|
help: "Dump coins in an easy-to-process format.",
|
|
|
|
})
|
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
const coinDump = await wallet.client.call(
|
|
|
|
WalletApiOperation.DumpCoins,
|
|
|
|
{},
|
|
|
|
);
|
2020-03-24 10:55:04 +01:00
|
|
|
console.log(JSON.stringify(coinDump, undefined, 2));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-12 12:32:58 +02:00
|
|
|
const coinPubListCodec = codecForList(codecForString());
|
2020-03-24 10:55:04 +01:00
|
|
|
|
|
|
|
advancedCli
|
|
|
|
.subcommand("suspendCoins", "suspend-coins", {
|
|
|
|
help: "Mark a coin as suspended, will not be used for payments.",
|
|
|
|
})
|
|
|
|
.requiredArgument("coinPubSpec", clk.STRING)
|
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
|
|
|
let coinPubList: string[];
|
|
|
|
try {
|
|
|
|
coinPubList = coinPubListCodec.decode(
|
|
|
|
JSON.parse(args.suspendCoins.coinPubSpec),
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
console.log("could not parse coin list:", e.message);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
for (const c of coinPubList) {
|
2021-06-15 18:52:43 +02:00
|
|
|
await wallet.client.call(WalletApiOperation.SetCoinSuspended, {
|
|
|
|
coinPub: c,
|
|
|
|
suspended: true,
|
|
|
|
});
|
2020-03-24 10:55:04 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
advancedCli
|
|
|
|
.subcommand("unsuspendCoins", "unsuspend-coins", {
|
|
|
|
help: "Mark a coin as suspended, will not be used for payments.",
|
|
|
|
})
|
|
|
|
.requiredArgument("coinPubSpec", clk.STRING)
|
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
|
|
|
let coinPubList: string[];
|
|
|
|
try {
|
|
|
|
coinPubList = coinPubListCodec.decode(
|
|
|
|
JSON.parse(args.unsuspendCoins.coinPubSpec),
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
console.log("could not parse coin list:", e.message);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
for (const c of coinPubList) {
|
2021-06-15 18:52:43 +02:00
|
|
|
await wallet.client.call(WalletApiOperation.SetCoinSuspended, {
|
|
|
|
coinPub: c,
|
|
|
|
suspended: false,
|
|
|
|
});
|
2020-03-24 10:55:04 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-21 23:09:43 +01:00
|
|
|
advancedCli
|
|
|
|
.subcommand("coins", "list-coins", {
|
|
|
|
help: "List coins.",
|
|
|
|
})
|
2020-03-24 10:55:04 +01:00
|
|
|
.action(async (args) => {
|
|
|
|
await withWallet(args, async (wallet) => {
|
2021-06-15 18:52:43 +02:00
|
|
|
const coins = await wallet.client.call(WalletApiOperation.DumpCoins, {});
|
|
|
|
for (const coin of coins.coins) {
|
|
|
|
console.log(`coin ${coin.coin_pub}`);
|
|
|
|
console.log(` exchange ${coin.exchange_base_url}`);
|
|
|
|
console.log(` denomPubHash ${coin.denom_pub_hash}`);
|
2019-11-30 00:36:20 +01:00
|
|
|
console.log(
|
2021-06-15 18:52:43 +02:00
|
|
|
` remaining amount ${Amounts.stringify(coin.remaining_value)}`,
|
2019-11-30 00:36:20 +01:00
|
|
|
);
|
2019-11-21 23:09:43 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const testCli = walletCli.subcommand("testingArgs", "testing", {
|
|
|
|
help: "Subcommands for testing GNU Taler deployments.",
|
|
|
|
});
|
|
|
|
|
2021-01-12 20:04:16 +01:00
|
|
|
testCli
|
|
|
|
.subcommand("listIntegrationtests", "list-integrationtests")
|
|
|
|
.action(async (args) => {
|
|
|
|
for (const t of getTestInfo()) {
|
|
|
|
console.log(t.name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
testCli
|
|
|
|
.subcommand("runIntegrationtests", "run-integrationtests")
|
|
|
|
.maybeArgument("pattern", clk.STRING, {
|
|
|
|
help: "Glob pattern to select which tests to run",
|
|
|
|
})
|
2021-03-02 14:19:01 +01:00
|
|
|
.maybeOption("suites", ["--suites"], clk.STRING, {
|
2021-05-21 12:03:09 +02:00
|
|
|
help: "Only run selected suites (comma-separated list)",
|
2021-03-02 14:19:01 +01:00
|
|
|
})
|
|
|
|
.flag("dryRun", ["--dry"], {
|
2021-04-14 18:21:23 +02:00
|
|
|
help: "Only print tests that will be selected to run.",
|
2021-03-02 14:19:01 +01:00
|
|
|
})
|
2021-01-12 20:04:16 +01:00
|
|
|
.action(async (args) => {
|
|
|
|
await runTests({
|
2021-03-02 14:19:01 +01:00
|
|
|
includePattern: args.runIntegrationtests.pattern,
|
|
|
|
suiteSpec: args.runIntegrationtests.suites,
|
|
|
|
dryRun: args.runIntegrationtests.dryRun,
|
2021-01-12 20:04:16 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-12-03 14:15:40 +01:00
|
|
|
async function read(stream: NodeJS.ReadStream) {
|
|
|
|
const chunks = [];
|
2020-12-14 16:45:15 +01:00
|
|
|
for await (const chunk of stream) chunks.push(chunk);
|
|
|
|
return Buffer.concat(chunks).toString("utf8");
|
2020-12-03 14:15:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
testCli.subcommand("tvgcheck", "tvgcheck").action(async (args) => {
|
|
|
|
const data = await read(process.stdin);
|
|
|
|
|
|
|
|
const lines = data.match(/[^\r\n]+/g);
|
|
|
|
|
|
|
|
if (!lines) {
|
|
|
|
throw Error("can't split lines");
|
|
|
|
}
|
|
|
|
|
2020-12-14 16:45:15 +01:00
|
|
|
const vals: Record<string, string> = {};
|
2020-12-03 14:15:40 +01:00
|
|
|
|
|
|
|
let inBlindSigningSection = false;
|
|
|
|
|
|
|
|
for (const line of lines) {
|
|
|
|
if (line === "blind signing:") {
|
|
|
|
inBlindSigningSection = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (line[0] !== " ") {
|
|
|
|
inBlindSigningSection = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (inBlindSigningSection) {
|
|
|
|
const m = line.match(/ (\w+) (\w+)/);
|
|
|
|
if (!m) {
|
|
|
|
console.log("bad format");
|
2020-12-14 16:45:15 +01:00
|
|
|
process.exit(2);
|
2020-12-03 14:15:40 +01:00
|
|
|
}
|
|
|
|
vals[m[1]] = m[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(vals);
|
|
|
|
|
|
|
|
const req = (k: string) => {
|
|
|
|
if (!vals[k]) {
|
|
|
|
throw Error(`no value for ${k}`);
|
|
|
|
}
|
|
|
|
return decodeCrock(vals[k]);
|
2020-12-14 16:45:15 +01:00
|
|
|
};
|
2020-12-03 14:15:40 +01:00
|
|
|
|
|
|
|
const myBm = rsaBlind(
|
|
|
|
req("message_hash"),
|
|
|
|
req("blinding_key_secret"),
|
|
|
|
req("rsa_public_key"),
|
|
|
|
);
|
|
|
|
|
|
|
|
deepStrictEqual(req("blinded_message"), myBm);
|
|
|
|
|
|
|
|
console.log("check passed!");
|
|
|
|
});
|
|
|
|
|
2020-08-05 21:00:36 +02:00
|
|
|
testCli.subcommand("cryptoworker", "cryptoworker").action(async (args) => {
|
|
|
|
const workerFactory = new NodeThreadCryptoWorkerFactory();
|
|
|
|
const cryptoApi = new CryptoApi(workerFactory);
|
|
|
|
const res = await cryptoApi.hashString("foo");
|
|
|
|
console.log(res);
|
|
|
|
});
|
2021-04-14 18:21:23 +02:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
if (process.env["TALER_WALLET_DEBUG_DENOMSEL_ALLOW_LATE"]) {
|
|
|
|
logger.warn("Allowing withdrawal of late denominations for debugging");
|
|
|
|
walletCoreDebugFlags.denomselAllowLate = true;
|
|
|
|
}
|
|
|
|
walletCli.run();
|
|
|
|
}
|