walletdb: refactor.

This commit is contained in:
Christopher Jeffrey 2016-10-23 03:02:06 -07:00
parent 282fe7e4d9
commit f9ffff8e80
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 12 additions and 9 deletions

View File

@ -1233,6 +1233,15 @@ TXDB.prototype.confirm = co(function* confirm(hash, block) {
if (!tx)
return;
if (tx.height !== -1)
throw new Error('TX is already confirmed.');
assert(block);
tx.height = block.height;
tx.block = block.block;
tx.ts = block.ts;
this.start();
try {

View File

@ -1835,9 +1835,6 @@ Wallet.prototype._add = co(function* add(tx, block) {
var result = false;
var i, orphan;
if (resolved.length === 0)
return true;
for (i = 0; i < resolved.length; i++) {
orphan = resolved[i];
if (yield this._insert(orphan.tx, orphan.block))

View File

@ -1608,12 +1608,9 @@ WalletDB.prototype._addBlock = co(function* addBlock(entry, txs) {
block = WalletBlock.fromEntry(entry);
// Atomicity doesn't matter here. If we crash
// during this loop, the automatic rescan will get
// the database back into the correct state.
for (i = 0; i < txs.length; i++) {
tx = txs[i];
if (yield this._insertTX(tx, block))
if (yield this._addTX(tx, block))
total++;
}
@ -1704,7 +1701,7 @@ WalletDB.prototype._removeBlock = co(function* removeBlock(entry) {
WalletDB.prototype.addTX = co(function* addTX(tx) {
var unlock = yield this.txLock.lock();
try {
return yield this._insertTX(tx);
return yield this._addTX(tx);
} finally {
unlock();
}
@ -1717,7 +1714,7 @@ WalletDB.prototype.addTX = co(function* addTX(tx) {
* @returns {Promise}
*/
WalletDB.prototype._insertTX = co(function* insertTX(tx, block) {
WalletDB.prototype._addTX = co(function* addTX(tx, block) {
var result = false;
var i, wids, wid, wallet;