jsbeautify
This commit is contained in:
parent
ead58e1e52
commit
5576dacf69
43
lib/Sync.js
43
lib/Sync.js
|
@ -40,14 +40,14 @@ function spec() {
|
|||
}
|
||||
|
||||
that.storeBlock(blockInfo.result, function(err) {
|
||||
if (!err) {
|
||||
var txs = blockInfo.result.tx;
|
||||
that.storeTxs(txs, function(err) {
|
||||
if (!err) {
|
||||
return that.getNextBlock(blockInfo.result.nextblockhash, cb);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!err) {
|
||||
var txs = blockInfo.result.tx;
|
||||
that.storeTxs(txs, function(err) {
|
||||
if (!err) {
|
||||
return that.getNextBlock(blockInfo.result.nextblockhash, cb);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -58,22 +58,22 @@ function spec() {
|
|||
if (err && ! err.toString().match(/E11000/)) {
|
||||
return cb(err);
|
||||
}
|
||||
cb();
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
Sync.prototype.storeTxs = function(txs, cb) {
|
||||
Transaction.createFromArray(txs, cb);
|
||||
};
|
||||
Sync.prototype.storeTxs = function(txs, cb) {
|
||||
Transaction.createFromArray(txs, cb);
|
||||
};
|
||||
|
||||
Sync.prototype.syncBlocks = function(reindex, cb) {
|
||||
var that = this;
|
||||
var genesisHash = this.network.genesisBlock.hash.reverse().toString('hex');
|
||||
|
||||
console.log('Syncing Blocks... '+reindex);
|
||||
console.log('Syncing Blocks... ' + reindex);
|
||||
if (reindex) {
|
||||
return this.getNextBlock(genesisHash, cb);
|
||||
}
|
||||
return this.getNextBlock(genesisHash, cb);
|
||||
}
|
||||
|
||||
Block.findOne({},
|
||||
{},
|
||||
|
@ -171,23 +171,23 @@ function spec() {
|
|||
console.log('Deleting Blocks...');
|
||||
that.db.collections.blocks.drop(cb);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
cb();
|
||||
}
|
||||
},
|
||||
function(cb) {
|
||||
if (opts.destroy) {
|
||||
console.log('Deleting TXs...');
|
||||
that.db.collections.transactions.drop(cb);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
cb();
|
||||
}
|
||||
},
|
||||
function(cb) {
|
||||
if (!opts.skip_blocks) {
|
||||
that.syncBlocks(opts.reindex, cb);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
cb();
|
||||
}
|
||||
},
|
||||
function(cb) {
|
||||
if (isSyncTxEnabled && ! opts.skip_txs) {
|
||||
|
@ -202,7 +202,6 @@ function spec() {
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
Sync.prototype.close = function() {
|
||||
console.log("closing connection");
|
||||
this.db.close();
|
||||
|
|
32
p2p.js
32
p2p.js
|
@ -1,6 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
var fs = require('fs');
|
||||
|
@ -106,33 +105,32 @@ sync.init();
|
|||
function handle_tx(info) {
|
||||
var tx = info.message.tx.getStandardizedObject();
|
||||
console.log('Handle tx: ' + tx.hash);
|
||||
sync.storeTxs([tx.hash], function(err) {
|
||||
if (err) {
|
||||
console.log('error in handle TX: '+err);
|
||||
}
|
||||
});
|
||||
sync.storeTxs([tx.hash], function(err) {
|
||||
if (err) {
|
||||
console.log('error in handle TX: ' + err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function handle_block(info) {
|
||||
var block = info.message.block;
|
||||
var now = Math.round(new Date().getTime() / 1000);
|
||||
var blockHash = coinUtil.formatHashFull(block.calcHash());
|
||||
console.log('Handle block: '+ blockHash);
|
||||
var blockHash = coinUtil.formatHashFull(block.calcHash());
|
||||
console.log('Handle block: ' + blockHash);
|
||||
sync.storeBlock({
|
||||
'hash': blockHash,
|
||||
'time': now
|
||||
'hash': blockHash,
|
||||
'time': now
|
||||
},
|
||||
function(err) {
|
||||
if (err) {
|
||||
console.log('error in handle Block: ' + err);
|
||||
} else {
|
||||
var hashes = block.txs.map(function(tx) {
|
||||
return coinUtil.formatHashFull(tx.hash);
|
||||
});
|
||||
sync.storeTxs(hashes, function(){});
|
||||
}
|
||||
});
|
||||
|
||||
var hashes = block.txs.map(function(tx) {
|
||||
return coinUtil.formatHashFull(tx.hash);
|
||||
});
|
||||
sync.storeTxs(hashes, function() {});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -14,32 +14,12 @@ var
|
|||
|
||||
mongoose.connection.on('error', function(err) { console.log(err); });
|
||||
|
||||
<<<<<<< HEAD
|
||||
describe('Block getInfo', function(){
|
||||
=======
|
||||
describe('Block fromHashWithInfo', function(){
|
||||
>>>>>>> fd86e6d074c5aa4642172b221b9e6f69f3fd8634
|
||||
|
||||
before(function(done) {
|
||||
mongoose.connect(config.db);
|
||||
done();
|
||||
});
|
||||
<<<<<<< HEAD
|
||||
|
||||
after(function(done) {
|
||||
mongoose.connection.close();
|
||||
done();
|
||||
});
|
||||
|
||||
it('should poll block\'s info from mongoose', function(done) {
|
||||
var block2 = Block.fromHashWithInfo(TESTING_BLOCK, function(err, b2) {
|
||||
if (err) done(err);
|
||||
|
||||
assert.equal(b2.hash, TESTING_BLOCK);
|
||||
done();
|
||||
});
|
||||
});
|
||||
=======
|
||||
|
||||
after(function(done) {
|
||||
mongoose.connection.close();
|
||||
|
@ -56,17 +36,11 @@ describe('Block fromHashWithInfo', function(){
|
|||
});
|
||||
});
|
||||
|
||||
>>>>>>> fd86e6d074c5aa4642172b221b9e6f69f3fd8634
|
||||
|
||||
it('should poll block\'s info from bitcoind', function(done) {
|
||||
var block2 = Block.fromHashWithInfo(TESTING_BLOCK, function(err, b2) {
|
||||
if (err) done(err);
|
||||
assert.equal(b2.info.hash, TESTING_BLOCK);
|
||||
<<<<<<< HEAD
|
||||
assert.equal(b2.info.chainwork, '00000000000000000000000000000000000000000000000000446af21d50acd3');
|
||||
=======
|
||||
assert.equal(b2.info.chainwork, '000000000000000000000000000000000000000000000000001b6dc969ffe847');
|
||||
>>>>>>> fd86e6d074c5aa4642172b221b9e6f69f3fd8634
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#! /usr/bin / env node
|
||||
# ! /usr/bin / env node
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -21,11 +21,10 @@ if (program.remove) {
|
|||
|
||||
}
|
||||
|
||||
|
||||
async.series([
|
||||
function(cb) {
|
||||
sync.init(program);
|
||||
cb();
|
||||
cb();
|
||||
},
|
||||
function(cb) {
|
||||
sync.import_history(program, function(err) {
|
||||
|
@ -35,11 +34,11 @@ function(cb) {
|
|||
else {
|
||||
console.log('Done!');
|
||||
}
|
||||
cb();
|
||||
cb();
|
||||
});
|
||||
},
|
||||
function(cb) {
|
||||
sync.close();
|
||||
cb();
|
||||
cb();
|
||||
}]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue