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 node = new FullNode(config.bcoin);
let doneSyncing = false;
function start(bestBlockHeight) {
node.open()
@ -21,20 +19,18 @@ function start(bestBlockHeight) {
});
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);
node.chain.db.getBlockView(block)
.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', () => {
doneSyncing = true;
});
node.on('error', (err) => {

View File

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