rpc: refactor.

This commit is contained in:
Christopher Jeffrey 2016-08-17 06:10:29 -07:00
parent 3841eb3e58
commit 0ca46228f5
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -770,12 +770,12 @@ RPC.prototype.getblock = function getblock(args, callback) {
if (!verbose) if (!verbose)
return callback(null, block.toRaw().toString('hex')); return callback(null, block.toRaw().toString('hex'));
return self.blockToJSON(entry, block, false, callback); return self._blockToJSON(entry, block, false, callback);
}); });
}); });
}; };
RPC.prototype.txToJSON = function txToJSON(tx) { RPC.prototype._txToJSON = function _txToJSON(tx) {
var self = this; var self = this;
return { return {
txid: tx.txid, txid: tx.txid,
@ -888,11 +888,11 @@ RPC.prototype.getblockheader = function getblockheader(args, callback) {
if (!verbose) if (!verbose)
return callback(null, entry.toRaw().toString('hex', 0, 80)); return callback(null, entry.toRaw().toString('hex', 0, 80));
return self.blockheaderToJSON(entry, callback); return self._headerToJSON(entry, callback);
}); });
}; };
RPC.prototype.blockheaderToJSON = function blockheaderToJSON(entry, callback) { RPC.prototype._headerToJSON = function _headerToJSON(entry, callback) {
var self = this; var self = this;
entry.getMedianTimeAsync(function(err, medianTime) { entry.getMedianTimeAsync(function(err, medianTime) {
if (err) if (err)
@ -922,7 +922,7 @@ RPC.prototype.blockheaderToJSON = function blockheaderToJSON(entry, callback) {
}); });
}; };
RPC.prototype.blockToJSON = function blockToJSON(entry, block, txDetails, callback) { RPC.prototype._blockToJSON = function _blockToJSON(entry, block, txDetails, callback) {
var self = this; var self = this;
entry.getMedianTimeAsync(function(err, medianTime) { entry.getMedianTimeAsync(function(err, medianTime) {
if (err) if (err)
@ -943,7 +943,7 @@ RPC.prototype.blockToJSON = function blockToJSON(entry, block, txDetails, callba
merkleroot: utils.revHex(entry.merkleRoot), merkleroot: utils.revHex(entry.merkleRoot),
tx: block.txs.map(function(tx) { tx: block.txs.map(function(tx) {
if (txDetails) if (txDetails)
return self.txToJSON(tx); return self._txToJSON(tx);
return tx.rhash; return tx.rhash;
}), }),
time: entry.ts, time: entry.ts,
@ -1120,7 +1120,7 @@ RPC.prototype.getmempoolentry = function getmempoolentry(args, callback) {
if (!entry) if (!entry)
return callback(new RPCError('Transaction not in mempool.')); return callback(new RPCError('Transaction not in mempool.'));
callback(null, this.entryToJSON(entry)); callback(null, this._entryToJSON(entry));
}; };
RPC.prototype.getrawmempool = function getrawmempool(args, callback) { RPC.prototype.getrawmempool = function getrawmempool(args, callback) {
@ -1151,7 +1151,7 @@ RPC.prototype.mempoolToJSON = function mempoolToJSON(verbose, callback) {
if (!entry) if (!entry)
continue; continue;
out[entry.tx.rhash] = this.entryToJSON(entry); out[entry.tx.rhash] = this._entryToJSON(entry);
} }
return callback(null, out); return callback(null, out);
@ -1162,7 +1162,7 @@ RPC.prototype.mempoolToJSON = function mempoolToJSON(verbose, callback) {
return callback(null, hashes.map(utils.revHex)); return callback(null, hashes.map(utils.revHex));
}; };
RPC.prototype.entryToJSON = function entryToJSON(entry) { RPC.prototype._entryToJSON = function _entryToJSON(entry) {
var tx = entry.tx; var tx = entry.tx;
return { return {
size: entry.size, size: entry.size,
@ -1911,7 +1911,7 @@ RPC.prototype.decoderawtransaction = function decoderawtransaction(args, callbac
tx = bcoin.tx.fromRaw(toString(args[0]), 'hex'); tx = bcoin.tx.fromRaw(toString(args[0]), 'hex');
callback(null, this.txToJSON(tx)); callback(null, this._txToJSON(tx));
}; };
RPC.prototype.decodescript = function decodescript(args, callback) { RPC.prototype.decodescript = function decodescript(args, callback) {
@ -1962,7 +1962,7 @@ RPC.prototype.getrawtransaction = function getrawtransaction(args, callback) {
if (!verbose) if (!verbose)
return callback(null, tx.toRaw().toString('hex')); return callback(null, tx.toRaw().toString('hex'));
json = self.txToJSON(tx); json = self._txToJSON(tx);
json.hex = tx.toRaw().toString('hex'); json.hex = tx.toRaw().toString('hex');
callback(null, json); callback(null, json);