Reverted async await to promise.

This commit is contained in:
tenthirtyone 2017-08-03 01:46:47 -04:00
parent ad5c2dae93
commit 3ee90bdbef

View File

@ -10,31 +10,36 @@ const node = new FullNode(config.bcoin);
logger.log('debug', logger.log('debug',
'Debug mode started'); 'Debug mode started');
(async () => { node.open()
logger.log('debug', .then()
'Starting Full Node');
await node.open(); node.open()
await node.connect(); .then(() => {
node.connect().then(() => {
node.on('connect', (entry, block) => { node.startSync();
block.height = entry.height;
processBlock(block);
}); });
});
node.on('tx', (tx) => { node.chain.on('connect', (entry, block) => {
logger.log('debug', console.log(entry.height);
'%s added to mempool.', tx.txid()); processBlock(entry, block);
}); });
node.startSync(); node.mempool.on('tx', (tx) => {
})(); console.log(tx);
});
function processBlock(block) { node.chain.on('full', () => {
node.mempool.getHistory().then(console.log);
});
function processBlock(entry, block) {
block.hash = util.revHex(block.hash().toString('hex')); block.hash = util.revHex(block.hash().toString('hex'));
logger.log('debug', logger.log('debug',
`New Block Height: ${block.height}, Hash: ${block.hash}`); `New Block Height: ${block.height}, Hash: ${block.hash}`);
console.log(entry);
const b = new Block({ const b = new Block({
hash: block.hash, hash: block.hash,
size: block.size, size: block.size,
@ -46,7 +51,7 @@ function processBlock(block) {
nonce: block.nonce, nonce: block.nonce,
bits: block.bits, bits: block.bits,
difficulty: block.bits, difficulty: block.bits,
chainwork: 0, chainwork: entry.chainwork,
confirmations: 0, confirmations: 0,
previousBlockHash: block.previousBlockHash, previousBlockHash: block.previousBlockHash,
nextBlockHash: 0, nextBlockHash: 0,