From 43b23b80dc91e5bb70f90ad71c6a91f3d210a5c6 Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Thu, 3 Aug 2017 18:08:04 -0400 Subject: [PATCH] Transaction, Input and Output models are wired or stubbed. Tomorrow/Tonight I wire up the API --- README.md | 20 ++++++++++++++++++++ lib/node/index.js | 35 +++++++++++++++++++++-------------- models/transaction.js | 2 -- test/data/bcoin-input.json | 17 +++++++++++++++++ 4 files changed, 58 insertions(+), 16 deletions(-) create mode 100644 test/data/bcoin-input.json diff --git a/README.md b/README.md index c003933..4f705f7 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,23 @@ npm start Logging is current defaulting to debug during dev. Bitcore logging is preceded by a timestamp. Bcoin logging with [info] +# Misc Gotchas / Needs Docs & clarity + +Mongo will create the bitcore db and a blocks/transactions collection automatically. These colls have indexes. Bcoin also syncs to the prefix set in config. To reset/start over you need to drop both collections and delete the bcoin datadir. + # Nginx The API is configured to run on port 3000 by default. Use the standard Nginx reverse proxy to flip http to https and handle ssl certs. +# Requirements + +1. git clone +2. npm install +3. npm run start +4. Bitcore starts, Bcoin syncs and Insight starts automagically. + +1, 2 & 3 are complete. 4 is also complete but insight still needs wired to mongo and the mongo data models are going to undergo more changes as we consolidate work and discover needs. The goal is still to go as far as possible with a stable framework and fill in the rest afterwards when work can be tasked/delegated. + # Priorities 1. Required Insight-UI @@ -33,3 +46,10 @@ The API is configured to run on port 3000 by default. Use the standard Nginx rev /txs sockets + +2. Mongo Models + +Some data is stubbed. This is due to Bcoin primitives being different from Bitcore. It's unclear whether Mongo models or multiple queries at the api layer will better serve us. Obviously multiple queries are easier but I would prefer a clear cut data model because that leads to fewer problems in the future and gives us greater flexibility in our API and the other microservices we implement in the future. + +# ToDo +Reorg testing - Bcoin will handle this but we need to account for this in our mongo indexes. \ No newline at end of file diff --git a/lib/node/index.js b/lib/node/index.js index e095148..4b78401 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -6,6 +6,8 @@ const db = require('../../lib/db'); const util = require('../../lib/util'); const BlockModel = require('../../models/block'); const TxModel = require('../../models/transaction').Transaction; +const InputModel = require('../../models/transaction').Input; +const OutputModel = require('../../models/transaction').Output; function start() { node.open() @@ -60,24 +62,29 @@ function processTx(entry, txs) { const txHash = util.revHex(tx.hash().toString('hex')); const blockHash = util.revHex(entry.hash); - 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: txHash, version: 1, lockTime: tx.lockTime, - vin: [], - vout: [], + vin: tx.inputs.map((input) => { + const inputJSON = input.toJSON(); + + return new InputModel({ + utxo: inputJSON.prevout.hash, + vout: inputJSON.prevout.index, + address: inputJSON.address, + amount: 0, + }); + }), + vout: tx.outputs.map((output) => { + const outputJSON = output.toJSON(); + + return new OutputModel({ + address: outputJSON.address, + amount: outputJSON.value, + vout: 0, + }); + }), blockHash: blockHash, blockHeight: entry.height, confirmations: 0, diff --git a/models/transaction.js b/models/transaction.js index 0688fba..f75c225 100644 --- a/models/transaction.js +++ b/models/transaction.js @@ -6,14 +6,12 @@ const InputSchema = new Schema({ 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({ diff --git a/test/data/bcoin-input.json b/test/data/bcoin-input.json new file mode 100644 index 0000000..9c04d88 --- /dev/null +++ b/test/data/bcoin-input.json @@ -0,0 +1,17 @@ +{ type: 'pubkeyhash', + subtype: undefined, + address: , + script: , + witness: , + redeem: undefined, + sequence: 4294967295, + prevout: , + coin: null } +{ prevout: + { hash: '9b56e70e5f2bf46358d0d5931a3ee9a7af6e1dd9bc6f3ef5730759e89cf8f603', + index: 0 }, + script: '48304502210093275988acbf1e540e5860af460517ba65f77c0855c28165ddc01a4933ac94d20220748590fe44ab5d97abc98510d6268d7a3ccbbc4a7a2c60dd7d9b6be530dc7e2e01410432cfefc384c53965332c503e0815a8134322721c60d62ec46a070a114d80a0bd33e7645bdf78eba6cd23824b233cd78159a22896d79f8ef371cf632b7556657c', + witness: '00', + sequence: 4294967295, + address: '1G6p7BydsiUyQd9vB1LR4N3uER9XcPiFaV', + coin: undefined }