git fixes
This commit is contained in:
parent
6995563437
commit
5ea85584c4
|
@ -7,6 +7,7 @@ var mongoose = require('mongoose'),
|
||||||
Schema = mongoose.Schema,
|
Schema = mongoose.Schema,
|
||||||
RpcClient = require('bitcore/RpcClient').class(),
|
RpcClient = require('bitcore/RpcClient').class(),
|
||||||
util = require('bitcore/util/util'),
|
util = require('bitcore/util/util'),
|
||||||
|
async = require('async'),
|
||||||
BitcoreBlock= require('bitcore/Block').class(),
|
BitcoreBlock= require('bitcore/Block').class(),
|
||||||
TransactionOut = require('./TransactionOut'),
|
TransactionOut = require('./TransactionOut'),
|
||||||
config = require('../../config/config')
|
config = require('../../config/config')
|
||||||
|
@ -87,12 +88,22 @@ BlockSchema.statics.customCreate = function(block, cb) {
|
||||||
newBlock.hashStr = block.hash;
|
newBlock.hashStr = block.hash;
|
||||||
newBlock.nextBlockHashStr = block.nextBlockHash;
|
newBlock.nextBlockHashStr = block.nextBlockHash;
|
||||||
|
|
||||||
TransactionOut.createFromArray(block.tx, function(err, inserted_txs, update_addrs) {
|
var insertedTxs, updateAddrs;
|
||||||
if (err) return cb(err);
|
|
||||||
|
|
||||||
newBlock.save(function(err) {
|
async.series([
|
||||||
return cb(err, newBlock, inserted_txs, update_addrs);
|
function(a_cb) {
|
||||||
|
TransactionOut.createFromTxs(block.tx, function(err, inInsertedTxs, inUpdateAddrs) {
|
||||||
|
insertedTxs = inInsertedTxs;
|
||||||
|
updateAddrs = inUpdateAddrs;
|
||||||
|
return a_cb(err);
|
||||||
});
|
});
|
||||||
|
}, function(a_cb) {
|
||||||
|
newBlock.save(function(err) {
|
||||||
|
return a_cb(err);
|
||||||
|
});
|
||||||
|
}],
|
||||||
|
function (err) {
|
||||||
|
return cb(err, newBlock, insertedTxs, updateAddrs);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -91,27 +91,20 @@ TransactionOutSchema.statics.removeFromTxId = function(txid, cb) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TransactionOutSchema.statics._explodeTransactionOuts = function(txid, cb) {
|
TransactionOutSchema.statics.storeTransactionOuts = function(txInfo, cb) {
|
||||||
|
|
||||||
var Self = this;
|
var Self = this;
|
||||||
var addrs = [];
|
var addrs = [];
|
||||||
var is_new = true;
|
var is_new = true;
|
||||||
|
|
||||||
// Is it from genesis block? (testnet==livenet)
|
|
||||||
// TODO: parse it from networks.genesisTX
|
|
||||||
if (txid === genesisTXID) return cb();
|
|
||||||
|
|
||||||
TransactionRpc.getRpcInfo(txid, function(err, info) {
|
var bTxId = new Buffer(txInfo.txid,'hex');
|
||||||
|
|
||||||
if (err || !info) return cb(err);
|
|
||||||
|
|
||||||
var bTxId = new Buffer(txid,'hex');
|
|
||||||
|
|
||||||
async.series([
|
async.series([
|
||||||
// Input Outputs (mark them as spended)
|
// Input Outpoints (mark them as spended)
|
||||||
function(p_c) {
|
function(p_c) {
|
||||||
if (info.isCoinBase) return p_c();
|
if (txInfo.isCoinBase) return p_c();
|
||||||
async.forEachLimit(info.vin, CONCURRENCY,
|
async.forEachLimit(txInfo.vin, CONCURRENCY,
|
||||||
function(i, next_out) {
|
function(i, next_out) {
|
||||||
var b = new Buffer(i.txid,'hex');
|
var b = new Buffer(i.txid,'hex');
|
||||||
var data = {
|
var data = {
|
||||||
|
@ -126,7 +119,7 @@ TransactionOutSchema.statics._explodeTransactionOuts = function(txid, cb) {
|
||||||
function (err) {
|
function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (!err.message.match(/E11000/)) {
|
if (!err.message.match(/E11000/)) {
|
||||||
console.log('ERR at TX %s: %s', txid, err);
|
console.log('ERR at TX %s: %s', txInfo.txid, err);
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +128,7 @@ TransactionOutSchema.statics._explodeTransactionOuts = function(txid, cb) {
|
||||||
},
|
},
|
||||||
// Parse Outputs
|
// Parse Outputs
|
||||||
function(p_c) {
|
function(p_c) {
|
||||||
async.forEachLimit(info.vout, CONCURRENCY,
|
async.forEachLimit(txInfo.vout, CONCURRENCY,
|
||||||
function(o, next_out) {
|
function(o, next_out) {
|
||||||
if (o.value && o.scriptPubKey &&
|
if (o.value && o.scriptPubKey &&
|
||||||
o.scriptPubKey.addresses &&
|
o.scriptPubKey.addresses &&
|
||||||
|
@ -158,7 +151,7 @@ TransactionOutSchema.statics._explodeTransactionOuts = function(txid, cb) {
|
||||||
Self.update({txidBuf: bTxId, index: o.n}, data, {upsert: true}, next_out);
|
Self.update({txidBuf: bTxId, index: o.n}, data, {upsert: true}, next_out);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log ('WARN in TX: %s could not parse OUTPUT %d', txid, o.n);
|
console.log ('WARN in TX: %s could not parse OUTPUT %d', txInfo.txid, o.n);
|
||||||
return next_out();
|
return next_out();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -168,20 +161,20 @@ TransactionOutSchema.statics._explodeTransactionOuts = function(txid, cb) {
|
||||||
is_new = false;
|
is_new = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log('ERR at TX %s: %s', txid, err);
|
console.log('ERR at TX %s: %s', txInfo.txid, err);
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return p_c();
|
return p_c();
|
||||||
});
|
});
|
||||||
}], function() {
|
}], function(err) {
|
||||||
return cb(null, addrs, is_new);
|
return cb(err, addrs, is_new);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
TransactionOutSchema.statics.createFromArray = function(txs, next) {
|
// txs can be a [hashes] or [txObjects]
|
||||||
|
TransactionOutSchema.statics.createFromTxs = function(txs, next) {
|
||||||
|
|
||||||
var Self = this;
|
var Self = this;
|
||||||
if (!txs) return next();
|
if (!txs) return next();
|
||||||
|
@ -191,9 +184,20 @@ TransactionOutSchema.statics.createFromArray = function(txs, next) {
|
||||||
|
|
||||||
async.forEachLimit(txs, CONCURRENCY, function(txid, cb, was_new) {
|
async.forEachLimit(txs, CONCURRENCY, function(txid, cb, was_new) {
|
||||||
|
|
||||||
Self._explodeTransactionOuts( txid, function(err, addrs) {
|
var txInfo;
|
||||||
|
async.series([
|
||||||
if (err) return next(err);
|
function(a_cb) {
|
||||||
|
// Is it from genesis block? (testnet==livenet)
|
||||||
|
// TODO: parse it from networks.genesisTX?
|
||||||
|
if (txid === genesisTXID) return a_cb();
|
||||||
|
TransactionRpc.getRpcInfo(txid, function(err, inInfo) {
|
||||||
|
txInfo =inInfo;
|
||||||
|
return a_cb(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(a_cb) {
|
||||||
|
Self.storeTransactionOuts(txInfo, function(err, addrs) {
|
||||||
|
if (err) return a_cb(err);
|
||||||
|
|
||||||
if (was_new) {
|
if (was_new) {
|
||||||
inserted_txs.push(txid);
|
inserted_txs.push(txid);
|
||||||
|
@ -202,8 +206,11 @@ TransactionOutSchema.statics.createFromArray = function(txs, next) {
|
||||||
updated_addrs[a].push(txid);
|
updated_addrs[a].push(txid);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return a_cb();
|
||||||
return cb();
|
});
|
||||||
|
}],
|
||||||
|
function(err) {
|
||||||
|
return cb(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
db: 'mongodb://localhost/insight-dev',
|
||||||
|
app: {
|
||||||
|
name: 'Insight - Development'
|
||||||
|
},
|
||||||
|
bitcoind: {
|
||||||
|
protocol: process.env.BITCOIND_PROTO || 'http',
|
||||||
|
user: process.env.BITCOIND_USER || 'user',
|
||||||
|
pass: process.env.BITCOIND_PASS || 'pass',
|
||||||
|
host: process.env.BITCOIND_HOST || '127.0.0.1',
|
||||||
|
port: process.env.BITCOIND_PORT || '18332',
|
||||||
|
p2pPort: process.env.BITCOIND_P2P_PORT || '18333',
|
||||||
|
disableAgent: true,
|
||||||
|
dataDir: process.env.BITCOIND_DATADIR || './testnet3',
|
||||||
|
},
|
||||||
|
network: process.env.INSIGHT_NETWORK || 'testnet',
|
||||||
|
disableP2pSync: false,
|
||||||
|
disableHistoricSync: false,
|
||||||
|
};
|
|
@ -0,0 +1,22 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
db: 'mongodb://localhost/insight-test',
|
||||||
|
app: {
|
||||||
|
name: 'Insight - Prod'
|
||||||
|
},
|
||||||
|
port: '3301',
|
||||||
|
bitcoind: {
|
||||||
|
protocol: process.env.BITCOIND_PROTO || 'http',
|
||||||
|
user: process.env.BITCOIND_USER || 'user',
|
||||||
|
pass: process.env.BITCOIND_PASS || 'pass',
|
||||||
|
host: process.env.BITCOIND_HOST || '127.0.0.1',
|
||||||
|
port: process.env.BITCOIND_PORT || '18332',
|
||||||
|
p2pPort: process.env.BITCOIND_P2P_PORT || '18333',
|
||||||
|
disableAgent: true,
|
||||||
|
dataDir: process.env.BITCOIND_DATADIR || './testnet3',
|
||||||
|
},
|
||||||
|
network: process.env.INSIGHT_NETWORK || 'testnet',
|
||||||
|
disableP2pSync: false,
|
||||||
|
disableHistoricSync: false,
|
||||||
|
};
|
|
@ -0,0 +1,22 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
db: 'mongodb://localhost/insight-test',
|
||||||
|
app: {
|
||||||
|
name: 'Insight - Test'
|
||||||
|
},
|
||||||
|
port: '3301',
|
||||||
|
bitcoind: {
|
||||||
|
protocol: process.env.BITCOIND_PROTO || 'http',
|
||||||
|
user: process.env.BITCOIND_USER || 'user',
|
||||||
|
pass: process.env.BITCOIND_PASS || 'pass',
|
||||||
|
host: process.env.BITCOIND_HOST || '127.0.0.1',
|
||||||
|
port: process.env.BITCOIND_PORT || '18332',
|
||||||
|
p2pPort: process.env.BITCOIND_P2P_PORT || '18333',
|
||||||
|
disableAgent: true,
|
||||||
|
dataDir: process.env.BITCOIND_DATADIR || './testnet3',
|
||||||
|
},
|
||||||
|
network: process.env.INSIGHT_NETWORK || 'testnet',
|
||||||
|
disableP2pSync: false,
|
||||||
|
disableHistoricSync: false,
|
||||||
|
};
|
|
@ -25,7 +25,7 @@ mongoose.connection.on('open', function() {
|
||||||
|
|
||||||
var b = new Buffer(hash,'hex');
|
var b = new Buffer(hash,'hex');
|
||||||
|
|
||||||
T.createFromArray([hash], function(err, ret) {
|
T.createFromTxs([hash], function(err, ret) {
|
||||||
|
|
||||||
console.log('Err:');
|
console.log('Err:');
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
|
|
@ -106,6 +106,11 @@ function spec() {
|
||||||
if (self.syncPercentage > 100) self.syncPercentage = 100;
|
if (self.syncPercentage > 100) self.syncPercentage = 100;
|
||||||
|
|
||||||
p(util.format('status: [%d%%] skipped: %d', self.syncPercentage, self.skippedBlocks));
|
p(util.format('status: [%d%%] skipped: %d', self.syncPercentage, self.skippedBlocks));
|
||||||
|
//TODO
|
||||||
|
if (self.syncPercentage>5) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
//
|
||||||
}
|
}
|
||||||
if (self.opts.shouldBroadcast) {
|
if (self.opts.shouldBroadcast) {
|
||||||
sockets.broadcastSyncInfo(self.info());
|
sockets.broadcastSyncInfo(self.info());
|
||||||
|
@ -328,18 +333,25 @@ function spec() {
|
||||||
|
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
|
|
||||||
|
|
||||||
|
var scanOpts = {};
|
||||||
|
|
||||||
if (!b) {
|
if (!b) {
|
||||||
p('Could not find Genesis block. Running FULL SYNC');
|
p('Could not find Genesis block. Running FULL SYNC');
|
||||||
|
if (config.bitcoind.dataDir) {
|
||||||
|
p('bitcoind dataDir configured...importing blocks from .dat files');
|
||||||
|
scanOpts.fromFiles = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
scanOpts.reverse = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
p('Genesis block found. Syncing upto known blocks.');
|
p('Genesis block found. Syncing upto known blocks.');
|
||||||
|
scanOpts.reverse = true;
|
||||||
|
scanOpts.upToExisting = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var scanOpts = {
|
|
||||||
reverse: true,
|
|
||||||
upToExisting: b ? true: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
return self.importHistory(scanOpts, next);
|
return self.importHistory(scanOpts, next);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -106,7 +106,7 @@ function spec() {
|
||||||
Sync.prototype.storeTxs = function(txs, cb) {
|
Sync.prototype.storeTxs = function(txs, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
TransactionOut.createFromArray(txs, function(err, inserted_txs, updated_addrs) {
|
TransactionOut.createFromTxs(txs, function(err, inserted_txs, updated_addrs) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
self._handleBroadcast(null, inserted_txs, updated_addrs);
|
self._handleBroadcast(null, inserted_txs, updated_addrs);
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "*",
|
"async": "*",
|
||||||
|
"glob": "*",
|
||||||
"classtool": "*",
|
"classtool": "*",
|
||||||
"commander": "*",
|
"commander": "*",
|
||||||
"bignum": "*",
|
"bignum": "*",
|
||||||
|
|
Loading…
Reference in New Issue