aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-10-16 22:58:53 +0200
committerFlorian Dold <florian@dold.me>2022-10-16 22:58:53 +0200
commitea1aff81df642000a1c458a91fc8aee239d3bd3a (patch)
treeb581857ac99a1863fd3bbd2ec810f1f15fece6af
parentb52b074a8dd119347307f1face35c1c60eb94c44 (diff)
wallet-cli: tweaks to withdrawal CLI
-rw-r--r--packages/taler-util/src/wallet-types.ts2
-rw-r--r--packages/taler-wallet-cli/src/index.ts179
-rw-r--r--packages/taler-wallet-core/src/wallet-api-types.ts8
3 files changed, 112 insertions, 77 deletions
diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts
index 7e538b2d9..3242e5f6d 100644
--- a/packages/taler-util/src/wallet-types.ts
+++ b/packages/taler-util/src/wallet-types.ts
@@ -1322,6 +1322,7 @@ export interface GetWithdrawalDetailsForUriRequest {
talerWithdrawUri: string;
restrictAge?: number;
}
+
export const codecForGetWithdrawalDetailsForUri =
(): Codec<GetWithdrawalDetailsForUriRequest> =>
buildCodecForObject<GetWithdrawalDetailsForUriRequest>()
@@ -1332,6 +1333,7 @@ export const codecForGetWithdrawalDetailsForUri =
export interface ListKnownBankAccountsRequest {
currency?: string;
}
+
export const codecForListKnownBankAccounts =
(): Codec<ListKnownBankAccountsRequest> =>
buildCodecForObject<ListKnownBankAccountsRequest>()
diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts
index b50e11883..311f0079f 100644
--- a/packages/taler-wallet-cli/src/index.ts
+++ b/packages/taler-wallet-cli/src/index.ts
@@ -348,6 +348,20 @@ transactionsCli
});
});
+walletCli
+ .subcommand("version", "version", {
+ help: "Show version details.",
+ })
+ .action(async (args) => {
+ await withWallet(args, async (wallet) => {
+ const versionInfo = await wallet.client.call(
+ WalletApiOperation.GetVersion,
+ {},
+ );
+ console.log(j2s(versionInfo));
+ });
+ });
+
transactionsCli
.subcommand("retryTransaction", "retry", {
help: "Retry a transaction.",
@@ -381,15 +395,17 @@ walletCli
});
});
-walletCli
- .subcommand("withdraw", "withdraw", {
- help: "Withdraw with a taler://withdraw/ URI",
- })
+const withdrawCli = walletCli.subcommand("withdraw", "withdraw", {
+ help: "Withdraw with a taler://withdraw/ URI",
+});
+
+withdrawCli
+ .subcommand("withdrawCheckUri", "check-uri")
.requiredArgument("uri", clk.STRING)
.maybeOption("restrictAge", ["--restrict-age"], clk.INT)
.action(async (args) => {
- const uri = args.withdraw.uri;
- const restrictAge = args.withdraw.restrictAge;
+ const uri = args.withdrawCheckUri.uri;
+ const restrictAge = args.withdrawCheckUri.restrictAge;
console.log(`age restriction requested (${restrictAge})`);
await withWallet(args, async (wallet) => {
const withdrawInfo = await wallet.client.call(
@@ -400,16 +416,44 @@ walletCli
},
);
console.log("withdrawInfo", withdrawInfo);
- const selectedExchange = withdrawInfo.defaultExchangeBaseUrl;
- if (!selectedExchange) {
- console.error("no suggested exchange!");
- process.exit(1);
- return;
- }
+ });
+ });
+
+withdrawCli
+ .subcommand("withdrawCheckAmount", "check-amount")
+ .requiredArgument("exchange", clk.STRING)
+ .requiredArgument("amount", clk.STRING)
+ .maybeOption("restrictAge", ["--restrict-age"], clk.INT)
+ .action(async (args) => {
+ const restrictAge = args.withdrawCheckAmount.restrictAge;
+ console.log(`age restriction requested (${restrictAge})`);
+ await withWallet(args, async (wallet) => {
+ const withdrawInfo = await wallet.client.call(
+ WalletApiOperation.GetWithdrawalDetailsForAmount,
+ {
+ amount: args.withdrawCheckAmount.amount,
+ exchangeBaseUrl: args.withdrawCheckAmount.exchange,
+ restrictAge,
+ },
+ );
+ console.log("withdrawInfo", withdrawInfo);
+ });
+ });
+
+withdrawCli
+ .subcommand("withdrawAcceptUri", "accept-uri")
+ .requiredArgument("uri", clk.STRING)
+ .requiredOption("exchange", ["--exchange"], clk.STRING)
+ .maybeOption("restrictAge", ["--restrict-age"], clk.INT)
+ .action(async (args) => {
+ const uri = args.withdrawAcceptUri.uri;
+ const restrictAge = args.withdrawAcceptUri.restrictAge;
+ console.log(`age restriction requested (${restrictAge})`);
+ await withWallet(args, async (wallet) => {
const res = await wallet.client.call(
WalletApiOperation.AcceptBankIntegratedWithdrawal,
{
- exchangeBaseUrl: selectedExchange,
+ exchangeBaseUrl: args.withdrawAcceptUri.exchange,
talerWithdrawUri: uri,
restrictAge,
},
@@ -492,6 +536,51 @@ walletCli
});
});
+withdrawCli
+ .subcommand("withdrawManually", "manual", {
+ 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",
+ })
+ .maybeOption("restrictAge", ["--restrict-age"], clk.INT)
+ .action(async (args) => {
+ await withWallet(args, async (wallet) => {
+ const exchangeBaseUrl = args.withdrawManually.exchange;
+ const amount = args.withdrawManually.amount;
+ const d = await wallet.client.call(
+ WalletApiOperation.GetWithdrawalDetailsForAmount,
+ {
+ amount: args.withdrawManually.amount,
+ exchangeBaseUrl: exchangeBaseUrl,
+ },
+ );
+ const acct = d.paytoUris[0];
+ if (!acct) {
+ console.log("exchange has no accounts");
+ return;
+ }
+ const resp = await wallet.client.call(
+ WalletApiOperation.AcceptManualWithdrawal,
+ {
+ amount,
+ exchangeBaseUrl,
+ restrictAge: parseInt(String(args.withdrawManually.restrictAge), 10),
+ },
+ );
+ const reservePub = resp.reservePub;
+ const completePaytoUri = addPaytoQueryParams(acct, {
+ amount: args.withdrawManually.amount,
+ message: `Taler top-up ${reservePub}`,
+ });
+ console.log("Created reserve", reservePub);
+ console.log("Payto URI", completePaytoUri);
+ });
+ });
+
const exchangesCli = walletCli.subcommand("exchangesCmd", "exchanges", {
help: "Manage exchanges.",
});
@@ -856,25 +945,6 @@ advancedCli
});
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) => {
- const details = await wallet.client.call(
- WalletApiOperation.GetWithdrawalDetailsForAmount,
- {
- amount: args.manualWithdrawalDetails.amount,
- exchangeBaseUrl: args.manualWithdrawalDetails.exchange,
- },
- );
- console.log(JSON.stringify(details, undefined, 2));
- });
- });
-
-advancedCli
.subcommand("decode", "decode", {
help: "Decode base32-crockford.",
})
@@ -892,51 +962,6 @@ advancedCli
console.log(p);
});
-advancedCli
- .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",
- })
- .maybeOption("restrictAge", ["--restrict-age"], clk.INT)
- .action(async (args) => {
- await withWallet(args, async (wallet) => {
- const exchangeBaseUrl = args.withdrawManually.exchange;
- const amount = args.withdrawManually.amount;
- const d = await wallet.client.call(
- WalletApiOperation.GetWithdrawalDetailsForAmount,
- {
- amount: args.withdrawManually.amount,
- exchangeBaseUrl: exchangeBaseUrl,
- },
- );
- const acct = d.paytoUris[0];
- if (!acct) {
- console.log("exchange has no accounts");
- return;
- }
- const resp = await wallet.client.call(
- WalletApiOperation.AcceptManualWithdrawal,
- {
- amount,
- exchangeBaseUrl,
- restrictAge: parseInt(String(args.withdrawManually.restrictAge), 10),
- },
- );
- const reservePub = resp.reservePub;
- const completePaytoUri = addPaytoQueryParams(acct, {
- amount: args.withdrawManually.amount,
- message: `Taler top-up ${reservePub}`,
- });
- console.log("Created reserve", reservePub);
- console.log("Payto URI", completePaytoUri);
- });
- });
-
const currenciesCli = walletCli.subcommand("currencies", "currencies", {
help: "Manage currencies.",
});
diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts
index 3841bd8d3..88e66ff9e 100644
--- a/packages/taler-wallet-core/src/wallet-api-types.ts
+++ b/packages/taler-wallet-core/src/wallet-api-types.ts
@@ -126,6 +126,7 @@ export enum WalletApiOperation {
ImportBackupRecovery = "importBackupRecovery",
GetBackupInfo = "getBackupInfo",
TrackDepositGroup = "trackDepositGroup",
+ GetVersion = "getVersion",
DeleteTransaction = "deleteTransaction",
RetryTransaction = "retryTransaction",
GetCoins = "getCoins",
@@ -160,6 +161,12 @@ export type InitWalletOp = {
response: {};
};
+export type GetVersionOp = {
+ op: WalletApiOperation.GetVersion;
+ request: {};
+ response: {};
+};
+
// group: Basic Wallet Information
/**
@@ -647,6 +654,7 @@ export type ForceRefreshOp = {
export type WalletOperations = {
[WalletApiOperation.InitWallet]: InitWalletOp;
+ [WalletApiOperation.GetVersion]: GetVersionOp;
[WalletApiOperation.WithdrawFakebank]: WithdrawFakebankOp;
[WalletApiOperation.PreparePayForUri]: PreparePayForUriOp;
[WalletApiOperation.WithdrawTestkudos]: WithdrawTestkudosOp;