Skip to content

Commit

Permalink
txdb: ignore locked value if bid not found
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Nov 29, 2022
1 parent 1af5245 commit 72659da
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/wallet/txdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,8 @@ class TXDB {
const prevout = tx.inputs[i].prevout;

const bb = await this.getBid(nameHash, prevout);
assert(bb);
if (!bb)
break;

if (height === -1) {
state.ulocked(path, -bb.lockup);
Expand Down Expand Up @@ -1812,7 +1813,8 @@ class TXDB {
const prevout = tx.inputs[i].prevout;

const bb = await this.getBid(nameHash, prevout);
assert(bb);
if (!bb)
break;

if (height === -1) {
state.ulocked(path, bb.lockup);
Expand Down
27 changes: 26 additions & 1 deletion test/wallet-rescan-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,9 @@ describe('Wallet rescan with namestate transitions', function() {
});

const {wdb} = node.require('walletdb');
let wallet1, wallet2;
let wallet1, wallet2, wallet3;
let addr1;
let heightBeforeReveal;

const name = rules.grindName(4, 4, network);

Expand Down Expand Up @@ -657,6 +658,8 @@ describe('Wallet rescan with namestate transitions', function() {
it('should reveal from each wallet', async () => {
await node.rpc.generateToAddress([biddingPeriod, addr1]);

heightBeforeReveal = node.chain.height;

// Wallet 1 only knows blind for one of the bids
const tx1 = await wallet1.sendReveal(name);
assert.strictEqual(tx1.outputs.length, 2);
Expand Down Expand Up @@ -699,5 +702,27 @@ describe('Wallet rescan with namestate transitions', function() {
assert(reveal.value);
}
});

it('should restore wallet 1 from seed into wallet 3', async () => {
const {mnemonic} = wallet1.master;
wallet3 = await wdb.create({mnemonic});
});

it('should just rescan reveal phase', async () => {
await wdb.rescan(heightBeforeReveal);

let bal1 = await wallet1.getBalance();
let bal3 = await wallet3.getBalance();

assert.notDeepStrictEqual(bal1, bal3);

// Complete rescan cleans everything up
await wdb.rescan(0);

bal1 = await wallet1.getBalance();
bal3 = await wallet3.getBalance();

assert.deepStrictEqual(bal1, bal3);
});
});
});

0 comments on commit 72659da

Please sign in to comment.