From c365ecb3ea319e1ca1fb3e7cbeb701f1f236b718 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 28 Feb 2017 15:15:52 -0800 Subject: [PATCH] rpc: improve getrawtransaction. --- lib/http/rpc.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/http/rpc.js b/lib/http/rpc.js index a2927ce7..c04f704a 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -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;