4

I am making some modifications to cryptonote-utils for a cryptonote with a different block format than what it is built for. I've never done serialization before so I am just now learning about the concept. Let's take this as our example from cryptonote_basic.h:

BEGIN_SERIALIZE()
VARINT_FIELD_N("major_version", major_version);
VARINT_FIELD(timestamp);
FIELD_N("nonce", nonce);
FIELD(nonce);
END_SERIALIZE()

I understand that we are essentially converting all of our fields to hex (EDIT:binary not hex) and lining them up against each other to be efficient and create our block, but I don't understand how that order is defined? Is it defined by the order that I write them within the BEGIN_SERIALIZE() macro or is the order based off of their tags (or something else maybe I am missing)? I would imagine they get serialized in the order I serialize them within the macro, but then I wonder why some fields have tags and others do not? Is the tag name important?

I'm not the best with templates, so looking through serialization.h is quite tough for me. I am also not quite sure when to use BEGIN_SERIALIZE_OBJECT vs BEGIN_SERIALIZE. Thanks for helping with my noob questions!

1 Answer 1

6

Those marcos were written by a Russian who had too much vodka =). I have done C++ since I was 11 and I needed two hours to make sense of what they do.

First of all they are generic. They are used thought the code, and the resulting structures can be converted to a binary (network) format or json, so what you are doing here is only setting out the names of the fields and what you want the serialiser to spit out.

  • I don't understand how that order is defined?

Unless you create a data structure, it will just be a dictionary (key-value list) in the order of the macros.

  • Is the tag name important?

It will be the key in the dictionary. By default it will be the variable name in the code, but you can set it to something else.

  • I am also not quite sure when to use BEGIN_SERIALIZE_OBJECT vs BEGIN_SERIALIZE

Unless you know what you are doing use BEGIN_SERIALIZE_OBJECT

1
  • Thank you very much, I made a lot of progress. I think I just need to work on the cryptonote-universal-pool code now github.com/DrCryptoToad
    – ron
    Jun 13, 2017 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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