diff --git a/lib/blockchain/chainentry.js b/lib/blockchain/chainentry.js index 737e8c2c..832d5481 100644 --- a/lib/blockchain/chainentry.js +++ b/lib/blockchain/chainentry.js @@ -566,7 +566,9 @@ ChainEntry.prototype.toInv = function toInv() { */ ChainEntry.prototype.inspect = function inspect() { - return this.toJSON(); + var json = this.toJSON(); + json.version = util.hex32(json.version); + return json; }; /** diff --git a/lib/mining/minerblock.js b/lib/mining/minerblock.js index 3004f6ab..cfe2d7e4 100644 --- a/lib/mining/minerblock.js +++ b/lib/mining/minerblock.js @@ -461,7 +461,7 @@ MinerBlock.prototype.iterate = function iterate() { */ MinerBlock.prototype.commit = function commit(nonce) { - var i, tx; + var i, j, tx, input; assert(!this.committed, 'Block is already committed.'); @@ -472,6 +472,12 @@ MinerBlock.prototype.commit = function commit(nonce) { for (i = 0; i < this.block.txs.length; i++) { tx = this.block.txs[i]; + + for (j = 0; j < tx.inputs.length; j++) { + input = tx.inputs[j]; + input.coin = null; + } + tx.setBlock(this.block, i); } }; diff --git a/lib/primitives/block.js b/lib/primitives/block.js index f35e75cb..5d0c46d2 100644 --- a/lib/primitives/block.js +++ b/lib/primitives/block.js @@ -569,7 +569,7 @@ Block.prototype.inspect = function inspect() { size: this.getSize(), virtualSize: this.getVirtualSize(), date: util.date(this.ts), - version: this.version, + version: util.hex32(this.version), prevBlock: util.revHex(this.prevBlock), merkleRoot: util.revHex(this.merkleRoot), commitmentHash: this.commitmentHash diff --git a/lib/primitives/headers.js b/lib/primitives/headers.js index 5cfb35cc..7979f4bb 100644 --- a/lib/primitives/headers.js +++ b/lib/primitives/headers.js @@ -64,7 +64,7 @@ Headers.prototype.inspect = function inspect() { hash: this.rhash, height: this.height, date: util.date(this.ts), - version: this.version, + version: util.hex32(this.version), prevBlock: util.revHex(this.prevBlock), merkleRoot: util.revHex(this.merkleRoot), ts: this.ts, diff --git a/lib/primitives/merkleblock.js b/lib/primitives/merkleblock.js index f6aa4057..ca8431e7 100644 --- a/lib/primitives/merkleblock.js +++ b/lib/primitives/merkleblock.js @@ -321,7 +321,7 @@ MerkleBlock.prototype.inspect = function inspect() { hash: this.rhash, height: this.height, date: util.date(this.ts), - version: this.version, + version: util.hex32(this.version), prevBlock: util.revHex(this.prevBlock), merkleRoot: util.revHex(this.merkleRoot), ts: this.ts, diff --git a/test/chain-test.js b/test/chain-test.js index dc59f74e..d797a35a 100644 --- a/test/chain-test.js +++ b/test/chain-test.js @@ -13,7 +13,7 @@ var cob = co.cob; describe('Chain', function() { var chain, wallet, node, miner, walletdb; - var tip1, tip2, cb1, cb2; + var tip1, tip2, cb1, cb2, mineBlock; this.timeout(5000); @@ -25,7 +25,7 @@ describe('Chain', function() { miner = node.miner; node.on('error', function() {}); - var mineBlock = co(function* mineBlock(tip, tx) { + mineBlock = co(function* mineBlock(tip, tx) { var attempt = yield miner.createBlock(tip); var redeemer; @@ -55,24 +55,6 @@ describe('Chain', function() { return yield attempt.mineAsync(); }); - function deleteCoins(tx) { - var i; - - if (tx.txs) { - deleteCoins(tx.txs); - return; - } - - if (Array.isArray(tx)) { - for (i = 0; i < tx.length; i++) - deleteCoins(tx[i]); - return; - } - - for (i = 0; i < tx.inputs.length; i++) - tx.inputs[i].coin = null; - } - it('should open chain and miner', cob(function* () { miner.mempool = null; constants.tx.COINBASE_MATURITY = 0; @@ -101,10 +83,8 @@ describe('Chain', function() { block2 = yield mineBlock(tip2, cb2); cb2 = block2.txs[0]; - deleteCoins(block1); yield chain.add(block1); - deleteCoins(block2); yield chain.add(block2); assert(chain.tip.hash === block1.hash('hex')); @@ -147,8 +127,6 @@ describe('Chain', function() { forked = true; }); - deleteCoins(block); - yield chain.add(block); assert(forked); @@ -175,7 +153,6 @@ describe('Chain', function() { var block = yield mineBlock(null, cb2); var entry, result; - deleteCoins(block); yield chain.add(block); entry = yield chain.db.getEntry(block.hash('hex')); @@ -191,8 +168,6 @@ describe('Chain', function() { var tip = chain.tip; var err; - deleteCoins(block); - try { yield chain.add(block); } catch (e) { @@ -209,8 +184,6 @@ describe('Chain', function() { var tip = chain.tip; var err; - deleteCoins(block); - try { yield chain.add(block); } catch (e) {