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() {
|
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) {
|
MinerBlock.prototype.commit = function commit(nonce) {
|
||||||
var i, tx;
|
var i, j, tx, input;
|
||||||
|
|
||||||
assert(!this.committed, 'Block is already committed.');
|
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++) {
|
for (i = 0; i < this.block.txs.length; i++) {
|
||||||
tx = this.block.txs[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);
|
tx.setBlock(this.block, i);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -569,7 +569,7 @@ Block.prototype.inspect = function inspect() {
|
|||||||
size: this.getSize(),
|
size: this.getSize(),
|
||||||
virtualSize: this.getVirtualSize(),
|
virtualSize: this.getVirtualSize(),
|
||||||
date: util.date(this.ts),
|
date: util.date(this.ts),
|
||||||
version: this.version,
|
version: util.hex32(this.version),
|
||||||
prevBlock: util.revHex(this.prevBlock),
|
prevBlock: util.revHex(this.prevBlock),
|
||||||
merkleRoot: util.revHex(this.merkleRoot),
|
merkleRoot: util.revHex(this.merkleRoot),
|
||||||
commitmentHash: this.commitmentHash
|
commitmentHash: this.commitmentHash
|
||||||
|
|||||||
@ -64,7 +64,7 @@ Headers.prototype.inspect = function inspect() {
|
|||||||
hash: this.rhash,
|
hash: this.rhash,
|
||||||
height: this.height,
|
height: this.height,
|
||||||
date: util.date(this.ts),
|
date: util.date(this.ts),
|
||||||
version: this.version,
|
version: util.hex32(this.version),
|
||||||
prevBlock: util.revHex(this.prevBlock),
|
prevBlock: util.revHex(this.prevBlock),
|
||||||
merkleRoot: util.revHex(this.merkleRoot),
|
merkleRoot: util.revHex(this.merkleRoot),
|
||||||
ts: this.ts,
|
ts: this.ts,
|
||||||
|
|||||||
@ -321,7 +321,7 @@ MerkleBlock.prototype.inspect = function inspect() {
|
|||||||
hash: this.rhash,
|
hash: this.rhash,
|
||||||
height: this.height,
|
height: this.height,
|
||||||
date: util.date(this.ts),
|
date: util.date(this.ts),
|
||||||
version: this.version,
|
version: util.hex32(this.version),
|
||||||
prevBlock: util.revHex(this.prevBlock),
|
prevBlock: util.revHex(this.prevBlock),
|
||||||
merkleRoot: util.revHex(this.merkleRoot),
|
merkleRoot: util.revHex(this.merkleRoot),
|
||||||
ts: this.ts,
|
ts: this.ts,
|
||||||
|
|||||||
@ -13,7 +13,7 @@ var cob = co.cob;
|
|||||||
|
|
||||||
describe('Chain', function() {
|
describe('Chain', function() {
|
||||||
var chain, wallet, node, miner, walletdb;
|
var chain, wallet, node, miner, walletdb;
|
||||||
var tip1, tip2, cb1, cb2;
|
var tip1, tip2, cb1, cb2, mineBlock;
|
||||||
|
|
||||||
this.timeout(5000);
|
this.timeout(5000);
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ describe('Chain', function() {
|
|||||||
miner = node.miner;
|
miner = node.miner;
|
||||||
node.on('error', function() {});
|
node.on('error', function() {});
|
||||||
|
|
||||||
var mineBlock = co(function* mineBlock(tip, tx) {
|
mineBlock = co(function* mineBlock(tip, tx) {
|
||||||
var attempt = yield miner.createBlock(tip);
|
var attempt = yield miner.createBlock(tip);
|
||||||
var redeemer;
|
var redeemer;
|
||||||
|
|
||||||
@ -55,24 +55,6 @@ describe('Chain', function() {
|
|||||||
return yield attempt.mineAsync();
|
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* () {
|
it('should open chain and miner', cob(function* () {
|
||||||
miner.mempool = null;
|
miner.mempool = null;
|
||||||
constants.tx.COINBASE_MATURITY = 0;
|
constants.tx.COINBASE_MATURITY = 0;
|
||||||
@ -101,10 +83,8 @@ describe('Chain', function() {
|
|||||||
block2 = yield mineBlock(tip2, cb2);
|
block2 = yield mineBlock(tip2, cb2);
|
||||||
cb2 = block2.txs[0];
|
cb2 = block2.txs[0];
|
||||||
|
|
||||||
deleteCoins(block1);
|
|
||||||
yield chain.add(block1);
|
yield chain.add(block1);
|
||||||
|
|
||||||
deleteCoins(block2);
|
|
||||||
yield chain.add(block2);
|
yield chain.add(block2);
|
||||||
|
|
||||||
assert(chain.tip.hash === block1.hash('hex'));
|
assert(chain.tip.hash === block1.hash('hex'));
|
||||||
@ -147,8 +127,6 @@ describe('Chain', function() {
|
|||||||
forked = true;
|
forked = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
deleteCoins(block);
|
|
||||||
|
|
||||||
yield chain.add(block);
|
yield chain.add(block);
|
||||||
|
|
||||||
assert(forked);
|
assert(forked);
|
||||||
@ -175,7 +153,6 @@ describe('Chain', function() {
|
|||||||
var block = yield mineBlock(null, cb2);
|
var block = yield mineBlock(null, cb2);
|
||||||
var entry, result;
|
var entry, result;
|
||||||
|
|
||||||
deleteCoins(block);
|
|
||||||
yield chain.add(block);
|
yield chain.add(block);
|
||||||
|
|
||||||
entry = yield chain.db.getEntry(block.hash('hex'));
|
entry = yield chain.db.getEntry(block.hash('hex'));
|
||||||
@ -191,8 +168,6 @@ describe('Chain', function() {
|
|||||||
var tip = chain.tip;
|
var tip = chain.tip;
|
||||||
var err;
|
var err;
|
||||||
|
|
||||||
deleteCoins(block);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
yield chain.add(block);
|
yield chain.add(block);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -209,8 +184,6 @@ describe('Chain', function() {
|
|||||||
var tip = chain.tip;
|
var tip = chain.tip;
|
||||||
var err;
|
var err;
|
||||||
|
|
||||||
deleteCoins(block);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
yield chain.add(block);
|
yield chain.add(block);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user