remove parsing txs from RPC
This commit is contained in:
parent
101ecd3481
commit
358b32e02a
|
@ -10,6 +10,7 @@ var common = require('./common');
|
|||
var TransactionDb = require('../../lib/TransactionDb').class();
|
||||
var BlockDb = require('../../lib/BlockDb').class();
|
||||
|
||||
var tDb = new TransactionDb();
|
||||
var bdb = new BlockDb();
|
||||
|
||||
|
||||
|
@ -17,7 +18,6 @@ var bdb = new BlockDb();
|
|||
* Find transaction by hash ...
|
||||
*/
|
||||
exports.transaction = function(req, res, next, txid) {
|
||||
var tDb = new TransactionDb();
|
||||
|
||||
tDb.fromIdWithInfo(txid, function(err, tx) {
|
||||
if (err || ! tx)
|
||||
|
@ -42,21 +42,13 @@ exports.show = function(req, res) {
|
|||
|
||||
|
||||
var getTransaction = function(txid, cb) {
|
||||
var tDb = new TransactionDb();
|
||||
|
||||
tDb.fromIdWithInfo(txid, function(err, tx) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
if (err) console.log(err);
|
||||
|
||||
if (!tx || !tx.info) {
|
||||
console.log('[transactions.js.48]:: TXid %s not found in RPC. CHECK THIS.', txid); //TODO
|
||||
// not check this. no
|
||||
tx = {
|
||||
info: {
|
||||
txid: txid
|
||||
}
|
||||
};
|
||||
console.log('[transactions.js.48]:: TXid %s not found in RPC. CHECK THIS.', txid);
|
||||
return ({ txid: txid });
|
||||
}
|
||||
|
||||
return cb(null, tx.info);
|
||||
|
|
21
lib/Rpc.js
21
lib/Rpc.js
|
@ -5,7 +5,6 @@ require('classtool');
|
|||
|
||||
function spec(b) {
|
||||
var RpcClient = require('bitcore/RpcClient').class(),
|
||||
BitcoreTransaction = require('bitcore/Transaction').class(),
|
||||
BitcoreBlock = require('bitcore/Block').class(),
|
||||
bitcoreUtil = require('bitcore/util/util'),
|
||||
util = require('util'),
|
||||
|
@ -16,25 +15,25 @@ function spec(b) {
|
|||
function Rpc() {
|
||||
}
|
||||
|
||||
Rpc._parseRpcResult = function(info) {
|
||||
Rpc._parseTxResult = function(info) {
|
||||
var b = new Buffer(info.hex,'hex');
|
||||
var tx = new BitcoreTransaction();
|
||||
tx.parse(b);
|
||||
|
||||
// Inputs
|
||||
if (tx.isCoinBase()) {
|
||||
info.isCoinBase = true;
|
||||
}
|
||||
// remove fields we dont need, to speed, and adapt the information
|
||||
delete info['hex'];
|
||||
|
||||
// Inputs => add index + coinBase flag
|
||||
var n =0;
|
||||
info.vin.forEach(function(i) {
|
||||
if (i.coinbase) info.isCoinBase = true;
|
||||
i.n = n++;
|
||||
delete i.scriptSig['hex'];
|
||||
});
|
||||
|
||||
// Outputs
|
||||
// Outputs => add total
|
||||
var valueOutSat = 0;
|
||||
info.vout.forEach( function(o) {
|
||||
valueOutSat += o.value * bitcoreUtil.COIN;
|
||||
delete o.scriptPubKey['hex'];
|
||||
});
|
||||
info.valueOut = parseInt(valueOutSat) / bitcoreUtil.COIN;
|
||||
info.size = b.length;
|
||||
|
@ -54,7 +53,7 @@ function spec(b) {
|
|||
return e;
|
||||
};
|
||||
|
||||
Rpc.getRpcInfo = function(txid, cb) {
|
||||
Rpc.getTxInfo = function(txid, cb) {
|
||||
var self = this;
|
||||
|
||||
bitcoreRpc.getRawTransaction(txid, 1, function(err, txInfo) {
|
||||
|
@ -63,7 +62,7 @@ function spec(b) {
|
|||
if (err && err.code === -5) return cb();
|
||||
if (err) return cb(self.errMsg(err));
|
||||
|
||||
var info = self._parseRpcResult(txInfo.result);
|
||||
var info = self._parseTxResult(txInfo.result);
|
||||
|
||||
return cb(null,info);
|
||||
});
|
||||
|
|
|
@ -246,7 +246,7 @@ function spec(b) {
|
|||
TransactionDb.prototype._getInfo = function(txid, next) {
|
||||
var self = this;
|
||||
|
||||
Rpc.getRpcInfo(txid, function(err, info) {
|
||||
Rpc.getTxInfo(txid, function(err, info) {
|
||||
if (err) return next(err);
|
||||
|
||||
self._fillOutpoints(info, function() {
|
||||
|
@ -677,7 +677,7 @@ function spec(b) {
|
|||
// TODO: parse it from networks.genesisTX?
|
||||
if (t === genesisTXID) return each_cb();
|
||||
|
||||
Rpc.getRpcInfo(t, function(err, inInfo) {
|
||||
Rpc.getTxInfo(t, function(err, inInfo) {
|
||||
if (!inInfo) return each_cb(err);
|
||||
|
||||
return self.add(inInfo, blockHash, each_cb);
|
||||
|
|
Loading…
Reference in New Issue