From c5e4aa024557fdacf22bdb548700d8a6e81f7f61 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 21 Feb 2017 10:08:57 -0800 Subject: [PATCH] rpc: refactor help handling. --- lib/http/rpc.js | 670 ++++++++++++++++++++++++------------------------ 1 file changed, 334 insertions(+), 336 deletions(-) diff --git a/lib/http/rpc.js b/lib/http/rpc.js index 45a98717..d448a178 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -77,242 +77,242 @@ util.inherits(RPC, EventEmitter); RPC.magic = 'Bitcoin Signed Message:\n'; -RPC.prototype.execute = function execute(json) { +RPC.prototype.execute = function execute(json, help) { switch (json.method) { case 'stop': - return this.stop(json.params); + return this.stop(json.params, help); case 'help': - return this.help(json.params); + return this.help(json.params, help); case 'getblockchaininfo': - return this.getblockchaininfo(json.params); + return this.getblockchaininfo(json.params, help); case 'getbestblockhash': - return this.getbestblockhash(json.params); + return this.getbestblockhash(json.params, help); case 'getblockcount': - return this.getblockcount(json.params); + return this.getblockcount(json.params, help); case 'getblock': - return this.getblock(json.params); + return this.getblock(json.params, help); case 'getblockhash': - return this.getblockhash(json.params); + return this.getblockhash(json.params, help); case 'getblockheader': - return this.getblockheader(json.params); + return this.getblockheader(json.params, help); case 'getchaintips': - return this.getchaintips(json.params); + return this.getchaintips(json.params, help); case 'getdifficulty': - return this.getdifficulty(json.params); + return this.getdifficulty(json.params, help); case 'getmempoolancestors': - return this.getmempoolancestors(json.params); + return this.getmempoolancestors(json.params, help); case 'getmempooldescendants': - return this.getmempooldescendants(json.params); + return this.getmempooldescendants(json.params, help); case 'getmempoolentry': - return this.getmempoolentry(json.params); + return this.getmempoolentry(json.params, help); case 'getmempoolinfo': - return this.getmempoolinfo(json.params); + return this.getmempoolinfo(json.params, help); case 'getrawmempool': - return this.getrawmempool(json.params); + return this.getrawmempool(json.params, help); case 'gettxout': - return this.gettxout(json.params); + return this.gettxout(json.params, help); case 'gettxoutsetinfo': - return this.gettxoutsetinfo(json.params); + return this.gettxoutsetinfo(json.params, help); case 'verifychain': - return this.verifychain(json.params); + return this.verifychain(json.params, help); case 'invalidateblock': - return this.invalidateblock(json.params); + return this.invalidateblock(json.params, help); case 'reconsiderblock': - return this.reconsiderblock(json.params); + return this.reconsiderblock(json.params, help); case 'getnetworkhashps': - return this.getnetworkhashps(json.params); + return this.getnetworkhashps(json.params, help); case 'getmininginfo': - return this.getmininginfo(json.params); + return this.getmininginfo(json.params, help); case 'prioritisetransaction': - return this.prioritisetransaction(json.params); + return this.prioritisetransaction(json.params, help); case 'getwork': - return this.getwork(json.params); + return this.getwork(json.params, help); case 'getworklp': - return this.getworklp(json.params); + return this.getworklp(json.params, help); case 'getblocktemplate': - return this.getblocktemplate(json.params); + return this.getblocktemplate(json.params, help); case 'submitblock': - return this.submitblock(json.params); + return this.submitblock(json.params, help); case 'verifyblock': - return this.verifyblock(json.params); + return this.verifyblock(json.params, help); case 'setgenerate': - return this.setgenerate(json.params); + return this.setgenerate(json.params, help); case 'getgenerate': - return this.getgenerate(json.params); + return this.getgenerate(json.params, help); case 'generate': - return this.generate(json.params); + return this.generate(json.params, help); case 'generatetoaddress': - return this.generatetoaddress(json.params); + return this.generatetoaddress(json.params, help); case 'estimatefee': - return this.estimatefee(json.params); + return this.estimatefee(json.params, help); case 'estimatepriority': - return this.estimatepriority(json.params); + return this.estimatepriority(json.params, help); case 'estimatesmartfee': - return this.estimatesmartfee(json.params); + return this.estimatesmartfee(json.params, help); case 'estimatesmartpriority': - return this.estimatesmartpriority(json.params); + return this.estimatesmartpriority(json.params, help); case 'getinfo': - return this.getinfo(json.params); + return this.getinfo(json.params, help); case 'validateaddress': - return this.validateaddress(json.params); + return this.validateaddress(json.params, help); case 'createmultisig': - return this.createmultisig(json.params); + return this.createmultisig(json.params, help); case 'createwitnessaddress': - return this.createwitnessaddress(json.params); + return this.createwitnessaddress(json.params, help); case 'verifymessage': - return this.verifymessage(json.params); + return this.verifymessage(json.params, help); case 'signmessagewithprivkey': - return this.signmessagewithprivkey(json.params); + return this.signmessagewithprivkey(json.params, help); case 'setmocktime': - return this.setmocktime(json.params); + return this.setmocktime(json.params, help); case 'getconnectioncount': - return this.getconnectioncount(json.params); + return this.getconnectioncount(json.params, help); case 'ping': - return this.ping(json.params); + return this.ping(json.params, help); case 'getpeerinfo': - return this.getpeerinfo(json.params); + return this.getpeerinfo(json.params, help); case 'addnode': - return this.addnode(json.params); + return this.addnode(json.params, help); case 'disconnectnode': - return this.disconnectnode(json.params); + return this.disconnectnode(json.params, help); case 'getaddednodeinfo': - return this.getaddednodeinfo(json.params); + return this.getaddednodeinfo(json.params, help); case 'getnettotals': - return this.getnettotals(json.params); + return this.getnettotals(json.params, help); case 'getnetworkinfo': - return this.getnetworkinfo(json.params); + return this.getnetworkinfo(json.params, help); case 'setban': - return this.setban(json.params); + return this.setban(json.params, help); case 'listbanned': - return this.listbanned(json.params); + return this.listbanned(json.params, help); case 'clearbanned': - return this.clearbanned(json.params); + return this.clearbanned(json.params, help); case 'getrawtransaction': - return this.getrawtransaction(json.params); + return this.getrawtransaction(json.params, help); case 'createrawtransaction': - return this.createrawtransaction(json.params); + return this.createrawtransaction(json.params, help); case 'decoderawtransaction': - return this.decoderawtransaction(json.params); + return this.decoderawtransaction(json.params, help); case 'decodescript': - return this.decodescript(json.params); + return this.decodescript(json.params, help); case 'sendrawtransaction': - return this.sendrawtransaction(json.params); + return this.sendrawtransaction(json.params, help); case 'signrawtransaction': - return this.signrawtransaction(json.params); + return this.signrawtransaction(json.params, help); case 'gettxoutproof': - return this.gettxoutproof(json.params); + return this.gettxoutproof(json.params, help); case 'verifytxoutproof': - return this.verifytxoutproof(json.params); + return this.verifytxoutproof(json.params, help); case 'fundrawtransaction': - return this.fundrawtransaction(json.params); + return this.fundrawtransaction(json.params, help); case 'resendwallettransactions': - return this.resendwallettransactions(json.params); + return this.resendwallettransactions(json.params, help); case 'abandontransaction': - return this.abandontransaction(json.params); + return this.abandontransaction(json.params, help); case 'addmultisigaddress': - return this.addmultisigaddress(json.params); + return this.addmultisigaddress(json.params, help); case 'addwitnessaddress': - return this.addwitnessaddress(json.params); + return this.addwitnessaddress(json.params, help); case 'backupwallet': - return this.backupwallet(json.params); + return this.backupwallet(json.params, help); case 'dumpprivkey': - return this.dumpprivkey(json.params); + return this.dumpprivkey(json.params, help); case 'dumpwallet': - return this.dumpwallet(json.params); + return this.dumpwallet(json.params, help); case 'encryptwallet': - return this.encryptwallet(json.params); + return this.encryptwallet(json.params, help); case 'getaccountaddress': - return this.getaccountaddress(json.params); + return this.getaccountaddress(json.params, help); case 'getaccount': - return this.getaccount(json.params); + return this.getaccount(json.params, help); case 'getaddressesbyaccount': - return this.getaddressesbyaccount(json.params); + return this.getaddressesbyaccount(json.params, help); case 'getbalance': - return this.getbalance(json.params); + return this.getbalance(json.params, help); case 'getnewaddress': - return this.getnewaddress(json.params); + return this.getnewaddress(json.params, help); case 'getrawchangeaddress': - return this.getrawchangeaddress(json.params); + return this.getrawchangeaddress(json.params, help); case 'getreceivedbyaccount': - return this.getreceivedbyaccount(json.params); + return this.getreceivedbyaccount(json.params, help); case 'getreceivedbyaddress': - return this.getreceivedbyaddress(json.params); + return this.getreceivedbyaddress(json.params, help); case 'gettransaction': - return this.gettransaction(json.params); + return this.gettransaction(json.params, help); case 'getunconfirmedbalance': - return this.getunconfirmedbalance(json.params); + return this.getunconfirmedbalance(json.params, help); case 'getwalletinfo': - return this.getwalletinfo(json.params); + return this.getwalletinfo(json.params, help); case 'importprivkey': - return this.importprivkey(json.params); + return this.importprivkey(json.params, help); case 'importwallet': - return this.importwallet(json.params); + return this.importwallet(json.params, help); case 'importaddress': - return this.importaddress(json.params); + return this.importaddress(json.params, help); case 'importprunedfunds': - return this.importprunedfunds(json.params); + return this.importprunedfunds(json.params, help); case 'importpubkey': - return this.importpubkey(json.params); + return this.importpubkey(json.params, help); case 'keypoolrefill': - return this.keypoolrefill(json.params); + return this.keypoolrefill(json.params, help); case 'listaccounts': - return this.listaccounts(json.params); + return this.listaccounts(json.params, help); case 'listaddressgroupings': - return this.listaddressgroupings(json.params); + return this.listaddressgroupings(json.params, help); case 'listlockunspent': - return this.listlockunspent(json.params); + return this.listlockunspent(json.params, help); case 'listreceivedbyaccount': - return this.listreceivedbyaccount(json.params); + return this.listreceivedbyaccount(json.params, help); case 'listreceivedbyaddress': - return this.listreceivedbyaddress(json.params); + return this.listreceivedbyaddress(json.params, help); case 'listsinceblock': - return this.listsinceblock(json.params); + return this.listsinceblock(json.params, help); case 'listtransactions': - return this.listtransactions(json.params); + return this.listtransactions(json.params, help); case 'listunspent': - return this.listunspent(json.params); + return this.listunspent(json.params, help); case 'lockunspent': - return this.lockunspent(json.params); + return this.lockunspent(json.params, help); case 'move': - return this.move(json.params); + return this.move(json.params, help); case 'sendfrom': - return this.sendfrom(json.params); + return this.sendfrom(json.params, help); case 'sendmany': - return this.sendmany(json.params); + return this.sendmany(json.params, help); case 'sendtoaddress': - return this.sendtoaddress(json.params); + return this.sendtoaddress(json.params, help); case 'setaccount': - return this.setaccount(json.params); + return this.setaccount(json.params, help); case 'settxfee': - return this.settxfee(json.params); + return this.settxfee(json.params, help); case 'signmessage': - return this.signmessage(json.params); + return this.signmessage(json.params, help); case 'walletlock': - return this.walletlock(json.params); + return this.walletlock(json.params, help); case 'walletpassphrasechange': - return this.walletpassphrasechange(json.params); + return this.walletpassphrasechange(json.params, help); case 'walletpassphrase': - return this.walletpassphrase(json.params); + return this.walletpassphrase(json.params, help); case 'removeprunedfunds': - return this.removeprunedfunds(json.params); + return this.removeprunedfunds(json.params, help); case 'getmemory': - return this.getmemory(json.params); + return this.getmemory(json.params, help); case 'selectwallet': - return this.selectwallet(json.params); + return this.selectwallet(json.params, help); case 'setloglevel': - return this.setloglevel(json.params); + return this.setloglevel(json.params, help); default: return Promise.reject(new Error('Not found: ' + json.method + '.')); @@ -323,10 +323,10 @@ RPC.prototype.execute = function execute(json) { * Overall control/query calls */ -RPC.prototype.getinfo = co(function* getinfo(args) { +RPC.prototype.getinfo = co(function* getinfo(args, help) { var balance; - if (args.help || args.length !== 0) + if (help || args.length !== 0) throw new RPCError('getinfo'); balance = yield this.wallet.getBalance(); @@ -351,7 +351,7 @@ RPC.prototype.getinfo = co(function* getinfo(args) { }; }); -RPC.prototype.help = co(function* help(args) { +RPC.prototype.help = co(function* _help(args, help) { var json; if (args.length === 0) @@ -362,13 +362,11 @@ RPC.prototype.help = co(function* help(args) { params: [] }; - json.params.help = true; - - return yield this.execute(json); + return yield this.execute(json, true); }); -RPC.prototype.stop = co(function* stop(args) { - if (args.help || args.length !== 0) +RPC.prototype.stop = co(function* stop(args, help) { + if (help || args.length !== 0) throw new RPCError('stop'); this.node.close(); @@ -380,8 +378,8 @@ RPC.prototype.stop = co(function* stop(args) { * P2P networking */ -RPC.prototype.getnetworkinfo = co(function* getnetworkinfo(args) { - if (args.help || args.length !== 0) +RPC.prototype.getnetworkinfo = co(function* getnetworkinfo(args, help) { + if (help || args.length !== 0) throw new RPCError('getnetworkinfo'); return { @@ -398,10 +396,10 @@ RPC.prototype.getnetworkinfo = co(function* getnetworkinfo(args) { }; }); -RPC.prototype.addnode = co(function* addnode(args) { +RPC.prototype.addnode = co(function* addnode(args, help) { var node, cmd, addr, peer; - if (args.help || args.length !== 2) + if (help || args.length !== 2) throw new RPCError('addnode "node" "add|remove|onetry"'); node = toString(args[0]); @@ -426,10 +424,10 @@ RPC.prototype.addnode = co(function* addnode(args) { return null; }); -RPC.prototype.disconnectnode = co(function* disconnectnode(args) { +RPC.prototype.disconnectnode = co(function* disconnectnode(args, help) { var addr, peer; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('disconnectnode "node"'); addr = toString(args[0]); @@ -443,11 +441,11 @@ RPC.prototype.disconnectnode = co(function* disconnectnode(args) { return null; }); -RPC.prototype.getaddednodeinfo = co(function* getaddednodeinfo(args) { +RPC.prototype.getaddednodeinfo = co(function* getaddednodeinfo(args, help) { var out = []; var addr, peer; - if (args.help || args.length < 1 || args.length > 2) + if (help || args.length < 1 || args.length > 2) throw new RPCError('getaddednodeinfo dummy ( "node" )'); if (args.length === 2) { @@ -480,19 +478,19 @@ RPC.prototype._toAddedNode = function _toAddedNode(peer) { }; }; -RPC.prototype.getconnectioncount = co(function* getconnectioncount(args) { - if (args.help || args.length !== 0) +RPC.prototype.getconnectioncount = co(function* getconnectioncount(args, help) { + if (help || args.length !== 0) throw new RPCError('getconnectioncount'); return this.pool.peers.size(); }); -RPC.prototype.getnettotals = co(function* getnettotals(args) { +RPC.prototype.getnettotals = co(function* getnettotals(args, help) { var sent = 0; var recv = 0; var peer; - if (args.help || args.length > 0) + if (help || args.length > 0) throw new RPCError('getnettotals'); for (peer = this.pool.peers.head(); peer; peer = peer.next) { @@ -507,12 +505,12 @@ RPC.prototype.getnettotals = co(function* getnettotals(args) { }; }); -RPC.prototype.getpeerinfo = co(function* getpeerinfo(args) { +RPC.prototype.getpeerinfo = co(function* getpeerinfo(args, help) { var peers = []; var id = 0; var peer, offset; - if (args.help || args.length !== 0) + if (help || args.length !== 0) throw new RPCError('getpeerinfo'); for (peer = this.pool.peers.head(); peer; peer = peer.next) { @@ -549,10 +547,10 @@ RPC.prototype.getpeerinfo = co(function* getpeerinfo(args) { return peers; }); -RPC.prototype.ping = co(function* ping(args) { +RPC.prototype.ping = co(function* ping(args, help) { var peer; - if (args.help || args.length !== 0) + if (help || args.length !== 0) throw new RPCError('ping'); for (peer = this.pool.peers.head(); peer; peer = peer.next) @@ -561,10 +559,10 @@ RPC.prototype.ping = co(function* ping(args) { return null; }); -RPC.prototype.setban = co(function* setban(args) { +RPC.prototype.setban = co(function* setban(args, help) { var addr; - if (args.help + if (help || args.length < 2 || (args[1] !== 'add' && args[1] !== 'remove')) { throw new RPCError('setban "ip(/netmask)"' @@ -586,10 +584,10 @@ RPC.prototype.setban = co(function* setban(args) { return null; }); -RPC.prototype.listbanned = co(function* listbanned(args) { +RPC.prototype.listbanned = co(function* listbanned(args, help) { var i, banned, keys, host, time; - if (args.help || args.length !== 0) + if (help || args.length !== 0) throw new RPCError('listbanned'); banned = []; @@ -609,8 +607,8 @@ RPC.prototype.listbanned = co(function* listbanned(args) { return banned; }); -RPC.prototype.clearbanned = co(function* clearbanned(args) { - if (args.help || args.length !== 0) +RPC.prototype.clearbanned = co(function* clearbanned(args, help) { + if (help || args.length !== 0) throw new RPCError('clearbanned'); this.pool.hosts.clearBanned(); @@ -675,8 +673,8 @@ RPC.prototype._getBIP9Softforks = co(function* _getBIP9Softforks() { }); /* Block chain and UTXO */ -RPC.prototype.getblockchaininfo = co(function* getblockchaininfo(args) { - if (args.help || args.length !== 0) +RPC.prototype.getblockchaininfo = co(function* getblockchaininfo(args, help) { + if (help || args.length !== 0) throw new RPCError('getblockchaininfo'); return { @@ -722,24 +720,24 @@ RPC.prototype._getDifficulty = function getDifficulty(entry) { return diff; }; -RPC.prototype.getbestblockhash = co(function* getbestblockhash(args) { - if (args.help || args.length !== 0) +RPC.prototype.getbestblockhash = co(function* getbestblockhash(args, help) { + if (help || args.length !== 0) throw new RPCError('getbestblockhash'); return this.chain.tip.rhash(); }); -RPC.prototype.getblockcount = co(function* getblockcount(args) { - if (args.help || args.length !== 0) +RPC.prototype.getblockcount = co(function* getblockcount(args, help) { + if (help || args.length !== 0) throw new RPCError('getblockcount'); return this.chain.tip.height; }); -RPC.prototype.getblock = co(function* getblock(args) { +RPC.prototype.getblock = co(function* getblock(args, help) { var hash, verbose, entry, block; - if (args.help || args.length < 1 || args.length > 2) + if (help || args.length < 1 || args.length > 2) throw new RPCError('getblock "hash" ( verbose )'); hash = toHash(args[0]); @@ -852,10 +850,10 @@ RPC.prototype._scriptToJSON = function scriptToJSON(script, hex) { return out; }; -RPC.prototype.getblockhash = co(function* getblockhash(args) { +RPC.prototype.getblockhash = co(function* getblockhash(args, help) { var height, hash; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('getblockhash index'); height = toNumber(args[0]); @@ -871,10 +869,10 @@ RPC.prototype.getblockhash = co(function* getblockhash(args) { return util.revHex(hash); }); -RPC.prototype.getblockheader = co(function* getblockheader(args) { +RPC.prototype.getblockheader = co(function* getblockheader(args, help) { var hash, verbose, entry; - if (args.help || args.length < 1 || args.length > 2) + if (help || args.length < 1 || args.length > 2) throw new RPCError('getblockheader "hash" ( verbose )'); hash = toHash(args[0]); @@ -951,10 +949,10 @@ RPC.prototype._blockToJSON = co(function* _blockToJSON(entry, block, txDetails) }; }); -RPC.prototype.getchaintips = co(function* getchaintips(args) { +RPC.prototype.getchaintips = co(function* getchaintips(args, help) { var i, hash, tips, result, entry, fork, main; - if (args.help || args.length !== 0) + if (help || args.length !== 0) throw new RPCError('getchaintips'); tips = yield this.chain.db.getTips(); @@ -988,15 +986,15 @@ RPC.prototype._findFork = co(function* _findFork(entry) { throw new Error('Fork not found.'); }); -RPC.prototype.getdifficulty = co(function* getdifficulty(args) { - if (args.help || args.length !== 0) +RPC.prototype.getdifficulty = co(function* getdifficulty(args, help) { + if (help || args.length !== 0) throw new RPCError('getdifficulty'); return this._getDifficulty(); }); -RPC.prototype.getmempoolinfo = co(function* getmempoolinfo(args) { - if (args.help || args.length !== 0) +RPC.prototype.getmempoolinfo = co(function* getmempoolinfo(args, help) { + if (help || args.length !== 0) throw new RPCError('getmempoolinfo'); if (!this.mempool) @@ -1011,11 +1009,11 @@ RPC.prototype.getmempoolinfo = co(function* getmempoolinfo(args) { }; }); -RPC.prototype.getmempoolancestors = co(function* getmempoolancestors(args) { +RPC.prototype.getmempoolancestors = co(function* getmempoolancestors(args, help) { var out = []; var i, hash, verbose, entry, entries; - if (args.help || args.length < 1 || args.length > 2) + if (help || args.length < 1 || args.length > 2) throw new RPCError('getmempoolancestors txid (verbose)'); if (!this.mempool) @@ -1051,11 +1049,11 @@ RPC.prototype.getmempoolancestors = co(function* getmempoolancestors(args) { return out; }); -RPC.prototype.getmempooldescendants = co(function* getmempooldescendants(args) { +RPC.prototype.getmempooldescendants = co(function* getmempooldescendants(args, help) { var out = []; var i, hash, verbose, entry, entries; - if (args.help || args.length < 1 || args.length > 2) + if (help || args.length < 1 || args.length > 2) throw new RPCError('getmempooldescendants txid (verbose)'); if (!this.mempool) @@ -1091,10 +1089,10 @@ RPC.prototype.getmempooldescendants = co(function* getmempooldescendants(args) { return out; }); -RPC.prototype.getmempoolentry = co(function* getmempoolentry(args) { +RPC.prototype.getmempoolentry = co(function* getmempoolentry(args, help) { var hash, entry; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('getmempoolentry txid'); if (!this.mempool) @@ -1113,10 +1111,10 @@ RPC.prototype.getmempoolentry = co(function* getmempoolentry(args) { return this._entryToJSON(entry); }); -RPC.prototype.getrawmempool = co(function* getrawmempool(args) { +RPC.prototype.getrawmempool = co(function* getrawmempool(args, help) { var verbose; - if (args.help || args.length > 1) + if (help || args.length > 1) throw new RPCError('getrawmempool ( verbose )'); verbose = false; @@ -1171,10 +1169,10 @@ RPC.prototype._entryToJSON = function _entryToJSON(entry) { }; }; -RPC.prototype.gettxout = co(function* gettxout(args) { +RPC.prototype.gettxout = co(function* gettxout(args, help) { var hash, index, mempool, coin; - if (args.help || args.length < 2 || args.length > 3) + if (help || args.length < 2 || args.length > 3) throw new RPCError('gettxout "txid" n ( includemempool )'); if (this.chain.options.spv) @@ -1212,11 +1210,11 @@ RPC.prototype.gettxout = co(function* gettxout(args) { }; }); -RPC.prototype.gettxoutproof = co(function* gettxoutproof(args) { +RPC.prototype.gettxoutproof = co(function* gettxoutproof(args, help) { var uniq = {}; var i, txids, block, hash, txid, tx, coins; - if (args.help || (args.length !== 1 && args.length !== 2)) + if (help || (args.length !== 1 && args.length !== 2)) throw new RPCError('gettxoutproof ["txid",...] ( blockhash )'); if (this.chain.options.spv) @@ -1278,11 +1276,11 @@ RPC.prototype.gettxoutproof = co(function* gettxoutproof(args) { return block.toRaw().toString('hex'); }); -RPC.prototype.verifytxoutproof = co(function* verifytxoutproof(args) { +RPC.prototype.verifytxoutproof = co(function* verifytxoutproof(args, help) { var out = []; var i, block, hash, entry; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('verifytxoutproof "proof"'); block = MerkleBlock.fromRaw(toString(args[0]), 'hex'); @@ -1303,8 +1301,8 @@ RPC.prototype.verifytxoutproof = co(function* verifytxoutproof(args) { return out; }); -RPC.prototype.gettxoutsetinfo = co(function* gettxoutsetinfo(args) { - if (args.help || args.length !== 0) +RPC.prototype.gettxoutsetinfo = co(function* gettxoutsetinfo(args, help) { + if (help || args.length !== 0) throw new RPCError('gettxoutsetinfo'); if (this.chain.options.spv) @@ -1321,8 +1319,8 @@ RPC.prototype.gettxoutsetinfo = co(function* gettxoutsetinfo(args) { }; }); -RPC.prototype.verifychain = co(function* verifychain(args) { - if (args.help || args.length > 2) +RPC.prototype.verifychain = co(function* verifychain(args, help) { + if (help || args.length > 2) throw new RPCError('verifychain ( checklevel numblocks )'); if (this.chain.options.spv) @@ -1436,12 +1434,12 @@ RPC.prototype.__creatework = co(function* _creatework() { }; }); -RPC.prototype.getworklp = co(function* getworklp(args) { +RPC.prototype.getworklp = co(function* getworklp(args, help) { yield this._onBlock(); return yield this._creatework(); }); -RPC.prototype.getwork = co(function* getwork(args) { +RPC.prototype.getwork = co(function* getwork(args, help) { var data; if (args.length > 1) @@ -1459,10 +1457,10 @@ RPC.prototype.getwork = co(function* getwork(args) { return yield this._creatework(); }); -RPC.prototype.submitblock = co(function* submitblock(args) { +RPC.prototype.submitblock = co(function* submitblock(args, help) { var block, tx; - if (args.help || args.length < 1 || args.length > 2) + if (help || args.length < 1 || args.length > 2) throw new RPCError('submitblock "hexdata" ( "jsonparametersobject" )'); block = Block.fromRaw(toString(args[0]), 'hex'); @@ -1512,7 +1510,7 @@ RPC.prototype.__submitblock = co(function* submitblock(block) { return null; }); -RPC.prototype.getblocktemplate = co(function* getblocktemplate(args) { +RPC.prototype.getblocktemplate = co(function* getblocktemplate(args, help) { var mode = 'template'; var version = -1; var coinbase = false; @@ -1520,7 +1518,7 @@ RPC.prototype.getblocktemplate = co(function* getblocktemplate(args) { var i, opt, lpid, cap, block; var coinbasevalue, coinbasetxn; - if (args.help || args.length > 1) + if (help || args.length > 1) throw new RPCError('getblocktemplate ( "jsonrequestobject" )'); if (args.length === 1) { @@ -1837,11 +1835,11 @@ RPC.prototype._totalTX = function _totalTX() { return this.mempool ? this.mempool.totalTX : 0; }; -RPC.prototype.getmininginfo = co(function* getmininginfo(args) { +RPC.prototype.getmininginfo = co(function* getmininginfo(args, help) { var attempt = this.attempt; var hashps; - if (args.help || args.length !== 0) + if (help || args.length !== 0) throw new RPCError('getmininginfo'); hashps = yield this._hashps(120, -1); @@ -1861,11 +1859,11 @@ RPC.prototype.getmininginfo = co(function* getmininginfo(args) { }; }); -RPC.prototype.getnetworkhashps = co(function* getnetworkhashps(args) { +RPC.prototype.getnetworkhashps = co(function* getnetworkhashps(args, help) { var lookup = 120; var height = -1; - if (args.help || args.length > 2) + if (help || args.length > 2) throw new RPCError('getnetworkhashps ( blocks height )'); if (args.length > 0) @@ -1877,10 +1875,10 @@ RPC.prototype.getnetworkhashps = co(function* getnetworkhashps(args) { return yield this._hashps(lookup, height); }); -RPC.prototype.prioritisetransaction = co(function* prioritisetransaction(args) { +RPC.prototype.prioritisetransaction = co(function* prioritisetransaction(args, help) { var hash, pri, fee, entry; - if (args.help || args.length !== 3) { + if (help || args.length !== 3) { throw new RPCError('prioritisetransaction' + ' '); } @@ -1955,10 +1953,10 @@ RPC.prototype._hashps = co(function* _hashps(lookup, height) { return ps; }); -RPC.prototype.verifyblock = co(function* verifyblock(args) { +RPC.prototype.verifyblock = co(function* verifyblock(args, help) { var block; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('verifyblock "block-hex"'); if (typeof args[0] !== 'string') @@ -1984,14 +1982,14 @@ RPC.prototype.verifyblock = co(function* verifyblock(args) { * Coin generation */ -RPC.prototype.getgenerate = co(function* getgenerate(args) { - if (args.help || args.length !== 0) +RPC.prototype.getgenerate = co(function* getgenerate(args, help) { + if (help || args.length !== 0) throw new RPCError('getgenerate'); return this.mining; }); -RPC.prototype.setgenerate = co(function* setgenerate(args) { - if (args.help || args.length < 1 || args.length > 2) +RPC.prototype.setgenerate = co(function* setgenerate(args, help) { + if (help || args.length < 1 || args.length > 2) throw new RPCError('setgenerate mine ( proclimit )'); this.mining = toBool(args[0]); @@ -2005,7 +2003,7 @@ RPC.prototype.setgenerate = co(function* setgenerate(args) { return this.mining; }); -RPC.prototype.generate = co(function* generate(args) { +RPC.prototype.generate = co(function* generate(args, help) { var unlock = yield this.locker.lock(); try { return yield this._generate(args); @@ -2014,10 +2012,10 @@ RPC.prototype.generate = co(function* generate(args) { } }); -RPC.prototype._generate = co(function* generate(args) { +RPC.prototype._generate = co(function* generate(args, help) { var numblocks; - if (args.help || args.length < 1 || args.length > 2) + if (help || args.length < 1 || args.length > 2) throw new RPCError('generate numblocks ( maxtries )'); numblocks = toNumber(args[0], 1); @@ -2038,7 +2036,7 @@ RPC.prototype._generateBlocks = co(function* _generateBlocks(blocks, address) { return hashes; }); -RPC.prototype.generatetoaddress = co(function* generatetoaddress(args) { +RPC.prototype.generatetoaddress = co(function* generatetoaddress(args, help) { var unlock = yield this.locker.lock(); try { return yield this._generatetoaddress(args); @@ -2047,10 +2045,10 @@ RPC.prototype.generatetoaddress = co(function* generatetoaddress(args) { } }); -RPC.prototype._generatetoaddress = co(function* generatetoaddress(args) { +RPC.prototype._generatetoaddress = co(function* generatetoaddress(args, help) { var numblocks, address; - if (args.help || args.length < 2 || args.length > 3) + if (help || args.length < 2 || args.length > 3) throw new RPCError('generatetoaddress numblocks address ( maxtries )'); numblocks = toNumber(args[0], 1); @@ -2063,12 +2061,12 @@ RPC.prototype._generatetoaddress = co(function* generatetoaddress(args) { * Raw transactions */ -RPC.prototype.createrawtransaction = co(function* createrawtransaction(args) { +RPC.prototype.createrawtransaction = co(function* createrawtransaction(args, help) { var inputs, sendTo, tx, locktime; var i, input, output, hash, index, sequence; var keys, addrs, key, value, address, b58; - if (args.help || args.length < 2 || args.length > 3) { + if (help || args.length < 2 || args.length > 3) { throw new RPCError('createrawtransaction' + ' [{"txid":"id","vout":n},...]' + ' {"address":amount,"data":"hex",...}' @@ -2154,10 +2152,10 @@ RPC.prototype.createrawtransaction = co(function* createrawtransaction(args) { return tx.toRaw().toString('hex'); }); -RPC.prototype.decoderawtransaction = co(function* decoderawtransaction(args) { +RPC.prototype.decoderawtransaction = co(function* decoderawtransaction(args, help) { var tx; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('decoderawtransaction "hexstring"'); tx = TX.fromRaw(toString(args[0]), 'hex'); @@ -2165,10 +2163,10 @@ RPC.prototype.decoderawtransaction = co(function* decoderawtransaction(args) { return this._txToJSON(tx); }); -RPC.prototype.decodescript = co(function* decodescript(args) { +RPC.prototype.decodescript = co(function* decodescript(args, help) { var data, script, address; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('decodescript "hex"'); data = toString(args[0]); @@ -2185,10 +2183,10 @@ RPC.prototype.decodescript = co(function* decodescript(args) { return script; }); -RPC.prototype.getrawtransaction = co(function* getrawtransaction(args) { +RPC.prototype.getrawtransaction = co(function* getrawtransaction(args, help) { var hash, verbose, json, tx; - if (args.help || args.length < 1 || args.length > 2) + if (help || args.length < 1 || args.length > 2) throw new RPCError('getrawtransaction "txid" ( verbose )'); hash = toHash(args[0]); @@ -2215,10 +2213,10 @@ RPC.prototype.getrawtransaction = co(function* getrawtransaction(args) { return json; }); -RPC.prototype.sendrawtransaction = co(function* sendrawtransaction(args) { +RPC.prototype.sendrawtransaction = co(function* sendrawtransaction(args, help) { var tx; - if (args.help || args.length < 1 || args.length > 2) + if (help || args.length < 1 || args.length > 2) throw new RPCError('sendrawtransaction "hexstring" ( allowhighfees )'); if (!util.isHex(args[0])) @@ -2231,11 +2229,11 @@ RPC.prototype.sendrawtransaction = co(function* sendrawtransaction(args) { return tx.txid(); }); -RPC.prototype.signrawtransaction = co(function* signrawtransaction(args) { +RPC.prototype.signrawtransaction = co(function* signrawtransaction(args, help) { var wallet = this.wallet; var tx; - if (args.help || args.length < 1 || args.length > 4) { + if (help || args.length < 1 || args.length > 4) { throw new RPCError('signrawtransaction' + ' "hexstring" (' + ' [{"txid":"id","vout":n,"scriptPubKey":"hex",' @@ -2353,11 +2351,11 @@ RPC.prototype._signrawtransaction = co(function* signrawtransaction(wallet, tx, }; }); -RPC.prototype.fundrawtransaction = co(function* fundrawtransaction(args) { +RPC.prototype.fundrawtransaction = co(function* fundrawtransaction(args, help) { var wallet = this.wallet; var tx, options, changeAddress, feeRate; - if (args.help || args.length < 1 || args.length > 2) + if (help || args.length < 1 || args.length > 2) throw new RPCError('fundrawtransaction "hexstring" ( options )'); if (!util.isHex(args[0])) @@ -2395,7 +2393,7 @@ RPC.prototype.fundrawtransaction = co(function* fundrawtransaction(args) { }; }); -RPC.prototype._createRedeem = co(function* _createRedeem(args) { +RPC.prototype._createRedeem = co(function* _createRedeem(args, help) { var wallet = this.wallet; var i, m, n, keys, hash, script, key, ring; @@ -2450,10 +2448,10 @@ RPC.prototype._createRedeem = co(function* _createRedeem(args) { * Utility Functions */ -RPC.prototype.createmultisig = co(function* createmultisig(args) { +RPC.prototype.createmultisig = co(function* createmultisig(args, help) { var script, address; - if (args.help || args.length < 2 || args.length > 2) + if (help || args.length < 2 || args.length > 2) throw new RPCError('createmultisig nrequired ["key",...]'); script = yield this._createRedeem(args); @@ -2465,10 +2463,10 @@ RPC.prototype.createmultisig = co(function* createmultisig(args) { }; }); -RPC.prototype.createwitnessaddress = co(function* createwitnessaddress(args) { +RPC.prototype.createwitnessaddress = co(function* createwitnessaddress(args, help) { var raw, script, program, address; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('createwitnessaddress "script"'); raw = toString(args[1]); @@ -2482,11 +2480,11 @@ RPC.prototype.createwitnessaddress = co(function* createwitnessaddress(args) { }; }); -RPC.prototype.validateaddress = co(function* validateaddress(args) { +RPC.prototype.validateaddress = co(function* validateaddress(args, help) { var wallet = this.wallet; var b58, address, json, path, script; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('validateaddress "bitcoinaddress"'); b58 = toString(args[0]); @@ -2521,10 +2519,10 @@ RPC.prototype.validateaddress = co(function* validateaddress(args) { return json; }); -RPC.prototype.verifymessage = co(function* verifymessage(args) { +RPC.prototype.verifymessage = co(function* verifymessage(args, help) { var address, sig, msg, hash, key; - if (args.help || args.length !== 3) + if (help || args.length !== 3) throw new RPCError('verifymessage "bitcoinaddress" "signature" "message"'); address = toString(args[0]); @@ -2550,10 +2548,10 @@ RPC.prototype.verifymessage = co(function* verifymessage(args) { return crypto.ccmp(key, hash); }); -RPC.prototype.signmessagewithprivkey = co(function* signmessagewithprivkey(args) { +RPC.prototype.signmessagewithprivkey = co(function* signmessagewithprivkey(args, help) { var key, msg, sig; - if (args.help || args.length !== 2) + if (help || args.length !== 2) throw new RPCError('signmessagewithprivkey "privkey" "message"'); key = toString(args[0]); @@ -2568,10 +2566,10 @@ RPC.prototype.signmessagewithprivkey = co(function* signmessagewithprivkey(args) return sig.toString('base64'); }); -RPC.prototype.estimatefee = co(function* estimatefee(args) { +RPC.prototype.estimatefee = co(function* estimatefee(args, help) { var blocks, fee; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('estimatefee nblocks'); if (!this.fees) @@ -2592,10 +2590,10 @@ RPC.prototype.estimatefee = co(function* estimatefee(args) { return fee; }); -RPC.prototype.estimatepriority = co(function* estimatepriority(args) { +RPC.prototype.estimatepriority = co(function* estimatepriority(args, help) { var blocks, pri; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('estimatepriority nblocks'); if (!this.fees) @@ -2611,10 +2609,10 @@ RPC.prototype.estimatepriority = co(function* estimatepriority(args) { return pri; }); -RPC.prototype.estimatesmartfee = co(function* estimatesmartfee(args) { +RPC.prototype.estimatesmartfee = co(function* estimatesmartfee(args, help) { var blocks, fee; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('estimatesmartfee nblocks'); if (!this.fees) @@ -2638,10 +2636,10 @@ RPC.prototype.estimatesmartfee = co(function* estimatesmartfee(args) { }; }); -RPC.prototype.estimatesmartpriority = co(function* estimatesmartpriority(args) { +RPC.prototype.estimatesmartpriority = co(function* estimatesmartpriority(args, help) { var blocks, pri; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('estimatesmartpriority nblocks'); if (!this.fees) @@ -2660,10 +2658,10 @@ RPC.prototype.estimatesmartpriority = co(function* estimatesmartpriority(args) { }; }); -RPC.prototype.invalidateblock = co(function* invalidateblock(args) { +RPC.prototype.invalidateblock = co(function* invalidateblock(args, help) { var hash; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('invalidateblock "hash"'); hash = toHash(args[0]); @@ -2676,10 +2674,10 @@ RPC.prototype.invalidateblock = co(function* invalidateblock(args) { return null; }); -RPC.prototype.reconsiderblock = co(function* reconsiderblock(args) { +RPC.prototype.reconsiderblock = co(function* reconsiderblock(args, help) { var hash; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('reconsiderblock "hash"'); hash = toHash(args[0]); @@ -2692,10 +2690,10 @@ RPC.prototype.reconsiderblock = co(function* reconsiderblock(args) { return null; }); -RPC.prototype.setmocktime = co(function* setmocktime(args) { +RPC.prototype.setmocktime = co(function* setmocktime(args, help) { var ts, delta; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('setmocktime timestamp'); ts = toNumber(args[0]); @@ -2716,12 +2714,12 @@ RPC.prototype.setmocktime = co(function* setmocktime(args) { * Wallet */ -RPC.prototype.resendwallettransactions = co(function* resendwallettransactions(args) { +RPC.prototype.resendwallettransactions = co(function* resendwallettransactions(args, help) { var wallet = this.wallet; var hashes = []; var i, tx, txs; - if (args.help || args.length !== 0) + if (help || args.length !== 0) throw new RPCError('resendwallettransactions'); txs = yield wallet.resend(); @@ -2734,8 +2732,8 @@ RPC.prototype.resendwallettransactions = co(function* resendwallettransactions(a return hashes; }); -RPC.prototype.addmultisigaddress = co(function* addmultisigaddress(args) { - if (args.help || args.length < 2 || args.length > 3) { +RPC.prototype.addmultisigaddress = co(function* addmultisigaddress(args, help) { + if (help || args.length < 2 || args.length > 3) { throw new RPCError('addmultisigaddress' + ' nrequired ["key",...] ( "account" )'); } @@ -2744,18 +2742,18 @@ RPC.prototype.addmultisigaddress = co(function* addmultisigaddress(args) { throw new Error('Not implemented.'); }); -RPC.prototype.addwitnessaddress = co(function* addwitnessaddress(args) { - if (args.help || args.length < 1 || args.length > 1) +RPC.prototype.addwitnessaddress = co(function* addwitnessaddress(args, help) { + if (help || args.length < 1 || args.length > 1) throw new RPCError('addwitnessaddress "address"'); // Unlikely to be implemented. throw new Error('Not implemented.'); }); -RPC.prototype.backupwallet = co(function* backupwallet(args) { +RPC.prototype.backupwallet = co(function* backupwallet(args, help) { var dest; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('backupwallet "destination"'); dest = toString(args[0]); @@ -2765,11 +2763,11 @@ RPC.prototype.backupwallet = co(function* backupwallet(args) { return null; }); -RPC.prototype.dumpprivkey = co(function* dumpprivkey(args) { +RPC.prototype.dumpprivkey = co(function* dumpprivkey(args, help) { var wallet = this.wallet; var hash, ring; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('dumpprivkey "bitcoinaddress"'); hash = Address.getHash(toString(args[0]), 'hex'); @@ -2785,11 +2783,11 @@ RPC.prototype.dumpprivkey = co(function* dumpprivkey(args) { return ring.toSecret(); }); -RPC.prototype.dumpwallet = co(function* dumpwallet(args) { +RPC.prototype.dumpwallet = co(function* dumpwallet(args, help) { var wallet = this.wallet; var i, file, time, address, fmt, str, out, hash, hashes, ring; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('dumpwallet "filename"'); if (!args[0] || typeof args[0] !== 'string') @@ -2841,11 +2839,11 @@ RPC.prototype.dumpwallet = co(function* dumpwallet(args) { return out; }); -RPC.prototype.encryptwallet = co(function* encryptwallet(args) { +RPC.prototype.encryptwallet = co(function* encryptwallet(args, help) { var wallet = this.wallet; var passphrase; - if (!wallet.master.encrypted && (args.help || args.help !== 1)) + if (!wallet.master.encrypted && (help || help !== 1)) throw new RPCError('encryptwallet "passphrase"'); if (wallet.master.encrypted) @@ -2861,11 +2859,11 @@ RPC.prototype.encryptwallet = co(function* encryptwallet(args) { return 'wallet encrypted; we do not need to stop!'; }); -RPC.prototype.getaccountaddress = co(function* getaccountaddress(args) { +RPC.prototype.getaccountaddress = co(function* getaccountaddress(args, help) { var wallet = this.wallet; var account; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('getaccountaddress "account"'); account = toString(args[0]); @@ -2881,11 +2879,11 @@ RPC.prototype.getaccountaddress = co(function* getaccountaddress(args) { return account.receive.getAddress('base58'); }); -RPC.prototype.getaccount = co(function* getaccount(args) { +RPC.prototype.getaccount = co(function* getaccount(args, help) { var wallet = this.wallet; var hash, path; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('getaccount "bitcoinaddress"'); hash = Address.getHash(args[0], 'hex'); @@ -2901,11 +2899,11 @@ RPC.prototype.getaccount = co(function* getaccount(args) { return path.name; }); -RPC.prototype.getaddressesbyaccount = co(function* getaddressesbyaccount(args) { +RPC.prototype.getaddressesbyaccount = co(function* getaddressesbyaccount(args, help) { var wallet = this.wallet; var i, path, account, address, addrs, paths; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('getaddressesbyaccount "account"'); account = toString(args[0]); @@ -2926,12 +2924,12 @@ RPC.prototype.getaddressesbyaccount = co(function* getaddressesbyaccount(args) { return addrs; }); -RPC.prototype.getbalance = co(function* getbalance(args) { +RPC.prototype.getbalance = co(function* getbalance(args, help) { var wallet = this.wallet; var minconf = 0; var account, value, balance; - if (args.help || args.length > 3) + if (help || args.length > 3) throw new RPCError('getbalance ( "account" minconf includeWatchonly )'); if (args.length >= 1) { @@ -2957,11 +2955,11 @@ RPC.prototype.getbalance = co(function* getbalance(args) { return Amount.btc(value, true); }); -RPC.prototype.getnewaddress = co(function* getnewaddress(args) { +RPC.prototype.getnewaddress = co(function* getnewaddress(args, help) { var wallet = this.wallet; var account, address; - if (args.help || args.length > 1) + if (help || args.length > 1) throw new RPCError('getnewaddress ( "account" )'); if (args.length === 1) @@ -2975,11 +2973,11 @@ RPC.prototype.getnewaddress = co(function* getnewaddress(args) { return address.getAddress('base58'); }); -RPC.prototype.getrawchangeaddress = co(function* getrawchangeaddress(args) { +RPC.prototype.getrawchangeaddress = co(function* getrawchangeaddress(args, help) { var wallet = this.wallet; var address; - if (args.help || args.length > 1) + if (help || args.length > 1) throw new RPCError('getrawchangeaddress'); address = yield wallet.createChange(); @@ -2987,7 +2985,7 @@ RPC.prototype.getrawchangeaddress = co(function* getrawchangeaddress(args) { return address.getAddress('base58'); }); -RPC.prototype.getreceivedbyaccount = co(function* getreceivedbyaccount(args) { +RPC.prototype.getreceivedbyaccount = co(function* getreceivedbyaccount(args, help) { var wallet = this.wallet; var minconf = 0; var total = 0; @@ -2995,7 +2993,7 @@ RPC.prototype.getreceivedbyaccount = co(function* getreceivedbyaccount(args) { var lastConf = -1; var i, j, path, wtx, output, conf, hash, account, paths, txs; - if (args.help || args.length < 1 || args.length > 2) + if (help || args.length < 1 || args.length > 2) throw new RPCError('getreceivedbyaccount "account" ( minconf )'); account = toString(args[0]); @@ -3037,13 +3035,13 @@ RPC.prototype.getreceivedbyaccount = co(function* getreceivedbyaccount(args) { return Amount.btc(total, true); }); -RPC.prototype.getreceivedbyaddress = co(function* getreceivedbyaddress(args) { +RPC.prototype.getreceivedbyaddress = co(function* getreceivedbyaddress(args, help) { var wallet = this.wallet; var minconf = 0; var total = 0; var i, j, hash, wtx, output, txs; - if (args.help || args.length < 1 || args.length > 2) + if (help || args.length < 1 || args.length > 2) throw new RPCError('getreceivedbyaddress "bitcoinaddress" ( minconf )'); hash = Address.getHash(toString(args[0]), 'hex'); @@ -3146,11 +3144,11 @@ RPC.prototype._toWalletTX = co(function* _toWalletTX(wtx) { }; }); -RPC.prototype.gettransaction = co(function* gettransaction(args) { +RPC.prototype.gettransaction = co(function* gettransaction(args, help) { var wallet = this.wallet; var hash, wtx; - if (args.help || args.length < 1 || args.length > 2) + if (help || args.length < 1 || args.length > 2) throw new RPCError('gettransaction "txid" ( includeWatchonly )'); hash = toHash(args[0]); @@ -3166,11 +3164,11 @@ RPC.prototype.gettransaction = co(function* gettransaction(args) { return yield this._toWalletTX(wtx); }); -RPC.prototype.abandontransaction = co(function* abandontransaction(args) { +RPC.prototype.abandontransaction = co(function* abandontransaction(args, help) { var wallet = this.wallet; var hash, result; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('abandontransaction "txid"'); hash = toHash(args[0]); @@ -3186,11 +3184,11 @@ RPC.prototype.abandontransaction = co(function* abandontransaction(args) { return null; }); -RPC.prototype.getunconfirmedbalance = co(function* getunconfirmedbalance(args) { +RPC.prototype.getunconfirmedbalance = co(function* getunconfirmedbalance(args, help) { var wallet = this.wallet; var balance; - if (args.help || args.length > 0) + if (help || args.length > 0) throw new RPCError('getunconfirmedbalance'); balance = yield wallet.getBalance(); @@ -3198,11 +3196,11 @@ RPC.prototype.getunconfirmedbalance = co(function* getunconfirmedbalance(args) { return Amount.btc(balance.unconfirmed, true); }); -RPC.prototype.getwalletinfo = co(function* getwalletinfo(args) { +RPC.prototype.getwalletinfo = co(function* getwalletinfo(args, help) { var wallet = this.wallet; var balance; - if (args.help || args.length !== 0) + if (help || args.length !== 0) throw new RPCError('getwalletinfo'); balance = yield wallet.getBalance(); @@ -3222,11 +3220,11 @@ RPC.prototype.getwalletinfo = co(function* getwalletinfo(args) { }; }); -RPC.prototype.importprivkey = co(function* importprivkey(args) { +RPC.prototype.importprivkey = co(function* importprivkey(args, help) { var wallet = this.wallet; var secret, label, rescan, key; - if (args.help || args.length < 1 || args.length > 3) + if (help || args.length < 1 || args.length > 3) throw new RPCError('importprivkey "bitcoinprivkey" ( "label" rescan )'); secret = toString(args[0]); @@ -3250,13 +3248,13 @@ RPC.prototype.importprivkey = co(function* importprivkey(args) { return null; }); -RPC.prototype.importwallet = co(function* importwallet(args) { +RPC.prototype.importwallet = co(function* importwallet(args, help) { var wallet = this.wallet; var file, keys, lines, line, parts; var i, secret, time, label, addr; var data, key, rescan; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('importwallet "filename" ( rescan )'); if (fs.unsupported) @@ -3309,11 +3307,11 @@ RPC.prototype.importwallet = co(function* importwallet(args) { return null; }); -RPC.prototype.importaddress = co(function* importaddress(args) { +RPC.prototype.importaddress = co(function* importaddress(args, help) { var wallet = this.wallet; var addr, label, rescan, p2sh; - if (args.help || args.length < 1 || args.length > 4) + if (help || args.length < 1 || args.length > 4) throw new RPCError('importaddress "address" ( "label" rescan p2sh )'); addr = toString(args[0]); @@ -3340,11 +3338,11 @@ RPC.prototype.importaddress = co(function* importaddress(args) { return null; }); -RPC.prototype.importpubkey = co(function* importpubkey(args) { +RPC.prototype.importpubkey = co(function* importpubkey(args, help) { var wallet = this.wallet; var pubkey, label, rescan, key; - if (args.help || args.length < 1 || args.length > 4) + if (help || args.length < 1 || args.length > 4) throw new RPCError('importpubkey "pubkey" ( "label" rescan )'); pubkey = toString(args[0]); @@ -3373,17 +3371,17 @@ RPC.prototype.importpubkey = co(function* importpubkey(args) { return null; }); -RPC.prototype.keypoolrefill = co(function* keypoolrefill(args) { - if (args.help || args.length > 1) +RPC.prototype.keypoolrefill = co(function* keypoolrefill(args, help) { + if (help || args.length > 1) throw new RPCError('keypoolrefill ( newsize )'); return null; }); -RPC.prototype.listaccounts = co(function* listaccounts(args) { +RPC.prototype.listaccounts = co(function* listaccounts(args, help) { var wallet = this.wallet; var i, map, accounts, account, balance; - if (args.help || args.length > 2) + if (help || args.length > 2) throw new RPCError('listaccounts ( minconf includeWatchonly)'); map = {}; @@ -3398,17 +3396,17 @@ RPC.prototype.listaccounts = co(function* listaccounts(args) { return map; }); -RPC.prototype.listaddressgroupings = co(function* listaddressgroupings(args) { - if (args.help) +RPC.prototype.listaddressgroupings = co(function* listaddressgroupings(args, help) { + if (help) throw new RPCError('listaddressgroupings'); throw new Error('Not implemented.'); }); -RPC.prototype.listlockunspent = co(function* listlockunspent(args) { +RPC.prototype.listlockunspent = co(function* listlockunspent(args, help) { var wallet = this.wallet; var i, outpoints, outpoint, out; - if (args.help || args.length > 0) + if (help || args.length > 0) throw new RPCError('listlockunspent'); outpoints = wallet.getLocked(); @@ -3425,11 +3423,11 @@ RPC.prototype.listlockunspent = co(function* listlockunspent(args) { return out; }); -RPC.prototype.listreceivedbyaccount = co(function* listreceivedbyaccount(args) { +RPC.prototype.listreceivedbyaccount = co(function* listreceivedbyaccount(args, help) { var minconf = 0; var includeEmpty = false; - if (args.help || args.length > 3) { + if (help || args.length > 3) { throw new RPCError('listreceivedbyaccount' + ' ( minconf includeempty includeWatchonly )'); } @@ -3443,11 +3441,11 @@ RPC.prototype.listreceivedbyaccount = co(function* listreceivedbyaccount(args) { return yield this._listReceived(minconf, includeEmpty, true); }); -RPC.prototype.listreceivedbyaddress = co(function* listreceivedbyaddress(args) { +RPC.prototype.listreceivedbyaddress = co(function* listreceivedbyaddress(args, help) { var minconf = 0; var includeEmpty = false; - if (args.help || args.length > 3) { + if (help || args.length > 3) { throw new RPCError('listreceivedbyaddress' + ' ( minconf includeempty includeWatchonly )'); } @@ -3560,14 +3558,14 @@ RPC.prototype._listReceived = co(function* _listReceived(minconf, empty, account return result; }); -RPC.prototype.listsinceblock = co(function* listsinceblock(args) { +RPC.prototype.listsinceblock = co(function* listsinceblock(args, help) { var wallet = this.wallet; var minconf = 0; var out = []; var i, block, highest, height; var txs, wtx, json; - if (args.help) { + if (help) { throw new RPCError('listsinceblock' + ' ( "blockhash" target-confirmations includeWatchonly)'); } @@ -3686,13 +3684,13 @@ RPC.prototype._toListTX = co(function* _toListTX(wtx) { }; }); -RPC.prototype.listtransactions = co(function* listtransactions(args) { +RPC.prototype.listtransactions = co(function* listtransactions(args, help) { var wallet = this.wallet; var account = null; var count = 10; var i, txs, wtx, json; - if (args.help || args.length > 4) { + if (help || args.length > 4) { throw new RPCError( 'listtransactions ( "account" count from includeWatchonly)'); } @@ -3722,14 +3720,14 @@ RPC.prototype.listtransactions = co(function* listtransactions(args) { return txs; }); -RPC.prototype.listunspent = co(function* listunspent(args) { +RPC.prototype.listunspent = co(function* listunspent(args, help) { var wallet = this.wallet; var minDepth = 1; var maxDepth = 9999999; var out = []; var i, addresses, addrs, depth, address, hash, coins, coin, ring; - if (args.help || args.length > 3) { + if (help || args.length > 3) { throw new RPCError('listunspent' + ' ( minconf maxconf ["address",...] )'); } @@ -3803,11 +3801,11 @@ RPC.prototype.listunspent = co(function* listunspent(args) { return out; }); -RPC.prototype.lockunspent = co(function* lockunspent(args) { +RPC.prototype.lockunspent = co(function* lockunspent(args, help) { var wallet = this.wallet; var i, unlock, outputs, output, outpoint; - if (args.help || args.length < 1 || args.length > 2) { + if (help || args.length < 1 || args.length > 2) { throw new RPCError('lockunspent' + ' unlock ([{"txid":"txid","vout":n},...])'); } @@ -3852,7 +3850,7 @@ RPC.prototype.lockunspent = co(function* lockunspent(args) { return true; }); -RPC.prototype.move = co(function* move(args) { +RPC.prototype.move = co(function* move(args, help) { // Not implementing: stupid and deprecated. throw new Error('Not implemented.'); }); @@ -3876,10 +3874,10 @@ RPC.prototype._send = co(function* _send(account, address, amount, subtractFee) return tx.txid(); }); -RPC.prototype.sendfrom = co(function* sendfrom(args) { +RPC.prototype.sendfrom = co(function* sendfrom(args, help) { var account, address, amount; - if (args.help || args.length < 3 || args.length > 6) { + if (help || args.length < 3 || args.length > 6) { throw new RPCError('sendfrom' + ' "fromaccount" "tobitcoinaddress"' + ' amount ( minconf "comment" "comment-to" )'); @@ -3895,7 +3893,7 @@ RPC.prototype.sendfrom = co(function* sendfrom(args) { return yield this._send(account, address, amount, false); }); -RPC.prototype.sendmany = co(function* sendmany(args) { +RPC.prototype.sendmany = co(function* sendmany(args, help) { var wallet = this.wallet; var minconf = 1; var outputs = []; @@ -3904,7 +3902,7 @@ RPC.prototype.sendmany = co(function* sendmany(args) { var i, keys, tx, key, value, address; var hash, output, options; - if (args.help || args.length < 2 || args.length > 5) { + if (help || args.length < 2 || args.length > 5) { throw new RPCError('sendmany' + ' "fromaccount" {"address":amount,...}' + ' ( minconf "comment" ["address",...] )'); @@ -3964,10 +3962,10 @@ RPC.prototype.sendmany = co(function* sendmany(args) { return tx.txid(); }); -RPC.prototype.sendtoaddress = co(function* sendtoaddress(args) { +RPC.prototype.sendtoaddress = co(function* sendtoaddress(args, help) { var address, amount, subtractFee; - if (args.help || args.length < 2 || args.length > 5) { + if (help || args.length < 2 || args.length > 5) { throw new RPCError('sendtoaddress' + ' "bitcoinaddress" amount' + ' ( "comment" "comment-to"' @@ -3981,16 +3979,16 @@ RPC.prototype.sendtoaddress = co(function* sendtoaddress(args) { return yield this._send(null, address, amount, subtractFee); }); -RPC.prototype.setaccount = co(function* setaccount(args) { - if (args.help || args.length < 1 || args.length > 2) +RPC.prototype.setaccount = co(function* setaccount(args, help) { + if (help || args.length < 1 || args.length > 2) throw new RPCError('setaccount "bitcoinaddress" "account"'); // Impossible to implement in bcoin: throw new Error('Not implemented.'); }); -RPC.prototype.settxfee = co(function* settxfee(args) { - if (args.help || args.length < 1 || args.length > 1) +RPC.prototype.settxfee = co(function* settxfee(args, help) { + if (help || args.length < 1 || args.length > 1) throw new RPCError('settxfee amount'); this.feeRate = toSatoshi(args[0]); @@ -3998,11 +3996,11 @@ RPC.prototype.settxfee = co(function* settxfee(args) { return true; }); -RPC.prototype.signmessage = co(function* signmessage(args) { +RPC.prototype.signmessage = co(function* signmessage(args, help) { var wallet = this.wallet; var address, msg, sig, ring; - if (args.help || args.length !== 2) + if (help || args.length !== 2) throw new RPCError('signmessage "bitcoinaddress" "message"'); address = toString(args[0]); @@ -4029,10 +4027,10 @@ RPC.prototype.signmessage = co(function* signmessage(args) { return sig.toString('base64'); }); -RPC.prototype.walletlock = co(function* walletlock(args) { +RPC.prototype.walletlock = co(function* walletlock(args, help) { var wallet = this.wallet; - if (args.help || (wallet.master.encrypted && args.length !== 0)) + if (help || (wallet.master.encrypted && args.length !== 0)) throw new RPCError('walletlock'); if (!wallet.master.encrypted) @@ -4043,11 +4041,11 @@ RPC.prototype.walletlock = co(function* walletlock(args) { return null; }); -RPC.prototype.walletpassphrasechange = co(function* walletpassphrasechange(args) { +RPC.prototype.walletpassphrasechange = co(function* walletpassphrasechange(args, help) { var wallet = this.wallet; var old, new_; - if (args.help || (wallet.master.encrypted && args.length !== 2)) { + if (help || (wallet.master.encrypted && args.length !== 2)) { throw new RPCError('walletpassphrasechange' + ' "oldpassphrase" "newpassphrase"'); } @@ -4066,11 +4064,11 @@ RPC.prototype.walletpassphrasechange = co(function* walletpassphrasechange(args) return null; }); -RPC.prototype.walletpassphrase = co(function* walletpassphrase(args) { +RPC.prototype.walletpassphrase = co(function* walletpassphrase(args, help) { var wallet = this.wallet; var passphrase, timeout; - if (args.help || (wallet.master.encrypted && args.length !== 2)) + if (help || (wallet.master.encrypted && args.length !== 2)) throw new RPCError('walletpassphrase "passphrase" timeout'); if (!wallet.master.encrypted) @@ -4090,10 +4088,10 @@ RPC.prototype.walletpassphrase = co(function* walletpassphrase(args) { return null; }); -RPC.prototype.importprunedfunds = co(function* importprunedfunds(args) { +RPC.prototype.importprunedfunds = co(function* importprunedfunds(args, help) { var tx, block, hash, label, height; - if (args.help || args.length < 2 || args.length > 3) { + if (help || args.length < 2 || args.length > 3) { throw new RPCError('importprunedfunds' + ' "rawtransaction" "txoutproof" ( "label" )'); } @@ -4134,11 +4132,11 @@ RPC.prototype.importprunedfunds = co(function* importprunedfunds(args) { return null; }); -RPC.prototype.removeprunedfunds = co(function* removeprunedfunds(args) { +RPC.prototype.removeprunedfunds = co(function* removeprunedfunds(args, help) { var wallet = this.wallet; var hash; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('removeprunedfunds "txid"'); hash = toHash(args[0]); @@ -4152,10 +4150,10 @@ RPC.prototype.removeprunedfunds = co(function* removeprunedfunds(args) { return null; }); -RPC.prototype.getmemory = co(function* getmemory(args) { +RPC.prototype.getmemory = co(function* getmemory(args, help) { var mem; - if (args.help || args.length !== 0) + if (help || args.length !== 0) throw new RPCError('getmemory'); if (!process.memoryUsage) @@ -4171,10 +4169,10 @@ RPC.prototype.getmemory = co(function* getmemory(args) { }; }); -RPC.prototype.selectwallet = co(function* selectwallet(args) { +RPC.prototype.selectwallet = co(function* selectwallet(args, help) { var id, wallet; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('selectwallet "id"'); id = toString(args[0]); @@ -4188,10 +4186,10 @@ RPC.prototype.selectwallet = co(function* selectwallet(args) { return null; }); -RPC.prototype.setloglevel = co(function* setloglevel(args) { +RPC.prototype.setloglevel = co(function* setloglevel(args, help) { var name, level; - if (args.help || args.length !== 1) + if (help || args.length !== 1) throw new RPCError('setloglevel "level"'); name = toString(args[0]);