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