ripple / ripple-binary-codec

Convert between json and hex representations of transactions and ledger entries on the XRP Ledger. Moved to: https://github.com/XRPLF/xrpl.js/tree/develop/packages/ripple-binary-codec
https://github.com/XRPLF/xrpl.js/tree/develop/packages/ripple-binary-codec
ISC License
19 stars 45 forks source link

Why is FIELDS a 2d array? #54

Closed iroskam closed 4 years ago

iroskam commented 4 years ago

All of the leafs of the FIELDS property are single JSON objects. It would be cleaner to have each of the named fields as properties of a single object identified by the FIELDS property.

Example:

"FIELDS": { "Generic":{ "nth":0, "isVLEncoded":false, "isSerialized":false, "isSigningField":false, "type":"Unknown" }, "Invalid":{ ... }

Having FIELDS as nested arrays instead of objects requires deeper referencing to get to each field. Having FIELDS as an object allows referencing to be strictly by field name.

Why is the FIELDS property in definitions.json a 2d array?

sublimator commented 4 years ago

They are presorted in their canonical order

sublimator commented 4 years ago

At least at the time I think that was the reason :) And it may or may not have been used. I think it was more something related to ripple-lib-java

iroskam commented 4 years ago

Thank you for the response. It is always a chore trying to remember architecture decisions from long ago. I was just curious. It seemed a little odd to make FIELDS an array and all members arrays since all other top level entries are objects. If FIELDS was an object and all members were objects each member could be referenced by name with the '.' operator instead of iterating and inspecting.

Anyway, thank you for your work pulling all this out of SField.cpp. definitions.json is being used as a starting point for serialization in multiple language libraries.

On Wed, May 27, 2020 at 2:49 AM Nicholas Dudfield notifications@github.com wrote:

At least at the time I think that was the reason :) And it may or may not have been used. I think it was more something related to ripple-lib-java

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ripple/ripple-binary-codec/issues/54#issuecomment-634581488, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOXGSHTRBCRBQ7IQWCP6VDRTTV25ANCNFSM4LD4VG7Q .

intelliot commented 4 years ago

There's a Python serialization library that uses definitions.json, so we will most likely keep the format the same. However, we will look into the possibility of scripting the generation of the definitions.json file (by parsing code in rippled) so that new things (e.g. Tickets) can be automatically added in the future.

For example, Fields are from https://github.com/ripple/rippled/blob/develop/src/ripple/protocol/impl/SField.cpp