Title: How to parse "utxos" structure from hex respresentation returned by Rest interfa Post by: lontivero on June 28, 2015, 11:28:14 PM Hi, I am developing a RestClient for consuming the bitcoind rest service and I found a problem parsing the utxos from the hex representation. This is what I do:
GET http://localhost:18332/rest/getutxos/b2cdfd7b89def827ff8af7cd9bff7627ff72e5e8b0f71210f92ea7a4000c5d75-0.hex That response with: eb6b070082b58a4bd66efb6043bbc3ac89796161743196fbf42d7fe8e9d3ef0300000000010000 Following the BIP64 https://github.com/bitcoin/bips/blob/master/bip-0064.mediawiki#specification (https://github.com/bitcoin/bips/blob/master/bip-0064.mediawiki#specification) I know that chainheight = 486379, chaintipHash = 0000000003efd3e9e87f2df4fb96317461617989acc3bb4360fb6ed64b8ab582 but I have no way to know how many bytes the bitmap has, and that is because I don't know how many utxos are. From the bitcoin repo I see Code: ssGetUTXOResponse << chainActive.Height() << chainActive.Tip()->GetBlockHash() << bitmap << outs; Is there any whay to know how many utxos the response has? UPDATE: A better question could be: how do I have to interprete the ending 3 bytes (010000 in hex)? Title: Re: How to parse "utxos" structure from hex respresentation returned by Rest interfa Post by: jonas.schnelli on June 30, 2015, 07:39:00 AM Code: jonasschnelli$ ./src/bitcoin-cli --regtest getbestblockhash Code: jonasschnelli$ ./src/bitcoin-cli --regtest getblock 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206 Code: curl 'http://localhost:18332/rest/getutxos/b2cdfd7b89def827ff8af7cd9bff7627ff72e5e8b0f71210f92ea7a4000c5d75-0.hex' 0000000006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f010000 First 4 bytes (00000000) is the chain height (int32) Next 32 bytes (6226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f) is the chain tip hash (little endian notation, so it's "reversed") Next 2 bytes (0100) is the bitmap where you can see if your queried outpoints are in the UTXO set. 01 = size, 00 = not in set (first queried outpoint is not in set,...). Next 1 bytes (00) is a serialized vector of a Coin (uint32_t nTxVer, uint32_t nHeight, CTxOut out). In this case it's empty. Also mind that you can have JSON output for getutxos: Code: curl 'http://localhost:18332/rest/getutxos/b2cdfd7b89def827ff8af7cd9bff7627ff72e5e8b0f71210f92ea7a4000c5d75-0.json' Title: Re: How to parse "utxos" structure from hex respresentation returned by Rest interfa Post by: lontivero on June 30, 2015, 04:31:27 PM Jonas, thank you very much. I have developed a REST Client for NBticoin (https://github.com/NicolasDorier/NBitcoin/commit/e9706957566dd9c65e7f5db73bc5972ad51a9ff9)
I think the rest interface is awesome and a very convenient way to communicate with the node. Nice Job. Thanks again. |