1

monerod has an option to include an extra message in a coinbase transaction with --extra-messages-file.

  • What format should the text in the file be? Hex, Decimal, or some other format?
  • Once the transaction is mined, how do you parse the data out of the extra field and decode the message back to plain text?
2

This option is available for the in-built miner. Reviewing how it's used:

  • Its expected format is one base64 string per line.
  • When the miner requests a block template to mine, it adds the current index line from the file as the extra_nonce field in the block template - this gets placed in the tx extra field.
  • When the miner finds a block, it increments the index counter so the next block template includes the next line from the file in the next extra_nonce.

So,

What format should the text in the file be? Hex, Decimal, or some other format?

Data is expected to be base64 encoded.

Once the transaction is mined, how do you parse the data out of the extra field and decode the message back to plain text?

You have to parse the tx's extra field. The format of this is a binary blob of tagged data. To read, you need to loop over it reading the tags and data like:

  1. Start at index 0 of the data
  2. Read the 1 byte tag
  3. If the tag is 0x00 (padding), continue to next byte and read (step 2)
  4. If the tag is 0x01 (pub key), skip over the next 32 bytes (the size of a pub key) and read next byte (step 2)
  5. If the tag is 0x02 (extra)
    • The next byte tells you the size of the data
    • Read size of bytes (this gets you your extra data)
  6. If any other tag found, read the next byte (size) then skip size bytes and goto step 2.

Keep looping until you have either found the tag/data you are looking for or read the whole field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.