walletdb: more refactoring.
This commit is contained in:
parent
45464c412f
commit
ffc17b48c2
@ -1119,19 +1119,20 @@ ChainDB.prototype.scan = co(function* scan(start, filter, iter) {
|
|||||||
|
|
||||||
while (entry) {
|
while (entry) {
|
||||||
block = yield this.getBlock(entry.hash);
|
block = yield this.getBlock(entry.hash);
|
||||||
|
txs = [];
|
||||||
total++;
|
total++;
|
||||||
|
|
||||||
if (!block) {
|
if (!block) {
|
||||||
if (!this.options.spv && !this.options.prune)
|
if (!this.options.spv && !this.options.prune)
|
||||||
throw new Error('Block not found.');
|
throw new Error('Block not found.');
|
||||||
|
yield iter(entry, txs);
|
||||||
|
entry = yield entry.getNext();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.info(
|
this.logger.info(
|
||||||
'Scanning block %s (%d).',
|
'Scanning block %s (%d).',
|
||||||
entry.rhash, block.height);
|
entry.rhash, entry.height);
|
||||||
|
|
||||||
txs = [];
|
|
||||||
|
|
||||||
for (i = 0; i < block.txs.length; i++) {
|
for (i = 0; i < block.txs.length; i++) {
|
||||||
tx = block.txs[i];
|
tx = block.txs[i];
|
||||||
|
|||||||
@ -136,7 +136,8 @@ main.genesis = {
|
|||||||
merkleRoot: '3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
merkleRoot: '3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
||||||
ts: 1231006505,
|
ts: 1231006505,
|
||||||
bits: 486604799,
|
bits: 486604799,
|
||||||
nonce: 2083236893
|
nonce: 2083236893,
|
||||||
|
height: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -501,7 +502,8 @@ testnet.genesis = {
|
|||||||
merkleRoot: '3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
merkleRoot: '3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
||||||
ts: 1296688602,
|
ts: 1296688602,
|
||||||
bits: 486604799,
|
bits: 486604799,
|
||||||
nonce: 414098458
|
nonce: 414098458,
|
||||||
|
height: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
testnet.genesisBlock =
|
testnet.genesisBlock =
|
||||||
@ -646,7 +648,8 @@ regtest.genesis = {
|
|||||||
merkleRoot: '3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
merkleRoot: '3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
||||||
ts: 1296688602,
|
ts: 1296688602,
|
||||||
bits: 545259519,
|
bits: 545259519,
|
||||||
nonce: 2
|
nonce: 2,
|
||||||
|
height: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
regtest.genesisBlock =
|
regtest.genesisBlock =
|
||||||
@ -788,7 +791,8 @@ segnet3.genesis = {
|
|||||||
merkleRoot: '3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
merkleRoot: '3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
||||||
ts: 1452831101,
|
ts: 1452831101,
|
||||||
bits: 486604799,
|
bits: 486604799,
|
||||||
nonce: 0
|
nonce: 0,
|
||||||
|
height: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
segnet3.genesisBlock =
|
segnet3.genesisBlock =
|
||||||
@ -907,7 +911,8 @@ segnet4.genesis = {
|
|||||||
merkleRoot: '3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
merkleRoot: '3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
||||||
ts: 1452831101,
|
ts: 1452831101,
|
||||||
bits: 503447551,
|
bits: 503447551,
|
||||||
nonce: 0
|
nonce: 0,
|
||||||
|
height: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
segnet4.genesisBlock =
|
segnet4.genesisBlock =
|
||||||
@ -1047,7 +1052,8 @@ simnet.genesis = {
|
|||||||
merkleRoot: '3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
merkleRoot: '3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
||||||
ts: 1401292357,
|
ts: 1401292357,
|
||||||
bits: 545259519,
|
bits: 545259519,
|
||||||
nonce: 2
|
nonce: 2,
|
||||||
|
height: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
simnet.genesisBlock =
|
simnet.genesisBlock =
|
||||||
|
|||||||
@ -1213,6 +1213,7 @@ WalletDB.prototype._rescan = co(function* rescan(chaindb, height) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (height == null) {
|
if (height == null) {
|
||||||
|
assert(this.network.block.keepBlocks > 36);
|
||||||
height = this.height - 36;
|
height = this.height - 36;
|
||||||
if (height < 0)
|
if (height < 0)
|
||||||
height = 0;
|
height = 0;
|
||||||
@ -1462,10 +1463,6 @@ WalletDB.prototype.writeGenesis = co(function* writeGenesis() {
|
|||||||
|
|
||||||
WalletDB.prototype.forceTip = co(function* forceTip(entry) {
|
WalletDB.prototype.forceTip = co(function* forceTip(entry) {
|
||||||
var tip = HeaderRecord.fromEntry(entry);
|
var tip = HeaderRecord.fromEntry(entry);
|
||||||
|
|
||||||
if (entry === this.network.genesis)
|
|
||||||
tip.height = 0;
|
|
||||||
|
|
||||||
yield this.setTip(tip);
|
yield this.setTip(tip);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1476,8 +1473,10 @@ WalletDB.prototype.forceTip = co(function* forceTip(entry) {
|
|||||||
|
|
||||||
WalletDB.prototype.getTip = co(function* getTip() {
|
WalletDB.prototype.getTip = co(function* getTip() {
|
||||||
var height = yield this.getHeight();
|
var height = yield this.getHeight();
|
||||||
|
|
||||||
if (height === -1)
|
if (height === -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
return yield this.getHeader(height);
|
return yield this.getHeader(height);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1655,7 +1654,7 @@ WalletDB.prototype._addBlock = co(function* addBlock(entry, txs) {
|
|||||||
var i, tip, tx;
|
var i, tip, tx;
|
||||||
|
|
||||||
if (entry.height <= this.height) {
|
if (entry.height <= this.height) {
|
||||||
this.logger.warning('Connecting low blocks.');
|
this.logger.warning('Wallet is connecting low blocks.');
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1673,7 +1672,7 @@ WalletDB.prototype._addBlock = co(function* addBlock(entry, txs) {
|
|||||||
|
|
||||||
for (i = 0; i < txs.length; i++) {
|
for (i = 0; i < txs.length; i++) {
|
||||||
tx = txs[i];
|
tx = txs[i];
|
||||||
if (yield this._addTX(tx, tip))
|
if (yield this._insert(tx, tip))
|
||||||
total++;
|
total++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1712,7 +1711,7 @@ WalletDB.prototype._removeBlock = co(function* removeBlock(entry) {
|
|||||||
var i, tx, tip, prev, block;
|
var i, tx, tip, prev, block;
|
||||||
|
|
||||||
if (entry.height > this.height) {
|
if (entry.height > this.height) {
|
||||||
this.logger.warning('Disconnecting high blocks.');
|
this.logger.warning('Wallet is disconnecting high blocks.');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1738,7 +1737,7 @@ WalletDB.prototype._removeBlock = co(function* removeBlock(entry) {
|
|||||||
|
|
||||||
for (i = block.txs.length - 1; i >= 0; i--) {
|
for (i = block.txs.length - 1; i >= 0; i--) {
|
||||||
tx = block.txs[i];
|
tx = block.txs[i];
|
||||||
yield this._unconfirmTX(tx, tip);
|
yield this._unconfirm(tx, tip);
|
||||||
}
|
}
|
||||||
|
|
||||||
yield this.setTip(prev);
|
yield this.setTip(prev);
|
||||||
@ -1774,7 +1773,7 @@ WalletDB.prototype.addTX = co(function* addTX(tx) {
|
|||||||
this.logger.warning('Retroactively inserting confirmed transaction.');
|
this.logger.warning('Retroactively inserting confirmed transaction.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return yield this._addTX(tx);
|
return yield this._insert(tx);
|
||||||
} finally {
|
} finally {
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
@ -1788,7 +1787,7 @@ WalletDB.prototype.addTX = co(function* addTX(tx) {
|
|||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
WalletDB.prototype._addTX = co(function* addTX(tx, block) {
|
WalletDB.prototype._insert = co(function* insert(tx, block) {
|
||||||
var result = false;
|
var result = false;
|
||||||
var i, wids, wid, wallet;
|
var i, wids, wid, wallet;
|
||||||
|
|
||||||
@ -1832,7 +1831,7 @@ WalletDB.prototype._addTX = co(function* addTX(tx, block) {
|
|||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
WalletDB.prototype._unconfirmTX = co(function* unconfirmTX(tx, block) {
|
WalletDB.prototype._unconfirm = co(function* unconfirm(tx, block) {
|
||||||
var i, wid, wallet;
|
var i, wid, wallet;
|
||||||
|
|
||||||
for (i = 0; i < tx.wids.length; i++) {
|
for (i = 0; i < tx.wids.length; i++) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user