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.
# 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

View File

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

View File

@ -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 = {

View File

@ -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] },
});

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