rpc: add u32 validation. rename node rpc methods.
This commit is contained in:
parent
59e9ef277a
commit
78a4f379f5
336
lib/http/rpc.js
336
lib/http/rpc.js
@ -80,85 +80,85 @@ RPC.prototype.init = function init() {
|
||||
this.add('stop', this.stop);
|
||||
this.add('help', this.help);
|
||||
|
||||
this.add('getblockchaininfo', this.getblockchaininfo);
|
||||
this.add('getbestblockhash', this.getbestblockhash);
|
||||
this.add('getblockcount', this.getblockcount);
|
||||
this.add('getblock', this.getblock);
|
||||
this.add('getblockhash', this.getblockhash);
|
||||
this.add('getblockheader', this.getblockheader);
|
||||
this.add('getchaintips', this.getchaintips);
|
||||
this.add('getdifficulty', this.getdifficulty);
|
||||
this.add('getmempoolancestors', this.getmempoolancestors);
|
||||
this.add('getmempooldescendants', this.getmempooldescendants);
|
||||
this.add('getmempoolentry', this.getmempoolentry);
|
||||
this.add('getmempoolinfo', this.getmempoolinfo);
|
||||
this.add('getrawmempool', this.getrawmempool);
|
||||
this.add('gettxout', this.gettxout);
|
||||
this.add('gettxoutsetinfo', this.gettxoutsetinfo);
|
||||
this.add('verifychain', this.verifychain);
|
||||
this.add('getblockchaininfo', this.getBlockchainInfo);
|
||||
this.add('getbestblockhash', this.getBestBlockHash);
|
||||
this.add('getblockcount', this.getBlockCount);
|
||||
this.add('getblock', this.getBlock);
|
||||
this.add('getblockhash', this.getBlockHash);
|
||||
this.add('getblockheader', this.getBlockHeader);
|
||||
this.add('getchaintips', this.getChainTips);
|
||||
this.add('getdifficulty', this.getDifficulty);
|
||||
this.add('getmempoolancestors', this.getMempoolAncestors);
|
||||
this.add('getmempooldescendants', this.getMempoolDescendants);
|
||||
this.add('getmempoolentry', this.getMempoolEntry);
|
||||
this.add('getmempoolinfo', this.getMempoolInfo);
|
||||
this.add('getrawmempool', this.getRawMempool);
|
||||
this.add('gettxout', this.getTXOut);
|
||||
this.add('gettxoutsetinfo', this.getTXOutSetInfo);
|
||||
this.add('verifychain', this.verifyChain);
|
||||
|
||||
this.add('invalidateblock', this.invalidateblock);
|
||||
this.add('reconsiderblock', this.reconsiderblock);
|
||||
this.add('invalidateblock', this.invalidateBlock);
|
||||
this.add('reconsiderblock', this.reconsiderBlock);
|
||||
|
||||
this.add('getnetworkhashps', this.getnetworkhashps);
|
||||
this.add('getmininginfo', this.getmininginfo);
|
||||
this.add('prioritisetransaction', this.prioritisetransaction);
|
||||
this.add('getwork', this.getwork);
|
||||
this.add('getworklp', this.getworklp);
|
||||
this.add('getblocktemplate', this.getblocktemplate);
|
||||
this.add('submitblock', this.submitblock);
|
||||
this.add('verifyblock', this.verifyblock);
|
||||
this.add('getnetworkhashps', this.getNetworkHashPS);
|
||||
this.add('getmininginfo', this.getMiningInfo);
|
||||
this.add('prioritisetransaction', this.prioritiseTransaction);
|
||||
this.add('getwork', this.getWork);
|
||||
this.add('getworklp', this.getWorkLongpoll);
|
||||
this.add('getblocktemplate', this.getBlockTemplate);
|
||||
this.add('submitblock', this.submitBlock);
|
||||
this.add('verifyblock', this.verifyBlock);
|
||||
|
||||
this.add('setgenerate', this.setgenerate);
|
||||
this.add('getgenerate', this.getgenerate);
|
||||
this.add('setgenerate', this.setGenerate);
|
||||
this.add('getgenerate', this.getGenerate);
|
||||
this.add('generate', this.generate);
|
||||
this.add('generatetoaddress', this.generatetoaddress);
|
||||
this.add('generatetoaddress', this.generateToAddress);
|
||||
|
||||
this.add('estimatefee', this.estimatefee);
|
||||
this.add('estimatepriority', this.estimatepriority);
|
||||
this.add('estimatesmartfee', this.estimatesmartfee);
|
||||
this.add('estimatesmartpriority', this.estimatesmartpriority);
|
||||
this.add('estimatefee', this.estimateFee);
|
||||
this.add('estimatepriority', this.estimatePriority);
|
||||
this.add('estimatesmartfee', this.estimateSmartFee);
|
||||
this.add('estimatesmartpriority', this.estimateSmartPriority);
|
||||
|
||||
this.add('getinfo', this.getinfo);
|
||||
this.add('validateaddress', this.validateaddress);
|
||||
this.add('createmultisig', this.createmultisig);
|
||||
this.add('createwitnessaddress', this.createwitnessaddress);
|
||||
this.add('verifymessage', this.verifymessage);
|
||||
this.add('signmessagewithprivkey', this.signmessagewithprivkey);
|
||||
this.add('getinfo', this.getInfo);
|
||||
this.add('validateaddress', this.validateAddress);
|
||||
this.add('createmultisig', this.createMultisig);
|
||||
this.add('createwitnessaddress', this.createWitnessAddress);
|
||||
this.add('verifymessage', this.verifyMessage);
|
||||
this.add('signmessagewithprivkey', this.signMessageWithPrivkey);
|
||||
|
||||
this.add('setmocktime', this.setmocktime);
|
||||
this.add('setmocktime', this.setMockTime);
|
||||
|
||||
this.add('getconnectioncount', this.getconnectioncount);
|
||||
this.add('getconnectioncount', this.getConnectionCount);
|
||||
this.add('ping', this.ping);
|
||||
this.add('getpeerinfo', this.getpeerinfo);
|
||||
this.add('addnode', this.addnode);
|
||||
this.add('disconnectnode', this.disconnectnode);
|
||||
this.add('getaddednodeinfo', this.getaddednodeinfo);
|
||||
this.add('getnettotals', this.getnettotals);
|
||||
this.add('getnetworkinfo', this.getnetworkinfo);
|
||||
this.add('setban', this.setban);
|
||||
this.add('listbanned', this.listbanned);
|
||||
this.add('clearbanned', this.clearbanned);
|
||||
this.add('getpeerinfo', this.getPeerInfo);
|
||||
this.add('addnode', this.addNode);
|
||||
this.add('disconnectnode', this.disconnectNode);
|
||||
this.add('getaddednodeinfo', this.getAddedNodeInfo);
|
||||
this.add('getnettotals', this.getNetTotals);
|
||||
this.add('getnetworkinfo', this.getNetworkInfo);
|
||||
this.add('setban', this.setBan);
|
||||
this.add('listbanned', this.listBanned);
|
||||
this.add('clearbanned', this.clearBanned);
|
||||
|
||||
this.add('getrawtransaction', this.getrawtransaction);
|
||||
this.add('createrawtransaction', this.createrawtransaction);
|
||||
this.add('decoderawtransaction', this.decoderawtransaction);
|
||||
this.add('decodescript', this.decodescript);
|
||||
this.add('sendrawtransaction', this.sendrawtransaction);
|
||||
this.add('signrawtransaction', this.signrawtransaction);
|
||||
this.add('getrawtransaction', this.getRawTransaction);
|
||||
this.add('createrawtransaction', this.createRawTransaction);
|
||||
this.add('decoderawtransaction', this.decodeRawTransaction);
|
||||
this.add('decodescript', this.decodeScript);
|
||||
this.add('sendrawtransaction', this.sendRawTransaction);
|
||||
this.add('signrawtransaction', this.signRawTransaction);
|
||||
|
||||
this.add('gettxoutproof', this.gettxoutproof);
|
||||
this.add('verifytxoutproof', this.verifytxoutproof);
|
||||
this.add('gettxoutproof', this.getTXOutProof);
|
||||
this.add('verifytxoutproof', this.verifyTXOutProof);
|
||||
|
||||
this.add('getmemory', this.getmemory);
|
||||
this.add('setloglevel', this.setloglevel);
|
||||
this.add('getmemory', this.getMemory);
|
||||
this.add('setloglevel', this.setLogLevel);
|
||||
};
|
||||
|
||||
/*
|
||||
* Overall control/query calls
|
||||
*/
|
||||
|
||||
RPC.prototype.getinfo = co(function* getinfo(args, help) {
|
||||
RPC.prototype.getInfo = co(function* getInfo(args, help) {
|
||||
if (help || args.length !== 0)
|
||||
throw new RPCError('getinfo');
|
||||
|
||||
@ -209,7 +209,7 @@ RPC.prototype.stop = co(function* stop(args, help) {
|
||||
* P2P networking
|
||||
*/
|
||||
|
||||
RPC.prototype.getnetworkinfo = co(function* getnetworkinfo(args, help) {
|
||||
RPC.prototype.getNetworkInfo = co(function* getNetworkInfo(args, help) {
|
||||
if (help || args.length !== 0)
|
||||
throw new RPCError('getnetworkinfo');
|
||||
|
||||
@ -227,7 +227,7 @@ RPC.prototype.getnetworkinfo = co(function* getnetworkinfo(args, help) {
|
||||
};
|
||||
});
|
||||
|
||||
RPC.prototype.addnode = co(function* addnode(args, help) {
|
||||
RPC.prototype.addNode = co(function* addNode(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var node = valid.str(0, '');
|
||||
var cmd = valid.str(1, '');
|
||||
@ -256,7 +256,7 @@ RPC.prototype.addnode = co(function* addnode(args, help) {
|
||||
return null;
|
||||
});
|
||||
|
||||
RPC.prototype.disconnectnode = co(function* disconnectnode(args, help) {
|
||||
RPC.prototype.disconnectNode = co(function* disconnectNode(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var addr = valid.str(0, '');
|
||||
var peer;
|
||||
@ -273,7 +273,7 @@ RPC.prototype.disconnectnode = co(function* disconnectnode(args, help) {
|
||||
return null;
|
||||
});
|
||||
|
||||
RPC.prototype.getaddednodeinfo = co(function* getaddednodeinfo(args, help) {
|
||||
RPC.prototype.getAddedNodeInfo = co(function* getAddedNodeInfo(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var addr = valid.str(1, '');
|
||||
var out = [];
|
||||
@ -311,14 +311,14 @@ RPC.prototype._toAddedNode = function _toAddedNode(peer) {
|
||||
};
|
||||
};
|
||||
|
||||
RPC.prototype.getconnectioncount = co(function* getconnectioncount(args, help) {
|
||||
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, help) {
|
||||
RPC.prototype.getNetTotals = co(function* getNetTotals(args, help) {
|
||||
var sent = 0;
|
||||
var recv = 0;
|
||||
var peer;
|
||||
@ -338,7 +338,7 @@ RPC.prototype.getnettotals = co(function* getnettotals(args, help) {
|
||||
};
|
||||
});
|
||||
|
||||
RPC.prototype.getpeerinfo = co(function* getpeerinfo(args, help) {
|
||||
RPC.prototype.getPeerInfo = co(function* getPeerInfo(args, help) {
|
||||
var peers = [];
|
||||
var id = 0;
|
||||
var peer, offset;
|
||||
@ -396,7 +396,7 @@ RPC.prototype.ping = co(function* ping(args, help) {
|
||||
return null;
|
||||
});
|
||||
|
||||
RPC.prototype.setban = co(function* setban(args, help) {
|
||||
RPC.prototype.setBan = co(function* setBan(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var addr = valid.str(0, '');
|
||||
var action = valid.str(1, '');
|
||||
@ -422,7 +422,7 @@ RPC.prototype.setban = co(function* setban(args, help) {
|
||||
return null;
|
||||
});
|
||||
|
||||
RPC.prototype.listbanned = co(function* listbanned(args, help) {
|
||||
RPC.prototype.listBanned = co(function* listBanned(args, help) {
|
||||
var i, banned, keys, host, time;
|
||||
|
||||
if (help || args.length !== 0)
|
||||
@ -445,7 +445,7 @@ RPC.prototype.listbanned = co(function* listbanned(args, help) {
|
||||
return banned;
|
||||
});
|
||||
|
||||
RPC.prototype.clearbanned = co(function* clearbanned(args, help) {
|
||||
RPC.prototype.clearBanned = co(function* clearBanned(args, help) {
|
||||
if (help || args.length !== 0)
|
||||
throw new RPCError('clearbanned');
|
||||
|
||||
@ -514,7 +514,7 @@ RPC.prototype._getBIP9Softforks = co(function* _getBIP9Softforks() {
|
||||
});
|
||||
|
||||
/* Block chain and UTXO */
|
||||
RPC.prototype.getblockchaininfo = co(function* getblockchaininfo(args, help) {
|
||||
RPC.prototype.getBlockchainInfo = co(function* getBlockchainInfo(args, help) {
|
||||
if (help || args.length !== 0)
|
||||
throw new RPCError('getblockchaininfo');
|
||||
|
||||
@ -536,7 +536,7 @@ RPC.prototype.getblockchaininfo = co(function* getblockchaininfo(args, help) {
|
||||
};
|
||||
});
|
||||
|
||||
RPC.prototype._getDifficulty = function getDifficulty(entry) {
|
||||
RPC.prototype._getDifficulty = function _getDifficulty(entry) {
|
||||
var shift, diff;
|
||||
|
||||
if (!entry) {
|
||||
@ -561,21 +561,21 @@ RPC.prototype._getDifficulty = function getDifficulty(entry) {
|
||||
return diff;
|
||||
};
|
||||
|
||||
RPC.prototype.getbestblockhash = co(function* getbestblockhash(args, help) {
|
||||
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, help) {
|
||||
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, help) {
|
||||
RPC.prototype.getBlock = co(function* getBlock(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var hash = valid.hash(0);
|
||||
var verbose = valid.bool(1, true);
|
||||
@ -687,15 +687,15 @@ RPC.prototype._scriptToJSON = function scriptToJSON(script, hex) {
|
||||
return out;
|
||||
};
|
||||
|
||||
RPC.prototype.getblockhash = co(function* getblockhash(args, help) {
|
||||
RPC.prototype.getBlockHash = co(function* getBlockHash(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var height = valid.num(0, -1);
|
||||
var height = valid.u32(0);
|
||||
var hash;
|
||||
|
||||
if (help || args.length !== 1)
|
||||
throw new RPCError('getblockhash index');
|
||||
|
||||
if (height < 0 || height > this.chain.height)
|
||||
if (height == null || height > this.chain.height)
|
||||
throw new RPCError('Block height out of range.');
|
||||
|
||||
hash = yield this.chain.db.getHash(height);
|
||||
@ -706,7 +706,7 @@ RPC.prototype.getblockhash = co(function* getblockhash(args, help) {
|
||||
return util.revHex(hash);
|
||||
});
|
||||
|
||||
RPC.prototype.getblockheader = co(function* getblockheader(args, help) {
|
||||
RPC.prototype.getBlockHeader = co(function* getBlockHeader(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var hash = valid.hash(0);
|
||||
var verbose = valid.bool(1, true);
|
||||
@ -782,7 +782,7 @@ RPC.prototype._blockToJSON = co(function* _blockToJSON(entry, block, txDetails)
|
||||
};
|
||||
});
|
||||
|
||||
RPC.prototype.getchaintips = co(function* getchaintips(args, help) {
|
||||
RPC.prototype.getChainTips = co(function* getChainTips(args, help) {
|
||||
var i, hash, tips, result, entry, fork, main;
|
||||
|
||||
if (help || args.length !== 0)
|
||||
@ -819,14 +819,14 @@ RPC.prototype._findFork = co(function* _findFork(entry) {
|
||||
throw new Error('Fork not found.');
|
||||
});
|
||||
|
||||
RPC.prototype.getdifficulty = co(function* getdifficulty(args, help) {
|
||||
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, help) {
|
||||
RPC.prototype.getMempoolInfo = co(function* getMempoolInfo(args, help) {
|
||||
if (help || args.length !== 0)
|
||||
throw new RPCError('getmempoolinfo');
|
||||
|
||||
@ -842,7 +842,7 @@ RPC.prototype.getmempoolinfo = co(function* getmempoolinfo(args, help) {
|
||||
};
|
||||
});
|
||||
|
||||
RPC.prototype.getmempoolancestors = co(function* getmempoolancestors(args, help) {
|
||||
RPC.prototype.getMempoolAncestors = co(function* getMempoolAncestors(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var hash = valid.hash(0);
|
||||
var verbose = valid.bool(1, false);
|
||||
@ -880,7 +880,7 @@ RPC.prototype.getmempoolancestors = co(function* getmempoolancestors(args, help)
|
||||
return out;
|
||||
});
|
||||
|
||||
RPC.prototype.getmempooldescendants = co(function* getmempooldescendants(args, help) {
|
||||
RPC.prototype.getMempoolDescendants = co(function* getMempoolDescendants(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var hash = valid.hash(0);
|
||||
var verbose = valid.bool(1, false);
|
||||
@ -918,7 +918,7 @@ RPC.prototype.getmempooldescendants = co(function* getmempooldescendants(args, h
|
||||
return out;
|
||||
});
|
||||
|
||||
RPC.prototype.getmempoolentry = co(function* getmempoolentry(args, help) {
|
||||
RPC.prototype.getMempoolEntry = co(function* getMempoolEntry(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var hash = valid.hash(0);
|
||||
var entry;
|
||||
@ -940,7 +940,7 @@ RPC.prototype.getmempoolentry = co(function* getmempoolentry(args, help) {
|
||||
return this._entryToJSON(entry);
|
||||
});
|
||||
|
||||
RPC.prototype.getrawmempool = co(function* getrawmempool(args, help) {
|
||||
RPC.prototype.getRawMempool = co(function* getRawMempool(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var verbose = valid.bool(0, false);
|
||||
var out = {};
|
||||
@ -989,10 +989,10 @@ RPC.prototype._entryToJSON = function _entryToJSON(entry) {
|
||||
};
|
||||
};
|
||||
|
||||
RPC.prototype.gettxout = co(function* gettxout(args, help) {
|
||||
RPC.prototype.getTXOut = co(function* getTXOut(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var hash = valid.hash(0);
|
||||
var index = valid.num(1);
|
||||
var index = valid.u32(1);
|
||||
var mempool = valid.bool(2, true);
|
||||
var coin;
|
||||
|
||||
@ -1005,7 +1005,7 @@ RPC.prototype.gettxout = co(function* gettxout(args, help) {
|
||||
if (this.chain.options.prune)
|
||||
throw new RPCError('Cannot get coins when pruned.');
|
||||
|
||||
if (!hash || index < 0)
|
||||
if (!hash || index == null)
|
||||
throw new RPCError('Invalid parameter.');
|
||||
|
||||
if (mempool)
|
||||
@ -1027,7 +1027,7 @@ RPC.prototype.gettxout = co(function* gettxout(args, help) {
|
||||
};
|
||||
});
|
||||
|
||||
RPC.prototype.gettxoutproof = co(function* gettxoutproof(args, help) {
|
||||
RPC.prototype.getTXOutProof = co(function* getTXOutProof(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var txids = valid.array(0);
|
||||
var hash = valid.hash(1);
|
||||
@ -1089,7 +1089,7 @@ RPC.prototype.gettxoutproof = co(function* gettxoutproof(args, help) {
|
||||
return block.toRaw().toString('hex');
|
||||
});
|
||||
|
||||
RPC.prototype.verifytxoutproof = co(function* verifytxoutproof(args, help) {
|
||||
RPC.prototype.verifyTXOutProof = co(function* verifyTXOutProof(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var data = valid.buf(0);
|
||||
var out = [];
|
||||
@ -1119,7 +1119,7 @@ RPC.prototype.verifytxoutproof = co(function* verifytxoutproof(args, help) {
|
||||
return out;
|
||||
});
|
||||
|
||||
RPC.prototype.gettxoutsetinfo = co(function* gettxoutsetinfo(args, help) {
|
||||
RPC.prototype.getTXOutSetInfo = co(function* getTXOutSetInfo(args, help) {
|
||||
if (help || args.length !== 0)
|
||||
throw new RPCError('gettxoutsetinfo');
|
||||
|
||||
@ -1137,10 +1137,10 @@ RPC.prototype.gettxoutsetinfo = co(function* gettxoutsetinfo(args, help) {
|
||||
};
|
||||
});
|
||||
|
||||
RPC.prototype.verifychain = co(function* verifychain(args, help) {
|
||||
RPC.prototype.verifyChain = co(function* verifyChain(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var level = valid.num(0);
|
||||
var blocks = valid.num(1);
|
||||
var level = valid.u32(0);
|
||||
var blocks = valid.u32(1);
|
||||
|
||||
if (help || args.length > 2)
|
||||
throw new RPCError('verifychain ( checklevel numblocks )');
|
||||
@ -1161,16 +1161,16 @@ RPC.prototype.verifychain = co(function* verifychain(args, help) {
|
||||
* Mining
|
||||
*/
|
||||
|
||||
RPC.prototype._submitwork = co(function* _submitwork(data) {
|
||||
RPC.prototype._submitWork = co(function* _submitWork(data) {
|
||||
var unlock = yield this.locker.lock();
|
||||
try {
|
||||
return yield this.__submitwork(data);
|
||||
return yield this.__submitWork(data);
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
});
|
||||
|
||||
RPC.prototype.__submitwork = co(function* _submitwork(data) {
|
||||
RPC.prototype.__submitWork = co(function* __submitWork(data) {
|
||||
var attempt = this.attempt;
|
||||
var block, entry, header, cb, cur;
|
||||
|
||||
@ -1233,16 +1233,16 @@ RPC.prototype.__submitwork = co(function* _submitwork(data) {
|
||||
return true;
|
||||
});
|
||||
|
||||
RPC.prototype._creatework = co(function* _creatework(data) {
|
||||
RPC.prototype._createWork = co(function* _createWork(data) {
|
||||
var unlock = yield this.locker.lock();
|
||||
try {
|
||||
return yield this.__creatework(data);
|
||||
return yield this.__createWork(data);
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
});
|
||||
|
||||
RPC.prototype.__creatework = co(function* _creatework() {
|
||||
RPC.prototype.__createWork = co(function* __createWork() {
|
||||
var attempt = yield this._getAttempt(true);
|
||||
var data, abbr;
|
||||
|
||||
@ -1264,12 +1264,12 @@ RPC.prototype.__creatework = co(function* _creatework() {
|
||||
};
|
||||
});
|
||||
|
||||
RPC.prototype.getworklp = co(function* getworklp(args, help) {
|
||||
RPC.prototype.getWorkLongpoll = co(function* getWorkLongpoll(args, help) {
|
||||
yield this._onBlock();
|
||||
return yield this._creatework();
|
||||
return yield this._createWork();
|
||||
});
|
||||
|
||||
RPC.prototype.getwork = co(function* getwork(args, help) {
|
||||
RPC.prototype.getWork = co(function* getWork(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var data = valid.buf(0);
|
||||
|
||||
@ -1280,13 +1280,13 @@ RPC.prototype.getwork = co(function* getwork(args, help) {
|
||||
if (!data)
|
||||
throw new RPCError('Invalid parameter.');
|
||||
|
||||
return yield this._submitwork(data);
|
||||
return yield this._submitWork(data);
|
||||
}
|
||||
|
||||
return yield this._creatework();
|
||||
});
|
||||
|
||||
RPC.prototype.submitblock = co(function* submitblock(args, help) {
|
||||
RPC.prototype.submitBlock = co(function* submitBlock(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var data = valid.buf(0);
|
||||
var block, tx;
|
||||
@ -1312,19 +1312,19 @@ RPC.prototype.submitblock = co(function* submitblock(args, help) {
|
||||
}
|
||||
}
|
||||
|
||||
return yield this._submitblock(block);
|
||||
return yield this._submitBlock(block);
|
||||
});
|
||||
|
||||
RPC.prototype._submitblock = co(function* submitblock(block) {
|
||||
RPC.prototype._submitBlock = co(function* _submitBlock(block) {
|
||||
var unlock = yield this.locker.lock();
|
||||
try {
|
||||
return yield this.__submitblock(block);
|
||||
return yield this.__submitBlock(block);
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
});
|
||||
|
||||
RPC.prototype.__submitblock = co(function* submitblock(block) {
|
||||
RPC.prototype.__submitBlock = co(function* __submitBlock(block) {
|
||||
var entry;
|
||||
|
||||
this.logger.info('Handling submitted block: %s.', block.rhash());
|
||||
@ -1349,7 +1349,7 @@ RPC.prototype.__submitblock = co(function* submitblock(block) {
|
||||
return null;
|
||||
});
|
||||
|
||||
RPC.prototype.getblocktemplate = co(function* getblocktemplate(args, help) {
|
||||
RPC.prototype.getBlockTemplate = co(function* getBlockTemplate(args, help) {
|
||||
var validator = new Validator([args]);
|
||||
var options = validator.obj(0, {});
|
||||
var valid = new Validator([options]);
|
||||
@ -1358,7 +1358,7 @@ RPC.prototype.getblocktemplate = co(function* getblocktemplate(args, help) {
|
||||
var data = valid.buf('data');
|
||||
var rules = valid.array('rules');
|
||||
var capabilities = valid.array('capabilities');
|
||||
var version = valid.num('maxversion', -1);
|
||||
var version = valid.u32('maxversion', -1);
|
||||
var coinbase = false;
|
||||
var i, cap, block, value, txn;
|
||||
|
||||
@ -1374,7 +1374,7 @@ RPC.prototype.getblocktemplate = co(function* getblocktemplate(args, help) {
|
||||
|
||||
block = Block.fromRaw(data);
|
||||
|
||||
return yield this._submitblock(block);
|
||||
return yield this._submitBlock(block);
|
||||
}
|
||||
|
||||
if (rules)
|
||||
@ -1664,14 +1664,14 @@ RPC.prototype._totalTX = function _totalTX() {
|
||||
return this.mempool ? this.mempool.totalTX : 0;
|
||||
};
|
||||
|
||||
RPC.prototype.getmininginfo = co(function* getmininginfo(args, help) {
|
||||
RPC.prototype.getMiningInfo = co(function* getMiningInfo(args, help) {
|
||||
var attempt = this.attempt;
|
||||
var hashps;
|
||||
|
||||
if (help || args.length !== 0)
|
||||
throw new RPCError('getmininginfo');
|
||||
|
||||
hashps = yield this._hashps(120, -1);
|
||||
hashps = yield this._hashps(120);
|
||||
|
||||
return {
|
||||
blocks: this.chain.height,
|
||||
@ -1688,10 +1688,10 @@ RPC.prototype.getmininginfo = co(function* getmininginfo(args, help) {
|
||||
};
|
||||
});
|
||||
|
||||
RPC.prototype.getnetworkhashps = co(function* getnetworkhashps(args, help) {
|
||||
RPC.prototype.getNetworkHashPS = co(function* getNetworkHashPS(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var lookup = valid.num(0, 120);
|
||||
var height = valid.num(1, -1);
|
||||
var lookup = valid.u32(0, 120);
|
||||
var height = valid.u32(1);
|
||||
|
||||
if (help || args.length > 2)
|
||||
throw new RPCError('getnetworkhashps ( blocks height )');
|
||||
@ -1699,10 +1699,10 @@ RPC.prototype.getnetworkhashps = co(function* getnetworkhashps(args, help) {
|
||||
return yield this._hashps(lookup, height);
|
||||
});
|
||||
|
||||
RPC.prototype.prioritisetransaction = co(function* prioritisetransaction(args, help) {
|
||||
RPC.prototype.prioritiseTransaction = co(function* prioritiseTransaction(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var hash = valid.hash(0);
|
||||
var pri = valid.num(1);
|
||||
var pri = valid.u64(1);
|
||||
var fee = valid.btc(2);
|
||||
var entry;
|
||||
|
||||
@ -1741,7 +1741,7 @@ RPC.prototype._hashps = co(function* _hashps(lookup, height) {
|
||||
var tip = this.chain.tip;
|
||||
var i, minTime, maxTime, workDiff, timeDiff, ps, entry;
|
||||
|
||||
if (height !== -1)
|
||||
if (height != null)
|
||||
tip = yield this.chain.db.getEntry(height);
|
||||
|
||||
if (!tip)
|
||||
@ -1777,7 +1777,7 @@ RPC.prototype._hashps = co(function* _hashps(lookup, height) {
|
||||
return ps;
|
||||
});
|
||||
|
||||
RPC.prototype.verifyblock = co(function* verifyblock(args, help) {
|
||||
RPC.prototype.verifyBlock = co(function* verifyBlock(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var data = valid.buf(0);
|
||||
var block;
|
||||
@ -1808,16 +1808,16 @@ RPC.prototype.verifyblock = co(function* verifyblock(args, help) {
|
||||
* Coin generation
|
||||
*/
|
||||
|
||||
RPC.prototype.getgenerate = co(function* getgenerate(args, help) {
|
||||
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, help) {
|
||||
RPC.prototype.setGenerate = co(function* setGenerate(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var mine = valid.bool(0, false);
|
||||
var limit = valid.num(0, 0);
|
||||
var limit = valid.u32(0, 0);
|
||||
|
||||
if (help || args.length < 1 || args.length > 2)
|
||||
throw new RPCError('setgenerate mine ( proclimit )');
|
||||
@ -1846,8 +1846,8 @@ RPC.prototype.generate = co(function* generate(args, help) {
|
||||
|
||||
RPC.prototype._generate = co(function* generate(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var blocks = valid.num(0, 1);
|
||||
var tries = valid.num(1);
|
||||
var blocks = valid.u32(0, 1);
|
||||
var tries = valid.u32(1);
|
||||
|
||||
if (help || args.length < 1 || args.length > 2)
|
||||
throw new RPCError('generate numblocks ( maxtries )');
|
||||
@ -1868,27 +1868,23 @@ RPC.prototype._generateBlocks = co(function* _generateBlocks(blocks, address, tr
|
||||
return hashes;
|
||||
});
|
||||
|
||||
RPC.prototype.generatetoaddress = co(function* generatetoaddress(args, help) {
|
||||
RPC.prototype.generateToAddress = co(function* generateToAddress(args, help) {
|
||||
var unlock = yield this.locker.lock();
|
||||
try {
|
||||
return yield this._generatetoaddress(args);
|
||||
return yield this._generateToAddress(args);
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
});
|
||||
|
||||
RPC.prototype._generatetoaddress = co(function* generatetoaddress(args, help) {
|
||||
RPC.prototype._generateToAddress = co(function* _generateToAddress(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var blocks = valid.num(0, 1);
|
||||
var blocks = valid.u32(0, 1);
|
||||
var addr = valid.str(1, '');
|
||||
var tries = valid.num(2, 1000000);
|
||||
|
||||
if (help || args.length < 2 || args.length > 3)
|
||||
throw new RPCError('generatetoaddress numblocks address ( maxtries )');
|
||||
|
||||
if (tries < 0)
|
||||
throw new RPCError('Invalid parameter.');
|
||||
|
||||
addr = Address.fromBase58(addr, this.network);
|
||||
|
||||
return yield this._generateBlocks(blocks, addr);
|
||||
@ -1898,11 +1894,11 @@ RPC.prototype._generatetoaddress = co(function* generatetoaddress(args, help) {
|
||||
* Raw transactions
|
||||
*/
|
||||
|
||||
RPC.prototype.createrawtransaction = co(function* createrawtransaction(args, help) {
|
||||
RPC.prototype.createRawTransaction = co(function* createRawTransaction(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var inputs = valid.array(0);
|
||||
var sendTo = valid.obj(1);
|
||||
var locktime = valid.num(2, -1);
|
||||
var locktime = valid.u32(2);
|
||||
var i, tx, input, output, hash, index, sequence;
|
||||
var keys, addrs, key, value, address, b58;
|
||||
|
||||
@ -1918,7 +1914,7 @@ RPC.prototype.createrawtransaction = co(function* createrawtransaction(args, hel
|
||||
|
||||
tx = new TX();
|
||||
|
||||
if (locktime !== -1)
|
||||
if (locktime != null)
|
||||
tx.setLocktime(locktime);
|
||||
|
||||
for (i = 0; i < inputs.length; i++) {
|
||||
@ -1926,13 +1922,13 @@ RPC.prototype.createrawtransaction = co(function* createrawtransaction(args, hel
|
||||
valid = new Validator([input]);
|
||||
|
||||
hash = valid.hash('txid');
|
||||
index = valid.num('vout');
|
||||
sequence = valid.num('sequence');
|
||||
index = valid.u32('vout');
|
||||
sequence = valid.u32('sequence', 0xffffffff);
|
||||
|
||||
if (tx.locktime)
|
||||
sequence--;
|
||||
|
||||
if (!hash || !util.isUInt32(index) || !util.isUInt32(sequence))
|
||||
if (!hash || index == null)
|
||||
throw new RPCError('Invalid parameter');
|
||||
|
||||
input = new Input();
|
||||
@ -1987,7 +1983,7 @@ RPC.prototype.createrawtransaction = co(function* createrawtransaction(args, hel
|
||||
return tx.toRaw().toString('hex');
|
||||
});
|
||||
|
||||
RPC.prototype.decoderawtransaction = co(function* decoderawtransaction(args, help) {
|
||||
RPC.prototype.decodeRawTransaction = co(function* decodeRawTransaction(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var data = valid.buf(0);
|
||||
var tx;
|
||||
@ -2003,7 +1999,7 @@ RPC.prototype.decoderawtransaction = co(function* decoderawtransaction(args, hel
|
||||
return this._txToJSON(tx);
|
||||
});
|
||||
|
||||
RPC.prototype.decodescript = co(function* decodescript(args, help) {
|
||||
RPC.prototype.decodeScript = co(function* decodeScript(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var data = valid.buf(0);
|
||||
var script, address;
|
||||
@ -2024,7 +2020,7 @@ RPC.prototype.decodescript = co(function* decodescript(args, help) {
|
||||
return script;
|
||||
});
|
||||
|
||||
RPC.prototype.getrawtransaction = co(function* getrawtransaction(args, help) {
|
||||
RPC.prototype.getRawTransaction = co(function* getRawTransaction(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var hash = valid.hash(0);
|
||||
var verbose = valid.bool(1, false);
|
||||
@ -2056,7 +2052,7 @@ RPC.prototype.getrawtransaction = co(function* getrawtransaction(args, help) {
|
||||
return json;
|
||||
});
|
||||
|
||||
RPC.prototype.sendrawtransaction = co(function* sendrawtransaction(args, help) {
|
||||
RPC.prototype.sendRawTransaction = co(function* sendRawTransaction(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var data = valid.buf(0);
|
||||
var tx;
|
||||
@ -2074,7 +2070,7 @@ RPC.prototype.sendrawtransaction = co(function* sendrawtransaction(args, help) {
|
||||
return tx.txid();
|
||||
});
|
||||
|
||||
RPC.prototype.signrawtransaction = co(function* signrawtransaction(args, help) {
|
||||
RPC.prototype.signRawTransaction = co(function* signRawTransaction(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var data = valid.buf(0);
|
||||
var tx;
|
||||
@ -2093,10 +2089,10 @@ RPC.prototype.signrawtransaction = co(function* signrawtransaction(args, help) {
|
||||
tx = MTX.fromRaw(data);
|
||||
tx.view = yield this.mempool.getSpentView(tx);
|
||||
|
||||
return yield this._signrawtransaction(tx, args);
|
||||
return yield this._signRawTransaction(tx, args);
|
||||
});
|
||||
|
||||
RPC.prototype._signrawtransaction = co(function* signrawtransaction(tx, args) {
|
||||
RPC.prototype._signRawTransaction = co(function* _signRawTransaction(tx, args) {
|
||||
var valid = new Validator([args]);
|
||||
var prevout = valid.array(1);
|
||||
var secrets = valid.array(2);
|
||||
@ -2124,7 +2120,7 @@ RPC.prototype._signrawtransaction = co(function* signrawtransaction(tx, args) {
|
||||
prev = prevout[i];
|
||||
valid = new Validator([prev]);
|
||||
hash = valid.hash('txid');
|
||||
index = valid.num('index');
|
||||
index = valid.u32('index');
|
||||
script = valid.buf('scriptPubKey');
|
||||
value = valid.btc('amount');
|
||||
redeem = valid.buf('redeemScript');
|
||||
@ -2195,10 +2191,10 @@ RPC.prototype._signrawtransaction = co(function* signrawtransaction(tx, args) {
|
||||
* Utility Functions
|
||||
*/
|
||||
|
||||
RPC.prototype.createmultisig = co(function* createmultisig(args, help) {
|
||||
RPC.prototype.createMultisig = co(function* createMultisig(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var keys = valid.array(1, []);
|
||||
var m = valid.num(0, 0);
|
||||
var m = valid.u32(0, 0);
|
||||
var n = keys.length;
|
||||
var i, script, key, address;
|
||||
|
||||
@ -2235,7 +2231,7 @@ RPC.prototype.createmultisig = co(function* createmultisig(args, help) {
|
||||
};
|
||||
});
|
||||
|
||||
RPC.prototype.createwitnessaddress = co(function* createwitnessaddress(args, help) {
|
||||
RPC.prototype.createWitnessAddress = co(function* createWitnessAddress(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var raw = valid.buf(0);
|
||||
var script, program, address;
|
||||
@ -2256,7 +2252,7 @@ RPC.prototype.createwitnessaddress = co(function* createwitnessaddress(args, hel
|
||||
};
|
||||
});
|
||||
|
||||
RPC.prototype.validateaddress = co(function* validateaddress(args, help) {
|
||||
RPC.prototype.validateAddress = co(function* validateAddress(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var b58 = valid.str(0, '');
|
||||
var address, script;
|
||||
@ -2283,7 +2279,7 @@ RPC.prototype.validateaddress = co(function* validateaddress(args, help) {
|
||||
};
|
||||
});
|
||||
|
||||
RPC.prototype.verifymessage = co(function* verifymessage(args, help) {
|
||||
RPC.prototype.verifyMessage = co(function* verifyMessage(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var b58 = valid.str(0, '');
|
||||
var sig = valid.buf(1, null, 'base64');
|
||||
@ -2310,7 +2306,7 @@ RPC.prototype.verifymessage = co(function* verifymessage(args, help) {
|
||||
return crypto.ccmp(key, hash);
|
||||
});
|
||||
|
||||
RPC.prototype.signmessagewithprivkey = co(function* signmessagewithprivkey(args, help) {
|
||||
RPC.prototype.signMessageWithPrivkey = co(function* signMessageWithPrivkey(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var key = valid.str(0, '');
|
||||
var msg = valid.str(1, '');
|
||||
@ -2328,9 +2324,9 @@ RPC.prototype.signmessagewithprivkey = co(function* signmessagewithprivkey(args,
|
||||
return sig.toString('base64');
|
||||
});
|
||||
|
||||
RPC.prototype.estimatefee = co(function* estimatefee(args, help) {
|
||||
RPC.prototype.estimateFee = co(function* estimateFee(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var blocks = valid.num(0, 1);
|
||||
var blocks = valid.u32(0, 1);
|
||||
var fee;
|
||||
|
||||
if (help || args.length !== 1)
|
||||
@ -2350,9 +2346,9 @@ RPC.prototype.estimatefee = co(function* estimatefee(args, help) {
|
||||
return Amount.btc(fee, true);
|
||||
});
|
||||
|
||||
RPC.prototype.estimatepriority = co(function* estimatepriority(args, help) {
|
||||
RPC.prototype.estimatePriority = co(function* estimatePriority(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var blocks = valid.num(0, 1);
|
||||
var blocks = valid.u32(0, 1);
|
||||
|
||||
if (help || args.length !== 1)
|
||||
throw new RPCError('estimatepriority nblocks');
|
||||
@ -2366,9 +2362,9 @@ RPC.prototype.estimatepriority = co(function* estimatepriority(args, help) {
|
||||
return this.fees.estimatePriority(blocks, false);
|
||||
});
|
||||
|
||||
RPC.prototype.estimatesmartfee = co(function* estimatesmartfee(args, help) {
|
||||
RPC.prototype.estimateSmartFee = co(function* estimateSmartFee(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var blocks = valid.num(0, 1);
|
||||
var blocks = valid.u32(0, 1);
|
||||
var fee;
|
||||
|
||||
if (help || args.length !== 1)
|
||||
@ -2393,9 +2389,9 @@ RPC.prototype.estimatesmartfee = co(function* estimatesmartfee(args, help) {
|
||||
};
|
||||
});
|
||||
|
||||
RPC.prototype.estimatesmartpriority = co(function* estimatesmartpriority(args, help) {
|
||||
RPC.prototype.estimateSmartPriority = co(function* estimateSmartPriority(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var blocks = valid.num(0, 1);
|
||||
var blocks = valid.u32(0, 1);
|
||||
var pri;
|
||||
|
||||
if (help || args.length !== 1)
|
||||
@ -2415,7 +2411,7 @@ RPC.prototype.estimatesmartpriority = co(function* estimatesmartpriority(args, h
|
||||
};
|
||||
});
|
||||
|
||||
RPC.prototype.invalidateblock = co(function* invalidateblock(args, help) {
|
||||
RPC.prototype.invalidateBlock = co(function* invalidateBlock(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var hash = valid.hash(0);
|
||||
|
||||
@ -2430,7 +2426,7 @@ RPC.prototype.invalidateblock = co(function* invalidateblock(args, help) {
|
||||
return null;
|
||||
});
|
||||
|
||||
RPC.prototype.reconsiderblock = co(function* reconsiderblock(args, help) {
|
||||
RPC.prototype.reconsiderBlock = co(function* reconsiderBlock(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var hash = valid.hash(0);
|
||||
|
||||
@ -2445,9 +2441,9 @@ RPC.prototype.reconsiderblock = co(function* reconsiderblock(args, help) {
|
||||
return null;
|
||||
});
|
||||
|
||||
RPC.prototype.setmocktime = co(function* setmocktime(args, help) {
|
||||
RPC.prototype.setMockTime = co(function* setMockTime(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var ts = valid.num(0);
|
||||
var ts = valid.u32(0);
|
||||
var delta;
|
||||
|
||||
if (help || args.length !== 1)
|
||||
@ -2465,14 +2461,14 @@ RPC.prototype.setmocktime = co(function* setmocktime(args, help) {
|
||||
return null;
|
||||
});
|
||||
|
||||
RPC.prototype.getmemory = co(function* getmemory(args, help) {
|
||||
RPC.prototype.getMemory = co(function* getMemory(args, help) {
|
||||
if (help || args.length !== 0)
|
||||
throw new RPCError('getmemory');
|
||||
|
||||
return util.memoryUsage();
|
||||
});
|
||||
|
||||
RPC.prototype.setloglevel = co(function* setloglevel(args, help) {
|
||||
RPC.prototype.setLogLevel = co(function* setLogLevel(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var level = valid.str(0, '');
|
||||
|
||||
|
||||
@ -166,7 +166,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
this.get('/coin/:hash/:index', co(function* (req, res) {
|
||||
var valid = req.valid();
|
||||
var hash = valid.hash('hash');
|
||||
var index = valid.num('index');
|
||||
var index = valid.u32('index');
|
||||
var coin;
|
||||
|
||||
enforce(hash, 'Hash is required.');
|
||||
@ -324,7 +324,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
// Estimate fee
|
||||
this.get('/fee', function(req, res) {
|
||||
var valid = req.valid();
|
||||
var blocks = valid.num('blocks');
|
||||
var blocks = valid.u32('blocks');
|
||||
var fee;
|
||||
|
||||
if (!this.fees) {
|
||||
@ -340,7 +340,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
// Reset chain
|
||||
this.post('/reset', co(function* (req, res) {
|
||||
var valid = req.valid();
|
||||
var height = valid.num('height');
|
||||
var height = valid.u32('height');
|
||||
|
||||
enforce(height != null, 'Hash or height is required.');
|
||||
|
||||
@ -493,7 +493,7 @@ HTTPServer.prototype.handleAuth = function handleAuth(socket) {
|
||||
|
||||
socket.hook('estimate fee', function(args) {
|
||||
var valid = new Validator([args]);
|
||||
var blocks = valid.num(0);
|
||||
var blocks = valid.u32(0);
|
||||
var rate;
|
||||
|
||||
if (!this.fees) {
|
||||
|
||||
@ -26,18 +26,12 @@ function Validator(data) {
|
||||
*/
|
||||
|
||||
Validator.prototype.init = function init(data) {
|
||||
var i, obj;
|
||||
|
||||
assert(data && typeof data === 'object');
|
||||
|
||||
if (!Array.isArray(data))
|
||||
data = [data];
|
||||
|
||||
for (i = 0; i < data.length; i++) {
|
||||
obj = data[i];
|
||||
assert(obj && typeof obj === 'object');
|
||||
this.data.push(obj);
|
||||
}
|
||||
this.data = data;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -91,7 +85,12 @@ Validator.prototype.get = function get(key, fallback) {
|
||||
|
||||
for (i = 0; i < this.data.length; i++) {
|
||||
map = this.data[i];
|
||||
|
||||
if (!map || typeof map !== 'object')
|
||||
throw new Error('Data is not an object.');
|
||||
|
||||
value = map[key];
|
||||
|
||||
if (value != null)
|
||||
return value;
|
||||
}
|
||||
@ -154,6 +153,50 @@ Validator.prototype.num = function num(key, fallback) {
|
||||
return value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a config option (as a number).
|
||||
* @param {String} key
|
||||
* @param {Object?} fallback
|
||||
* @returns {Number|null}
|
||||
*/
|
||||
|
||||
Validator.prototype.u32 = function u32(key, fallback) {
|
||||
var value = this.num(key);
|
||||
|
||||
if (fallback === undefined)
|
||||
fallback = null;
|
||||
|
||||
if (value === null)
|
||||
return fallback;
|
||||
|
||||
if (value % 1 !== 0 || value < 0 || value > 0xffffffff)
|
||||
throw new Error(key + ' must be a uint32.');
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a config option (as a number).
|
||||
* @param {String} key
|
||||
* @param {Object?} fallback
|
||||
* @returns {Number|null}
|
||||
*/
|
||||
|
||||
Validator.prototype.u64 = function u64(key, fallback) {
|
||||
var value = this.num(key);
|
||||
|
||||
if (fallback === undefined)
|
||||
fallback = null;
|
||||
|
||||
if (value === null)
|
||||
return fallback;
|
||||
|
||||
if (value % 1 !== 0 || value < 0 || value > 0x1fffffffffffff)
|
||||
throw new Error(key + ' must be a uint64.');
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a config option (as a number).
|
||||
* @param {String} key
|
||||
@ -184,7 +227,12 @@ Validator.prototype.amt = function amt(key, fallback) {
|
||||
if (!isFinite(value))
|
||||
throw new Error(key + ' must be a number.');
|
||||
|
||||
return value * 1e8;
|
||||
value *= 1e8;
|
||||
|
||||
if (value % 1 !== 0 || value < 0 || value > 0x1fffffffffffff)
|
||||
throw new Error(key + ' must be a uint64.');
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -203,7 +251,12 @@ Validator.prototype.btc = function btc(key, fallback) {
|
||||
if (value === null)
|
||||
return fallback;
|
||||
|
||||
return value * 1e8;
|
||||
value *= 1e8;
|
||||
|
||||
if (value % 1 !== 0 || value < 0 || value > 0x1fffffffffffff)
|
||||
throw new Error(key + ' must be a uint64.');
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -168,7 +168,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
// Rescan
|
||||
this.post('/_admin/rescan', co(function* (req, res) {
|
||||
var valid = req.valid();
|
||||
var height = valid.num('height');
|
||||
var height = valid.u32('height');
|
||||
|
||||
res.send(200, { success: true });
|
||||
|
||||
@ -222,8 +222,8 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
wallet = yield this.walletdb.create({
|
||||
id: valid.str('id'),
|
||||
type: valid.str('type'),
|
||||
m: valid.num('m'),
|
||||
n: valid.num('n'),
|
||||
m: valid.u32('m'),
|
||||
n: valid.u32('n'),
|
||||
passphrase: valid.str('passphrase'),
|
||||
master: valid.str('master'),
|
||||
mnemonic: valid.str('mnemonic'),
|
||||
@ -265,9 +265,9 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
witness: valid.bool('witness'),
|
||||
watchOnly: valid.bool('watchOnly'),
|
||||
type: valid.str('type'),
|
||||
m: valid.num('m'),
|
||||
n: valid.num('n'),
|
||||
lookahead: valid.num('lookahead')
|
||||
m: valid.u32('m'),
|
||||
n: valid.u32('n'),
|
||||
lookahead: valid.u32('lookahead')
|
||||
};
|
||||
|
||||
account = yield req.wallet.createAccount(options, passphrase);
|
||||
@ -294,7 +294,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
this.post('/:id/unlock', co(function* (req, res) {
|
||||
var valid = req.valid();
|
||||
var passphrase = valid.str('passphrase');
|
||||
var timeout = valid.num('timeout');
|
||||
var timeout = valid.u32('timeout');
|
||||
enforce(passphrase, 'Passphrase is required.');
|
||||
yield req.wallet.unlock(passphrase, timeout);
|
||||
res.send(200, { success: true });
|
||||
@ -352,12 +352,12 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
|
||||
options = {
|
||||
rate: valid.amt('rate'),
|
||||
blocks: valid.num('blocks'),
|
||||
blocks: valid.u32('blocks'),
|
||||
maxFee: valid.amt('maxFee'),
|
||||
selection: valid.str('selection'),
|
||||
smart: valid.bool('smart'),
|
||||
subtractFee: valid.bool('subtractFee'),
|
||||
depth: valid.num(['confirmations', 'depth']),
|
||||
depth: valid.u32(['confirmations', 'depth']),
|
||||
outputs: []
|
||||
};
|
||||
|
||||
@ -398,7 +398,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
selection: valid.str('selection'),
|
||||
smart: valid.bool('smart'),
|
||||
subtractFee: valid.bool('subtractFee'),
|
||||
depth: valid.num(['confirmations', 'depth']),
|
||||
depth: valid.u32(['confirmations', 'depth']),
|
||||
outputs: []
|
||||
};
|
||||
|
||||
@ -444,7 +444,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
this.post('/:id/zap', co(function* (req, res) {
|
||||
var valid = req.valid();
|
||||
var acct = valid.str('account');
|
||||
var age = valid.num('age');
|
||||
var age = valid.u32('age');
|
||||
enforce(age, 'Age is required.');
|
||||
yield req.wallet.zap(acct, age);
|
||||
res.send(200, { success: true });
|
||||
@ -468,7 +468,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
// Get Block Record
|
||||
this.get('/:id/block/:height', co(function* (req, res) {
|
||||
var valid = req.valid();
|
||||
var height = valid.num('height');
|
||||
var height = valid.u32('height');
|
||||
var block;
|
||||
|
||||
enforce(height != null, 'Height is required.');
|
||||
@ -614,7 +614,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
this.put('/:id/locked/:hash/:index', co(function* (req, res) {
|
||||
var valid = req.valid();
|
||||
var hash = valid.hash('hash');
|
||||
var index = valid.num('index');
|
||||
var index = valid.u32('index');
|
||||
var outpoint;
|
||||
|
||||
enforce(hash, 'Hash is required.');
|
||||
@ -629,7 +629,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
this.del('/:id/locked/:hash/:index', co(function* (req, res) {
|
||||
var valid = req.valid();
|
||||
var hash = valid.hash('hash');
|
||||
var index = valid.num('index');
|
||||
var index = valid.u32('index');
|
||||
var outpoint;
|
||||
|
||||
enforce(hash, 'Hash is required.');
|
||||
@ -644,7 +644,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
this.get('/:id/coin/:hash/:index', co(function* (req, res) {
|
||||
var valid = req.valid();
|
||||
var hash = valid.hash('hash');
|
||||
var index = valid.num('index');
|
||||
var index = valid.u32('index');
|
||||
var coin;
|
||||
|
||||
enforce(hash, 'Hash is required.');
|
||||
@ -708,9 +708,9 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
var i, options, txs, details, item;
|
||||
|
||||
options = {
|
||||
start: valid.num('start'),
|
||||
end: valid.num('end'),
|
||||
limit: valid.num('limit'),
|
||||
start: valid.u32('start'),
|
||||
end: valid.u32('end'),
|
||||
limit: valid.u32('limit'),
|
||||
reverse: valid.bool('reverse')
|
||||
};
|
||||
|
||||
@ -730,7 +730,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
this.get('/:id/tx/last', co(function* (req, res) {
|
||||
var valid = req.valid();
|
||||
var acct = valid.str('account');
|
||||
var limit = valid.num('limit');
|
||||
var limit = valid.u32('limit');
|
||||
var txs = yield req.wallet.getLast(acct, limit);
|
||||
var details = yield req.wallet.toDetails(txs);
|
||||
var result = [];
|
||||
|
||||
@ -370,7 +370,7 @@ RPC.prototype.getbalance = co(function* getbalance(args, help) {
|
||||
var wallet = this.wallet;
|
||||
var valid = new Validator([args]);
|
||||
var name = valid.str(0);
|
||||
var minconf = valid.num(1, 0);
|
||||
var minconf = valid.u32(1, 0);
|
||||
var watchOnly = valid.bool(2, false);
|
||||
var value, balance;
|
||||
|
||||
@ -388,7 +388,7 @@ RPC.prototype.getbalance = co(function* getbalance(args, help) {
|
||||
|
||||
balance = yield wallet.getBalance(name);
|
||||
|
||||
if (minconf)
|
||||
if (minconf > 0)
|
||||
value = balance.confirmed;
|
||||
else
|
||||
value = balance.unconfirmed;
|
||||
@ -429,7 +429,7 @@ RPC.prototype.getreceivedbyaccount = co(function* getreceivedbyaccount(args, hel
|
||||
var wallet = this.wallet;
|
||||
var valid = new Validator([args]);
|
||||
var name = valid.str(0);
|
||||
var minconf = valid.num(0, 0);
|
||||
var minconf = valid.u32(0, 0);
|
||||
var height = this.wdb.state.height;
|
||||
var total = 0;
|
||||
var filter = {};
|
||||
@ -477,7 +477,7 @@ RPC.prototype.getreceivedbyaddress = co(function* getreceivedbyaddress(args, hel
|
||||
var wallet = this.wallet;
|
||||
var valid = new Validator([args]);
|
||||
var addr = valid.str(0, '');
|
||||
var minconf = valid.num(1, 0);
|
||||
var minconf = valid.u32(1, 0);
|
||||
var hash = Address.getHash(addr, 'hex');
|
||||
var height = this.wdb.state.height;
|
||||
var total = 0;
|
||||
@ -797,7 +797,7 @@ RPC.prototype.keypoolrefill = co(function* keypoolrefill(args, help) {
|
||||
RPC.prototype.listaccounts = co(function* listaccounts(args, help) {
|
||||
var wallet = this.wallet;
|
||||
var valid = new Validator([args]);
|
||||
var minconf = valid.num(0, 0);
|
||||
var minconf = valid.u32(0, 0);
|
||||
var watchOnly = valid.bool(1, false);
|
||||
var map = {};
|
||||
var i, accounts, account, balance, value;
|
||||
@ -854,7 +854,7 @@ RPC.prototype.listlockunspent = co(function* listlockunspent(args, help) {
|
||||
|
||||
RPC.prototype.listreceivedbyaccount = co(function* listreceivedbyaccount(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var minconf = valid.num(0, 0);
|
||||
var minconf = valid.u32(0, 0);
|
||||
var includeEmpty = valid.bool(1, false);
|
||||
var watchOnly = valid.bool(2, false);
|
||||
|
||||
@ -868,7 +868,7 @@ RPC.prototype.listreceivedbyaccount = co(function* listreceivedbyaccount(args, h
|
||||
|
||||
RPC.prototype.listreceivedbyaddress = co(function* listreceivedbyaddress(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var minconf = valid.num(0, 0);
|
||||
var minconf = valid.u32(0, 0);
|
||||
var includeEmpty = valid.bool(1, false);
|
||||
var watchOnly = valid.bool(2, false);
|
||||
|
||||
@ -985,7 +985,7 @@ RPC.prototype.listsinceblock = co(function* listsinceblock(args, help) {
|
||||
var chainHeight = this.wdb.state.height;
|
||||
var valid = new Validator([args]);
|
||||
var block = valid.hash(0);
|
||||
var minconf = valid.num(1, 0);
|
||||
var minconf = valid.u32(1, 0);
|
||||
var watchOnly = valid.bool(2, false);
|
||||
var height = -1;
|
||||
var out = [];
|
||||
@ -1112,8 +1112,8 @@ RPC.prototype.listtransactions = co(function* listtransactions(args, help) {
|
||||
var wallet = this.wallet;
|
||||
var valid = new Validator([args]);
|
||||
var name = valid.str(0);
|
||||
var count = valid.num(1, 10);
|
||||
var from = valid.num(2, 0);
|
||||
var count = valid.u32(1, 10);
|
||||
var from = valid.u32(2, 0);
|
||||
var watchOnly = valid.bool(3, false);
|
||||
var end = from + count;
|
||||
var out = [];
|
||||
@ -1130,9 +1130,6 @@ RPC.prototype.listtransactions = co(function* listtransactions(args, help) {
|
||||
if (name === '')
|
||||
name = 'default';
|
||||
|
||||
if (count < 0)
|
||||
count = 10;
|
||||
|
||||
txs = yield wallet.getHistory();
|
||||
|
||||
common.sortTX(txs);
|
||||
@ -1151,8 +1148,8 @@ RPC.prototype.listtransactions = co(function* listtransactions(args, help) {
|
||||
RPC.prototype.listunspent = co(function* listunspent(args, help) {
|
||||
var wallet = this.wallet;
|
||||
var valid = new Validator([args]);
|
||||
var minDepth = valid.num(0, 1);
|
||||
var maxDepth = valid.num(1, 9999999);
|
||||
var minDepth = valid.u32(0, 1);
|
||||
var maxDepth = valid.u32(1, 9999999);
|
||||
var addrs = valid.array(2);
|
||||
var height = this.wdb.state.height;
|
||||
var out = [];
|
||||
@ -1249,9 +1246,9 @@ RPC.prototype.lockunspent = co(function* lockunspent(args, help) {
|
||||
output = outputs[i];
|
||||
valid = new Validator([output]);
|
||||
hash = valid.hash('txid');
|
||||
index = valid.num('vout');
|
||||
index = valid.u32('vout');
|
||||
|
||||
if (hash == null || index == null || index < 0)
|
||||
if (hash == null || index == null)
|
||||
throw new RPCError('Invalid parameter.');
|
||||
|
||||
outpoint = new Outpoint();
|
||||
@ -1278,9 +1275,9 @@ RPC.prototype.sendfrom = co(function* sendfrom(args, help) {
|
||||
var wallet = this.wallet;
|
||||
var valid = new Validator([args]);
|
||||
var name = valid.str(0);
|
||||
var addr = valid.str(1, '');
|
||||
var value = valid.btc(2, -1);
|
||||
var minconf = valid.num(3, 0);
|
||||
var addr = valid.str(1);
|
||||
var value = valid.btc(2);
|
||||
var minconf = valid.u32(3, 0);
|
||||
var options, tx;
|
||||
|
||||
if (help || args.length < 3 || args.length > 6) {
|
||||
@ -1289,7 +1286,7 @@ RPC.prototype.sendfrom = co(function* sendfrom(args, help) {
|
||||
+ ' amount ( minconf "comment" "comment-to" )');
|
||||
}
|
||||
|
||||
if (!addr || value < 0)
|
||||
if (!addr || value == null)
|
||||
throw new RPCError('Invalid parameter.');
|
||||
|
||||
addr = Address.fromBase58(addr, this.network);
|
||||
@ -1318,7 +1315,7 @@ RPC.prototype.sendmany = co(function* sendmany(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var name = valid.str(0);
|
||||
var sendTo = valid.obj(1);
|
||||
var minconf = valid.num(2, 1);
|
||||
var minconf = valid.u32(2, 1);
|
||||
var subtractFee = valid.bool(4, false);
|
||||
var outputs = [];
|
||||
var uniq = {};
|
||||
@ -1375,8 +1372,8 @@ RPC.prototype.sendmany = co(function* sendmany(args, help) {
|
||||
RPC.prototype.sendtoaddress = co(function* sendtoaddress(args, help) {
|
||||
var wallet = this.wallet;
|
||||
var valid = new Validator([args]);
|
||||
var addr = valid.str(0, '');
|
||||
var value = valid.btc(1, -1);
|
||||
var addr = valid.str(0);
|
||||
var value = valid.btc(1);
|
||||
var subtractFee = valid.bool(4, false);
|
||||
var options, tx;
|
||||
|
||||
@ -1389,7 +1386,7 @@ RPC.prototype.sendtoaddress = co(function* sendtoaddress(args, help) {
|
||||
|
||||
addr = Address.fromBase58(addr, this.network);
|
||||
|
||||
if (value < 0)
|
||||
if (!addr || value == null)
|
||||
throw new RPCError('Invalid parameter.');
|
||||
|
||||
options = {
|
||||
@ -1416,12 +1413,12 @@ RPC.prototype.setaccount = co(function* setaccount(args, help) {
|
||||
|
||||
RPC.prototype.settxfee = co(function* settxfee(args, help) {
|
||||
var valid = new Validator([args]);
|
||||
var rate = valid.btc(0, -1);
|
||||
var rate = valid.btc(0);
|
||||
|
||||
if (help || args.length < 1 || args.length > 1)
|
||||
throw new RPCError('settxfee amount');
|
||||
|
||||
if (rate < 0)
|
||||
if (rate == null)
|
||||
throw new RPCError('Invalid parameter.');
|
||||
|
||||
this.feeRate = rate;
|
||||
@ -1500,7 +1497,7 @@ RPC.prototype.walletpassphrase = co(function* walletpassphrase(args, help) {
|
||||
var wallet = this.wallet;
|
||||
var valid = new Validator([args]);
|
||||
var passphrase = valid.str(0, '');
|
||||
var timeout = valid.num(1, -1);
|
||||
var timeout = valid.u32(1);
|
||||
|
||||
if (help || (wallet.master.encrypted && args.length !== 2))
|
||||
throw new RPCError('walletpassphrase "passphrase" timeout');
|
||||
@ -1511,7 +1508,7 @@ RPC.prototype.walletpassphrase = co(function* walletpassphrase(args, help) {
|
||||
if (passphrase.length < 1)
|
||||
throw new RPCError('Invalid parameter');
|
||||
|
||||
if (timeout < 0)
|
||||
if (timeout == null)
|
||||
throw new RPCError('Invalid parameter');
|
||||
|
||||
yield wallet.unlock(passphrase, timeout);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user