Better input handling. Huge increase in performance and accuracy.

This commit is contained in:
tenthirtyone 2017-08-25 17:25:26 -04:00
parent afc063fb97
commit df2beddf16
2 changed files with 28 additions and 41 deletions

View File

@ -7,8 +7,6 @@ const socket = require('../../lib/api/socket');
const db = require('../../lib/db'); const db = require('../../lib/db');
const node = new FullNode(config.bcoin); const node = new FullNode(config.bcoin);
let doneSyncing = false;
function start(bestBlockHeight) { function start(bestBlockHeight) {
node.open() node.open()
@ -21,20 +19,18 @@ function start(bestBlockHeight) {
}); });
node.chain.on('connect', (entry, block) => { node.chain.on('connect', (entry, block) => {
// Saved block acts like a journal
BlockParser.parse(entry, block);
TxParser.parse(entry, block.txs);
socket.processBlock(entry, block);
db.blocks.bestHeight(entry.height); db.blocks.bestHeight(entry.height);
node.chain.db.getBlockView(block) node.chain.db.getBlockView(block)
.then((view) => { .then((view) => {
console.log(view); const fullBlock = block.getJSON(node.network, view, entry.height);
BlockParser.parse(entry, block);
TxParser.parse(entry, fullBlock.txs);
}); });
}); });
node.chain.on('full', () => { node.chain.on('full', () => {
doneSyncing = true;
}); });
node.on('error', (err) => { node.on('error', (err) => {

View File

@ -7,44 +7,35 @@ const logger = require('../logger');
const db = require('../db'); const db = require('../db');
function parse(entry, txs) { function parse(entry, txs) {
// findEmptyInputs();
txs.forEach((tx) => { txs.forEach((tx) => {
const txJSON = tx.toJSON();
const txRAW = tx.toRaw();
const t = new TxModel({ const t = new TxModel({
hash: txJSON.hash, hash: tx.hash,
witnessHash: txJSON.witnessHash, witnessHash: tx.witnessHash,
fee: txJSON.fee, fee: tx.fee,
rate: txJSON.rate, rate: tx.rate,
size: txRAW.length, size: tx.size,
ps: txJSON.ps, ps: tx.ps,
height: entry.height, height: entry.height,
block: util.revHex(entry.hash), block: util.revHex(entry.hash),
ts: entry.ts, ts: entry.ts,
date: txJSON.date, date: entry.tx,
index: txJSON.index, index: tx.index,
version: txJSON.version, version: tx.version,
flag: txJSON.flag, flag: tx.flag,
inputs: tx.inputs.map((input) => { inputs: tx.inputs.map(input => new InputModel({
const inputJSON = input.toJSON(); value: input.coin ? input.coin.value : 0,
return new InputModel({ prevout: input.prevout,
prevout: inputJSON.prevout, script: input.script,
script: inputJSON.script, witness: input.witness,
witness: inputJSON.witness, sequence: input.sequence,
sequence: inputJSON.sequence, address: input.coin ? input.coin.address : '',
address: inputJSON.address, })),
}); outputs: tx.outputs.map(output => new OutputModel({
}), address: output.address,
outputs: tx.outputs.map((output) => { script: output.script,
const outputJSON = output.toJSON(); value: output.value,
return new OutputModel({ })),
address: outputJSON.address, lockTime: tx.locktime,
script: outputJSON.script,
value: outputJSON.value,
});
}),
lockTime: txJSON.locktime,
chain: config.bcoin.network, chain: config.bcoin.network,
}); });