From df2beddf16b278db5bc403385bd81a0c8a672b0c Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Fri, 25 Aug 2017 17:25:26 -0400 Subject: [PATCH] Better input handling. Huge increase in performance and accuracy. --- server/lib/node/index.js | 12 +++---- server/lib/parser/transaction.js | 57 ++++++++++++++------------------ 2 files changed, 28 insertions(+), 41 deletions(-) diff --git a/server/lib/node/index.js b/server/lib/node/index.js index 458c872..cd99eb7 100644 --- a/server/lib/node/index.js +++ b/server/lib/node/index.js @@ -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) => { diff --git a/server/lib/parser/transaction.js b/server/lib/parser/transaction.js index c6bf908..6cc1482 100644 --- a/server/lib/parser/transaction.js +++ b/server/lib/parser/transaction.js @@ -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, });