Skip to content

Commit

Permalink
wallet: only use unspent coins when building batch transactions
Browse files Browse the repository at this point in the history
This will prevent the "Could not resolve preferred inputs" error
that is thrown when a user sends a single reveal followed by a
revealAll
  • Loading branch information
pinheadmz committed Sep 23, 2022
1 parent add8609 commit 58334e3
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/wallet/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,7 @@ class Wallet extends EventEmitter {
continue;

const {hash, index} = prevout;
const coin = await this.getCoin(hash, index);
const coin = await this.getUnspentCoin(hash, index);

if (!coin)
continue;
Expand Down Expand Up @@ -2300,7 +2300,7 @@ class Wallet extends EventEmitter {
if (prevout.equals(ns.owner))
continue;

const coin = await this.getCoin(hash, index);
const coin = await this.getUnspentCoin(hash, index);

if (!coin)
continue;
Expand Down Expand Up @@ -4296,6 +4296,22 @@ class Wallet extends EventEmitter {
return this.txdb.getCoin(hash, index);
}

/**
* Get an unspent coin from the wallet.
* @param {Hash} hash
* @param {Number} index
* @returns {Promise} - Returns {@link Coin}.
*/

async getUnspentCoin(hash, index) {
const credit = await this.txdb.getCredit(hash, index);

if (credit.spent)
return null;

return credit.coin;
}

/**
* Get a transaction from the wallet.
* @param {Hash} hash
Expand Down

0 comments on commit 58334e3

Please sign in to comment.