rpc: improve getrawtransaction.

This commit is contained in:
Christopher Jeffrey 2017-02-28 15:15:52 -08:00
parent 9f09de4867
commit c365ecb3ea
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -2187,7 +2187,7 @@ RPC.prototype.decodescript = co(function* decodescript(args, help) {
});
RPC.prototype.getrawtransaction = co(function* getrawtransaction(args, help) {
var hash, verbose, json, tx;
var hash, verbose, json, meta, tx, entry;
if (help || args.length < 1 || args.length > 2)
throw new RPCError('getrawtransaction "txid" ( verbose )');
@ -2202,15 +2202,21 @@ RPC.prototype.getrawtransaction = co(function* getrawtransaction(args, help) {
if (args.length > 1)
verbose = toBool(args[1]);
tx = yield this.node.getTX(hash);
meta = yield this.node.getMeta(hash);
if (!tx)
if (!meta)
throw new RPCError('Transaction not found.');
tx = meta.tx;
if (!verbose)
return tx.toRaw().toString('hex');
json = this._txToJSON(tx);
if (meta.block)
entry = yield this.chain.db.getEntry(meta.block);
json = this._txToJSON(tx, entry);
json.time = meta.ps;
json.hex = tx.toRaw().toString('hex');
return json;