Add client command for getrawtransaction, more indexing speed-up
This commit is contained in:
+36
-60
@@ -160,56 +160,50 @@ function find_tx(txid, cb) {
|
||||
});
|
||||
}
|
||||
|
||||
function save_tx(txid, cb) {
|
||||
function save_tx(txid, blockheight, cb) {
|
||||
//var s_timer = new Date().getTime();
|
||||
lib.get_rawtransaction(txid, function(tx){
|
||||
if (tx != 'There was an error. Check your console.') {
|
||||
lib.get_block(tx.blockhash, function(block){
|
||||
if (block) {
|
||||
lib.prepare_vin(tx, function(vin) {
|
||||
lib.prepare_vout(tx.vout, txid, vin, ((typeof tx.vjoinsplit === 'undefined' || tx.vjoinsplit == null) ? [] : tx.vjoinsplit), function(vout, nvin) {
|
||||
lib.syncLoop(vin.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
update_address(nvin[i].addresses, txid, nvin[i].amount, 'vin', function(){
|
||||
loop.next();
|
||||
lib.prepare_vin(tx, function(vin) {
|
||||
lib.prepare_vout(tx.vout, txid, vin, ((typeof tx.vjoinsplit === 'undefined' || tx.vjoinsplit == null) ? [] : tx.vjoinsplit), function(vout, nvin) {
|
||||
lib.syncLoop(vin.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
update_address(nvin[i].addresses, txid, nvin[i].amount, 'vin', function(){
|
||||
loop.next();
|
||||
});
|
||||
}, function(){
|
||||
lib.syncLoop(vout.length, function (subloop) {
|
||||
var t = subloop.iteration();
|
||||
if (vout[t].addresses) {
|
||||
update_address(vout[t].addresses, txid, vout[t].amount, 'vout', function(){
|
||||
subloop.next();
|
||||
});
|
||||
}, function(){
|
||||
lib.syncLoop(vout.length, function (subloop) {
|
||||
var t = subloop.iteration();
|
||||
if (vout[t].addresses) {
|
||||
update_address(vout[t].addresses, txid, vout[t].amount, 'vout', function(){
|
||||
subloop.next();
|
||||
});
|
||||
} else {
|
||||
subloop.next();
|
||||
}
|
||||
}, function(){
|
||||
lib.calculate_total(vout, function(total){
|
||||
var newTx = new Tx({
|
||||
txid: tx.txid,
|
||||
vin: nvin,
|
||||
vout: vout,
|
||||
total: total.toFixed(8),
|
||||
timestamp: tx.time,
|
||||
blockhash: tx.blockhash,
|
||||
blockindex: blockheight,
|
||||
});
|
||||
newTx.save(function(err) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
} else {
|
||||
subloop.next();
|
||||
//console.log('txid: ');
|
||||
return cb();
|
||||
}
|
||||
}, function(){
|
||||
lib.calculate_total(vout, function(total){
|
||||
var newTx = new Tx({
|
||||
txid: tx.txid,
|
||||
vin: nvin,
|
||||
vout: vout,
|
||||
total: total.toFixed(8),
|
||||
timestamp: tx.time,
|
||||
blockhash: tx.blockhash,
|
||||
blockindex: block.height,
|
||||
});
|
||||
newTx.save(function(err) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
} else {
|
||||
//console.log('txid: ');
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return cb('block not found: ' + tx.blockhash);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return cb('tx not found: ' + txid);
|
||||
@@ -445,24 +439,6 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
create_tx: function(txid, cb) {
|
||||
is_locked("db_index", function (exists) {
|
||||
if (exists) {
|
||||
console.log("db_index lock file exists...");
|
||||
return cb();
|
||||
} else {
|
||||
save_tx(txid, function(err){
|
||||
if (err) {
|
||||
return cb(err);
|
||||
} else {
|
||||
//console.log('tx stored: %s', txid);
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
create_txs: function(block, cb) {
|
||||
is_locked("db_index", function (exists) {
|
||||
if (exists) {
|
||||
@@ -471,7 +447,7 @@ module.exports = {
|
||||
} else {
|
||||
lib.syncLoop(block.tx.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
save_tx(block.tx[i], function(err){
|
||||
save_tx(block.tx[i], block.height, function(err){
|
||||
if (err) {
|
||||
loop.next();
|
||||
} else {
|
||||
@@ -853,7 +829,7 @@ module.exports = {
|
||||
tx = null;
|
||||
subloop.next();
|
||||
} else {
|
||||
save_tx(block.tx[i], function(err){
|
||||
save_tx(block.tx[i], block.height, function(err){
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
|
||||
+16
-4
@@ -147,10 +147,22 @@ module.exports = {
|
||||
},
|
||||
|
||||
get_rawtransaction: function(hash, cb) {
|
||||
var uri = base_url + 'getrawtransaction?txid=' + hash + '&decrypt=1';
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
return cb(body);
|
||||
});
|
||||
if (settings.use_rpc) {
|
||||
var uri = base_url + 'getrawtransaction?txid=' + hash + '&decrypt=1';
|
||||
request({uri: uri, json: true}, function (error, response, body) {
|
||||
return cb(body);
|
||||
});
|
||||
} else {
|
||||
client.command([{method:'getrawtransaction', parameters: [hash, 1]}], function(err, response){
|
||||
if(err){console.log('Error: ', err); onlyConsole.trace(err)}
|
||||
else{
|
||||
if(response[0].name == 'RpcError'){
|
||||
return cb('There was an error. Check your console.');
|
||||
}
|
||||
return cb(response[0]);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
get_maxmoney: function(cb) {
|
||||
|
||||
Reference in New Issue
Block a user