From f9ffff8e80b2bee92beade7f6e5f9ff5bc11045f Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 23 Oct 2016 03:02:06 -0700 Subject: [PATCH] walletdb: refactor. --- lib/wallet/txdb.js | 9 +++++++++ lib/wallet/wallet.js | 3 --- lib/wallet/walletdb.js | 9 +++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/wallet/txdb.js b/lib/wallet/txdb.js index 261fc3c1..6e8bf329 100644 --- a/lib/wallet/txdb.js +++ b/lib/wallet/txdb.js @@ -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 { diff --git a/lib/wallet/wallet.js b/lib/wallet/wallet.js index 270cdb41..50d5d9c3 100644 --- a/lib/wallet/wallet.js +++ b/lib/wallet/wallet.js @@ -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)) diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index c177ad33..bf31a2ef 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -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;