1

I am currently working with the Monero daemon RPC and have a little problem understanding the format of the binary request (/get_o_indexes.bin for example).

Does anyone have an example of how should I generate my binary request with Python's requests library?

cialu
  • 1,661
  • 13
  • 44
Jeremy V.
  • 13
  • 3

1 Answers1

1

To call the binary methods, you have to send raw binary data as an application/octet-stream in the request body and read the binary data sent back in the response body.

There's a StackOverflow answer that shows making binary requests using Python here. Quoting the requests library example:

import requests

data = 'test data'
res = requests.post(url='http://localhost:8888',
                data=data,
                headers={'Content-Type': 'application/octet-stream'})

Here you would replace data with the binary tx id (which is 32 bytes), wrapped as a Levin packet. A brief overview can be found here.

For working out how to serialize the request data and deserialize the returned response data, you should start by looking in this folder.

Here is an annotated response for the interested:

0111010101010201        signature
01                      version
0c                      section
09 6f5f696e6465786573   field: string length then data: o_indexes
85                      type (uint64 | array flag)
08                      length 2 (0x08 >> 2)
aca87f0000000000        idx
ada87f0000000000        idx
06 737461747573         field: string length then data: status
0a                      type (string)
08                      length 2 (0x08 >> 2)
4f4b                    OK
09 756e74727573746564   field: string length then data: untrusted
0b                      type (bool)
00                      false

Here is a quick and dirty example of calling then parsing the response using Python.

jtgrassie
  • 19,601
  • 4
  • 17
  • 54