Skip to content

Generating animo converters instead of manually creating them #7

@stevenkhong

Description

@stevenkhong

Cosmos SDK introduced SIGN_MODE_DIRECT which replaces the original sign mode (now differentiated as SIGN_MODE_LEGACY_AMINO_JSON) cosmos-sdk docs. However, most ledger devices/apps only support the legacy mode, which requires dApps to support both sign modes. In order to support the legacy mode, the dApp will need to provide an Amino converter for each protobuf type, to convert the object instance into an Amino JSON used for the signing.

In the legacy Carbon JS SDK implementation, the Amino converters were manually written for each new type added (example). We would like to explore possibility of generating the type converters instead. The information is already available in the type .proto files, however I am not sure if the generator we're using ts-proto is able to parse it.

An snippet of the source .proto file:

message MsgCreateToken {
  option (cosmos.msg.v1.signer) = "creator";
  option (amino.name) = "carbon/MsgCreateToken"; // <-- amino type converters need this
  option (gogoproto.goproto_getters) = false;

  string creator = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  CreateTokenParams create_token_params = 2 [ (gogoproto.nullable) = false ];
}

message CreateTokenParams {
  option (gogoproto.goproto_getters) = false;

  string creator = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  string name = 2;
  string symbol = 3;
  int64 decimals = 4;
  uint64 chain_id = 5;
  uint64 bridge_id = 6;
  string bridge_address = 7;
  string token_address = 8;
}

The Animo types is usually registered when instantiating some version of a signing client.

const aminoTypes = getAminoTypes();
SigningStargateClient.connectWithSigner(rpcUrl, signer, { aminoTypes });

To summarise, there're two main unknowns we need to get past before knowing we can proceed with implementing a generator for animo types.

  • can existing TypeScript generator include animo.name option in the output? otherwise does it make sense to extract if using another tool/script?
  • is it possible to auto map the sdk/Dec, Long, Duration and other common types, such that majority of the amino type converter generations can be automated?

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions