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:
- Start at index 0 of the data
- Read the 1 byte tag
- If the tag is 0x00 (padding), continue to next byte and read (step 2)
- 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)
- 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)
- 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.