From 5bf176485b6bffd19e8917f61cbd4a3a2d44d655 Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Mon, 7 Aug 2017 15:28:58 -0400 Subject: [PATCH] logging out inputs and outputs for parsing & attaching to addresses --- config/index.js | 4 ++-- lib/node/index.js | 4 +++- lib/parser/address.js | 40 +++++++++++++++++++++++++++++++++++++++ lib/parser/block.js | 1 + lib/parser/index.js | 2 ++ lib/parser/transaction.js | 6 +++--- models/address.js | 15 +++++++++++++++ models/transaction.js | 8 +++----- 8 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 lib/parser/address.js create mode 100644 models/address.js diff --git a/config/index.js b/config/index.js index 7830f23..d4e3946 100644 --- a/config/index.js +++ b/config/index.js @@ -7,8 +7,8 @@ const config = { checkpoints: true, workers: true, logLevel: 'info', - 'max-inbound': 100, - 'max-outbound': 100, + 'max-inbound': 10, + 'max-outbound': 10, }, mongodb: { uri: 'mongodb://localhost/bitcore', diff --git a/lib/node/index.js b/lib/node/index.js index e77de9b..4599107 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -2,6 +2,7 @@ const FullNode = require('bcoin/lib/node/fullnode'); const logger = require('../../lib/logger'); const BlockParser = require('../parser').Block; const TxParser = require('../parser').Transaction; +const addrParser = require('../parser').Address; const config = require('../../config'); const node = new FullNode(config.bcoin); @@ -19,10 +20,11 @@ function start() { 'New Block & Ledger Entry'); BlockParser.parse(entry, block); TxParser.parse(entry, block.txs); + addrParser.parse(entry, block.txs); }); node.pool.on('peer', (peer) => { - //console.log(peer); + // console.log(peer); }); node.on('error', (err) => { diff --git a/lib/parser/address.js b/lib/parser/address.js new file mode 100644 index 0000000..c791a17 --- /dev/null +++ b/lib/parser/address.js @@ -0,0 +1,40 @@ +const AddressModel = require('../../models/address'); +const InputModel = require('../../models/input'); +const OutputModel = require('../../models/output'); +const config = require('../../config'); +const util = require('../../lib/util'); +const logger = require('../logger'); + +function parse(entry, txs) { + txs.forEach((tx) => { + //const txJSON = tx.toJSON(); + + tx.outputs.forEach((output) => { + const outputJSON = output.toJSON(); + console.log(outputJSON); + /* + return new OutputModel({ + address: outputJSON.address, + script: outputJSON.script, + value: outputJSON.value, + });*/ + }); + + tx.inputs.forEach((input) => { + const inputJSON = input.toJSON(); + console.log(inputJSON); +/* return new InputModel({ + prevout: inputJSON.prevout, + script: inputJSON.script, + witness: inputJSON.witness, + sequence: inputJSON.sequence, + address: inputJSON.address, + }); + })*/ + }); + }); +} + +module.exports = { + parse, +}; diff --git a/lib/parser/block.js b/lib/parser/block.js index fd559c3..3ee02e3 100644 --- a/lib/parser/block.js +++ b/lib/parser/block.js @@ -8,6 +8,7 @@ function parse(entry, block) { const blockJSON = block.toJSON(); const reward = util.calcBlockReward(entry.height); + // Can probably use destructuring to build something nicer const newBlock = new BlockModel({ hash: blockJSON.hash, height: entry.height, diff --git a/lib/parser/index.js b/lib/parser/index.js index 8989195..b73118c 100644 --- a/lib/parser/index.js +++ b/lib/parser/index.js @@ -1,7 +1,9 @@ const Block = require('./block'); const Transaction = require('./transaction'); +const Address = require('./address'); module.exports = { Block, Transaction, + Address, }; diff --git a/lib/parser/transaction.js b/lib/parser/transaction.js index c7d4bb2..b21e450 100644 --- a/lib/parser/transaction.js +++ b/lib/parser/transaction.js @@ -1,6 +1,6 @@ -const TxModel = require('../../models/transaction').Transaction; -const InputModel = require('../../models/transaction').Input; -const OutputModel = require('../../models/transaction').Output; +const TxModel = require('../../models/transaction'); +const InputModel = require('../../models/input'); +const OutputModel = require('../../models/output'); const config = require('../../config'); const util = require('../../lib/util'); const logger = require('../logger'); diff --git a/models/address.js b/models/address.js new file mode 100644 index 0000000..728b5f4 --- /dev/null +++ b/models/address.js @@ -0,0 +1,15 @@ +const mongoose = require('mongoose'); +const Input = require('./input'); +const Output = require('./output'); + +const Schema = mongoose.Schema; + +const AddressSchema = new Schema({ + address: String, + inputs: [Input.schema], + outputs: [Output.schema], +}); + +const Address = mongoose.model('Address', AddressSchema); + +module.exports = Address; diff --git a/models/transaction.js b/models/transaction.js index c7d6e86..73c4f4d 100644 --- a/models/transaction.js +++ b/models/transaction.js @@ -1,6 +1,6 @@ const mongoose = require('mongoose'); -const Input = require('./input'); -const Output = require('./output'); +const Input = require('./input'); +const Output = require('./output'); const Schema = mongoose.Schema; @@ -24,6 +24,4 @@ const TransactionSchema = new Schema({ const Transaction = mongoose.model('Transaction', TransactionSchema); -module.exports = { - Transaction, -}; +module.exports = Transaction;