diff --git a/README.md b/README.md index 719f0e6..865e25f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@ Rebuilt Bitcore with Bcoin engine and Insight API sitting on top of Mongo. # Requirements -Mongodo running on your system +Mongodo running on your system. + +PR has been submitted to Bcoin repo to fix a bug in their script library that is causing our sync process to crash when one of their checks to a tx script assesses if this is a pay to pubkey input. This is Bcoin-specific and should not affect syncing via DC Pool # Usage npm install diff --git a/config/config.js b/config/config.js index 17747b7..d6a7cee 100644 --- a/config/config.js +++ b/config/config.js @@ -5,6 +5,7 @@ const config = { checkpoints: true, workers: true, logLevel: 'info', + 'max-inbound': 100, }, mongodb: { uri: 'mongodb://localhost/bitcore', diff --git a/lib/node/index.js b/lib/node/index.js index b3a26dc..a352f5d 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -5,7 +5,7 @@ const logger = require('../../lib/logger'); const db = require('../../lib/db'); const util = require('../../lib/util'); const BlockModel = require('../../models/block'); -const TxModel = require('../../models/transaction'); +const TxModel = require('../../models/transaction').Transaction; function start() { node.open() @@ -16,22 +16,22 @@ function start() { }); node.chain.on('connect', (entry, block) => { + logger.log('debug', + 'New Block & Ledger Entry'); processBlock(entry, block); }); } function processBlock(entry, block, cb) { - block.hash = util.revHex(block.hash().toString('hex')); + const blockHash = util.revHex(block.hash().toString('hex')); + const newBlock = new BlockModel({ - hash: block.hash, + hash: blockHash, size: block.size, height: block.height, version: block.version, merkleRoot: block.merkleRoot, - tx: block.txs.map((tx) => { - processTx(tx); - return util.revHex(tx.hash().toString('hex')); - }), + tx: block.txs.map(tx => util.revHex(tx.hash().toString('hex'))), time: block.ts, nonce: block.nonce, bits: block.bits, @@ -51,25 +51,53 @@ function processBlock(entry, block, cb) { if (err) { console.log(err.message); } + processTx(entry, block.txs); }); } -function processTx(tx) { - console.log(tx); - const t = new Transaction({ - txid: String, - chain: String, - blockHeight: Number, - blockHash: String, - blockTime: Date, - blockTimeNormalized: Date, - inputs: [Input], - outputs: [Output], - coinbase: Boolean, - fee: Number, - inputsProcessed: Boolean, - wallets: { type: [Schema.Types.ObjectId] }, +function processTx(entry, txs) { + txs.forEach((tx) => { + const hash = util.revHex(tx.hash().toString('hex')); + + const inputs = tx.inputs.map((input) => { + console.log('input'); + console.log(input); + console.log(input.toJSON()); + }); + + const outputs = tx.outputs.map((output) => { + console.log('output'); + console.log(output); + console.log(output.toJSON()); + }); + + const t = new TxModel({ + txid: hash, + chain: config.bcoin.network, + blockHeight: entry.height, + blockHash: '123', + blockTime: 0, + blockTimeNormalized: 0, + inputs: [], + outputs: [], + coinbase: false, + fee: 0, + inputsProcessed: false, + }); + console.log(hash); + t.save((err) => { + if (err) { + console.log(err.message); + } + }); }); + + // console.log(util.revHex(tx.hash().toString('hex'))); + // tx.hash = util.revHex(tx.hash().toString('hex')); + // entry.hash = util.revHex(entry.hash().toString('hex')); + /* + + */ } module.exports = { diff --git a/models/transaction.js b/models/transaction.js index 998d793..f5783d2 100644 --- a/models/transaction.js +++ b/models/transaction.js @@ -18,6 +18,7 @@ const OutputSchema = new Schema({ const TransactionSchema = new Schema({ txid: String, + version: Number, chain: String, blockHeight: Number, blockHash: String, @@ -28,6 +29,7 @@ const TransactionSchema = new Schema({ coinbase: Boolean, fee: Number, inputsProcessed: Boolean, + lockTime: Number, wallets: { type: [Schema.Types.ObjectId] }, }); diff --git a/test/data/bcoin-entry.json b/test/data/bcoin-entry.json new file mode 100644 index 0000000..ac6b35e --- /dev/null +++ b/test/data/bcoin-entry.json @@ -0,0 +1,9 @@ +{ hash: '000000000000079920b5c47176825c3b4caa21a4149a5eac21c5396c1381b620', + version: '00000001', + prevBlock: '00000000000005ea8ac3629d24dfb688712b5bb78d8bde36e4947543197b7b65', + merkleRoot: '9842e0adaf6e08a8077ec9259e6302bd19f74013531541a3f229a6d0ce634540', + ts: 1309051460, + bits: 437004818, + nonce: 3677140808, + height: 133291, + chainwork: '0000000000000000000000000000000000000000000000017507fa3944ff9f68' } diff --git a/test/data/insight-tx.json b/test/data/insight-tx.json new file mode 100644 index 0000000..e69de29