miner: clear coins.
This commit is contained in:
parent
85adb1acec
commit
20cdb1adbc
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user