Bitcoin Forum
June 25, 2024, 03:54:36 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to parse "utxos" structure from hex respresentation returned by Rest interfa  (Read 755 times)
lontivero (OP)
Full Member
***
Offline Offline

Activity: 164
Merit: 128

Amazing times are coming


View Profile
June 28, 2015, 11:28:14 PM
Last edit: June 29, 2015, 01:35:48 AM by lontivero
 #1

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 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;
string ssGetUTXOResponseString = ssGetUTXOResponse.str();

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)?
jonas.schnelli
Member
**
Offline Offline

Activity: 66
Merit: 10

bitcoin core contributor


View Profile WWW
June 30, 2015, 07:39:00 AM
 #2

Code:
jonasschnelli$ ./src/bitcoin-cli --regtest getbestblockhash
0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206

Code:
jonasschnelli$ ./src/bitcoin-cli --regtest getblock 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206
{
  "hash": "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206",
  "confirmations": 1,
  "size": 285,
  "height": 0,
  "version": 1,
  "merkleroot": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
  "tx": [
    "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
  ],
  "time": 1296688602,
  "nonce": 2,
  "bits": "207fffff",
  "difficulty": 0.00000000,
  "chainwork": "0000000000000000000000000000000000000000000000000000000000000002"
}

Code:
curl 'http://localhost:18332/rest/getutxos/b2cdfd7b89def827ff8af7cd9bff7627ff72e5e8b0f71210f92ea7a4000c5d75-0.hex'
0000000006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f010000

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'
lontivero (OP)
Full Member
***
Offline Offline

Activity: 164
Merit: 128

Amazing times are coming


View Profile
June 30, 2015, 04:31:27 PM
 #3

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.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!