wallet-cli: tweaks to withdrawal CLI

This commit is contained in:
Florian Dold 2022-10-16 22:58:53 +02:00
parent b52b074a8d
commit ea1aff81df
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
3 changed files with 112 additions and 77 deletions

View File

@ -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>()

View File

@ -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.",
});
@ -855,25 +944,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.",
});

View File

@ -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;