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

use implicit recursion similar to fromPartial for toAmino/fromAmino #49

Open
pyramation opened this issue May 4, 2022 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@pyramation
Copy link
Collaborator

pyramation commented May 4, 2022

currently the toAmino/fromAmino functionality requires the proto parser store and proto refs so that it can query information about nested dependencies and imports.

This could be simplified by taking an approach for amino encoding similar to how fromPartial, fromJSON, toJSON and other methods inspired from ts-proto

This could be accomplished by adding toAminoandfromAmino` methods to the message objects:

export const MsgCreateValidator = {
  encode(message: MsgCreateValidator, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.description !== undefined) {
      Description.encode(message.description, writer.uint32(10).fork()).ldelim();
    }
    if (message.commission !== undefined) {
      CommissionRates.encode(message.commission, writer.uint32(18).fork()).ldelim();
    }
  }
  toAmino(message, obj) {
      if (message.description !== undefined) {
         obj.description = Description.toAmino(message.description);
     }
  }
@pyramation pyramation added the enhancement New feature or request label May 4, 2022
@pyramation
Copy link
Collaborator Author

this may be required for infinitely recursive structures.

Part of why this PR didn't get merged, it seemed that some structures were infinitely nested: #198

@pyramation
Copy link
Collaborator Author

pyramation commented Nov 26, 2022

types themselves

encoders

  • string
  • numbers
  • long
  • enum (using functions)

duration types

@pyramation
Copy link
Collaborator Author

enum example

  "/cosmos.gov.v1beta1.MsgVote": {
    aminoType: "cosmos-sdk/MsgVote",
    toAmino: ({ option, proposalId, voter }: MsgVote): AminoMsgVote["value"] => {
      return {
        option: option,
        proposal_id: proposalId.toString(),
        voter: voter,
      };
    },
    fromAmino: ({ option, proposal_id, voter }: AminoMsgVote["value"]): MsgVote => {
      return {
        option: voteOptionFromJSON(option),
        proposalId: Long.fromString(proposal_id),
        voter: voter,
      };
    },
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant