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; talerWithdrawUri: string;
restrictAge?: number; restrictAge?: number;
} }
export const codecForGetWithdrawalDetailsForUri = export const codecForGetWithdrawalDetailsForUri =
(): Codec<GetWithdrawalDetailsForUriRequest> => (): Codec<GetWithdrawalDetailsForUriRequest> =>
buildCodecForObject<GetWithdrawalDetailsForUriRequest>() buildCodecForObject<GetWithdrawalDetailsForUriRequest>()
@ -1332,6 +1333,7 @@ export const codecForGetWithdrawalDetailsForUri =
export interface ListKnownBankAccountsRequest { export interface ListKnownBankAccountsRequest {
currency?: string; currency?: string;
} }
export const codecForListKnownBankAccounts = export const codecForListKnownBankAccounts =
(): Codec<ListKnownBankAccountsRequest> => (): Codec<ListKnownBankAccountsRequest> =>
buildCodecForObject<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 transactionsCli
.subcommand("retryTransaction", "retry", { .subcommand("retryTransaction", "retry", {
help: "Retry a transaction.", help: "Retry a transaction.",
@ -381,15 +395,17 @@ walletCli
}); });
}); });
walletCli const withdrawCli = walletCli.subcommand("withdraw", "withdraw", {
.subcommand("withdraw", "withdraw", { help: "Withdraw with a taler://withdraw/ URI",
help: "Withdraw with a taler://withdraw/ URI", });
})
withdrawCli
.subcommand("withdrawCheckUri", "check-uri")
.requiredArgument("uri", clk.STRING) .requiredArgument("uri", clk.STRING)
.maybeOption("restrictAge", ["--restrict-age"], clk.INT) .maybeOption("restrictAge", ["--restrict-age"], clk.INT)
.action(async (args) => { .action(async (args) => {
const uri = args.withdraw.uri; const uri = args.withdrawCheckUri.uri;
const restrictAge = args.withdraw.restrictAge; const restrictAge = args.withdrawCheckUri.restrictAge;
console.log(`age restriction requested (${restrictAge})`); console.log(`age restriction requested (${restrictAge})`);
await withWallet(args, async (wallet) => { await withWallet(args, async (wallet) => {
const withdrawInfo = await wallet.client.call( const withdrawInfo = await wallet.client.call(
@ -400,16 +416,44 @@ walletCli
}, },
); );
console.log("withdrawInfo", withdrawInfo); console.log("withdrawInfo", withdrawInfo);
const selectedExchange = withdrawInfo.defaultExchangeBaseUrl; });
if (!selectedExchange) { });
console.error("no suggested exchange!");
process.exit(1); withdrawCli
return; .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( const res = await wallet.client.call(
WalletApiOperation.AcceptBankIntegratedWithdrawal, WalletApiOperation.AcceptBankIntegratedWithdrawal,
{ {
exchangeBaseUrl: selectedExchange, exchangeBaseUrl: args.withdrawAcceptUri.exchange,
talerWithdrawUri: uri, talerWithdrawUri: uri,
restrictAge, 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", { const exchangesCli = walletCli.subcommand("exchangesCmd", "exchanges", {
help: "Manage 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 advancedCli
.subcommand("decode", "decode", { .subcommand("decode", "decode", {
help: "Decode base32-crockford.", help: "Decode base32-crockford.",
@ -892,51 +962,6 @@ advancedCli
console.log(p); 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", { const currenciesCli = walletCli.subcommand("currencies", "currencies", {
help: "Manage currencies.", help: "Manage currencies.",
}); });

View File

@ -126,6 +126,7 @@ export enum WalletApiOperation {
ImportBackupRecovery = "importBackupRecovery", ImportBackupRecovery = "importBackupRecovery",
GetBackupInfo = "getBackupInfo", GetBackupInfo = "getBackupInfo",
TrackDepositGroup = "trackDepositGroup", TrackDepositGroup = "trackDepositGroup",
GetVersion = "getVersion",
DeleteTransaction = "deleteTransaction", DeleteTransaction = "deleteTransaction",
RetryTransaction = "retryTransaction", RetryTransaction = "retryTransaction",
GetCoins = "getCoins", GetCoins = "getCoins",
@ -160,6 +161,12 @@ export type InitWalletOp = {
response: {}; response: {};
}; };
export type GetVersionOp = {
op: WalletApiOperation.GetVersion;
request: {};
response: {};
};
// group: Basic Wallet Information // group: Basic Wallet Information
/** /**
@ -647,6 +654,7 @@ export type ForceRefreshOp = {
export type WalletOperations = { export type WalletOperations = {
[WalletApiOperation.InitWallet]: InitWalletOp; [WalletApiOperation.InitWallet]: InitWalletOp;
[WalletApiOperation.GetVersion]: GetVersionOp;
[WalletApiOperation.WithdrawFakebank]: WithdrawFakebankOp; [WalletApiOperation.WithdrawFakebank]: WithdrawFakebankOp;
[WalletApiOperation.PreparePayForUri]: PreparePayForUriOp; [WalletApiOperation.PreparePayForUri]: PreparePayForUriOp;
[WalletApiOperation.WithdrawTestkudos]: WithdrawTestkudosOp; [WalletApiOperation.WithdrawTestkudos]: WithdrawTestkudosOp;