Skip to content

Commit

Permalink
Merge pull request #1889 from ExchangeUnion/grpc-arg-check
Browse files Browse the repository at this point in the history
fix: grpc throws error for addpair/withdraw for wrong argument (#1844)
  • Loading branch information
sangaman authored Sep 15, 2020
2 parents d9ddd1c + 48a0a33 commit 15f53bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
4 changes: 4 additions & 0 deletions lib/cli/commands/addpair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export const handler = async (argv: Arguments<any>) => {
quoteCurrency = argv.quote_currency;
} else {
[baseCurrency, quoteCurrency] = argv.pair_id.split('/');
if (!baseCurrency || !quoteCurrency) {
console.error(`${argv.pair_id} is not a valid pair`);
process.exit(1);
}
}
request.setBaseCurrency(baseCurrency.toUpperCase());
request.setQuoteCurrency(quoteCurrency.toUpperCase());
Expand Down
28 changes: 14 additions & 14 deletions lib/cli/commands/walletwithdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,42 @@ import { WithdrawRequest } from '../../proto/xudrpc_pb';
import { callback, loadXudClient } from '../command';
import { coinsToSats } from '../utils';

export const command = 'walletwithdraw [amount] [currency] [destination] [fee]';
export const command = 'walletwithdraw <amount> <currency> <destination> [fee]';

export const describe = 'withdraws on-chain funds from xud';

export const builder = (argv: Argv) => argv
.option('amount', {
description: 'the amount to withdraw',
type: 'number',
.positional('amount', {
description: 'the amount to withdraw, `all` withdraws everything',
type: 'string',
})
.option('currency', {
.positional('currency', {
description: 'the ticker symbol of the currency to withdraw.',
type: 'string',
})
.option('destination', {
.positional('destination', {
description: 'the address to send withdrawn funds to',
type: 'string',
})
.option('fee', {
description: 'the fee in satoshis (or equivalent) per byte',
type: 'number',
})
.option('all', {
description: 'whether to withdraw all available funds',
type: 'boolean',
})
.example('$0 walletwithdraw 0.1 BTC 1BitcoinEaterAddressDontSendf59kuE', 'withdraws 0.1 BTC')
.example('$0 walletwithdraw 0.1 BTC 1BitcoinEaterAddressDontSendf59kuE 20', 'withdraws 0.1 BTC using 20 sats/byte')
.example('$0 walletwithdraw --all --currency BTC --address 1BitcoinEaterAddressDontSendf59kuE', 'withdraws all BTC');
.example('$0 walletwithdraw all BTC 1BitcoinEaterAddressDontSendf59kuE', 'withdraws all BTC');

export const handler = async (argv: Arguments<any>) => {
const request = new WithdrawRequest();
request.setCurrency(argv.currency.toUpperCase());
if (argv.all) {
request.setAll(argv.all);
if (argv.amount === 'all') {
request.setAll(true);
} else {
request.setAmount(coinsToSats(argv.amount));
if (isNaN(argv.amount)) {
console.error('amount is not a valid number');
process.exit(1);
}
request.setAmount(coinsToSats(parseFloat(argv.amount)));
}
request.setDestination(argv.destination);
request.setFee(argv.fee);
Expand Down

0 comments on commit 15f53bb

Please sign in to comment.