logging out inputs and outputs for parsing & attaching to addresses
This commit is contained in:
parent
1143bd803a
commit
5bf176485b
@ -7,8 +7,8 @@ const config = {
|
|||||||
checkpoints: true,
|
checkpoints: true,
|
||||||
workers: true,
|
workers: true,
|
||||||
logLevel: 'info',
|
logLevel: 'info',
|
||||||
'max-inbound': 100,
|
'max-inbound': 10,
|
||||||
'max-outbound': 100,
|
'max-outbound': 10,
|
||||||
},
|
},
|
||||||
mongodb: {
|
mongodb: {
|
||||||
uri: 'mongodb://localhost/bitcore',
|
uri: 'mongodb://localhost/bitcore',
|
||||||
|
|||||||
@ -2,6 +2,7 @@ const FullNode = require('bcoin/lib/node/fullnode');
|
|||||||
const logger = require('../../lib/logger');
|
const logger = require('../../lib/logger');
|
||||||
const BlockParser = require('../parser').Block;
|
const BlockParser = require('../parser').Block;
|
||||||
const TxParser = require('../parser').Transaction;
|
const TxParser = require('../parser').Transaction;
|
||||||
|
const addrParser = require('../parser').Address;
|
||||||
const config = require('../../config');
|
const config = require('../../config');
|
||||||
|
|
||||||
const node = new FullNode(config.bcoin);
|
const node = new FullNode(config.bcoin);
|
||||||
@ -19,10 +20,11 @@ function start() {
|
|||||||
'New Block & Ledger Entry');
|
'New Block & Ledger Entry');
|
||||||
BlockParser.parse(entry, block);
|
BlockParser.parse(entry, block);
|
||||||
TxParser.parse(entry, block.txs);
|
TxParser.parse(entry, block.txs);
|
||||||
|
addrParser.parse(entry, block.txs);
|
||||||
});
|
});
|
||||||
|
|
||||||
node.pool.on('peer', (peer) => {
|
node.pool.on('peer', (peer) => {
|
||||||
//console.log(peer);
|
// console.log(peer);
|
||||||
});
|
});
|
||||||
|
|
||||||
node.on('error', (err) => {
|
node.on('error', (err) => {
|
||||||
|
|||||||
40
lib/parser/address.js
Normal file
40
lib/parser/address.js
Normal file
@ -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,
|
||||||
|
};
|
||||||
@ -8,6 +8,7 @@ function parse(entry, block) {
|
|||||||
const blockJSON = block.toJSON();
|
const blockJSON = block.toJSON();
|
||||||
const reward = util.calcBlockReward(entry.height);
|
const reward = util.calcBlockReward(entry.height);
|
||||||
|
|
||||||
|
// Can probably use destructuring to build something nicer
|
||||||
const newBlock = new BlockModel({
|
const newBlock = new BlockModel({
|
||||||
hash: blockJSON.hash,
|
hash: blockJSON.hash,
|
||||||
height: entry.height,
|
height: entry.height,
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
const Block = require('./block');
|
const Block = require('./block');
|
||||||
const Transaction = require('./transaction');
|
const Transaction = require('./transaction');
|
||||||
|
const Address = require('./address');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Block,
|
Block,
|
||||||
Transaction,
|
Transaction,
|
||||||
|
Address,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
const TxModel = require('../../models/transaction').Transaction;
|
const TxModel = require('../../models/transaction');
|
||||||
const InputModel = require('../../models/transaction').Input;
|
const InputModel = require('../../models/input');
|
||||||
const OutputModel = require('../../models/transaction').Output;
|
const OutputModel = require('../../models/output');
|
||||||
const config = require('../../config');
|
const config = require('../../config');
|
||||||
const util = require('../../lib/util');
|
const util = require('../../lib/util');
|
||||||
const logger = require('../logger');
|
const logger = require('../logger');
|
||||||
|
|||||||
15
models/address.js
Normal file
15
models/address.js
Normal file
@ -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;
|
||||||
@ -1,6 +1,6 @@
|
|||||||
const mongoose = require('mongoose');
|
const mongoose = require('mongoose');
|
||||||
const Input = require('./input');
|
const Input = require('./input');
|
||||||
const Output = require('./output');
|
const Output = require('./output');
|
||||||
|
|
||||||
const Schema = mongoose.Schema;
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
@ -24,6 +24,4 @@ const TransactionSchema = new Schema({
|
|||||||
|
|
||||||
const Transaction = mongoose.model('Transaction', TransactionSchema);
|
const Transaction = mongoose.model('Transaction', TransactionSchema);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = Transaction;
|
||||||
Transaction,
|
|
||||||
};
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user