cli: minor.

This commit is contained in:
Christopher Jeffrey 2017-07-05 16:56:55 -07:00
parent 1bd42c526a
commit f4685fab34
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

112
bin/cli
View File

@ -39,16 +39,20 @@ CLI.prototype.getWallets = async function getWallets() {
}; };
CLI.prototype.createWallet = async function createWallet() { CLI.prototype.createWallet = async function createWallet() {
let options = { id: this.config.str(0) }; let options, wallet;
let wallet;
options.type = this.config.str('type'); options = {
options.master = this.config.str('master'); id: this.config.str([0, 'id']),
options.mnemonic = this.config.str('mnemonic'); type: this.config.str('type'),
options.m = this.config.num('m'); master: this.config.str('master'),
options.n = this.config.num('n'); mnemonic: this.config.str('mnemonic'),
options.witness = this.config.bool('witness'); m: this.config.num('m'),
options.passphrase = this.config.str('passphrase'); n: this.config.num('n'),
witness: this.config.bool('witness'),
passphrase: this.config.str('passphrase'),
watchOnly: false,
accountKey: null
};
if (this.config.has('watch')) { if (this.config.has('watch')) {
options.watchOnly = true; options.watchOnly = true;
@ -73,19 +77,22 @@ CLI.prototype.getKey = async function getKey() {
CLI.prototype.getWIF = async function getWIF() { CLI.prototype.getWIF = async function getWIF() {
let address = this.config.str(0); let address = this.config.str(0);
let key = await this.wallet.getWIF(address, this.config.str('passphrase')); let passphrase = this.config.str('passphrase');
let key = await this.wallet.getWIF(address, passphrase);
this.log(key.privateKey); this.log(key.privateKey);
}; };
CLI.prototype.addSharedKey = async function addSharedKey() { CLI.prototype.addSharedKey = async function addSharedKey() {
let key = this.config.str(0); let key = this.config.str(0);
await this.wallet.addSharedKey(this.config.str('account'), key); let account = this.config.str('account');
await this.wallet.addSharedKey(account, key);
this.log('Added key.'); this.log('Added key.');
}; };
CLI.prototype.removeSharedKey = async function removeSharedKey() { CLI.prototype.removeSharedKey = async function removeSharedKey() {
let key = this.config.str(0); let key = this.config.str(0);
await this.wallet.removeSharedKey(this.config.str('account'), key); let account = this.config.str('account');
await this.wallet.removeSharedKey(account, key);
this.log('Removed key.'); this.log('Removed key.');
}; };
@ -102,15 +109,16 @@ CLI.prototype.getAccount = async function getAccount() {
}; };
CLI.prototype.createAccount = async function createAccount() { CLI.prototype.createAccount = async function createAccount() {
let name = this.config.str(0); let name = this.config.str([0, 'name']);
let options = {}; let options, account;
let account;
options.type = this.config.str('type'); options = {
options.m = this.config.num('m'); type: this.config.str('type'),
options.n = this.config.num('n'); m: this.config.num('m'),
options.witness = this.config.bool('witness'); n: this.config.num('n'),
options.accountKey = this.config.str('watch'); witness: this.config.bool('witness'),
accountKey: this.config.str('watch')
};
account = await this.wallet.createAccount(name, options); account = await this.wallet.createAccount(name, options);
@ -204,17 +212,20 @@ CLI.prototype.getCoin = async function getCoin() {
}; };
CLI.prototype.getWalletHistory = async function getWalletHistory() { CLI.prototype.getWalletHistory = async function getWalletHistory() {
let txs = await this.wallet.getHistory(this.config.str('account')); let account = this.config.str('account');
let txs = await this.wallet.getHistory(account);
this.log(txs); this.log(txs);
}; };
CLI.prototype.getWalletPending = async function getWalletPending() { CLI.prototype.getWalletPending = async function getWalletPending() {
let txs = await this.wallet.getPending(this.config.str('account')); let account = this.config.str('account');
let txs = await this.wallet.getPending(account);
this.log(txs); this.log(txs);
}; };
CLI.prototype.getWalletCoins = async function getWalletCoins() { CLI.prototype.getWalletCoins = async function getWalletCoins() {
let coins = await this.wallet.getCoins(this.config.str('account')); let account = this.config.str('account');
let coins = await this.wallet.getCoins(account);
this.log(coins); this.log(coins);
}; };
@ -255,7 +266,8 @@ CLI.prototype.listenWallet = async function listenWallet() {
}; };
CLI.prototype.getBalance = async function getBalance() { CLI.prototype.getBalance = async function getBalance() {
let balance = await this.wallet.getBalance(this.config.str('account')); let account = this.config.str('account');
let balance = await this.wallet.getBalance(account);
this.log(balance); this.log(balance);
}; };
@ -265,15 +277,18 @@ CLI.prototype.getMempool = async function getMempool() {
}; };
CLI.prototype.sendTX = async function sendTX() { CLI.prototype.sendTX = async function sendTX() {
let output = {}; let option, options, tx;
let options, tx;
if (this.config.has('script')) { if (this.config.has('script')) {
output.script = this.config.str('script'); output = {
output.value = this.config.str(['value', 0]); script: this.config.str('script'),
value: this.config.str([0, 'value'])
};
} else { } else {
output.address = this.config.str(['address', 0]); output = {
output.value = this.config.str(['value', 1]); address: this.config.str([0, 'address']),
value: this.config.str([1, 'value'])
};
} }
options = { options = {
@ -291,15 +306,18 @@ CLI.prototype.sendTX = async function sendTX() {
}; };
CLI.prototype.createTX = async function createTX() { CLI.prototype.createTX = async function createTX() {
let output = {}; let output, options, tx;
let options, tx;
if (this.config.has('script')) { if (this.config.has('script')) {
output.script = this.config.str('script'); output = {
output.value = this.config.str(['value', 0]); script: this.config.str('script'),
value: this.config.str([0, 'value'])
};
} else { } else {
output.address = this.config.str(['address', 0]); output = {
output.value = this.config.str(['value', 1]); address: this.config.str([0, 'address']),
value: this.config.str([1, 'value'])
};
} }
options = { options = {
@ -316,19 +334,15 @@ CLI.prototype.createTX = async function createTX() {
}; };
CLI.prototype.signTX = async function signTX() { CLI.prototype.signTX = async function signTX() {
let options = {}; let passphrase = this.config.str('passphrase');
let raw = this.config.str(['tx', 0]); let raw = this.config.str([0, 'tx']);
let tx; let tx = await this.wallet.sign(raw, { passphrase });
options.passphrase = this.config.str('passphrase');
tx = await this.wallet.sign(raw, options);
this.log(tx); this.log(tx);
}; };
CLI.prototype.zapWallet = async function zapWallet() { CLI.prototype.zapWallet = async function zapWallet() {
let age = this.config.num('age', 72 * 60 * 60); let age = this.config.num([0, 'age'], 72 * 60 * 60);
await this.wallet.zap(this.config.str('account'), age); await this.wallet.zap(this.config.str('account'), age);
this.log('Zapped!'); this.log('Zapped!');
}; };
@ -370,12 +384,7 @@ CLI.prototype.retoken = async function retoken() {
CLI.prototype.rescan = async function rescan() { CLI.prototype.rescan = async function rescan() {
let height = this.config.num(0); let height = this.config.num(0);
if (!util.isUInt32(height))
height = null;
await this.client.rescan(height); await this.client.rescan(height);
this.log('Rescanning...'); this.log('Rescanning...');
}; };
@ -452,9 +461,10 @@ CLI.prototype.unlock = async function unlock() {
CLI.prototype.rpc = async function rpc() { CLI.prototype.rpc = async function rpc() {
let method = this.argv.shift(); let method = this.argv.shift();
let params = []; let params = [];
let arg, param, result; let result;
for (arg of this.argv) { for (let arg of this.argv) {
let param;
try { try {
param = JSON.parse(arg); param = JSON.parse(arg);
} catch (e) { } catch (e) {