node start wired up
This commit is contained in:
parent
aaef1c7273
commit
06b24d85b7
1
index.js
1
index.js
@ -10,3 +10,4 @@ Api.listen(3000, () => {
|
|||||||
'listening on port 3000');
|
'listening on port 3000');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
node.start();
|
||||||
|
|||||||
@ -6,44 +6,51 @@ const logger = require('../../lib/logger');
|
|||||||
const db = require('../../lib/db');
|
const db = require('../../lib/db');
|
||||||
const util = require('../../lib/util');
|
const util = require('../../lib/util');
|
||||||
|
|
||||||
node.open()
|
|
||||||
.then(() => {
|
|
||||||
node.connect().then(() => {
|
|
||||||
node.startSync();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
node.chain.on('connect', (entry, block) => {
|
function start() {
|
||||||
processBlock(entry, block);
|
node.open()
|
||||||
});
|
.then(() => {
|
||||||
|
node.connect().then(() => {
|
||||||
function processBlock(entry, block, cb) {
|
node.startSync();
|
||||||
block.hash = util.revHex(block.hash().toString('hex'))
|
});
|
||||||
const b = new BlockSchema({
|
|
||||||
hash: block.hash,
|
|
||||||
size: block.size,
|
|
||||||
height: block.height,
|
|
||||||
version: block.version,
|
|
||||||
merkleRoot: block.merkleRoot,
|
|
||||||
tx: block.txs.map(tx => util.revHex(tx.hash().toString('hex'))),
|
|
||||||
time: block.ts,
|
|
||||||
nonce: block.nonce,
|
|
||||||
bits: block.bits,
|
|
||||||
difficulty: block.bits,
|
|
||||||
chainwork: entry.chainwork,
|
|
||||||
confirmations: 0,
|
|
||||||
previousBlockHash: block.previousBlockHash,
|
|
||||||
nextBlockHash: 0,
|
|
||||||
reward: 0,
|
|
||||||
timeNormalized: block.ts,
|
|
||||||
isMainChain: true,
|
|
||||||
poolInfo: Object,
|
|
||||||
transactionCount: block.txs.length,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
b.save((err) => {
|
node.chain.on('connect', (entry, block) => {
|
||||||
if (err) {
|
processBlock(entry, block);
|
||||||
console.log(err.message);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function processBlock(entry, block, cb) {
|
||||||
|
block.hash = util.revHex(block.hash().toString('hex'))
|
||||||
|
const b = new BlockSchema({
|
||||||
|
hash: block.hash,
|
||||||
|
size: block.size,
|
||||||
|
height: block.height,
|
||||||
|
version: block.version,
|
||||||
|
merkleRoot: block.merkleRoot,
|
||||||
|
tx: block.txs.map(tx => util.revHex(tx.hash().toString('hex'))),
|
||||||
|
time: block.ts,
|
||||||
|
nonce: block.nonce,
|
||||||
|
bits: block.bits,
|
||||||
|
difficulty: block.bits,
|
||||||
|
chainwork: entry.chainwork,
|
||||||
|
confirmations: 0,
|
||||||
|
previousBlockHash: block.previousBlockHash,
|
||||||
|
nextBlockHash: 0,
|
||||||
|
reward: 0,
|
||||||
|
timeNormalized: block.ts,
|
||||||
|
isMainChain: true,
|
||||||
|
poolInfo: Object,
|
||||||
|
transactionCount: block.txs.length,
|
||||||
|
});
|
||||||
|
|
||||||
|
b.save((err) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(err.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
start,
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user