diff --git a/lib/node/index.js b/lib/node/index.js index a6eaec0..b3a26dc 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -22,7 +22,7 @@ function start() { function processBlock(entry, block, cb) { block.hash = util.revHex(block.hash().toString('hex')); - const b = new BlockModel({ + const newBlock = new BlockModel({ hash: block.hash, size: block.size, height: block.height, @@ -47,7 +47,7 @@ function processBlock(entry, block, cb) { transactionCount: block.txs.length, }); - b.save((err) => { + newBlock.save((err) => { if (err) { console.log(err.message); } @@ -55,8 +55,21 @@ function processBlock(entry, block, cb) { } function processTx(tx) { - console.log(util.revHex(tx.hash().toString('hex'))); - + 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] }, + }); } module.exports = { diff --git a/models/input.js b/models/input.js deleted file mode 100644 index 82cda75..0000000 --- a/models/input.js +++ /dev/null @@ -1,14 +0,0 @@ -const mongoose = require('mongoose'); -const Schema = mongoose.Schema; - -const Input = new Schema({ - utxo: String, - vout: Number, - address: String, - amount: Number, - wallets: { type: [Schema.Types.ObjectId] }, -}); - -const Input = mongoose.model('Input', Input); - -module.exports = Input; \ No newline at end of file diff --git a/models/output.js b/models/output.js deleted file mode 100644 index 80429c2..0000000 --- a/models/output.js +++ /dev/null @@ -1,13 +0,0 @@ -const mongoose = require('mongoose'); -const Schema = mongoose.Schema; - -const Output = new Schema({ - address: String, - amount: Number, - vout: Number, - wallets: { type: [Schema.Types.ObjectId] }, -}); - -const Output = mongoose.model('Output', Output); - -module.exports = Output; \ No newline at end of file diff --git a/models/transaction.js b/models/transaction.js index a107ba0..998d793 100644 --- a/models/transaction.js +++ b/models/transaction.js @@ -1,5 +1,21 @@ +const mongoose = require('mongoose'); const Schema = mongoose.Schema; +const InputSchema = new Schema({ + utxo: String, + vout: Number, + address: String, + amount: Number, + wallets: { type: [Schema.Types.ObjectId] }, +}); + +const OutputSchema = new Schema({ + address: String, + amount: Number, + vout: Number, + wallets: { type: [Schema.Types.ObjectId] }, +}); + const TransactionSchema = new Schema({ txid: String, chain: String, @@ -7,8 +23,8 @@ const TransactionSchema = new Schema({ blockHash: String, blockTime: Date, blockTimeNormalized: Date, - inputs: [Input], - outputs: [Output], + inputs: [InputSchema], + outputs: [OutputSchema], coinbase: Boolean, fee: Number, inputsProcessed: Boolean, @@ -27,7 +43,12 @@ TransactionSchema.index({ wallets: 1 }, { sparse: true }); TransactionSchema.index({ 'inputs.wallets': 1 }, { sparse: true }); TransactionSchema.index({ 'outputs.wallets': 1 }, { sparse: true }); -const Block = mongoose.model('Transaction', TransactionSchema); - -module.exports = Block; +const Transaction = mongoose.model('Transaction', TransactionSchema); +const Input = mongoose.model('Input', InputSchema); +const Output = mongoose.model('Output', OutputSchema); +module.exports = { + Transaction, + Input, + Output +};