bitpay / bitcore

A full stack for bitcoin and blockchain-based applications
https://bitcore.io/
MIT License
4.81k stars 2.08k forks source link

Q: Should we filter out `conflicting` coins when fetching unspent outputs ? #3576

Closed peng-huang-ch closed 1 year ago

peng-huang-ch commented 1 year ago

Use the Get Transaction Outputs by Address

https://****/api/DOGE/mainnet/address/DS2cpSDvZXHzhZEyBEbTNuQTgonoHkFM4n/?unspent=true

the result contains conflicting coins.

[
    {
        "_id": "6435026ee26b85d3ccb3bfa0",
        "chain": "DOGE",
        "network": "mainnet",
        "coinbase": false,
        "mintIndex": 1,
        "spentTxid": "",
        "mintTxid": "7d256872edff56b65d1c444f467b3bbb5bf766e7b3ef25452f24aa12af306ca0",
        "mintHeight": 4671846,
        "spentHeight": -2,
        "address": "DS2cpSDvZXHzhZEyBEbTNuQTgonoHkFM4n",
        "script": "76a914e521015b004d2d5023d5cd6bcd14ff297697d5f388ac",
        "value": 7738340,
        "confirmations": -1
    },
        ...
    {
        "_id": "63f091852e2b2be930f32466",
        "chain": "DOGE",
        "network": "mainnet",
        "coinbase": false,
        "mintIndex": 0,
        "spentTxid": "",
        "mintTxid": "006140516e2133d4fee801d99f08b5097f64246313fa8619ee9440a62b5b6d5d",
        "mintHeight": -3,
        "spentHeight": -2,
        "address": "DS2cpSDvZXHzhZEyBEbTNuQTgonoHkFM4n",
        "script": "76a914e521015b004d2d5023d5cd6bcd14ff297697d5f388ac",
        "value": 20000000,
        "confirmations": -1
    }
]

Expect:

remove the conflicting coins.

The getBalanceForAddress will filter out the conflicting coins.

There should be the same logic for getting unspent outputs?

if (args.unspent) {
      query.spentHeight = { $lt: SpentHeightIndicators.minimum };
     query.mintHeight = { $gt: SpentHeightIndicators.conflicting };  // add this line to filter out conflicting
 }
kajoseph commented 1 year ago

It might be a good idea to add a query param to that API endpoint that signals whether or not to include conflicting.

peng-huang-ch commented 1 year ago

@kajoseph I would add a query params like https://****/api/DOGE/mainnet/address/DS2cpSDvZXHzhZEyBEbTNuQTgonoHkFM4n/?unspent=true&conflicting=false. should I make a pr or just close it.

kajoseph commented 1 year ago

PRs are welcome :)

peng-huang-ch commented 1 year ago

@kajoseph Please review the #3591, THX.