MeshJS / mesh

An open-source library to advance Web3 development on Cardano

Home Page:https://meshjs.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Coin Selection issue (have enough UTXO but not been selected)

eric248550 opened this issue · comments

I got the bug that the app wallet selects unmatch UTXO, either Keep Relevant, Largest First, and Largest First Multi-Asset have bug for this scenario.
There are 3 UTXOs in the wallet, but it only collects 2 UTXOs (which is not enough), below is how you can reproduce:

const addressUtxos = [
  {
    "input": {
      "outputIndex": 0,
      "txHash": "51bb82d8b7fee0bd918070bb3a1243a2ad6ad74a4caa768a25828574d610add9"
    },
    "output": {
      "address": "addr_test1vrf5jujz3ch9fxq7e443hqu6tuh9ftle56plj42zxnfvfhqrny0hc",
      "amount": [
        {
          "unit": "lovelace",
          "quantity": "1025780"
        },
        {
          "unit": "d4ff40a8c0386b2e3e6045e6fedfdd74302c352d430f4f54d3a8721b41574f4f",
          "quantity": "1000"
        }
      ]
    }
  },
  {
    "input": {
      "outputIndex": 0,
      "txHash": "78c9d64068e09b9bad7c139460922448901cb02b38e3dcee020bba4c17811d50"
    },
    "output": {
      "address": "addr_test1vrf5jujz3ch9fxq7e443hqu6tuh9ftle56plj42zxnfvfhqrny0hc",
      "amount": [
        {
          "unit": "lovelace",
          "quantity": "123000000"
        }
      ]
    }
  },
  {
    "input": {
      "outputIndex": 1,
      "txHash": "78c9d64068e09b9bad7c139460922448901cb02b38e3dcee020bba4c17811d50"
    },
    "output": {
      "address": "addr_test1vrf5jujz3ch9fxq7e443hqu6tuh9ftle56plj42zxnfvfhqrny0hc",
      "amount": [
        {
          "unit": "lovelace",
          "quantity": "1142150"
        },
        {
          "unit": "d4ff40a8c0386b2e3e6045e6fedfdd74302c352d430f4f54d3a8721b41574f4f",
          "quantity": "123"
        }
      ]
    }
  }
]

assetMap.set(
    'd4ff40a8c0386b2e3e6045e6fedfdd74302c352d430f4f54d3a8721b41574f4f',
    '1123',
);
assetMap.set(
    'lovelace',
    '120142150',
);

 const selectedUtxos = keepRelevant(assetMap, addressUtxos);
console.log(JSON.stringify(selectedUtxos, null, 2));

Even there's a enough ADA utxo (123000000 lovelace), that utxo won't be selected

I can confirm I experience this same issue.