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

feat: Add proto annotations for amino json #412

Merged
merged 2 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions crypto/keys/ed25519/keys.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 19 additions & 14 deletions crypto/keys/multisig/keys.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions crypto/keys/secp256k1/keys.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions proto/amino/amino.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
syntax = "proto3";

package amino;

import "google/protobuf/descriptor.proto";

// TODO(fdymylja): once we fully migrate to protov2 the go_package needs to be updated.
// We need this right now because gogoproto codegen needs to import the extension.
option go_package = "github.com/cosmos/cosmos-sdk/types/tx/amino";

extend google.protobuf.MessageOptions {
// name is the string used when registering a concrete
// type into the Amino type registry, via the Amino codec's
// `RegisterConcrete()` method. This string MUST be at most 39
// characters long, or else the message will be rejected by the
// Ledger hardware device.
string name = 11110001;

// encoding describes the encoding format used by Amino for the given
// message. The field type is chosen to be a string for
// flexibility, but it should ideally be short and expected to be
// machine-readable, for example "base64" or "utf8_json". We
// highly recommend to use underscores for word separation instead of spaces.
//
// If left empty, then the Amino encoding is expected to be the same as the
// Protobuf one.
//
// This annotation should not be confused with the `encoding`
// one which operates on the field level.
string message_encoding = 11110002;
}

extend google.protobuf.FieldOptions {
// encoding describes the encoding format used by Amino for
// the given field. The field type is chosen to be a string for
// flexibility, but it should ideally be short and expected to be
// machine-readable, for example "base64" or "utf8_json". We
// highly recommend to use underscores for word separation instead of spaces.
//
// If left empty, then the Amino encoding is expected to be the same as the
// Protobuf one.
//
// This annotation should not be confused with the
// `message_encoding` one which operates on the message level.
string encoding = 11110003;

// field_name sets a different field name (i.e. key name) in
// the amino JSON object for the given field.
//
// Example:
//
// message Foo {
// string bar = 1 [(amino.field_name) = "baz"];
// }
//
// Then the Amino encoding of Foo will be:
// `{"baz":"some value"}`
string field_name = 11110004;

// dont_omitempty sets the field in the JSON object even if
// its value is empty, i.e. equal to the Golang zero value. To learn what
// the zero values are, see https://go.dev/ref/spec#The_zero_value.
//
// Fields default to `omitempty`, which is the default behavior when this
// annotation is unset. When set to true, then the field value in the
// JSON object will be set, i.e. not `undefined`.
//
// Example:
//
// message Foo {
// string bar = 1;
// string baz = 2 [(amino.dont_omitempty) = true];
// }
//
// f := Foo{};
// out := AminoJSONEncoder(&f);
// out == {"baz":""}
bool dont_omitempty = 11110005;
}
11 changes: 9 additions & 2 deletions proto/cosmos/auth/v1beta1/auth.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
syntax = "proto3";
package cosmos.auth.v1beta1;

import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
Expand All @@ -11,21 +12,26 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/auth/types";
// for basic account functionality. Any custom account type should extend this
// type for additional functionality (e.g. vesting).
message BaseAccount {
option (amino.name) = "cosmos-sdk/BaseAccount";
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (gogoproto.equal) = false;

option (cosmos_proto.implements_interface) = "AccountI";

string address = 1;
google.protobuf.Any pub_key = 2
[(gogoproto.jsontag) = "public_key,omitempty", (gogoproto.moretags) = "yaml:\"public_key\""];
google.protobuf.Any pub_key = 2 [
(gogoproto.jsontag) = "public_key,omitempty",
(gogoproto.moretags) = "yaml:\"public_key\"",
(amino.field_name) = "public_key"
];
uint64 account_number = 3 [(gogoproto.moretags) = "yaml:\"account_number\""];
uint64 sequence = 4;
}

// ModuleAccount defines an account for modules that holds coins on a pool.
message ModuleAccount {
option (amino.name) = "cosmos-sdk/ModuleAccount";
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (cosmos_proto.implements_interface) = "ModuleAccountI";
Expand All @@ -37,6 +43,7 @@ message ModuleAccount {

// Params defines the parameters for the auth module.
message Params {
option (amino.name) = "cosmos-sdk/x/auth/Params";
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;

Expand Down
3 changes: 2 additions & 1 deletion proto/cosmos/auth/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ package cosmos.auth.v1beta1;
import "google/protobuf/any.proto";
import "gogoproto/gogo.proto";
import "cosmos/auth/v1beta1/auth.proto";
import "amino/amino.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/auth/types";

// GenesisState defines the auth module's genesis state.
message GenesisState {
// params defines all the paramaters of the module.
Params params = 1 [(gogoproto.nullable) = false];
Params params = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];

// accounts are the accounts present at genesis.
repeated google.protobuf.Any accounts = 2;
Expand Down
2 changes: 2 additions & 0 deletions proto/cosmos/authz/v1beta1/authz.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
syntax = "proto3";
package cosmos.authz.v1beta1;

import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";
import "google/protobuf/timestamp.proto";
import "gogoproto/gogo.proto";
Expand All @@ -13,6 +14,7 @@ option (gogoproto.goproto_getters_all) = false;
// GenericAuthorization gives the grantee unrestricted permissions to execute
// the provided method on behalf of the granter's account.
message GenericAuthorization {
option (amino.name) = "cosmos-sdk/GenericAuthorization";
option (cosmos_proto.implements_interface) = "Authorization";

// Msg, identified by it's type URL, to grant unrestricted permissions to execute
Expand Down
3 changes: 2 additions & 1 deletion proto/cosmos/authz/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ syntax = "proto3";
package cosmos.authz.v1beta1;

import "gogoproto/gogo.proto";
import "amino/amino.proto";
import "cosmos/authz/v1beta1/authz.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/authz";

// GenesisState defines the authz module's genesis state.
message GenesisState {
repeated GrantAuthorization authorization = 1 [(gogoproto.nullable) = false];
repeated GrantAuthorization authorization = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}
9 changes: 8 additions & 1 deletion proto/cosmos/authz/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "cosmos/authz/v1beta1/authz.proto";
import "amino/amino.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/authz";
option (gogoproto.goproto_getters_all) = false;
Expand All @@ -31,10 +32,12 @@ service Msg {
// MsgGrant is a request type for Grant method. It declares authorization to the grantee
// on behalf of the granter with the provided expiration time.
message MsgGrant {
option (amino.name) = "cosmos-sdk/MsgGrant";

string granter = 1;
string grantee = 2;

cosmos.authz.v1beta1.Grant grant = 3 [(gogoproto.nullable) = false];
cosmos.authz.v1beta1.Grant grant = 3 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

// MsgExecResponse defines the Msg/MsgExecResponse response type.
Expand All @@ -46,6 +49,8 @@ message MsgExecResponse {
// authorizations granted to the grantee. Each message should have only
// one signer corresponding to the granter of the authorization.
message MsgExec {
option (amino.name) = "cosmos-sdk/MsgExec";

string grantee = 1;
// Authorization Msg requests to execute. Each msg must implement Authorization interface
// The x/authz will try to find a grant matching (msg.signers[0], grantee, MsgTypeURL(msg))
Expand All @@ -59,6 +64,8 @@ message MsgGrantResponse {}
// MsgRevoke revokes any authorization with the provided sdk.Msg type on the
// granter's account with that has been granted to the grantee.
message MsgRevoke {
option (amino.name) = "cosmos-sdk/MsgRevoke";

string granter = 1;
string grantee = 2;
string msg_type_url = 3;
Expand Down
10 changes: 8 additions & 2 deletions proto/cosmos/bank/v1beta1/authz.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
syntax = "proto3";
package cosmos.bank.v1beta1;

import "amino/amino.proto";
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";
Expand All @@ -13,7 +14,12 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/bank/types";
// Since: cosmos-sdk 0.43
message SendAuthorization {
option (cosmos_proto.implements_interface) = "Authorization";
option (amino.name) = "cosmos-sdk/SendAuthorization";

repeated cosmos.base.v1beta1.Coin spend_limit = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
repeated cosmos.base.v1beta1.Coin spend_limit = 1 [
(gogoproto.nullable) = false,

(amino.dont_omitempty) = true,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}
Loading