Processing tx, input and output. About to refactor tx models to fit insight

This commit is contained in:
tenthirtyone 2017-08-03 15:21:07 -04:00
parent 8c5f296980
commit ea7e7aae34
6 changed files with 65 additions and 23 deletions

View File

@ -2,7 +2,9 @@
Rebuilt Bitcore with Bcoin engine and Insight API sitting on top of Mongo. Rebuilt Bitcore with Bcoin engine and Insight API sitting on top of Mongo.
# Requirements # 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 # Usage
npm install npm install

View File

@ -5,6 +5,7 @@ const config = {
checkpoints: true, checkpoints: true,
workers: true, workers: true,
logLevel: 'info', logLevel: 'info',
'max-inbound': 100,
}, },
mongodb: { mongodb: {
uri: 'mongodb://localhost/bitcore', uri: 'mongodb://localhost/bitcore',

View File

@ -5,7 +5,7 @@ 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');
const BlockModel = require('../../models/block'); const BlockModel = require('../../models/block');
const TxModel = require('../../models/transaction'); const TxModel = require('../../models/transaction').Transaction;
function start() { function start() {
node.open() node.open()
@ -16,22 +16,22 @@ function start() {
}); });
node.chain.on('connect', (entry, block) => { node.chain.on('connect', (entry, block) => {
logger.log('debug',
'New Block & Ledger Entry');
processBlock(entry, block); processBlock(entry, block);
}); });
} }
function processBlock(entry, block, cb) { 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({ const newBlock = new BlockModel({
hash: block.hash, hash: blockHash,
size: block.size, size: block.size,
height: block.height, height: block.height,
version: block.version, version: block.version,
merkleRoot: block.merkleRoot, merkleRoot: block.merkleRoot,
tx: block.txs.map((tx) => { tx: block.txs.map(tx => util.revHex(tx.hash().toString('hex'))),
processTx(tx);
return util.revHex(tx.hash().toString('hex'));
}),
time: block.ts, time: block.ts,
nonce: block.nonce, nonce: block.nonce,
bits: block.bits, bits: block.bits,
@ -51,25 +51,53 @@ function processBlock(entry, block, cb) {
if (err) { if (err) {
console.log(err.message); console.log(err.message);
} }
processTx(entry, block.txs);
}); });
} }
function processTx(tx) { function processTx(entry, txs) {
console.log(tx); txs.forEach((tx) => {
const t = new Transaction({ const hash = util.revHex(tx.hash().toString('hex'));
txid: String,
chain: String, const inputs = tx.inputs.map((input) => {
blockHeight: Number, console.log('input');
blockHash: String, console.log(input);
blockTime: Date, console.log(input.toJSON());
blockTimeNormalized: Date, });
inputs: [Input],
outputs: [Output], const outputs = tx.outputs.map((output) => {
coinbase: Boolean, console.log('output');
fee: Number, console.log(output);
inputsProcessed: Boolean, console.log(output.toJSON());
wallets: { type: [Schema.Types.ObjectId] }, });
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 = { module.exports = {

View File

@ -18,6 +18,7 @@ const OutputSchema = new Schema({
const TransactionSchema = new Schema({ const TransactionSchema = new Schema({
txid: String, txid: String,
version: Number,
chain: String, chain: String,
blockHeight: Number, blockHeight: Number,
blockHash: String, blockHash: String,
@ -28,6 +29,7 @@ const TransactionSchema = new Schema({
coinbase: Boolean, coinbase: Boolean,
fee: Number, fee: Number,
inputsProcessed: Boolean, inputsProcessed: Boolean,
lockTime: Number,
wallets: { type: [Schema.Types.ObjectId] }, wallets: { type: [Schema.Types.ObjectId] },
}); });

View File

@ -0,0 +1,9 @@
{ hash: '000000000000079920b5c47176825c3b4caa21a4149a5eac21c5396c1381b620',
version: '00000001',
prevBlock: '00000000000005ea8ac3629d24dfb688712b5bb78d8bde36e4947543197b7b65',
merkleRoot: '9842e0adaf6e08a8077ec9259e6302bd19f74013531541a3f229a6d0ce634540',
ts: 1309051460,
bits: 437004818,
nonce: 3677140808,
height: 133291,
chainwork: '0000000000000000000000000000000000000000000000017507fa3944ff9f68' }

View File