mesg-foundation / engine

Build apps or autonomous workflows with reusable, shareable integrations connecting any service, app, blockchain or decentralized network.
https://mesg.com/
Apache License 2.0
130 stars 13 forks source link

Remove map from proto.Struct #1493

Closed NicolasMahe closed 4 years ago

NicolasMahe commented 4 years ago

As amino doesn't support map, and it's complicated to implement and map are much heavier than array when dealing with lots of data (repetition of the keys), we should remove map from proto.Struct type. The order will play a very important role to know which value belongs to which inputs/outputs/events' definition from the mesg.yml.

The engine already define its own proto.Struct type, so we just need to make a few adjustment, update the encoding/decoding functions of the js library, and update the go services.

message Value { // The kind of value. oneof kind { // Represents a null value. NullValue null_value = 1 [ (gogoproto.moretags) = 'hash:"name:1"' ]; ... // Represents a structured value.

Here an example of those previous modifications from the service used in e2e:

- Data: &types.Struct{
-   Fields: map[string]*types.Value{
-       "msg": &types.Value{
-           Kind: &types.Value_StringValue{
-               StringValue: exec.TaskKey,
-           },
+ Data: []*types.Value{
+   &types.Value{
+       Kind: &types.Value_StringValue{
+           StringValue: exec.TaskKey,
        },
    },
},

This issue is a breaking change from the API point of view, but with the right update on the js library, it should not break the API of the js lib ;)

NicolasMahe commented 4 years ago

This issue is not relevant as we find solution to transform map to array when encoding in amino and map are really useful and easy to sort for deterministic encoding.