From 8bbec1ee3f30b87ce4230be513c3e6ac9cba5a2d Mon Sep 17 00:00:00 2001 From: TAKAMI Torao Date: Fri, 8 Jul 2022 21:20:24 +0900 Subject: [PATCH 1/4] revert BaseAccount.PubKey fields and Marshal/UnmarshalJSONPB/JSON --- baseapp/block_gas_test.go | 2 +- docs/core/proto-docs.md | 397 +++++++++---------- proto/cosmos/auth/v1beta1/auth.proto | 21 +- x/auth/keeper/keeper.go | 5 +- x/auth/types/account.go | 250 +----------- x/auth/types/account_test.go | 41 +- x/auth/types/auth.pb.go | 289 +++----------- x/auth/vesting/types/vesting_account.go | 171 -------- x/auth/vesting/types/vesting_account_test.go | 75 +--- x/wasm/keeper/keeper_test.go | 4 +- x/wasm/keeper/submsg_test.go | 8 +- 11 files changed, 302 insertions(+), 961 deletions(-) diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index e2bd90077e..497df386e5 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -124,7 +124,7 @@ func TestBaseApp_BlockGas(t *testing.T) { require.Equal(t, []byte("ok"), okValue) } // check block gas is always consumed - baseGas := uint64(35030) // baseGas is the gas consumed before tx msg + baseGas := uint64(40043) // baseGas is the gas consumed before tx msg expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas) if expGasConsumed > txtypes.MaxGasWanted { // capped by gasLimit diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index c37b4c79f0..2310bf67e2 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -4,21 +4,6 @@ ## Table of Contents -- [cosmos/crypto/ed25519/keys.proto](#cosmos/crypto/ed25519/keys.proto) - - [PrivKey](#cosmos.crypto.ed25519.PrivKey) - - [PubKey](#cosmos.crypto.ed25519.PubKey) - -- [cosmos/crypto/multisig/keys.proto](#cosmos/crypto/multisig/keys.proto) - - [LegacyAminoPubKey](#cosmos.crypto.multisig.LegacyAminoPubKey) - -- [cosmos/crypto/secp256k1/keys.proto](#cosmos/crypto/secp256k1/keys.proto) - - [PrivKey](#cosmos.crypto.secp256k1.PrivKey) - - [PubKey](#cosmos.crypto.secp256k1.PubKey) - -- [cosmos/crypto/secp256r1/keys.proto](#cosmos/crypto/secp256r1/keys.proto) - - [PrivKey](#cosmos.crypto.secp256r1.PrivKey) - - [PubKey](#cosmos.crypto.secp256r1.PubKey) - - [cosmos/auth/v1beta1/auth.proto](#cosmos/auth/v1beta1/auth.proto) - [BaseAccount](#cosmos.auth.v1beta1.BaseAccount) - [ModuleAccount](#cosmos.auth.v1beta1.ModuleAccount) @@ -212,10 +197,25 @@ - [Msg](#cosmos.crisis.v1beta1.Msg) +- [cosmos/crypto/ed25519/keys.proto](#cosmos/crypto/ed25519/keys.proto) + - [PrivKey](#cosmos.crypto.ed25519.PrivKey) + - [PubKey](#cosmos.crypto.ed25519.PubKey) + +- [cosmos/crypto/multisig/keys.proto](#cosmos/crypto/multisig/keys.proto) + - [LegacyAminoPubKey](#cosmos.crypto.multisig.LegacyAminoPubKey) + - [cosmos/crypto/multisig/v1beta1/multisig.proto](#cosmos/crypto/multisig/v1beta1/multisig.proto) - [CompactBitArray](#cosmos.crypto.multisig.v1beta1.CompactBitArray) - [MultiSignature](#cosmos.crypto.multisig.v1beta1.MultiSignature) +- [cosmos/crypto/secp256k1/keys.proto](#cosmos/crypto/secp256k1/keys.proto) + - [PrivKey](#cosmos.crypto.secp256k1.PrivKey) + - [PubKey](#cosmos.crypto.secp256k1.PubKey) + +- [cosmos/crypto/secp256r1/keys.proto](#cosmos/crypto/secp256r1/keys.proto) + - [PrivKey](#cosmos.crypto.secp256r1.PrivKey) + - [PubKey](#cosmos.crypto.secp256r1.PubKey) + - [cosmos/distribution/v1beta1/distribution.proto](#cosmos/distribution/v1beta1/distribution.proto) - [CommunityPoolSpendProposal](#cosmos.distribution.v1beta1.CommunityPoolSpendProposal) - [CommunityPoolSpendProposalWithDeposit](#cosmos.distribution.v1beta1.CommunityPoolSpendProposalWithDeposit) @@ -1086,187 +1086,6 @@ - -

Top

- -## cosmos/crypto/ed25519/keys.proto - - - - - -### PrivKey -Deprecated: PrivKey defines a ed25519 private key. -NOTE: ed25519 keys must not be used in SDK apps except in a tendermint validator context. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `key` | [bytes](#bytes) | | | - - - - - - - - -### PubKey -PubKey is an ed25519 public key for handling Tendermint keys in SDK. -It's needed for Any serialization and SDK compatibility. -It must not be used in a non Tendermint key context because it doesn't implement -ADR-28. Nevertheless, you will like to use ed25519 in app user level -then you must create a new proto message and follow ADR-28 for Address construction. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `key` | [bytes](#bytes) | | | - - - - - - - - - - - - - - - - -

Top

- -## cosmos/crypto/multisig/keys.proto - - - - - -### LegacyAminoPubKey -LegacyAminoPubKey specifies a public key type -which nests multiple public keys and a threshold, -it uses legacy amino address rules. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `threshold` | [uint32](#uint32) | | | -| `public_keys` | [google.protobuf.Any](#google.protobuf.Any) | repeated | | - - - - - - - - - - - - - - - - -

Top

- -## cosmos/crypto/secp256k1/keys.proto - - - - - -### PrivKey -PrivKey defines a secp256k1 private key. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `key` | [bytes](#bytes) | | | - - - - - - - - -### PubKey -PubKey defines a secp256k1 public key -Key is the compressed form of the pubkey. The first byte depends is a 0x02 byte -if the y-coordinate is the lexicographically largest of the two associated with -the x-coordinate. Otherwise the first byte is a 0x03. -This prefix is followed with the x-coordinate. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `key` | [bytes](#bytes) | | | - - - - - - - - - - - - - - - - -

Top

- -## cosmos/crypto/secp256r1/keys.proto -Since: cosmos-sdk 0.43 - - - - -### PrivKey -PrivKey defines a secp256r1 ECDSA private key. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `secret` | [bytes](#bytes) | | secret number serialized using big-endian encoding | - - - - - - - - -### PubKey -PubKey defines a secp256r1 ECDSA public key. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `key` | [bytes](#bytes) | | Point on secp256r1 curve in a compressed representation as specified in section 4.3.6 of ANSI X9.62: https://webstore.ansi.org/standards/ascx9/ansix9621998 | - - - - - - - - - - - - - - -

Top

@@ -1285,10 +1104,7 @@ type for additional functionality (e.g. vesting). | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `address` | [string](#string) | | | -| `ed25519_pub_key` | [cosmos.crypto.ed25519.PubKey](#cosmos.crypto.ed25519.PubKey) | | | -| `secp256k1_pub_key` | [cosmos.crypto.secp256k1.PubKey](#cosmos.crypto.secp256k1.PubKey) | | | -| `secp256r1_pub_key` | [cosmos.crypto.secp256r1.PubKey](#cosmos.crypto.secp256r1.PubKey) | | | -| `multisig_pub_key` | [cosmos.crypto.multisig.LegacyAminoPubKey](#cosmos.crypto.multisig.LegacyAminoPubKey) | | | +| `pub_key` | [google.protobuf.Any](#google.protobuf.Any) | | | | `account_number` | [uint64](#uint64) | | | | `sequence` | [uint64](#uint64) | | | @@ -3738,6 +3554,91 @@ Msg defines the bank Msg service. + +

Top

+ +## cosmos/crypto/ed25519/keys.proto + + + + + +### PrivKey +Deprecated: PrivKey defines a ed25519 private key. +NOTE: ed25519 keys must not be used in SDK apps except in a tendermint validator context. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `key` | [bytes](#bytes) | | | + + + + + + + + +### PubKey +PubKey is an ed25519 public key for handling Tendermint keys in SDK. +It's needed for Any serialization and SDK compatibility. +It must not be used in a non Tendermint key context because it doesn't implement +ADR-28. Nevertheless, you will like to use ed25519 in app user level +then you must create a new proto message and follow ADR-28 for Address construction. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `key` | [bytes](#bytes) | | | + + + + + + + + + + + + + + + + +

Top

+ +## cosmos/crypto/multisig/keys.proto + + + + + +### LegacyAminoPubKey +LegacyAminoPubKey specifies a public key type +which nests multiple public keys and a threshold, +it uses legacy amino address rules. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `threshold` | [uint32](#uint32) | | | +| `public_keys` | [google.protobuf.Any](#google.protobuf.Any) | repeated | | + + + + + + + + + + + + + + +

Top

@@ -3780,6 +3681,102 @@ signed and with which modes. + + + + + + + + + + + +

Top

+ +## cosmos/crypto/secp256k1/keys.proto + + + + + +### PrivKey +PrivKey defines a secp256k1 private key. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `key` | [bytes](#bytes) | | | + + + + + + + + +### PubKey +PubKey defines a secp256k1 public key +Key is the compressed form of the pubkey. The first byte depends is a 0x02 byte +if the y-coordinate is the lexicographically largest of the two associated with +the x-coordinate. Otherwise the first byte is a 0x03. +This prefix is followed with the x-coordinate. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `key` | [bytes](#bytes) | | | + + + + + + + + + + + + + + + + +

Top

+ +## cosmos/crypto/secp256r1/keys.proto +Since: cosmos-sdk 0.43 + + + + +### PrivKey +PrivKey defines a secp256r1 ECDSA private key. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `secret` | [bytes](#bytes) | | secret number serialized using big-endian encoding | + + + + + + + + +### PubKey +PubKey defines a secp256r1 ECDSA public key. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `key` | [bytes](#bytes) | | Point on secp256r1 curve in a compressed representation as specified in section 4.3.6 of ANSI X9.62: https://webstore.ansi.org/standards/ascx9/ansix9621998 | + + + + + diff --git a/proto/cosmos/auth/v1beta1/auth.proto b/proto/cosmos/auth/v1beta1/auth.proto index b20433d136..bf86fef41b 100644 --- a/proto/cosmos/auth/v1beta1/auth.proto +++ b/proto/cosmos/auth/v1beta1/auth.proto @@ -1,12 +1,9 @@ syntax = "proto3"; package cosmos.auth.v1beta1; -import "cosmos/crypto/ed25519/keys.proto"; -import "cosmos/crypto/multisig/keys.proto"; -import "cosmos/crypto/secp256k1/keys.proto"; -import "cosmos/crypto/secp256r1/keys.proto"; import "cosmos_proto/cosmos.proto"; import "gogoproto/gogo.proto"; +import "google/protobuf/any.proto"; option go_package = "github.com/line/lbm-sdk/x/auth/types"; @@ -20,17 +17,11 @@ message BaseAccount { option (cosmos_proto.implements_interface) = "AccountI"; - string address = 1; - cosmos.crypto.ed25519.PubKey ed25519_pub_key = 2 - [(gogoproto.jsontag) = "ed25519_public_key,omitempty", (gogoproto.moretags) = "yaml:\"ed25519_public_key\""]; - cosmos.crypto.secp256k1.PubKey secp256k1_pub_key = 3 - [(gogoproto.jsontag) = "secp256k1_public_key,omitempty", (gogoproto.moretags) = "yaml:\"secp256k1_public_key\""]; - cosmos.crypto.secp256r1.PubKey secp256r1_pub_key = 4 - [(gogoproto.jsontag) = "secp256r1_public_key,omitempty", (gogoproto.moretags) = "yaml:\"secp256r1_public_key\""]; - cosmos.crypto.multisig.LegacyAminoPubKey multisig_pub_key = 5 - [(gogoproto.jsontag) = "multisig_public_key,omitempty", (gogoproto.moretags) = "yaml:\"multisig_public_key\""]; - uint64 account_number = 6 [(gogoproto.moretags) = "yaml:\"account_number\""]; - uint64 sequence = 7; + string address = 1; + google.protobuf.Any pub_key = 2 + [(gogoproto.jsontag) = "public_key,omitempty", (gogoproto.moretags) = "yaml:\"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. diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 9e7d034f61..cad4379cbe 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -226,13 +226,14 @@ func (ak AccountKeeper) decodeAccount(bz []byte) types.AccountI { // MarshalAccount protobuf serializes an Account interface func (ak AccountKeeper) MarshalAccount(accountI types.AccountI) ([]byte, error) { // nolint:interfacer - return types.MarshalAccountX(ak.cdc, accountI) + return ak.cdc.MarshalInterface(accountI) } // UnmarshalAccount returns an Account interface from raw encoded account // bytes of a Proto-based Account type func (ak AccountKeeper) UnmarshalAccount(bz []byte) (types.AccountI, error) { - return types.UnmarshalAccountX(ak.cdc, bz) + var acc types.AccountI + return acc, ak.cdc.UnmarshalInterface(bz, &acc) } // GetCodec return codec.Codec object used by the keeper diff --git a/x/auth/types/account.go b/x/auth/types/account.go index 5f520d4178..e7940112e7 100644 --- a/x/auth/types/account.go +++ b/x/auth/types/account.go @@ -1,24 +1,17 @@ package types import ( - "bytes" "encoding/json" "errors" "fmt" - "strconv" "strings" - "github.com/gogo/protobuf/jsonpb" "github.com/gogo/protobuf/proto" "github.com/line/ostracon/crypto" "gopkg.in/yaml.v2" "github.com/line/lbm-sdk/codec" codectypes "github.com/line/lbm-sdk/codec/types" - "github.com/line/lbm-sdk/crypto/keys/ed25519" - "github.com/line/lbm-sdk/crypto/keys/multisig" - "github.com/line/lbm-sdk/crypto/keys/secp256k1" - "github.com/line/lbm-sdk/crypto/keys/secp256r1" cryptotypes "github.com/line/lbm-sdk/crypto/types" sdk "github.com/line/lbm-sdk/types" ) @@ -29,14 +22,6 @@ var ( _ codectypes.UnpackInterfacesMessage = (*BaseAccount)(nil) _ GenesisAccount = (*ModuleAccount)(nil) _ ModuleAccountI = (*ModuleAccount)(nil) - - BaseAccountSig = []byte("bacc") - ModuleAccountSig = []byte("macc") - - PubKeyTypeSecp256k1 = byte(1) - PubKeyTypeSecp256R1 = byte(2) - PubKeyTypeEd25519 = byte(3) - PubKeyTypeMultisig = byte(4) ) // NewBaseAccount creates a new BaseAccount object @@ -86,34 +71,27 @@ func (acc *BaseAccount) SetAddress(addr sdk.AccAddress) error { // GetPubKey - Implements sdk.AccountI. func (acc BaseAccount) GetPubKey() (pk cryptotypes.PubKey) { - if acc.Ed25519PubKey != nil { - return acc.Ed25519PubKey - } else if acc.Secp256K1PubKey != nil { - return acc.Secp256K1PubKey - } else if acc.Secp256R1PubKey != nil { - return acc.Secp256R1PubKey - } else if acc.MultisigPubKey != nil { - return acc.MultisigPubKey + if acc.PubKey == nil { + return nil } - return nil + content, ok := acc.PubKey.GetCachedValue().(cryptotypes.PubKey) + if !ok { + return nil + } + return content } // SetPubKey - Implements sdk.AccountI. func (acc *BaseAccount) SetPubKey(pubKey cryptotypes.PubKey) error { if pubKey == nil { - acc.Ed25519PubKey, acc.Secp256K1PubKey, acc.Secp256R1PubKey, acc.MultisigPubKey = nil, nil, nil, nil - } else if pk, ok := pubKey.(*ed25519.PubKey); ok { - acc.Ed25519PubKey, acc.Secp256K1PubKey, acc.Secp256R1PubKey, acc.MultisigPubKey = pk, nil, nil, nil - } else if pk, ok := pubKey.(*secp256k1.PubKey); ok { - acc.Ed25519PubKey, acc.Secp256K1PubKey, acc.Secp256R1PubKey, acc.MultisigPubKey = nil, pk, nil, nil - } else if pk, ok := pubKey.(*secp256r1.PubKey); ok { - acc.Ed25519PubKey, acc.Secp256K1PubKey, acc.Secp256R1PubKey, acc.MultisigPubKey = nil, nil, pk, nil - } else if pk, ok := pubKey.(*multisig.LegacyAminoPubKey); ok { - acc.Ed25519PubKey, acc.Secp256K1PubKey, acc.Secp256R1PubKey, acc.MultisigPubKey = nil, nil, nil, pk - } else { - return fmt.Errorf("invalid pubkey") + acc.PubKey = nil + return nil } - return nil + any, err := codectypes.NewAnyWithValue(pubKey) + if err == nil { + acc.PubKey = any + } + return err } // GetAccountNumber - Implements AccountI @@ -140,7 +118,7 @@ func (acc *BaseAccount) SetSequence(seq uint64) error { // Validate checks for errors on the account fields func (acc BaseAccount) Validate() error { - if acc.Address == "" || acc.GetPubKey() == nil { + if acc.Address == "" || acc.PubKey == nil { return nil } @@ -167,22 +145,11 @@ func (acc BaseAccount) MarshalYAML() (interface{}, error) { // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (acc BaseAccount) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { - if acc.MultisigPubKey != nil { - return codectypes.UnpackInterfaces(acc.MultisigPubKey, unpacker) - } - return nil -} - -func (acc *BaseAccount) MarshalX() ([]byte, error) { - bz, err := acc.Marshal() - if err != nil { - return nil, err + if acc.PubKey == nil { + return nil } - t := BaseAccountSig - b := make([]byte, len(t)+len(bz)) - copy(b, t) - copy(b[len(t):], bz) - return b, nil + var pubKey cryptotypes.PubKey + return unpacker.UnpackAny(acc.PubKey, &pubKey) } // NewModuleAddress creates an AccAddress from the hash of the module's name @@ -257,18 +224,6 @@ func (ma ModuleAccount) Validate() error { return ma.BaseAccount.Validate() } -func (ma *ModuleAccount) MarshalX() ([]byte, error) { - bz, err := ma.Marshal() - if err != nil { - return nil, err - } - t := ModuleAccountSig - b := make([]byte, len(t)+len(bz)) - copy(b, t) - copy(b[len(t):], bz) - return b, nil -} - type moduleAccountPretty struct { Address sdk.AccAddress `json:"address" yaml:"address"` PubKey string `json:"public_key" yaml:"public_key"` @@ -359,41 +314,6 @@ type AccountI interface { // Ensure that account implements stringer String() string - - MarshalX() ([]byte, error) -} - -func MarshalAccountX(cdc codec.BinaryCodec, acc AccountI) ([]byte, error) { - if bacc, ok := acc.(*BaseAccount); ok && bacc.MultisigPubKey == nil { - return acc.MarshalX() - } else if macc, ok := acc.(*ModuleAccount); ok && macc.MultisigPubKey == nil { - return acc.MarshalX() - } else { - return cdc.MarshalInterface(acc) - } -} - -func UnmarshalAccountX(cdc codec.BinaryCodec, bz []byte) (AccountI, error) { - sigLen := len(BaseAccountSig) - if len(bz) < sigLen { - return nil, fmt.Errorf("invalid data") - } - if bytes.Equal(bz[:sigLen], BaseAccountSig) { - acc := &BaseAccount{} - if err := acc.Unmarshal(bz[sigLen:]); err != nil { - return nil, err - } - return acc, nil - } else if bytes.Equal(bz[:sigLen], ModuleAccountSig) { - acc := &ModuleAccount{} - if err := acc.Unmarshal(bz[sigLen:]); err != nil { - return nil, err - } - return acc, nil - } else { - var acc AccountI - return acc, cdc.UnmarshalInterface(bz, &acc) - } } // ModuleAccountI defines an account interface for modules that hold tokens in @@ -427,135 +347,3 @@ type GenesisAccount interface { Validate() error } - -// custom json marshaler for BaseAccount & ModuleAccount - -type PubKeyJSON struct { - Type byte `json:"type"` - Key []byte `json:"key"` -} - -type BaseAccountJSON struct { - Address string `json:"address"` - PubKey PubKeyJSON `json:"pub_key"` - AccountNumber uint64 `json:"account_number,string"` - Sequence string `json:"sequence"` -} - -func (acc BaseAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) { - var bi BaseAccountJSON - - bi.Address = acc.GetAddress().String() - bi.AccountNumber = acc.GetAccountNumber() - bi.Sequence = strconv.FormatUint(acc.Sequence, 10) - var bz []byte - var err error - if acc.Secp256K1PubKey != nil { - bi.PubKey.Type = PubKeyTypeSecp256k1 - bz, err = acc.Secp256K1PubKey.Marshal() - } else if acc.Secp256R1PubKey != nil { - bi.PubKey.Type = PubKeyTypeSecp256R1 - bz, err = acc.Secp256R1PubKey.Marshal() - } else if acc.Ed25519PubKey != nil { - bi.PubKey.Type = PubKeyTypeEd25519 - bz, err = acc.Ed25519PubKey.Marshal() - } else if acc.MultisigPubKey != nil { - bi.PubKey.Type = PubKeyTypeMultisig - bz, err = acc.MultisigPubKey.Marshal() - } - if err != nil { - return nil, err - } - bi.PubKey.Key = bz - return json.Marshal(bi) -} - -func (acc *BaseAccount) UnmarshalJSONPB(m *jsonpb.Unmarshaler, bz []byte) error { - var bi BaseAccountJSON - - err := json.Unmarshal(bz, &bi) - if err != nil { - return err - } - /* TODO: do we need to validate address format here - err = sdk.ValidateAccAddress(bi.Address) - if err != nil { - return err - } - */ - - acc.Address = bi.Address - acc.AccountNumber = bi.AccountNumber - acc.Sequence, err = strconv.ParseUint(bi.Sequence, 10, 64) - if err != nil { - return err - } - - switch bi.PubKey.Type { - case PubKeyTypeEd25519: - pk := new(ed25519.PubKey) - if err := pk.Unmarshal(bi.PubKey.Key); err != nil { - return err - } - acc.SetPubKey(pk) - case PubKeyTypeSecp256k1: - pk := new(secp256k1.PubKey) - if err := pk.Unmarshal(bi.PubKey.Key); err != nil { - return err - } - acc.SetPubKey(pk) - case PubKeyTypeSecp256R1: - pk := new(secp256r1.PubKey) - if err := pk.Unmarshal(bi.PubKey.Key); err != nil { - return err - } - acc.SetPubKey(pk) - case PubKeyTypeMultisig: - pk := new(multisig.LegacyAminoPubKey) - if err := pk.Unmarshal(bi.PubKey.Key); err != nil { - return err - } - acc.SetPubKey(pk) - } - return nil -} - -type ModuleAccountJSON struct { - BaseAccount json.RawMessage `json:"base_account"` - Name string `json:"name"` - Permissions []string `json:"permissions"` -} - -func (ma ModuleAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) { - var mi ModuleAccountJSON - - bz, err := ma.BaseAccount.MarshalJSONPB(m) - if err != nil { - return nil, err - } - mi.BaseAccount = bz - mi.Name = ma.Name - mi.Permissions = ma.Permissions - - return json.Marshal(mi) -} - -func (ma *ModuleAccount) UnmarshalJSONPB(m *jsonpb.Unmarshaler, bz []byte) error { - var mi ModuleAccountJSON - - err := json.Unmarshal(bz, &mi) - if err != nil { - return err - } - - ma.Name = mi.Name - ma.Permissions = mi.Permissions - - ba := new(BaseAccount) - if err := m.Unmarshal(strings.NewReader(string(mi.BaseAccount)), ba); err != nil { - return err - } - ma.BaseAccount = ba - - return nil -} diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index 1037621f44..745ecf8f4b 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -4,10 +4,9 @@ import ( "encoding/json" "errors" "fmt" - "strings" + cryptotypes "github.com/line/lbm-sdk/crypto/types" "testing" - "github.com/gogo/protobuf/jsonpb" "github.com/stretchr/testify/require" yaml "gopkg.in/yaml.v2" @@ -55,6 +54,7 @@ func TestBaseAddressPubKey(t *testing.T) { func TestBaseAccountMarshalUnmarshalJSON(t *testing.T) { interfaceRegistry := types2.NewInterfaceRegistry() + interfaceRegistry.RegisterImplementations((*cryptotypes.PubKey)(nil), &secp256k1.PubKey{}) cdc := codec.NewProtoCodec(interfaceRegistry) _, pub, addr := testdata.KeyTestPubAddr() @@ -65,7 +65,11 @@ func TestBaseAccountMarshalUnmarshalJSON(t *testing.T) { var acc2 types.BaseAccount cdc.MustUnmarshalJSON(bz, &acc2) - require.Equal(t, acc, &acc2) + require.Equal(t, acc.AccountNumber, acc2.AccountNumber) + require.Equal(t, acc.PubKey.TypeUrl, acc2.PubKey.TypeUrl) + require.Equal(t, acc.PubKey.Value, acc2.PubKey.Value) + require.Equal(t, acc.Address, acc2.Address) + require.Equal(t, acc.Sequence, acc2.Sequence) } func TestBaseSequence(t *testing.T) { @@ -216,37 +220,6 @@ func TestModuleAccountJSON(t *testing.T) { require.Equal(t, acc.String(), a.String()) } -func TestModuleAccountJSONPB(t *testing.T) { - pubkey := secp256k1.GenPrivKey().PubKey() - addr := sdk.BytesToAccAddress(pubkey.Address()) - baseAcc := types.NewBaseAccount(addr, nil, 10, 50) - acc := types.NewModuleAccount(baseAcc, "test", types.Burner) - - jm := jsonpb.Marshaler{} - bz, err := acc.MarshalJSONPB(&jm) - require.NoError(t, err) - - jum := jsonpb.Unmarshaler{} - addr2 := sdk.AccAddress("") - baseAcc2 := types.NewBaseAccount(addr2, nil, 0, 0) - acc2 := types.NewModuleAccount(baseAcc2, "") - err = acc2.UnmarshalJSONPB(&jum, bz) - require.NoError(t, err) - - // error on bad bytes - err = acc2.UnmarshalJSONPB(&jum, bz[:len(bz)/2]) - require.Error(t, err) -} - -func TestBaseAccountJSONPB(t *testing.T) { - baseAccountJson := `{"address":"link1rrfywnytlm87ywes0hvxn4rhm4grrn9qquqljc","pub_key":{"type":0,"key":null},"account_number":"10","sequence":"50"}` - ba := new(types.BaseAccount) - jum := jsonpb.Unmarshaler{} - err := jum.Unmarshal(strings.NewReader(baseAccountJson), ba) - require.NoError(t, err) - require.Equal(t, ba.AccountNumber, uint64(10)) -} - func TestGenesisAccountsContains(t *testing.T) { pubkey := secp256k1.GenPrivKey().PubKey() addr := sdk.BytesToAccAddress(pubkey.Address()) diff --git a/x/auth/types/auth.pb.go b/x/auth/types/auth.pb.go index 966f0dd776..f785fe91cd 100644 --- a/x/auth/types/auth.pb.go +++ b/x/auth/types/auth.pb.go @@ -7,10 +7,7 @@ import ( fmt "fmt" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" - ed25519 "github.com/line/lbm-sdk/crypto/keys/ed25519" - multisig "github.com/line/lbm-sdk/crypto/keys/multisig" - secp256k1 "github.com/line/lbm-sdk/crypto/keys/secp256k1" - secp256r1 "github.com/line/lbm-sdk/crypto/keys/secp256r1" + types "github.com/line/lbm-sdk/codec/types" _ "github.com/regen-network/cosmos-proto" io "io" math "math" @@ -32,13 +29,10 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // for basic account functionality. Any custom account type should extend this // type for additional functionality (e.g. vesting). type BaseAccount struct { - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - Ed25519PubKey *ed25519.PubKey `protobuf:"bytes,2,opt,name=ed25519_pub_key,json=ed25519PubKey,proto3" json:"ed25519_public_key,omitempty" yaml:"ed25519_public_key"` - Secp256K1PubKey *secp256k1.PubKey `protobuf:"bytes,3,opt,name=secp256k1_pub_key,json=secp256k1PubKey,proto3" json:"secp256k1_public_key,omitempty" yaml:"secp256k1_public_key"` - Secp256R1PubKey *secp256r1.PubKey `protobuf:"bytes,4,opt,name=secp256r1_pub_key,json=secp256r1PubKey,proto3" json:"secp256r1_public_key,omitempty" yaml:"secp256r1_public_key"` - MultisigPubKey *multisig.LegacyAminoPubKey `protobuf:"bytes,5,opt,name=multisig_pub_key,json=multisigPubKey,proto3" json:"multisig_public_key,omitempty" yaml:"multisig_public_key"` - AccountNumber uint64 `protobuf:"varint,6,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty" yaml:"account_number"` - Sequence uint64 `protobuf:"varint,7,opt,name=sequence,proto3" json:"sequence,omitempty"` + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + PubKey *types.Any `protobuf:"bytes,2,opt,name=pub_key,json=pubKey,proto3" json:"public_key,omitempty" yaml:"public_key"` + AccountNumber uint64 `protobuf:"varint,3,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty" yaml:"account_number"` + Sequence uint64 `protobuf:"varint,4,opt,name=sequence,proto3" json:"sequence,omitempty"` } func (m *BaseAccount) Reset() { *m = BaseAccount{} } @@ -197,58 +191,49 @@ func init() { func init() { proto.RegisterFile("cosmos/auth/v1beta1/auth.proto", fileDescriptor_7e1f7e915d020d2d) } var fileDescriptor_7e1f7e915d020d2d = []byte{ - // 817 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x95, 0x41, 0x6f, 0xdc, 0x44, - 0x14, 0xc7, 0xd7, 0xc4, 0x4d, 0x93, 0xd9, 0x26, 0x25, 0x4e, 0xda, 0x6e, 0xb6, 0xad, 0xc7, 0x58, - 0x1c, 0x82, 0x44, 0x6c, 0x25, 0x28, 0x48, 0x5d, 0x89, 0x42, 0x5c, 0x38, 0x54, 0xb4, 0x55, 0xe4, - 0x48, 0x1c, 0xb8, 0x18, 0xdb, 0x3b, 0x6c, 0xac, 0xec, 0xec, 0xb8, 0x33, 0xe3, 0x6a, 0xdd, 0x33, - 0x07, 0x4e, 0x88, 0x03, 0x07, 0x8e, 0xf9, 0x10, 0xfd, 0x06, 0x5c, 0x38, 0x46, 0x3d, 0x71, 0x72, - 0xd1, 0xe6, 0x82, 0x72, 0xdc, 0x4f, 0x80, 0x3c, 0x63, 0x3b, 0xf6, 0xc6, 0x82, 0xde, 0xfc, 0xde, - 0xfb, 0xbf, 0x37, 0xbf, 0x59, 0xbf, 0xbf, 0x17, 0xe8, 0x21, 0x61, 0x98, 0x30, 0xdb, 0x4f, 0xf8, - 0x89, 0xfd, 0x6a, 0x2f, 0x40, 0xdc, 0xdf, 0x13, 0x81, 0x15, 0x53, 0xc2, 0x89, 0xb6, 0x29, 0xeb, - 0x96, 0x48, 0x15, 0xf5, 0xbe, 0x51, 0x34, 0x85, 0x34, 0x8d, 0x39, 0xb1, 0xd1, 0x70, 0xff, 0xe0, - 0x60, 0xef, 0x91, 0x7d, 0x8a, 0x52, 0x26, 0xdb, 0xfa, 0x1f, 0x35, 0x15, 0x38, 0x19, 0xf3, 0x88, - 0x45, 0xa3, 0xba, 0xc4, 0x6c, 0x4a, 0x18, 0x0a, 0xe3, 0xfd, 0x83, 0xcf, 0x4f, 0xf7, 0xfe, 0x5f, - 0x43, 0x1b, 0x9a, 0x6d, 0xa9, 0xf1, 0x44, 0x64, 0x17, 0xb8, 0xb2, 0xb4, 0x35, 0x22, 0x23, 0x22, - 0xf3, 0xf9, 0x93, 0xcc, 0x9a, 0xef, 0x6e, 0x80, 0xae, 0xe3, 0x33, 0x74, 0x18, 0x86, 0x24, 0x99, - 0x70, 0xad, 0x07, 0x6e, 0xfa, 0xc3, 0x21, 0x45, 0x8c, 0xf5, 0x14, 0x43, 0xd9, 0x59, 0x75, 0xcb, - 0x50, 0xfb, 0x49, 0x01, 0xb7, 0x8b, 0xcb, 0x79, 0x71, 0x12, 0x78, 0xa7, 0x28, 0xed, 0x7d, 0x60, - 0x28, 0x3b, 0xdd, 0xfd, 0x87, 0x56, 0x71, 0x90, 0x24, 0xb3, 0x0a, 0x95, 0x75, 0x94, 0x04, 0xdf, - 0xa2, 0xd4, 0xf9, 0xe2, 0x32, 0x83, 0x0f, 0x6a, 0x9d, 0xe3, 0x28, 0xcc, 0x9b, 0x3f, 0x25, 0x38, - 0xe2, 0x08, 0xc7, 0x3c, 0x9d, 0x67, 0x70, 0x3b, 0xf5, 0xf1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0x4c, 0xd5, 0x71, 0x5a, + 0x4c, 0x41, 0xf5, 0x61, 0x05, 0x81, 0x5e, 0xd4, 0xda, 0x7a, 0x79, 0xd6, 0x94, 0x1e, 0xb3, 0xa6, + 0x3b, 0xfd, 0x4c, 0xd9, 0x98, 0x6a, 0x7a, 0x3c, 0x72, 0x0c, 0x32, 0x45, 0x9d, 0xdd, 0x76, 0x1c, + 0xa2, 0x59, 0x1b, 0x64, 0x66, 0x6d, 0x7b, 0x21, 0xff, 0xcd, 0x0a, 0xe6, 0xce, 0xf7, 0xbe, 0x2c, + 0xdc, 0xf4, 0x65, 0xe1, 0x57, 0x5f, 0x16, 0xbe, 0xdc, 0xc9, 0x85, 0x9b, 0x3b, 0xb9, 0xf0, 0xe3, + 0x4e, 0x2e, 0x7c, 0x78, 0xe6, 0x07, 0xf4, 0x34, 0x71, 0x75, 0x0f, 0x23, 0xa3, 0x1b, 0x84, 0xd0, + 0xe8, 0xba, 0xa8, 0x41, 0x3a, 0x67, 0x46, 0x8f, 0x7f, 0x55, 0x68, 0x1a, 0x41, 0xe2, 0xce, 0xb1, + 0x3f, 0xe9, 0x8b, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xd1, 0xd1, 0xcd, 0x72, 0x71, 0x04, 0x00, 0x00, } @@ -311,52 +296,16 @@ func (m *BaseAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { if m.Sequence != 0 { i = encodeVarintAuth(dAtA, i, uint64(m.Sequence)) i-- - dAtA[i] = 0x38 + dAtA[i] = 0x20 } if m.AccountNumber != 0 { i = encodeVarintAuth(dAtA, i, uint64(m.AccountNumber)) i-- - dAtA[i] = 0x30 - } - if m.MultisigPubKey != nil { - { - size, err := m.MultisigPubKey.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintAuth(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x2a - } - if m.Secp256R1PubKey != nil { - { - size, err := m.Secp256R1PubKey.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintAuth(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - if m.Secp256K1PubKey != nil { - { - size, err := m.Secp256K1PubKey.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintAuth(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a + dAtA[i] = 0x18 } - if m.Ed25519PubKey != nil { + if m.PubKey != nil { { - size, err := m.Ed25519PubKey.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.PubKey.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -496,20 +445,8 @@ func (m *BaseAccount) Size() (n int) { if l > 0 { n += 1 + l + sovAuth(uint64(l)) } - if m.Ed25519PubKey != nil { - l = m.Ed25519PubKey.Size() - n += 1 + l + sovAuth(uint64(l)) - } - if m.Secp256K1PubKey != nil { - l = m.Secp256K1PubKey.Size() - n += 1 + l + sovAuth(uint64(l)) - } - if m.Secp256R1PubKey != nil { - l = m.Secp256R1PubKey.Size() - n += 1 + l + sovAuth(uint64(l)) - } - if m.MultisigPubKey != nil { - l = m.MultisigPubKey.Size() + if m.PubKey != nil { + l = m.PubKey.Size() n += 1 + l + sovAuth(uint64(l)) } if m.AccountNumber != 0 { @@ -637,7 +574,7 @@ func (m *BaseAccount) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Ed25519PubKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field PubKey", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -664,122 +601,14 @@ func (m *BaseAccount) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Ed25519PubKey == nil { - m.Ed25519PubKey = &ed25519.PubKey{} + if m.PubKey == nil { + m.PubKey = &types.Any{} } - if err := m.Ed25519PubKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.PubKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Secp256K1PubKey", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthAuth - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Secp256K1PubKey == nil { - m.Secp256K1PubKey = &secp256k1.PubKey{} - } - if err := m.Secp256K1PubKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Secp256R1PubKey", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthAuth - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Secp256R1PubKey == nil { - m.Secp256R1PubKey = &secp256r1.PubKey{} - } - if err := m.Secp256R1PubKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MultisigPubKey", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAuth - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthAuth - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthAuth - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.MultisigPubKey == nil { - m.MultisigPubKey = &multisig.LegacyAminoPubKey{} - } - if err := m.MultisigPubKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 6: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field AccountNumber", wireType) } @@ -798,7 +627,7 @@ func (m *BaseAccount) Unmarshal(dAtA []byte) error { break } } - case 7: + case 4: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) } diff --git a/x/auth/vesting/types/vesting_account.go b/x/auth/vesting/types/vesting_account.go index cb3f28bd8c..bf5648b4c2 100644 --- a/x/auth/vesting/types/vesting_account.go +++ b/x/auth/vesting/types/vesting_account.go @@ -1,11 +1,9 @@ package types import ( - "encoding/json" "errors" "time" - "github.com/gogo/protobuf/jsonpb" yaml "gopkg.in/yaml.v2" cryptotypes "github.com/line/lbm-sdk/crypto/types" @@ -198,54 +196,6 @@ func (bva BaseVestingAccount) MarshalYAML() (interface{}, error) { return marshalYaml(out) } -type vestingAccountJSON struct { - BaseAccount json.RawMessage `json:"base_account"` - OriginalVesting sdk.Coins `json:"original_vesting"` - DelegatedFree sdk.Coins `json:"delegated_free"` - DelegatedVesting sdk.Coins `json:"delegated_vesting"` - EndTime int64 `json:"end_time"` - - StartTime int64 `json:"start_time,omitempty"` - VestingPeriods Periods `json:"vesting_periods,omitempty"` -} - -func (bva BaseVestingAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) { - bz, err := bva.BaseAccount.MarshalJSONPB(m) - if err != nil { - return nil, err - } - alias := vestingAccountJSON{ - BaseAccount: bz, - OriginalVesting: bva.OriginalVesting, - DelegatedFree: bva.DelegatedFree, - DelegatedVesting: bva.DelegatedVesting, - EndTime: bva.EndTime, - } - - return json.Marshal(alias) -} - -func (bva *BaseVestingAccount) UnmarshalJSONPB(m *jsonpb.Unmarshaler, bz []byte) error { - var va vestingAccountJSON - - err := json.Unmarshal(bz, &va) - if err != nil { - return err - } - - var ba authtypes.BaseAccount - if err := (&ba).UnmarshalJSONPB(m, va.BaseAccount); err != nil { - return err - } - bva.BaseAccount = &ba - bva.OriginalVesting = va.OriginalVesting - bva.DelegatedFree = va.DelegatedFree - bva.DelegatedVesting = va.DelegatedVesting - bva.EndTime = va.EndTime - - return nil -} - // Continuous Vesting Account var _ vestexported.VestingAccount = (*ContinuousVestingAccount)(nil) @@ -355,45 +305,6 @@ func (cva ContinuousVestingAccount) MarshalYAML() (interface{}, error) { return marshalYaml(out) } -func (cva ContinuousVestingAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) { - bz, err := cva.BaseVestingAccount.BaseAccount.MarshalJSONPB(m) - if err != nil { - return nil, err - } - alias := vestingAccountJSON{ - BaseAccount: bz, - OriginalVesting: cva.BaseVestingAccount.OriginalVesting, - DelegatedFree: cva.BaseVestingAccount.DelegatedFree, - DelegatedVesting: cva.BaseVestingAccount.DelegatedVesting, - EndTime: cva.BaseVestingAccount.EndTime, - StartTime: cva.StartTime, - } - return json.Marshal(alias) -} - -func (cva *ContinuousVestingAccount) UnmarshalJSONPB(m *jsonpb.Unmarshaler, bz []byte) error { - var va vestingAccountJSON - - err := json.Unmarshal(bz, &va) - if err != nil { - return err - } - - var ba authtypes.BaseAccount - if err := (&ba).UnmarshalJSONPB(m, va.BaseAccount); err != nil { - return err - } - cva.BaseVestingAccount = &BaseVestingAccount{ - BaseAccount: &ba, - OriginalVesting: va.OriginalVesting, - DelegatedFree: va.DelegatedFree, - DelegatedVesting: va.DelegatedVesting, - EndTime: va.EndTime, - } - cva.StartTime = va.StartTime - return nil -} - // Periodic Vesting Account var _ vestexported.VestingAccount = (*PeriodicVestingAccount)(nil) @@ -533,49 +444,6 @@ func (pva PeriodicVestingAccount) MarshalYAML() (interface{}, error) { return marshalYaml(out) } -func (pva PeriodicVestingAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) { - bz, err := pva.BaseVestingAccount.BaseAccount.MarshalJSONPB(m) - if err != nil { - return nil, err - } - alias := vestingAccountJSON{ - BaseAccount: bz, - OriginalVesting: pva.BaseVestingAccount.OriginalVesting, - DelegatedFree: pva.BaseVestingAccount.DelegatedFree, - DelegatedVesting: pva.BaseVestingAccount.DelegatedVesting, - EndTime: pva.BaseVestingAccount.EndTime, - StartTime: pva.StartTime, - VestingPeriods: pva.VestingPeriods, - } - - return json.Marshal(alias) -} - -func (pva *PeriodicVestingAccount) UnmarshalJSONPB(m *jsonpb.Unmarshaler, bz []byte) error { - var va vestingAccountJSON - - err := json.Unmarshal(bz, &va) - if err != nil { - return err - } - - var ba authtypes.BaseAccount - if err := (&ba).UnmarshalJSONPB(m, va.BaseAccount); err != nil { - return err - } - pva.BaseVestingAccount = &BaseVestingAccount{ - BaseAccount: &ba, - OriginalVesting: va.OriginalVesting, - DelegatedFree: va.DelegatedFree, - DelegatedVesting: va.DelegatedVesting, - EndTime: va.EndTime, - } - pva.StartTime = va.StartTime - pva.VestingPeriods = va.VestingPeriods - - return nil -} - // Delayed Vesting Account var _ vestexported.VestingAccount = (*DelayedVestingAccount)(nil) @@ -643,45 +511,6 @@ func (dva DelayedVestingAccount) String() string { return out.(string) } -func (dva DelayedVestingAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) { - bz, err := dva.BaseAccount.MarshalJSONPB(m) - if err != nil { - return nil, err - } - alias := vestingAccountJSON{ - BaseAccount: bz, - OriginalVesting: dva.BaseVestingAccount.OriginalVesting, - DelegatedFree: dva.BaseVestingAccount.DelegatedFree, - DelegatedVesting: dva.BaseVestingAccount.DelegatedVesting, - EndTime: dva.BaseVestingAccount.EndTime, - } - - return json.Marshal(alias) -} - -func (dva *DelayedVestingAccount) UnmarshalJSONPB(m *jsonpb.Unmarshaler, bz []byte) error { - var va vestingAccountJSON - - err := json.Unmarshal(bz, &va) - if err != nil { - return err - } - - var ba authtypes.BaseAccount - if err := (&ba).UnmarshalJSONPB(m, va.BaseAccount); err != nil { - return err - } - dva.BaseVestingAccount = &BaseVestingAccount{ - BaseAccount: &ba, - OriginalVesting: va.OriginalVesting, - DelegatedFree: va.DelegatedFree, - DelegatedVesting: va.DelegatedVesting, - EndTime: va.EndTime, - } - - return nil -} - //----------------------------------------------------------------------------- // Permanent Locked Vesting Account diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index 273982e167..90e5b5c279 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -4,7 +4,6 @@ import ( "testing" "time" - "github.com/gogo/protobuf/jsonpb" osttime "github.com/line/ostracon/types/time" "github.com/stretchr/testify/require" @@ -804,87 +803,21 @@ func TestPermanentLockedAccountMarshal(t *testing.T) { require.NotNil(t, err) } -func TestBaseVestingAccountMarshalJSONPB(t *testing.T) { +func TestBaseVestingAccountMarshal(t *testing.T) { baseAcc, coins := initBaseAccount() acc := types.NewBaseVestingAccount(baseAcc, coins, time.Now().Unix()) - jm := jsonpb.Marshaler{} - bz, err := acc.MarshalJSONPB(&jm) + bz, err := acc.Marshal() require.NoError(t, err) - jum := jsonpb.Unmarshaler{} acc2 := types.NewBaseVestingAccount(nil, sdk.NewCoins(), 0) - err = acc2.UnmarshalJSONPB(&jum, bz) + err = acc2.Unmarshal(bz) require.NoError(t, err) require.IsType(t, &types.BaseVestingAccount{}, acc2) require.Equal(t, acc.String(), acc2.String()) // error on bad bytes - err = acc2.UnmarshalJSONPB(&jum, bz[:len(bz)/2]) - require.Error(t, err) -} - -func TestContinuousVestingAccountMarshalJSONPB(t *testing.T) { - baseAcc, coins := initBaseAccount() - baseVesting := types.NewBaseVestingAccount(baseAcc, coins, time.Now().Unix()) - acc := types.NewContinuousVestingAccountRaw(baseVesting, baseVesting.EndTime) - - jm := jsonpb.Marshaler{} - bz, err := acc.MarshalJSONPB(&jm) - require.NoError(t, err) - - jum := jsonpb.Unmarshaler{} - baseVesting2 := types.NewBaseVestingAccount(nil, sdk.NewCoins(), 0) - acc2 := types.NewContinuousVestingAccountRaw(baseVesting2, baseVesting2.EndTime) - err = acc2.UnmarshalJSONPB(&jum, bz) - require.NoError(t, err) - require.IsType(t, &types.ContinuousVestingAccount{}, acc2) - require.Equal(t, acc.String(), acc2.String()) - - // error on bad bytes - err = acc2.UnmarshalJSONPB(&jum, bz[:len(bz)/2]) - require.Error(t, err) -} - -func TestPeriodicVestingAccountMarshalJSONPB(t *testing.T) { - baseAcc, coins := initBaseAccount() - baseVesting := types.NewBaseVestingAccount(baseAcc, coins, time.Now().Unix()) - acc := types.NewPeriodicVestingAccountRaw(baseVesting, baseVesting.EndTime, types.Periods{types.Period{3600, coins}}) - - jm := jsonpb.Marshaler{} - bz, err := acc.MarshalJSONPB(&jm) - require.NoError(t, err) - - jum := jsonpb.Unmarshaler{} - baseVesting2 := types.NewBaseVestingAccount(nil, sdk.NewCoins(), 0) - acc2 := types.NewPeriodicVestingAccountRaw(baseVesting2, baseVesting2.EndTime, types.Periods{}) - err = acc2.UnmarshalJSONPB(&jum, bz) - require.NoError(t, err) - require.IsType(t, &types.PeriodicVestingAccount{}, acc2) - require.Equal(t, acc.String(), acc2.String()) - - // error on bad bytes - err = acc2.UnmarshalJSONPB(&jum, bz[:len(bz)/2]) - require.Error(t, err) -} - -func TestDelayedVestingAccountMarshalJSONPB(t *testing.T) { - baseAcc, coins := initBaseAccount() - acc := types.NewDelayedVestingAccount(baseAcc, coins, time.Now().Unix()) - - jm := jsonpb.Marshaler{} - bz, err := acc.MarshalJSONPB(&jm) - require.NoError(t, err) - - jum := jsonpb.Unmarshaler{} - acc2 := types.NewDelayedVestingAccount(nil, sdk.NewCoins(), 0) - err = acc2.UnmarshalJSONPB(&jum, bz) - require.NoError(t, err) - require.IsType(t, &types.DelayedVestingAccount{}, acc2) - require.Equal(t, acc.String(), acc2.String()) - - // error on bad bytes - err = acc2.UnmarshalJSONPB(&jum, bz[:len(bz)/2]) + err = acc2.Unmarshal(bz[:len(bz)/2]) require.Error(t, err) } diff --git a/x/wasm/keeper/keeper_test.go b/x/wasm/keeper/keeper_test.go index 5b2d78f271..5d2511c532 100644 --- a/x/wasm/keeper/keeper_test.go +++ b/x/wasm/keeper/keeper_test.go @@ -398,7 +398,7 @@ func TestInstantiate(t *testing.T) { gasAfter := ctx.GasMeter().GasConsumed() if types.EnableGasVerification { - require.Equal(t, uint64(0x19aff), gasAfter-gasBefore) + require.Equal(t, uint64(106175), gasAfter-gasBefore) } // ensure it is stored properly @@ -632,7 +632,7 @@ func TestExecute(t *testing.T) { // make sure gas is properly deducted from ctx gasAfter := ctx.GasMeter().GasConsumed() if types.EnableGasVerification { - require.Equal(t, uint64(0x1739a), gasAfter-gasBefore) + require.Equal(t, uint64(96282), gasAfter-gasBefore) } // ensure bob now exists and got both payments released bobAcct = accKeeper.GetAccount(ctx, bob) diff --git a/x/wasm/keeper/submsg_test.go b/x/wasm/keeper/submsg_test.go index e8eb64eaf1..38981a9939 100644 --- a/x/wasm/keeper/submsg_test.go +++ b/x/wasm/keeper/submsg_test.go @@ -247,14 +247,14 @@ func TestDispatchSubMsgErrorHandling(t *testing.T) { "send tokens": { submsgID: 5, msg: validBankSend, - resultAssertions: []assertion{assertReturnedEvents(3), assertGasUsed(113000, 113100)}, + resultAssertions: []assertion{assertReturnedEvents(3), assertGasUsed(113000, 114147)}, }, "not enough tokens": { submsgID: 6, msg: invalidBankSend, subMsgError: true, // uses less gas than the send tokens (cost of bank transfer) - resultAssertions: []assertion{assertGasUsed(76900, 77000), assertErrorString("codespace: sdk, code: 5")}, + resultAssertions: []assertion{assertGasUsed(76900, 77113), assertErrorString("codespace: sdk, code: 5")}, }, "out of gas panic with no gas limit": { submsgID: 7, @@ -267,7 +267,7 @@ func TestDispatchSubMsgErrorHandling(t *testing.T) { msg: validBankSend, gasLimit: &subGasLimit, // uses same gas as call without limit (note we do not charge the 40k on reply) - resultAssertions: []assertion{assertReturnedEvents(3), assertGasUsed(113100, 113200)}, + resultAssertions: []assertion{assertReturnedEvents(3), assertGasUsed(113100, 114249)}, }, "not enough tokens with limit": { submsgID: 16, @@ -275,7 +275,7 @@ func TestDispatchSubMsgErrorHandling(t *testing.T) { subMsgError: true, gasLimit: &subGasLimit, // uses same gas as call without limit (note we do not charge the 40k on reply) - resultAssertions: []assertion{assertGasUsed(77000, 77100), assertErrorString("codespace: sdk, code: 5")}, + resultAssertions: []assertion{assertGasUsed(77000, 77113), assertErrorString("codespace: sdk, code: 5")}, }, "out of gas caught with gas limit": { submsgID: 17, From 9192e9eb6b365991770fef1c63e15d3e44bf9e05 Mon Sep 17 00:00:00 2001 From: TAKAMI Torao Date: Tue, 12 Jul 2022 10:53:35 +0900 Subject: [PATCH 2/4] remove the two test cases that don't exist in the cosmos-sdk --- x/auth/types/account_test.go | 24 -------------------- x/auth/vesting/types/vesting_account_test.go | 18 --------------- 2 files changed, 42 deletions(-) diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index 745ecf8f4b..a86a28be92 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -4,15 +4,11 @@ import ( "encoding/json" "errors" "fmt" - cryptotypes "github.com/line/lbm-sdk/crypto/types" "testing" "github.com/stretchr/testify/require" yaml "gopkg.in/yaml.v2" - "github.com/line/lbm-sdk/codec" - types2 "github.com/line/lbm-sdk/codec/types" - "github.com/line/lbm-sdk/crypto/keys/secp256k1" "github.com/line/lbm-sdk/testutil/testdata" sdk "github.com/line/lbm-sdk/types" @@ -52,26 +48,6 @@ func TestBaseAddressPubKey(t *testing.T) { require.EqualValues(t, addr2, acc2.GetAddress()) } -func TestBaseAccountMarshalUnmarshalJSON(t *testing.T) { - interfaceRegistry := types2.NewInterfaceRegistry() - interfaceRegistry.RegisterImplementations((*cryptotypes.PubKey)(nil), &secp256k1.PubKey{}) - - cdc := codec.NewProtoCodec(interfaceRegistry) - _, pub, addr := testdata.KeyTestPubAddr() - acc := types.NewBaseAccountWithAddress(addr) - acc.SetPubKey(pub) - - bz := cdc.MustMarshalJSON(acc) - var acc2 types.BaseAccount - - cdc.MustUnmarshalJSON(bz, &acc2) - require.Equal(t, acc.AccountNumber, acc2.AccountNumber) - require.Equal(t, acc.PubKey.TypeUrl, acc2.PubKey.TypeUrl) - require.Equal(t, acc.PubKey.Value, acc2.PubKey.Value) - require.Equal(t, acc.Address, acc2.Address) - require.Equal(t, acc.Sequence, acc2.Sequence) -} - func TestBaseSequence(t *testing.T) { _, _, addr := testdata.KeyTestPubAddr() acc := types.NewBaseAccountWithAddress(addr) diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index 90e5b5c279..557213b008 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -803,24 +803,6 @@ func TestPermanentLockedAccountMarshal(t *testing.T) { require.NotNil(t, err) } -func TestBaseVestingAccountMarshal(t *testing.T) { - baseAcc, coins := initBaseAccount() - acc := types.NewBaseVestingAccount(baseAcc, coins, time.Now().Unix()) - - bz, err := acc.Marshal() - require.NoError(t, err) - - acc2 := types.NewBaseVestingAccount(nil, sdk.NewCoins(), 0) - err = acc2.Unmarshal(bz) - require.NoError(t, err) - require.IsType(t, &types.BaseVestingAccount{}, acc2) - require.Equal(t, acc.String(), acc2.String()) - - // error on bad bytes - err = acc2.Unmarshal(bz[:len(bz)/2]) - require.Error(t, err) -} - func initBaseAccount() (*authtypes.BaseAccount, sdk.Coins) { _, _, addr := testdata.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} From fa39cdbfb78a52b054cded4eeb74868406c7c193 Mon Sep 17 00:00:00 2001 From: TAKAMI Torao Date: Tue, 12 Jul 2022 11:13:34 +0900 Subject: [PATCH 3/4] make ProtoBuf format differences as similar to cosmos-sdk as possible --- proto/cosmos/bank/v1beta1/query.proto | 10 +++++----- proto/cosmos/base/snapshots/v1beta1/snapshot.proto | 2 +- proto/cosmos/base/store/v1beta1/snapshot.proto | 2 +- proto/cosmos/evidence/v1beta1/evidence.proto | 2 +- proto/cosmos/gov/v1beta1/gov.proto | 8 ++++---- proto/cosmos/mint/v1beta1/mint.proto | 3 ++- proto/cosmos/slashing/v1beta1/tx.proto | 2 +- proto/cosmos/staking/v1beta1/staking.proto | 5 +++-- proto/cosmos/staking/v1beta1/tx.proto | 6 ++++-- proto/cosmos/tx/v1beta1/service.proto | 2 +- proto/cosmos/vesting/v1beta1/tx.proto | 2 +- 11 files changed, 24 insertions(+), 20 deletions(-) diff --git a/proto/cosmos/bank/v1beta1/query.proto b/proto/cosmos/bank/v1beta1/query.proto index 0b7de93438..013ddd4371 100644 --- a/proto/cosmos/bank/v1beta1/query.proto +++ b/proto/cosmos/bank/v1beta1/query.proto @@ -49,7 +49,7 @@ service Query { // QueryBalanceRequest is the request type for the Query/Balance RPC method. message QueryBalanceRequest { - option (gogoproto.equal) = false; + option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; // address is the address to query balances for. @@ -67,7 +67,7 @@ message QueryBalanceResponse { // QueryBalanceRequest is the request type for the Query/AllBalances RPC method. message QueryAllBalancesRequest { - option (gogoproto.equal) = false; + option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; // address is the address to query balances for. @@ -82,7 +82,7 @@ message QueryAllBalancesRequest { message QueryAllBalancesResponse { // balances is the balances of all the coins. repeated cosmos.base.v1beta1.Coin balances = 1 - [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/line/lbm-sdk/types.Coins"]; + [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/line/lbm-sdk/types.Coins"]; // pagination defines the pagination in the response. cosmos.base.query.v1beta1.PageResponse pagination = 2; @@ -91,7 +91,7 @@ message QueryAllBalancesResponse { // QueryTotalSupplyRequest is the request type for the Query/TotalSupply RPC // method. message QueryTotalSupplyRequest { - option (gogoproto.equal) = false; + option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; // pagination defines an optional pagination for the request. @@ -105,7 +105,7 @@ message QueryTotalSupplyRequest { message QueryTotalSupplyResponse { // supply is the supply of the coins repeated cosmos.base.v1beta1.Coin supply = 1 - [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/line/lbm-sdk/types.Coins"]; + [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/line/lbm-sdk/types.Coins"]; // pagination defines the pagination in the response. // diff --git a/proto/cosmos/base/snapshots/v1beta1/snapshot.proto b/proto/cosmos/base/snapshots/v1beta1/snapshot.proto index 605e19592a..cca4dd67ad 100644 --- a/proto/cosmos/base/snapshots/v1beta1/snapshot.proto +++ b/proto/cosmos/base/snapshots/v1beta1/snapshot.proto @@ -17,4 +17,4 @@ message Snapshot { // Metadata contains SDK-specific snapshot metadata. message Metadata { repeated bytes chunk_hashes = 1; // SHA-256 chunk hashes -} +} \ No newline at end of file diff --git a/proto/cosmos/base/store/v1beta1/snapshot.proto b/proto/cosmos/base/store/v1beta1/snapshot.proto index bf62ab841c..45f670cdb3 100644 --- a/proto/cosmos/base/store/v1beta1/snapshot.proto +++ b/proto/cosmos/base/store/v1beta1/snapshot.proto @@ -25,4 +25,4 @@ message SnapshotIAVLItem { bytes value = 2; int64 version = 3; int32 height = 4; -} +} \ No newline at end of file diff --git a/proto/cosmos/evidence/v1beta1/evidence.proto b/proto/cosmos/evidence/v1beta1/evidence.proto index 87138296ae..e9d5c5cc82 100644 --- a/proto/cosmos/evidence/v1beta1/evidence.proto +++ b/proto/cosmos/evidence/v1beta1/evidence.proto @@ -18,4 +18,4 @@ message Equivocation { google.protobuf.Timestamp time = 2 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; int64 power = 3; string consensus_address = 4 [(gogoproto.moretags) = "yaml:\"consensus_address\""]; -} +} \ No newline at end of file diff --git a/proto/cosmos/gov/v1beta1/gov.proto b/proto/cosmos/gov/v1beta1/gov.proto index 3c19ad98aa..791a3ccdf4 100644 --- a/proto/cosmos/gov/v1beta1/gov.proto +++ b/proto/cosmos/gov/v1beta1/gov.proto @@ -115,9 +115,9 @@ enum ProposalStatus { message TallyResult { option (gogoproto.equal) = true; - string yes = 1 [(gogoproto.customtype) = "github.com/line/lbm-sdk/types.Int", (gogoproto.nullable) = false]; - string abstain = 2 [(gogoproto.customtype) = "github.com/line/lbm-sdk/types.Int", (gogoproto.nullable) = false]; - string no = 3 [(gogoproto.customtype) = "github.com/line/lbm-sdk/types.Int", (gogoproto.nullable) = false]; + string yes = 1 [(gogoproto.customtype) = "github.com/line/lbm-sdk/types.Int", (gogoproto.nullable) = false]; + string abstain = 2 [(gogoproto.customtype) = "github.com/line/lbm-sdk/types.Int", (gogoproto.nullable) = false]; + string no = 3 [(gogoproto.customtype) = "github.com/line/lbm-sdk/types.Int", (gogoproto.nullable) = false]; string no_with_veto = 4 [ (gogoproto.customtype) = "github.com/line/lbm-sdk/types.Int", (gogoproto.nullable) = false, @@ -136,7 +136,7 @@ message Vote { // Deprecated: Prefer to use `options` instead. This field is set in queries // if and only if `len(options) == 1` and that option has weight 1. In all // other cases, this field will default to VOTE_OPTION_UNSPECIFIED. - VoteOption option = 3 [deprecated = true]; + VoteOption option = 3 [deprecated = true]; // Since: cosmos-sdk 0.43 repeated WeightedVoteOption options = 4 [(gogoproto.nullable) = false]; } diff --git a/proto/cosmos/mint/v1beta1/mint.proto b/proto/cosmos/mint/v1beta1/mint.proto index 06157a34a4..a8c6f74a12 100644 --- a/proto/cosmos/mint/v1beta1/mint.proto +++ b/proto/cosmos/mint/v1beta1/mint.proto @@ -8,7 +8,8 @@ import "gogoproto/gogo.proto"; // Minter represents the minting state. message Minter { // current annual inflation rate - string inflation = 1 [(gogoproto.customtype) = "github.com/line/lbm-sdk/types.Dec", (gogoproto.nullable) = false]; + string inflation = 1 + [(gogoproto.customtype) = "github.com/line/lbm-sdk/types.Dec", (gogoproto.nullable) = false]; // current annual expected provisions string annual_provisions = 2 [ (gogoproto.moretags) = "yaml:\"annual_provisions\"", diff --git a/proto/cosmos/slashing/v1beta1/tx.proto b/proto/cosmos/slashing/v1beta1/tx.proto index 6dca7de8e2..bc9e0b2124 100644 --- a/proto/cosmos/slashing/v1beta1/tx.proto +++ b/proto/cosmos/slashing/v1beta1/tx.proto @@ -23,4 +23,4 @@ message MsgUnjail { } // MsgUnjailResponse defines the Msg/Unjail response type -message MsgUnjailResponse {} +message MsgUnjailResponse {} \ No newline at end of file diff --git a/proto/cosmos/staking/v1beta1/staking.proto b/proto/cosmos/staking/v1beta1/staking.proto index b90e6180b8..44f763ca3b 100644 --- a/proto/cosmos/staking/v1beta1/staking.proto +++ b/proto/cosmos/staking/v1beta1/staking.proto @@ -18,7 +18,7 @@ option go_package = "github.com/line/lbm-sdk/x/staking/types"; // (`n` is set by the staking module's `historical_entries` parameter). message HistoricalInfo { ostracon.types.Header header = 1 [(gogoproto.nullable) = false]; - repeated Validator valset = 2 [(gogoproto.nullable) = false]; + repeated Validator valset = 2 [(gogoproto.nullable) = false]; } // CommissionRates defines the initial commission rates to be used for creating @@ -245,7 +245,8 @@ message RedelegationEntry { (gogoproto.moretags) = "yaml:\"initial_balance\"" ]; // shares_dst is the amount of destination-validator shares created by redelegation. - string shares_dst = 4 [(gogoproto.customtype) = "github.com/line/lbm-sdk/types.Dec", (gogoproto.nullable) = false]; + string shares_dst = 4 + [(gogoproto.customtype) = "github.com/line/lbm-sdk/types.Dec", (gogoproto.nullable) = false]; } // Redelegation contains the list of a particular delegator's redelegating bonds diff --git a/proto/cosmos/staking/v1beta1/tx.proto b/proto/cosmos/staking/v1beta1/tx.proto index 2ccdd3f410..1d2924de75 100644 --- a/proto/cosmos/staking/v1beta1/tx.proto +++ b/proto/cosmos/staking/v1beta1/tx.proto @@ -65,8 +65,10 @@ message MsgEditValidator { // it's not mandatory to update. If not updated, the deserialized rate will be // zero with no way to distinguish if an update was intended. // REF: #2373 - string commission_rate = 3 - [(gogoproto.customtype) = "github.com/line/lbm-sdk/types.Dec", (gogoproto.moretags) = "yaml:\"commission_rate\""]; + string commission_rate = 3 [ + (gogoproto.customtype) = "github.com/line/lbm-sdk/types.Dec", + (gogoproto.moretags) = "yaml:\"commission_rate\"" + ]; string min_self_delegation = 4 [ (gogoproto.customtype) = "github.com/line/lbm-sdk/types.Int", (gogoproto.moretags) = "yaml:\"min_self_delegation\"" diff --git a/proto/cosmos/tx/v1beta1/service.proto b/proto/cosmos/tx/v1beta1/service.proto index 709723b8eb..925f4a37cc 100644 --- a/proto/cosmos/tx/v1beta1/service.proto +++ b/proto/cosmos/tx/v1beta1/service.proto @@ -131,4 +131,4 @@ message GetTxResponse { cosmos.tx.v1beta1.Tx tx = 1; // tx_response is the queried TxResponses. cosmos.base.abci.v1beta1.TxResponse tx_response = 2; -} +} \ No newline at end of file diff --git a/proto/cosmos/vesting/v1beta1/tx.proto b/proto/cosmos/vesting/v1beta1/tx.proto index a8e739a833..4834fa35f2 100644 --- a/proto/cosmos/vesting/v1beta1/tx.proto +++ b/proto/cosmos/vesting/v1beta1/tx.proto @@ -28,4 +28,4 @@ message MsgCreateVestingAccount { } // MsgCreateVestingAccountResponse defines the Msg/CreateVestingAccount response type. -message MsgCreateVestingAccountResponse {} +message MsgCreateVestingAccountResponse {} \ No newline at end of file From 39ec0f920c60c22b94ed5923925be0ffd7942411 Mon Sep 17 00:00:00 2001 From: TAKAMI Torao Date: Tue, 12 Jul 2022 13:29:13 +0900 Subject: [PATCH 4/4] make x/bank/keeper diffferences as similar to cosmos-sdk --- x/bank/keeper/keeper.go | 4 +--- x/bank/keeper/send.go | 5 +---- x/bank/keeper/view.go | 12 +++--------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index 6cdc31e421..0914d5b04c 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -237,9 +237,7 @@ func (k BaseKeeper) GetDenomMetaData(ctx sdk.Context, denom string) (types.Metad } var metadata types.Metadata - if err := metadata.Unmarshal(bz); err != nil { - panic(err) - } + k.cdc.MustUnmarshal(bz, &metadata) return metadata, true } diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index 3116f1633d..7aaa79ebd1 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -259,10 +259,7 @@ func (k BaseSendKeeper) setBalance(ctx sdk.Context, addr sdk.AccAddress, balance if balance.IsZero() { accountStore.Delete([]byte(balance.Denom)) } else { - bz, err := balance.Marshal() - if err != nil { - return err - } + bz := k.cdc.MustMarshal(&balance) accountStore.Set([]byte(balance.Denom), bz) } diff --git a/x/bank/keeper/view.go b/x/bank/keeper/view.go index 404245f220..cc76144840 100644 --- a/x/bank/keeper/view.go +++ b/x/bank/keeper/view.go @@ -107,9 +107,7 @@ func (k BaseViewKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom s } var balance sdk.Coin - if err := balance.Unmarshal(bz); err != nil { - panic(err) - } + k.cdc.MustUnmarshal(bz, &balance) return balance } @@ -175,9 +173,7 @@ func (k BaseViewKeeper) IterateAccountBalances(ctx sdk.Context, addr sdk.AccAddr for ; iterator.Valid(); iterator.Next() { var balance sdk.Coin - if err := balance.Unmarshal(iterator.Value()); err != nil { - panic(err) - } + k.cdc.MustUnmarshal(iterator.Value(), &balance) if cb(balance) { break @@ -205,9 +201,7 @@ func (k BaseViewKeeper) IterateAllBalances(ctx sdk.Context, cb func(sdk.AccAddre } var balance sdk.Coin - if err := balance.Unmarshal(iterator.Value()); err != nil { - panic(err) - } + k.cdc.MustUnmarshal(iterator.Value(), &balance) if cb(address, balance) { break