diff --git a/lib/BlockDb.js b/lib/BlockDb.js index 8d43cda2..c38d2598 100644 --- a/lib/BlockDb.js +++ b/lib/BlockDb.js @@ -139,6 +139,8 @@ function spec(b) { BlockDb.prototype.fromHashWithInfo = function(hash, cb) { + var self = this; + rpc.getBlock(hash, function(err, info) { // Not found? if (err && err.code === -5) return cb(); @@ -146,9 +148,16 @@ function spec(b) { if (info.result.height) info.result.reward = BitcoreBlock.getBlockValue(info.result.height) / util.COIN ; - return cb(null, { - hash: hash, - info: info.result, + + self.isMain(hash, function(err, val) { + if (err) return cb(err); + + info.result.isMainChain = val ? true : false; + + return cb(null, { + hash: hash, + info: info.result, + }); }); }); }; diff --git a/lib/TransactionDb.js b/lib/TransactionDb.js index 3b4ee25c..e5ac6ee6 100644 --- a/lib/TransactionDb.js +++ b/lib/TransactionDb.js @@ -16,7 +16,7 @@ function spec(b) { // to sum up addr balance var ADDR_PREFIX = 'txouts-addr-'; //txouts-addr---- => + btc_sat - var SPEND_PREFIX = 'txouts-spend-';//txouts-spend-- => [txid(in),n(in),ts] + var SPEND_PREFIX = 'txouts-spend-';//txouts-spend---- = ts // TODO: use bitcore networks module var genesisTXID = '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'; @@ -70,10 +70,33 @@ function spec(b) { }); }; - TransactionDb.prototype.fromTxId = function(txid, cb) { + TransactionDb.prototype._addSpendInfo = function(r, txid, index) { + if (r.spendTxId) { + if (!r.multipleSpendAttempts) { + r.multipleSpendAttempts = [{ + txid: r.spendTxId, + index: r.index, + }]; + } + r.multipleSpendAttempts.push({ + txid: txid, + index: parseInt(index), + }); + } + else { + r.spendTxId = txid; + r.spendIndex = parseInt(index); + } + }; + + // This is not used now + TransactionDb.prototype.fromTxId = function(txid, cb) { + var self = this; var k = OUTS_PREFIX + txid; var ret=[]; + var idx={}; + var i = 0; // outs. db.createReadStream({start: k, end: k + '~'}) @@ -85,27 +108,23 @@ function spec(b) { value_sat: parseInt(v[1]), index: parseInt(k[2]), }); + idx[parseInt(k[2])]= i++; }) .on('error', function (err) { return cb(err); }) .on('end', function () { + var k = SPEND_PREFIX + txid; - var l = ret.length; db.createReadStream({start: k, end: k + '~'}) .on('data', function (data) { var k = data.key.split('-'); - var v = data.value.split(':'); - var set=0; - for(var i=0; i Height - {{block.height}} + {{block.height}} + (Mainchain) + (Orphaned) Block Reward diff --git a/test/integration/99-sync.js b/test/integration/99-sync.js.descructive-test similarity index 100% rename from test/integration/99-sync.js rename to test/integration/99-sync.js.descructive-test diff --git a/test/integration/addr.json b/test/integration/addr.json index 2fcc42fa..eb315663 100644 --- a/test/integration/addr.json +++ b/test/integration/addr.json @@ -43,9 +43,9 @@ }, { "addr": "mzW2hdZN2um7WBvTDerdahKqRgj3md9C29", - "txApperances": 6046, - "balance": 1149.19744101, - "totalReceived": 1149.19744101, + "txApperances": 6047, + "balance": 1199.74393851, + "totalReceived": 1199.74393851, "totalSent": 0 }, {