Blockchair / Blockchair.Support

Public repository for issues and feature requests. Submit your favorite bug!
434 stars 318 forks source link

Capability to query UTXO/unspents of an address #192

Open Polve opened 5 years ago

Polve commented 5 years ago

I found no easy way to get a list of unspents for a certain address, i.e. the result of a call similar to this one on insight:

https://domain.ext/api/addrs/addr1,addr2/utxo

The only way I found is starting from an address, and if it has unspent_output_count > 0 check all his transactions, then cycle for every output of each transaction, and if recipient is the same one we are looking for, and is_spent is false then keep the index.

Not very handy (and a lot of load on your server): is there a simpler way?

Har01d commented 5 years ago

Hi,

It’s possible to query the UTXO set of an address this way: api.blockchair.com/{:chain}/outputs?q=recipient({:address}),is_spent(false)

Additionally please see #188 (there’s a rarely occurring bug in this filter).

But I think a good idea would be to also add api.blockchair.com/{:chain}/dashboards/address/{:address}/utxo, api.blockchair.com/{:chain}/dashboards/addresses/{:address1},{:address2}.../utxo, and api.blockchair.com/{:chain}/dashboards/xpub/{:xpub}/utxo endpoints in case someone needs the UTXO set of a set of addresses.

Har01d commented 5 years ago

It turned out that this feature was somewhat fast to implement. It’s not in production yet (we’ll be testing it and schedule to one of the next updates), but here’s how it will look like.

E.g. api.blockchair.com/bitcoin/dashboards/addresses/192kkZSRQHrS4dnBoPGgoYB6WeC1HXyYZe,17iyRRXBHJKbv5DKPPkttWewm3CHdNPGQd will yield:

Screenshot

So there will be no need for a separate request, the utxo data will be available in the utxo array. This will work for the following endpoints:

Each UTXO element will contain

I’ll ask some of our API users to review that.

Polve commented 5 years ago

That's great!

The only thing I would ask, when querying multiple addresses, is in the UTXO element to know also the address related to that utxo otherwise we will need another query to know which one is (that's needed for correct signing)

Har01d commented 5 years ago

@Polve, I think that’s absolutely reasonable.

Screenshot
Har01d commented 5 years ago

This feature is now available for general access, please see the changelog for v.2.0.26: https://github.com/Blockchair/Blockchair.Support/blob/master/API.md

We’ve also made an easy way to iterate through the results.

CC @Polve @thecreation @torzikup @vserpokryl

vserpokryl commented 5 years ago

@Har01d why scriptPubKey (script_hex) property is not in UTXO? It is absolutely required for bitcoin cash transaction signing.

Har01d commented 5 years ago

@vserpokryl, it’s available in the addresses array:

Screenshot 2019-06-20 at 15 48 39

(https://api.blockchair.com/bitcoin/dashboards/addresses/192kkZSRQHrS4dnBoPGgoYB6WeC1HXyYZe,17iyRRXBHJKbv5DKPPkttWewm3CHdNPGQd)

I see no reason to duplicate scripts into the utxo array.

andkom commented 5 years ago

would be great if there was transaction_count per address

Har01d commented 5 years ago

@andkom, please open a separate feature request for that. I think it’s possible to implement that, but what are the use cases?