Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to from amino #537

Merged
merged 10 commits into from
Dec 11, 2023
Merged

Fix to from amino #537

merged 10 commits into from
Dec 11, 2023

Conversation

Zetazzz
Copy link
Collaborator

@Zetazzz Zetazzz commented Dec 10, 2023

Fixed toAmino and fromAmino implementations
refactored fromAmino method generating process:
fix strict null check build errors
omitempty and dont_omitempty handling for fields of all types and tested
bytesFromBase64 for bytes and bytes array
test every type for amino encoding and fixed some legacy bugs

Examples:
Amino type:

export interface AminoEncodingTestAmino {
  // scalar values without (amino.dont_omitempty) option can be optional in Amino type.
  b?: boolean;
  // scalar values with (amino.dont_omitempty) = true option is required in Amino type.
  // the field will be filled with default value of the type.
  d_o_b: boolean;
}

fromAmino:

  fromAmino(object: AminoEncodingTestAmino): AminoEncodingTest {
    const message = createBaseAminoEncodingTest();
    // if there's no input value, default logic from createBaseAminoEncodingTest() will be 
    // applied for both with or without (amino.dont_omitempty) = true
    if (object.b !== undefined && object.b !== null) {
      message.b = object.b;
    }
    // if there's no input value, default logic from createBaseAminoEncodingTest() will be 
    // applied for both with or without (amino.dont_omitempty) = true
    if (object.d_o_b !== undefined && object.d_o_b !== null) {
      message.dOB = object.d_o_b;
    }
  }

toAmino:

  toAmino(message: AminoEncodingTest): AminoEncodingTestAmino {
    const obj: any = {};
    obj.b = message.b;
    // default value will be applied with (amino.dont_omitempty) = true
    obj.d_o_b = message.dOB ?? false;
  }

@Zetazzz Zetazzz marked this pull request as ready for review December 11, 2023 01:57
@Zetazzz Zetazzz merged commit 7117236 into main Dec 11, 2023
2 checks passed
@Zetazzz Zetazzz mentioned this pull request Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant