xud
Version:
Exchange Union Daemon
62 lines • 3.03 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = exports.builder = exports.describe = exports.command = void 0;
const enums_1 = require("../../constants/enums");
const xudrpc_pb_1 = require("../../proto/xudrpc_pb");
const command_1 = require("../command");
exports.command = 'addcurrency <currency> <swap_client> [decimal_places] [token_address]';
exports.describe = 'add a currency';
exports.builder = (argv) => argv
.positional('currency', {
description: 'the ticker symbol for the currency',
type: 'string',
})
.positional('swap_client', {
description: 'the payment channel network client for swaps',
type: 'string',
choices: ['Lnd', 'Connext'],
coerce: (swapClientStr) => {
const swapClientLower = swapClientStr.toLowerCase();
return swapClientLower.charAt(0).toUpperCase() + swapClientLower.slice(1);
},
})
.option('decimal_places', {
description: 'the places to the right of the decimal point of the smallest subunit (e.g. satoshi)',
default: 8,
type: 'number',
})
.option('token_address', {
description: 'the contract address for tokens such as ERC20',
type: 'string',
coerce: (address) => {
if (address.startsWith('0x')) {
return address;
}
// yargs converts only number addresses into decimal, so we need to revert it to hexadecimal
const hexAddress = address.toString(16);
return `0x${hexAddress.padStart(41 - hexAddress.length, '0')}`;
},
})
.example('$0 addcurrency BTC Lnd', 'add BTC')
.example('$0 addcurrency ETH Connext 18 0x0000000000000000000000000000000000000000', 'add ETH');
exports.handler = (argv) => __awaiter(void 0, void 0, void 0, function* () {
if (isNaN(argv.decimal_places) || argv.decimal_places >= 100 || argv.decimal_places < 0) {
throw 'decimal_places must be a number between 0 and 100';
}
const request = new xudrpc_pb_1.Currency();
request.setCurrency(argv.currency.toUpperCase());
request.setSwapClient(Number(enums_1.SwapClientType[argv.swap_client]));
request.setTokenAddress(argv.token_address);
request.setDecimalPlaces(argv.decimal_places);
(yield command_1.loadXudClient(argv)).addCurrency(request, command_1.callback(argv));
});
//# sourceMappingURL=addcurrency.js.map