From 7d5cade288c0731208b4e353b12da0459487f176 Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Thu, 3 Aug 2017 16:19:53 -0400 Subject: [PATCH] Transactions syncing, inputs and outputs mocked up. Bcoin data for tx, inputs and outputs varies depending on the vanilla object vs the object.toJSON() method Bcoin attaches to its primitives. Will likely need to redress this as Bcoin changes but for now this is how we move forward. --- README.md | 20 +++++++++++- lib/node/index.js | 42 ++++++++++++++----------- models/transaction.js | 20 ++++++------ test/data/bcoin-tx.json | 64 +++++++++++++++++++++++++-------------- test/data/insight-tx.json | 62 +++++++++++++++++++++++++++++++++++++ 5 files changed, 157 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 865e25f..c003933 100644 --- a/README.md +++ b/README.md @@ -14,4 +14,22 @@ Logging is current defaulting to debug during dev. Bitcore logging is preceded b # 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. \ No newline at end of file +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. + +# Priorities +1. Required Insight-UI + +/addr/:addrStr/?noTxList=1 +/block/:blockhash +/blocks +/block-index/:blockHeight +/currency +/version +/status +/sync +/peer +/tx/:txId +/txs +/txs + +sockets diff --git a/lib/node/index.js b/lib/node/index.js index a352f5d..e095148 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -57,34 +57,40 @@ function processBlock(entry, block, cb) { function processTx(entry, txs) { txs.forEach((tx) => { - const hash = util.revHex(tx.hash().toString('hex')); + 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()); + //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()); + //console.log('output'); + //console.log(output); + //console.log(output.toJSON()); }); const t = new TxModel({ - txid: hash, - chain: config.bcoin.network, + txid: txHash, + version: 1, + lockTime: tx.lockTime, + vin: [], + vout: [], + blockHash: blockHash, blockHeight: entry.height, - blockHash: '123', - blockTime: 0, - blockTimeNormalized: 0, - inputs: [], - outputs: [], - coinbase: false, - fee: 0, - inputsProcessed: false, + confirmations: 0, + time: entry.ts, + blockTime: entry.ts, + blockTimeNormalized: entry.ts, + valueOut: tx.value, + size: tx.size, + valueIn: tx.value, + fees: tx.fee, + chain: config.bcoin.network, }); - console.log(hash); + console.log(txHash); t.save((err) => { if (err) { console.log(err.message); diff --git a/models/transaction.js b/models/transaction.js index f5783d2..0688fba 100644 --- a/models/transaction.js +++ b/models/transaction.js @@ -19,18 +19,20 @@ const OutputSchema = new Schema({ const TransactionSchema = new Schema({ txid: String, version: Number, - chain: String, - blockHeight: Number, + lockTime: Number, + vin: [InputSchema], + vout: [OutputSchema], blockHash: String, + blockHeight: Number, + confirmations: Number, + time: Date, blockTime: Date, blockTimeNormalized: Date, - inputs: [InputSchema], - outputs: [OutputSchema], - coinbase: Boolean, - fee: Number, - inputsProcessed: Boolean, - lockTime: Number, - wallets: { type: [Schema.Types.ObjectId] }, + valueOut: Number, + size: Number, + valueIn: Number, + fees: Number, + chain: String, }); TransactionSchema.index({ txid: 1 }, { unique: true }); diff --git a/test/data/bcoin-tx.json b/test/data/bcoin-tx.json index 4d0aead..eb4301e 100644 --- a/test/data/bcoin-tx.json +++ b/test/data/bcoin-tx.json @@ -1,11 +1,11 @@ -{ hash: 'ed1be20876b90b857a4ddb32e72f334df997cf45f5a33b3578f0dda65abacd57', - witnessHash: 'ed1be20876b90b857a4ddb32e72f334df997cf45f5a33b3578f0dda65abacd57', - size: 404, - virtualSize: 404, - value: '7.49', +{ hash: '0fa53ce8b5aa3eb9e46a9dde25c26df02f4b0cf11eb0920be2780a8c7b9a6e33', + witnessHash: '0fa53ce8b5aa3eb9e46a9dde25c26df02f4b0cf11eb0920be2780a8c7b9a6e33', + size: 135, + virtualSize: 135, + value: '50.0', fee: '0.0', rate: '0.0', - minFee: '0.00000404', + minFee: '0.00000135', height: -1, block: null, ts: 0, @@ -14,27 +14,45 @@ version: 1, flag: 1, inputs: - [ { type: 'pubkeyhash', + [ { type: 'coinbase', subtype: undefined, - address: , - script: , + address: undefined, + script: , witness: , redeem: undefined, sequence: 4294967295, - prevout: , - coin: null }, - { type: 'pubkeyhash', - subtype: undefined, - address: , - script: , - witness: , - redeem: undefined, - sequence: 4294967295, - prevout: , + prevout: , coin: null } ], outputs: - [ { type: 'pubkeyhash', - value: '7.49', - script: , - address: } ], + [ { type: 'pubkey', + value: '50.0', + script: , + address: } ], + locktime: 0 } + +toJSON(): + +{ hash: '0fa53ce8b5aa3eb9e46a9dde25c26df02f4b0cf11eb0920be2780a8c7b9a6e33', + witnessHash: '0fa53ce8b5aa3eb9e46a9dde25c26df02f4b0cf11eb0920be2780a8c7b9a6e33', + fee: undefined, + rate: undefined, + ps: 1501788263, + height: undefined, + block: undefined, + ts: undefined, + date: undefined, + index: undefined, + version: 1, + flag: 1, + inputs: + [ { prevout: [Object], + script: '04ffff001d02de00', + witness: '00', + sequence: 4294967295, + address: undefined, + coin: undefined } ], + outputs: + [ { value: 5000000000, + script: '41042200490195c16c77e0d5b28079e218ddf23c0cf23e770b5e1ad0589d03a803cc188a1c79601dd181a67dc121a2bf2c5b2313c89f2b2be758caca6c7ab56959acac', + address: '15WLVXrj2owbChece54ibqqukk2PcA4TLt' } ], locktime: 0 } diff --git a/test/data/insight-tx.json b/test/data/insight-tx.json index e69de29..3b6566d 100644 --- a/test/data/insight-tx.json +++ b/test/data/insight-tx.json @@ -0,0 +1,62 @@ +{ + "txid": "b2da7a4efeee11d74be9e1cae735861b29db3268356fdc103d456c63ee680ce7", + "version": 1, + "locktime": 0, + "vin": [ + { + "txid": "4f54901d6bdb6b319cc71e0c9fd2bbd2438dbb3012e2e3ed58b806ccbdaaf17f", + "vout": 0, + "sequence": 4294967295, + "n": 0, + "scriptSig": { + "hex": "4730440220524768cb6ace93625e3247ba05908e4ecd175a82397ac9831ca772e9a1a82e880220638df1b591bee299e539018d0e72bc3fd26ebee0e31a68de48454ca414aef2e10141047f1dbd4f3ef4f5435511d337120821cf9d3a3a72f8e8065dc86cf92941f1c480f59e670ebc83f09935cbd103e9c2ab8e0c061b24a8f1cd30f31a2d4e067ece2d", + "asm": "30440220524768cb6ace93625e3247ba05908e4ecd175a82397ac9831ca772e9a1a82e880220638df1b591bee299e539018d0e72bc3fd26ebee0e31a68de48454ca414aef2e1[ALL] 047f1dbd4f3ef4f5435511d337120821cf9d3a3a72f8e8065dc86cf92941f1c480f59e670ebc83f09935cbd103e9c2ab8e0c061b24a8f1cd30f31a2d4e067ece2d" + }, + "addr": "15VSWTF7qRzBhQzo45ATu6jMc3CuBCd4XN", + "valueSat": 14263520000, + "value": 142.6352, + "doubleSpentTxID": null + } + ], + "vout": [ + { + "value": "142.02520000", + "n": 0, + "scriptPubKey": { + "hex": "76a914ad62df6af0462dc5ca2007013c3c4dca1fcfb72388ac", + "asm": "OP_DUP OP_HASH160 ad62df6af0462dc5ca2007013c3c4dca1fcfb723 OP_EQUALVERIFY OP_CHECKSIG", + "addresses": [ + "1GonLz5Q87PS6PRYMc1SF8Kmgsz8XQbPSM" + ], + "type": "pubkeyhash" + }, + "spentTxId": "25079d76d0bb1a38489a738967e9e48d52c58a698810d4d9e8c1a0b2b2b0b3d5", + "spentIndex": 0, + "spentHeight": 132000 + }, + { + "value": "0.61000000", + "n": 1, + "scriptPubKey": { + "hex": "76a914096c81f7272f89900e1621e46d4f38202885b31e88ac", + "asm": "OP_DUP OP_HASH160 096c81f7272f89900e1621e46d4f38202885b31e OP_EQUALVERIFY OP_CHECKSIG", + "addresses": [ + "1rq4yP5EgxmduuhwcoR4x36Qw6NS4NM78" + ], + "type": "pubkeyhash" + }, + "spentTxId": "d75f552d9e00d3325cc8db2534734c8bc83f617d46deded4772eeec9d2210055", + "spentIndex": 11, + "spentHeight": 134969 + } + ], + "blockhash": "000000000000060c631d74547fe0ab596b54440403ce86bba8bf3a405fdf4984", + "blockheight": 131997, + "confirmations": 346893, + "time": 1308551232, + "blocktime": 1308551232, + "valueOut": 142.6352, + "size": 257, + "valueIn": 142.6352, + "fees": 0 +} \ No newline at end of file