21centurymotorcompany / bitd

DEPRECATED. Replaced with Planaria https://planaria.network
82 stars 38 forks source link

UTXO #4

Open unwriter opened 5 years ago

unwriter commented 5 years ago

Support Unspent outputs.

Currently it's easy to aggregate and filter outputs in many different ways, but bitdb doesn't provide info on which one of them are already spent.

Thinking about some potential use cases for this would be helpful in designing the architecture.

deeb33 commented 5 years ago

All the use cases I can think of come down to wallet type functionality, something like a block explorer, or maybe a simple balance checker. It seems to me, in the first two cases you're going to want both incoming and outgoing TXs. The last case might make use of selecting for only unspent outputs. Perhaps my imagination is limited as I tend to think in terms of a browser based Memo interface.

My first pass at playing with bitdb was to find the balance on a given address, which necessitates finding the UTXO set. It comes down to a single bitdb query to fetch the TXs for the address and two passes, first through the outputs and then the inputs. I've attached the code.

addrinfogeneric.txt

vinarmani commented 5 years ago

Basically what I did was take the JS logic from above (create an array of relevant ins and outs) and then attempt to translate it to jq, which is new to me. The result is an array of confirmed UTXOs objects in the format of:

{"o":"ee2d431267af5b54a680e2bab7cae2502c30e3eb36473b735519889c79e380f8:0","v":1882} {"o":"_txhash:index","v":_amount_insatoshis}

This works for confirmed txs. At the moment, it doesn't appear that the jq response functionality can be used to work with both the unconfirmed and confirmed databases at once. If you want to parse both confirmed and unconfirmed UTXOs, for now it looks like this has to be done client side. In that case, this call below can be modified to just return the full input and output sets for both the "u" and "c" databases.

View In Explorer