wallet-coinselector: skip non-existent coins.

This commit is contained in:
Nodari Chkuaselidze 2025-05-21 13:15:57 +04:00
parent 1121e8eefe
commit dded017126
No known key found for this signature in database
GPG key ID: B018A7BB437D1F05
2 changed files with 10 additions and 6 deletions

View file

@ -120,8 +120,8 @@ exports.wdb = {
*
* Coin Selection
* --------------
* Sc[value][tx-hash][index] -> dummy (Confirmed coins by value)
* SC[account][value][tx-hash][index] -> dummy
* Sv[value][tx-hash][index] -> dummy (Confirmed coins by value)
* Sv[account][value][tx-hash][index] -> dummy
* (Confirmed coins by account + value)
*
* Su[value][tx-hash][index] -> dummy (Unconfirmed coins by value)

View file

@ -13,7 +13,8 @@ const base58 = require('bcrypto/lib/encoding/base58');
const bio = require('bufio');
const blake2b = require('bcrypto/lib/blake2b');
const cleanse = require('bcrypto/lib/cleanse');
const {BufferSet} = require('buffer-map');
const bufmap = require('buffer-map');
const BufferSet = bufmap.BufferSet;
const TXDB = require('./txdb');
const Path = require('./path');
const common = require('./common');
@ -48,7 +49,6 @@ const {
/** @typedef {import('bdb').DB} DB */
/** @typedef {ReturnType<DB['batch']>} Batch */
/** @typedef {import('buffer-map').BufferMap} BufferMap */
/** @typedef {import('../types').Base58String} Base58String */
/** @typedef {import('../types').Hash} Hash */
/** @typedef {import('../types').Amount} Amount */
@ -1278,7 +1278,7 @@ class Wallet extends EventEmitter {
*/
async select(mtx, options) {
const selection = options.selection || 'dbvalue';
const selection = options.selection || 'value';
switch (selection) {
case 'all':
@ -5754,7 +5754,7 @@ class WalletCoinSource extends AbstractCoinSource {
/**
* Resolve coins.
* @param {BufferMap<Number>} inputs
* @param {bufmap.BufferMap<Number>} inputs
* @param {Coin[]} coins - Coin per input.
* @returns {Promise<void>}
*/
@ -5778,6 +5778,10 @@ class WalletCoinSource extends AbstractCoinSource {
}
const coin = await this.txdb.getCoin(outpoint.hash, outpoint.index);
if (!coin)
continue;
coins[idx] = coin;
inputs.delete(key);
}