From 552fd9459b7ac6efbb19dfac3c14189565eeefde Mon Sep 17 00:00:00 2001 From: "Steve H. Jung" Date: Tue, 13 Jul 2021 17:36:24 +0900 Subject: [PATCH] perf: internal objects optimization (BaseAccount, Balance, Supply & MsgSEnd) 1. replaced cdc.(Un)MarshalInterface() by protobuf (Un)Marshal for internal objects: BaseAccount, Balance & Supply 2. PubKey in BaseAccount is secp256k1.PubKey, not interface, to avoid 'Any' type handling 3. address fields in the above objects and MsgSend (hence tx as well) are no longer strings, but sdk.AccAddress --- docs/core/proto-docs.md | 122 ++++++++++++------------ proto/lfb/auth/v1beta1/auth.proto | 5 +- proto/lfb/bank/v1beta1/bank.proto | 4 +- proto/lfb/bank/v1beta1/genesis.proto | 2 +- proto/lfb/bank/v1beta1/tx.proto | 4 +- proto/lfb/gov/v1beta1/gov.proto | 6 +- proto/lfb/staking/v1beta1/tx.proto | 6 +- simapp/simd/cmd/genaccounts.go | 2 +- simapp/simd/cmd/testnet.go | 2 +- x/auth/keeper/keeper.go | 5 +- x/auth/types/account.go | 108 +++++++++++++-------- x/auth/types/auth.pb.go | 116 +++++++++++----------- x/auth/vesting/types/vesting_account.go | 21 +--- x/bank/exported/exported.go | 2 + x/bank/keeper/genesis.go | 6 +- x/bank/keeper/keeper.go | 9 +- x/bank/keeper/msg_server.go | 17 +--- x/bank/keeper/send.go | 27 +++--- x/bank/keeper/view.go | 14 ++- x/bank/simulation/genesis.go | 2 +- x/bank/simulation/operations.go | 16 +--- x/bank/types/balance.go | 15 +-- x/bank/types/bank.pb.go | 106 ++++++++++---------- x/bank/types/genesis.go | 5 +- x/bank/types/genesis.pb.go | 20 ++-- x/bank/types/msgs.go | 36 +++---- x/bank/types/supply.go | 13 +++ x/bank/types/tx.pb.go | 60 ++++++------ 28 files changed, 377 insertions(+), 374 deletions(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 00fed73cb1..a14c162146 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -224,6 +224,10 @@ - [Header](#ibc.lightclients.tendermint.v1.Header) - [Misbehaviour](#ibc.lightclients.tendermint.v1.Misbehaviour) +- [lfb/crypto/secp256k1/keys.proto](#lfb/crypto/secp256k1/keys.proto) + - [PrivKey](#lfb.crypto.secp256k1.PrivKey) + - [PubKey](#lfb.crypto.secp256k1.PubKey) + - [lfb/auth/v1beta1/auth.proto](#lfb/auth/v1beta1/auth.proto) - [BaseAccount](#lfb.auth.v1beta1.BaseAccount) - [ModuleAccount](#lfb.auth.v1beta1.ModuleAccount) @@ -371,10 +375,6 @@ - [CompactBitArray](#lfb.crypto.multisig.v1beta1.CompactBitArray) - [MultiSignature](#lfb.crypto.multisig.v1beta1.MultiSignature) -- [lfb/crypto/secp256k1/keys.proto](#lfb/crypto/secp256k1/keys.proto) - - [PrivKey](#lfb.crypto.secp256k1.PrivKey) - - [PubKey](#lfb.crypto.secp256k1.PubKey) - - [lfb/distribution/v1beta1/distribution.proto](#lfb/distribution/v1beta1/distribution.proto) - [CommunityPoolSpendProposal](#lfb.distribution.v1beta1.CommunityPoolSpendProposal) - [CommunityPoolSpendProposalWithDeposit](#lfb.distribution.v1beta1.CommunityPoolSpendProposalWithDeposit) @@ -3828,6 +3828,56 @@ that implements Misbehaviour interface expected by ICS-02 + + + + + + + + + + + +

Top

+ +## lfb/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) | | | + + + + + @@ -3855,8 +3905,8 @@ type for additional functionality (e.g. vesting). | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `address` | [string](#string) | | | -| `pub_key` | [google.protobuf.Any](#google.protobuf.Any) | | | +| `address` | [bytes](#bytes) | | | +| `pub_key` | [lfb.crypto.secp256k1.PubKey](#lfb.crypto.secp256k1.PubKey) | | | | `account_number` | [uint64](#uint64) | | | | `sequence` | [uint64](#uint64) | | | @@ -4108,7 +4158,7 @@ Input models transaction input. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `address` | [string](#string) | | | +| `address` | [bytes](#bytes) | | | | `coins` | [lfb.base.v1beta1.Coin](#lfb.base.v1beta1.Coin) | repeated | | @@ -4143,7 +4193,7 @@ Output models transaction outputs. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `address` | [string](#string) | | | +| `address` | [bytes](#bytes) | | | | `coins` | [lfb.base.v1beta1.Coin](#lfb.base.v1beta1.Coin) | repeated | | @@ -4225,7 +4275,7 @@ genesis state. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `address` | [string](#string) | | address is the address of the balance holder. | +| `address` | [bytes](#bytes) | | address is the address of the balance holder. | | `coins` | [lfb.base.v1beta1.Coin](#lfb.base.v1beta1.Coin) | repeated | coins defines the different coins this balance holds. | @@ -4542,8 +4592,8 @@ MsgSend represents a message to send coins from one account to another. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `from_address` | [string](#string) | | | -| `to_address` | [string](#string) | | | +| `from_address` | [bytes](#bytes) | | | +| `to_address` | [bytes](#bytes) | | | | `amount` | [lfb.base.v1beta1.Coin](#lfb.base.v1beta1.Coin) | repeated | | @@ -5674,56 +5724,6 @@ signed and with which modes. - - - - - - - - - - - -

Top

- -## lfb/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) | | | - - - - - diff --git a/proto/lfb/auth/v1beta1/auth.proto b/proto/lfb/auth/v1beta1/auth.proto index 2e9cd9c895..d6af341e0e 100644 --- a/proto/lfb/auth/v1beta1/auth.proto +++ b/proto/lfb/auth/v1beta1/auth.proto @@ -1,6 +1,7 @@ syntax = "proto3"; package lfb.auth.v1beta1; +import "lfb/crypto/secp256k1/keys.proto"; import "cosmos_proto/cosmos.proto"; import "gogoproto/gogo.proto"; import "google/protobuf/any.proto"; @@ -17,8 +18,8 @@ message BaseAccount { option (cosmos_proto.implements_interface) = "AccountI"; - string address = 1; - google.protobuf.Any pub_key = 2 + bytes address = 1; + lfb.crypto.secp256k1.PubKey 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; diff --git a/proto/lfb/bank/v1beta1/bank.proto b/proto/lfb/bank/v1beta1/bank.proto index c6419fdf7b..1132f88e12 100644 --- a/proto/lfb/bank/v1beta1/bank.proto +++ b/proto/lfb/bank/v1beta1/bank.proto @@ -28,7 +28,7 @@ message Input { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; - string address = 1; + bytes address = 1; repeated lfb.base.v1beta1.Coin coins = 2 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/line/lfb-sdk/types.Coins"]; } @@ -38,7 +38,7 @@ message Output { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; - string address = 1; + bytes address = 1; repeated lfb.base.v1beta1.Coin coins = 2 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/line/lfb-sdk/types.Coins"]; } diff --git a/proto/lfb/bank/v1beta1/genesis.proto b/proto/lfb/bank/v1beta1/genesis.proto index 7e2c807f2c..3ec196789a 100644 --- a/proto/lfb/bank/v1beta1/genesis.proto +++ b/proto/lfb/bank/v1beta1/genesis.proto @@ -30,7 +30,7 @@ message Balance { option (gogoproto.goproto_getters) = false; // address is the address of the balance holder. - string address = 1; + bytes address = 1; // coins defines the different coins this balance holds. repeated lfb.base.v1beta1.Coin coins = 2 diff --git a/proto/lfb/bank/v1beta1/tx.proto b/proto/lfb/bank/v1beta1/tx.proto index 51c1d0b58d..acc8462b1e 100644 --- a/proto/lfb/bank/v1beta1/tx.proto +++ b/proto/lfb/bank/v1beta1/tx.proto @@ -21,8 +21,8 @@ message MsgSend { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; - string from_address = 1 [(gogoproto.moretags) = "yaml:\"from_address\""]; - string to_address = 2 [(gogoproto.moretags) = "yaml:\"to_address\""]; + bytes from_address = 1 [(gogoproto.moretags) = "yaml:\"from_address\""]; + bytes to_address = 2 [(gogoproto.moretags) = "yaml:\"to_address\""]; repeated lfb.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/line/lfb-sdk/types.Coins"]; } diff --git a/proto/lfb/gov/v1beta1/gov.proto b/proto/lfb/gov/v1beta1/gov.proto index b3e4c4277d..eee872cbda 100644 --- a/proto/lfb/gov/v1beta1/gov.proto +++ b/proto/lfb/gov/v1beta1/gov.proto @@ -103,9 +103,9 @@ enum ProposalStatus { message TallyResult { option (gogoproto.equal) = true; - string yes = 1 [(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Int", (gogoproto.nullable) = false]; - string abstain = 2 [(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Int", (gogoproto.nullable) = false]; - string no = 3 [(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Int", (gogoproto.nullable) = false]; + string yes = 1 [(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Int", (gogoproto.nullable) = false]; + string abstain = 2 [(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Int", (gogoproto.nullable) = false]; + string no = 3 [(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Int", (gogoproto.nullable) = false]; string no_with_veto = 4 [ (gogoproto.customtype) = "github.com/line/lfb-sdk/types.Int", (gogoproto.nullable) = false, diff --git a/proto/lfb/staking/v1beta1/tx.proto b/proto/lfb/staking/v1beta1/tx.proto index d8ee677c9e..8001bffa15 100644 --- a/proto/lfb/staking/v1beta1/tx.proto +++ b/proto/lfb/staking/v1beta1/tx.proto @@ -65,10 +65,8 @@ 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/lfb-sdk/types.Dec", - (gogoproto.moretags) = "yaml:\"commission_rate\"" - ]; + string commission_rate = 3 + [(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Dec", (gogoproto.moretags) = "yaml:\"commission_rate\""]; string min_self_delegation = 4 [ (gogoproto.customtype) = "github.com/line/lfb-sdk/types.Int", (gogoproto.moretags) = "yaml:\"min_self_delegation\"" diff --git a/simapp/simd/cmd/genaccounts.go b/simapp/simd/cmd/genaccounts.go index 96cbd86c9a..d92f104a5e 100644 --- a/simapp/simd/cmd/genaccounts.go +++ b/simapp/simd/cmd/genaccounts.go @@ -84,7 +84,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa // create concrete account type based on input parameters var genAccount authtypes.GenesisAccount - balances := banktypes.Balance{Address: addr.String(), Coins: coins.Sort()} + balances := banktypes.Balance{Address: addr, Coins: coins.Sort()} baseAccount := authtypes.NewBaseAccount(addr, nil, 0, 0) if !vestingAmt.IsZero() { diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index ea82cf7996..756b18b78c 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -203,7 +203,7 @@ func InitTestnet( sdk.NewCoin(sdk.DefaultBondDenom, accStakingTokens), } - genBalances = append(genBalances, banktypes.Balance{Address: addr.String(), Coins: coins.Sort()}) + genBalances = append(genBalances, banktypes.Balance{Address: addr, Coins: coins.Sort()}) genAccounts = append(genAccounts, authtypes.NewBaseAccount(addr, nil, 0, 0)) valTokens := sdk.TokensFromConsensusPower(100) diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 96a7544661..d45efab67b 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -217,14 +217,13 @@ 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 ak.cdc.MarshalInterface(accountI) + return accountI.MarshalX() } // 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) { - var acc types.AccountI - return acc, ak.cdc.UnmarshalInterface(bz, &acc) + return types.UnmarshalAccountX(bz) } // GetCodec return codec.Marshaler object used by the keeper diff --git a/x/auth/types/account.go b/x/auth/types/account.go index acf6e3075d..89bee1b3b0 100644 --- a/x/auth/types/account.go +++ b/x/auth/types/account.go @@ -13,6 +13,7 @@ import ( "github.com/line/lfb-sdk/codec" codectypes "github.com/line/lfb-sdk/codec/types" + "github.com/line/lfb-sdk/crypto/keys/secp256k1" cryptotypes "github.com/line/lfb-sdk/crypto/types" sdk "github.com/line/lfb-sdk/types" ) @@ -23,13 +24,16 @@ var ( _ codectypes.UnpackInterfacesMessage = (*BaseAccount)(nil) _ GenesisAccount = (*ModuleAccount)(nil) _ ModuleAccountI = (*ModuleAccount)(nil) + + BaseAccountSig = []byte("bacc") + ModuleAccountSig = []byte("macc") ) // NewBaseAccount creates a new BaseAccount object //nolint:interfacer func NewBaseAccount(address sdk.AccAddress, pubKey cryptotypes.PubKey, accountNumber, sequence uint64) *BaseAccount { acc := &BaseAccount{ - Address: address.String(), + Address: address, AccountNumber: accountNumber, Sequence: sequence, } @@ -50,14 +54,13 @@ func ProtoBaseAccount() AccountI { // NewBaseAccountWithAddress - returns a new base account with a given address func NewBaseAccountWithAddress(addr sdk.AccAddress) *BaseAccount { return &BaseAccount{ - Address: addr.String(), + Address: addr, } } // GetAddress - Implements sdk.AccountI. func (acc BaseAccount) GetAddress() sdk.AccAddress { - addr, _ := sdk.AccAddressFromBech32(acc.Address) - return addr + return sdk.AccAddress(acc.Address) } // SetAddress - Implements sdk.AccountI. @@ -66,20 +69,16 @@ func (acc *BaseAccount) SetAddress(addr sdk.AccAddress) error { return errors.New("cannot override BaseAccount address") } - acc.Address = addr.String() + acc.Address = addr.Bytes() return nil } // GetPubKey - Implements sdk.AccountI. -func (acc BaseAccount) GetPubKey() (pk cryptotypes.PubKey) { +func (acc BaseAccount) GetPubKey() cryptotypes.PubKey { if acc.PubKey == nil { return nil } - content, ok := acc.PubKey.GetCachedValue().(cryptotypes.PubKey) - if !ok { - return nil - } - return content + return acc.PubKey } // SetPubKey - Implements sdk.AccountI. @@ -87,12 +86,12 @@ func (acc *BaseAccount) SetPubKey(pubKey cryptotypes.PubKey) error { if pubKey == nil { acc.PubKey = nil return nil + } else if pk, ok := pubKey.(*secp256k1.PubKey); !ok { + return fmt.Errorf("invalid pubkey") + } else { + acc.PubKey = pk } - any, err := codectypes.NewAnyWithValue(pubKey) - if err == nil { - acc.PubKey = any - } - return err + return nil } // GetAccountNumber - Implements AccountI @@ -119,16 +118,11 @@ func (acc *BaseAccount) SetSequence(seq uint64) error { // Validate checks for errors on the account fields func (acc BaseAccount) Validate() error { - if acc.Address == "" || acc.PubKey == nil { + if acc.Address == nil || acc.PubKey == nil { return nil } - accAddr, err := sdk.AccAddressFromBech32(acc.Address) - if err != nil { - return err - } - - if !bytes.Equal(acc.GetPubKey().Address().Bytes(), accAddr.Bytes()) { + if !bytes.Equal(acc.GetPubKey().Address().Bytes(), acc.Address) { return errors.New("account address and pubkey address do not match") } @@ -151,11 +145,19 @@ func (acc BaseAccount) MarshalYAML() (interface{}, error) { // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (acc BaseAccount) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { - if acc.PubKey == nil { - return nil + return nil +} + +func (acc *BaseAccount) MarshalX() ([]byte, error) { + bz, err := acc.Marshal() + if err != nil { + return nil, err } - var pubKey cryptotypes.PubKey - return unpacker.UnpackAny(acc.PubKey, &pubKey) + t := BaseAccountSig + b := make([]byte, len(t)+len(bz)) + copy(b, t) + copy(b[len(t):], bz) + return b, nil } // NewModuleAddress creates an AccAddress from the hash of the module's name @@ -228,13 +230,25 @@ func (ma ModuleAccount) Validate() error { return errors.New("module account name cannot be blank") } - if ma.Address != sdk.AccAddress(crypto.AddressHash([]byte(ma.Name))).String() { + if !bytes.Equal(ma.Address, sdk.AccAddress(crypto.AddressHash([]byte(ma.Name))).Bytes()) { return fmt.Errorf("address %s cannot be derived from the module name '%s'", ma.Address, ma.Name) } 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"` @@ -251,13 +265,8 @@ func (ma ModuleAccount) String() string { // MarshalYAML returns the YAML representation of a ModuleAccount. func (ma ModuleAccount) MarshalYAML() (interface{}, error) { - accAddr, err := sdk.AccAddressFromBech32(ma.Address) - if err != nil { - return nil, err - } - bs, err := yaml.Marshal(moduleAccountPretty{ - Address: accAddr, + Address: ma.Address, PubKey: "", AccountNumber: ma.AccountNumber, Sequence: ma.Sequence, @@ -274,13 +283,8 @@ func (ma ModuleAccount) MarshalYAML() (interface{}, error) { // MarshalJSON returns the JSON representation of a ModuleAccount. func (ma ModuleAccount) MarshalJSON() ([]byte, error) { - accAddr, err := sdk.AccAddressFromBech32(ma.Address) - if err != nil { - return nil, err - } - return json.Marshal(moduleAccountPretty{ - Address: accAddr, + Address: ma.Address, PubKey: "", AccountNumber: ma.AccountNumber, Sequence: ma.Sequence, @@ -303,6 +307,28 @@ func (ma *ModuleAccount) UnmarshalJSON(bz []byte) error { return nil } +func UnmarshalAccountX(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 { + return nil, fmt.Errorf("invalid header") + } +} + // AccountI is an interface used to store coins at a given address within state. // It presumes a notion of sequence numbers for replay protection, // a notion of account numbers for replay protection for previously pruned accounts, @@ -326,6 +352,8 @@ type AccountI interface { // Ensure that account implements stringer String() string + + MarshalX() ([]byte, error) } // ModuleAccountI defines an account interface for modules that hold tokens in diff --git a/x/auth/types/auth.pb.go b/x/auth/types/auth.pb.go index 6bbf8ac0dd..86c4336319 100644 --- a/x/auth/types/auth.pb.go +++ b/x/auth/types/auth.pb.go @@ -7,7 +7,8 @@ import ( fmt "fmt" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" - types "github.com/line/lfb-sdk/codec/types" + _ "github.com/line/lfb-sdk/codec/types" + secp256k1 "github.com/line/lfb-sdk/crypto/keys/secp256k1" _ "github.com/regen-network/cosmos-proto" io "io" math "math" @@ -29,10 +30,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"` - 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"` + Address []byte `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + PubKey *secp256k1.PubKey `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{} } @@ -191,50 +192,51 @@ func init() { func init() { proto.RegisterFile("lfb/auth/v1beta1/auth.proto", fileDescriptor_f89657c3058cd869) } var fileDescriptor_f89657c3058cd869 = []byte{ - // 678 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x54, 0x3d, 0x4f, 0xdb, 0x5a, - 0x18, 0x8e, 0x6f, 0x72, 0xf9, 0x38, 0x01, 0x74, 0x31, 0x01, 0x9c, 0x70, 0xaf, 0x1d, 0x59, 0x77, - 0xc8, 0xd0, 0xd8, 0x4a, 0x2a, 0x2a, 0x91, 0x01, 0x15, 0xd3, 0x0e, 0xa8, 0x05, 0x21, 0x23, 0x75, - 0xa8, 0x5a, 0x59, 0xc7, 0xce, 0x89, 0xb1, 0xf0, 0xf1, 0x31, 0x3e, 0xc7, 0x28, 0xe6, 0x17, 0x74, - 0xec, 0xd8, 0x91, 0x1f, 0xc1, 0x0f, 0xe8, 0xd8, 0x11, 0x31, 0x75, 0x72, 0xab, 0xb0, 0x54, 0x1d, - 0xb3, 0x57, 0xaa, 0xe2, 0xe3, 0x84, 0x04, 0xd1, 0xed, 0x3c, 0xef, 0xf3, 0xbc, 0xcf, 0xfb, 0x95, - 0x18, 0x6c, 0xf9, 0x3d, 0x5b, 0x87, 0x31, 0x3b, 0xd5, 0x2f, 0x5a, 0x36, 0x62, 0xb0, 0x95, 0x01, - 0x2d, 0x8c, 0x08, 0x23, 0xe2, 0x3f, 0x7e, 0xcf, 0xd6, 0x32, 0x9c, 0x93, 0xb5, 0xaa, 0x43, 0x28, - 0x26, 0xd4, 0xca, 0x78, 0x9d, 0x03, 0x2e, 0xae, 0x55, 0x5c, 0xe2, 0x12, 0x1e, 0x1f, 0xbd, 0xf2, - 0x68, 0xd5, 0x25, 0xc4, 0xf5, 0x91, 0x9e, 0x21, 0x3b, 0xee, 0xe9, 0x30, 0x48, 0x38, 0xa5, 0xfe, - 0x12, 0x40, 0xd9, 0x80, 0x14, 0xed, 0x39, 0x0e, 0x89, 0x03, 0x26, 0x4a, 0x60, 0x1e, 0x76, 0xbb, - 0x11, 0xa2, 0x54, 0x12, 0xea, 0x42, 0x63, 0xd1, 0x1c, 0x43, 0xf1, 0x1d, 0x98, 0x0f, 0x63, 0xdb, - 0x3a, 0x43, 0x89, 0xf4, 0x57, 0x5d, 0x68, 0x94, 0xdb, 0x15, 0x8d, 0xdb, 0x6a, 0x63, 0x5b, 0x6d, - 0x2f, 0x48, 0x8c, 0xe6, 0xcf, 0x54, 0xa9, 0x84, 0xb1, 0xed, 0x7b, 0xce, 0x48, 0xfb, 0x84, 0x60, - 0x8f, 0x21, 0x1c, 0xb2, 0x64, 0x98, 0x2a, 0xab, 0x09, 0xc4, 0x7e, 0x47, 0xbd, 0x67, 0x55, 0x73, - 0x2e, 0x8c, 0xed, 0x57, 0x28, 0x11, 0x9f, 0x83, 0x15, 0xc8, 0x5b, 0xb0, 0x82, 0x18, 0xdb, 0x28, - 0x92, 0x8a, 0x75, 0xa1, 0x51, 0x32, 0xaa, 0xc3, 0x54, 0x59, 0xe7, 0x69, 0xb3, 0xbc, 0x6a, 0x2e, - 0xe7, 0x81, 0xa3, 0x0c, 0x8b, 0x35, 0xb0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, 0x90, 0xee, 0xf7, 0xec, 0x26, 0xed, 0x9e, 0xe9, 0x7d, 0xfe, 0x3d, 0x61, - 0x49, 0x88, 0xa8, 0x3d, 0x97, 0xfd, 0x43, 0x9f, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xdb, 0x9e, - 0xd5, 0x94, 0x68, 0x04, 0x00, 0x00, + // 697 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x54, 0xbf, 0x4f, 0xe3, 0x48, + 0x14, 0x8e, 0x49, 0x8e, 0x1f, 0x13, 0x40, 0x87, 0x09, 0x60, 0x02, 0x67, 0x47, 0xd6, 0x15, 0x29, + 0x2e, 0xb6, 0x92, 0x13, 0x27, 0x91, 0x02, 0xdd, 0x99, 0xbb, 0x02, 0xdd, 0x81, 0x90, 0x91, 0xae, + 0x58, 0x69, 0x65, 0x8d, 0x9d, 0x89, 0xb1, 0xe2, 0xc9, 0x18, 0xcf, 0x18, 0xc5, 0xf4, 0x2b, 0x6d, + 0xb9, 0xe5, 0x96, 0xfc, 0x11, 0xfc, 0x01, 0x5b, 0x6e, 0x89, 0xa8, 0xb6, 0xf2, 0xae, 0x42, 0xb3, + 0xda, 0x32, 0x7f, 0xc1, 0xca, 0x33, 0x49, 0x48, 0x10, 0xdb, 0xcd, 0xf7, 0xbe, 0xf7, 0xbd, 0xf7, + 0xcd, 0x7b, 0x63, 0x83, 0xbd, 0xb0, 0xeb, 0x9a, 0x30, 0x61, 0x97, 0xe6, 0x75, 0xd3, 0x45, 0x0c, + 0x36, 0x39, 0x30, 0xa2, 0x98, 0x30, 0x22, 0xff, 0x1c, 0x76, 0x5d, 0x83, 0xe3, 0x31, 0x59, 0xd5, + 0xf2, 0x74, 0x2f, 0x4e, 0x23, 0x46, 0x4c, 0x8a, 0xbc, 0xa8, 0x75, 0xf0, 0x47, 0xaf, 0x69, 0xf6, + 0x50, 0x4a, 0x85,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0x91, 0x04, 0x00, 0x00, } func (this *Params) Equal(that interface{}) bool { @@ -544,7 +546,7 @@ func (m *BaseAccount) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowAuth @@ -554,23 +556,25 @@ func (m *BaseAccount) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthAuth } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthAuth } if postIndex > l { return io.ErrUnexpectedEOF } - m.Address = string(dAtA[iNdEx:postIndex]) + m.Address = append(m.Address[:0], dAtA[iNdEx:postIndex]...) + if m.Address == nil { + m.Address = []byte{} + } iNdEx = postIndex case 2: if wireType != 2 { @@ -602,7 +606,7 @@ func (m *BaseAccount) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.PubKey == nil { - m.PubKey = &types.Any{} + m.PubKey = &secp256k1.PubKey{} } if err := m.PubKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err diff --git a/x/auth/vesting/types/vesting_account.go b/x/auth/vesting/types/vesting_account.go index daf3fe3440..30c3e36ace 100644 --- a/x/auth/vesting/types/vesting_account.go +++ b/x/auth/vesting/types/vesting_account.go @@ -183,13 +183,8 @@ func (bva BaseVestingAccount) String() string { // MarshalYAML returns the YAML representation of a BaseVestingAccount. func (bva BaseVestingAccount) MarshalYAML() (interface{}, error) { - accAddr, err := sdk.AccAddressFromBech32(bva.Address) - if err != nil { - return nil, err - } - alias := vestingAccountYAML{ - Address: accAddr, + Address: bva.Address, AccountNumber: bva.AccountNumber, Sequence: bva.Sequence, OriginalVesting: bva.OriginalVesting, @@ -311,13 +306,8 @@ func (cva ContinuousVestingAccount) String() string { // MarshalYAML returns the YAML representation of a ContinuousVestingAccount. func (cva ContinuousVestingAccount) MarshalYAML() (interface{}, error) { - accAddr, err := sdk.AccAddressFromBech32(cva.Address) - if err != nil { - return nil, err - } - alias := vestingAccountYAML{ - Address: accAddr, + Address: cva.Address, AccountNumber: cva.AccountNumber, Sequence: cva.Sequence, OriginalVesting: cva.OriginalVesting, @@ -469,13 +459,8 @@ func (pva PeriodicVestingAccount) String() string { // MarshalYAML returns the YAML representation of a PeriodicVestingAccount. func (pva PeriodicVestingAccount) MarshalYAML() (interface{}, error) { - accAddr, err := sdk.AccAddressFromBech32(pva.Address) - if err != nil { - return nil, err - } - alias := vestingAccountYAML{ - Address: accAddr, + Address: pva.Address, AccountNumber: pva.AccountNumber, Sequence: pva.Sequence, OriginalVesting: pva.OriginalVesting, diff --git a/x/bank/exported/exported.go b/x/bank/exported/exported.go index 5d0773ff55..e2a986e782 100644 --- a/x/bank/exported/exported.go +++ b/x/bank/exported/exported.go @@ -26,4 +26,6 @@ type SupplyI interface { String() string ValidateBasic() error + + MarshalX() ([]byte, error) } diff --git a/x/bank/keeper/genesis.go b/x/bank/keeper/genesis.go index f2ef5e1a5d..f6757e8c1e 100644 --- a/x/bank/keeper/genesis.go +++ b/x/bank/keeper/genesis.go @@ -15,11 +15,7 @@ func (k BaseKeeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) { genState.Balances = types.SanitizeGenesisBalances(genState.Balances) for _, balance := range genState.Balances { - addr, err := sdk.AccAddressFromBech32(balance.Address) - if err != nil { - panic(err) - } - + addr := balance.GetAddress() if err := k.SetBalances(ctx, addr, balance.Coins); err != nil { panic(fmt.Errorf("error on setting balances %w", err)) } diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index 617a7c14f4..a6df0c9d4b 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -190,7 +190,9 @@ func (k BaseKeeper) GetDenomMetaData(ctx sdk.Context, denom string) types.Metada } var metadata types.Metadata - k.cdc.MustUnmarshalBinaryBare(bz, &metadata) + if err := metadata.Unmarshal(bz); err != nil { + panic(err) + } return metadata } @@ -409,12 +411,11 @@ func (k BaseKeeper) trackUndelegation(ctx sdk.Context, addr sdk.AccAddress, amt // MarshalSupply protobuf serializes a Supply interface func (k BaseKeeper) MarshalSupply(supplyI exported.SupplyI) ([]byte, error) { - return k.cdc.MarshalInterface(supplyI) + return supplyI.MarshalX() } // UnmarshalSupply returns a Supply interface from raw encoded supply // bytes of a Proto-based Supply type func (k BaseKeeper) UnmarshalSupply(bz []byte) (exported.SupplyI, error) { - var evi exported.SupplyI - return evi, k.cdc.UnmarshalInterface(bz, &evi) + return types.UnmarshalSupplyX(bz) } diff --git a/x/bank/keeper/msg_server.go b/x/bank/keeper/msg_server.go index 66132e4325..b948887337 100644 --- a/x/bank/keeper/msg_server.go +++ b/x/bank/keeper/msg_server.go @@ -29,20 +29,14 @@ func (k msgServer) Send(goCtx context.Context, msg *types.MsgSend) (*types.MsgSe if err := k.SendEnabledCoins(ctx, msg.Amount...); err != nil { return nil, err } - from, err := sdk.AccAddressFromBech32(msg.FromAddress) - if err != nil { - return nil, err - } - to, err := sdk.AccAddressFromBech32(msg.ToAddress) - if err != nil { - return nil, err - } + from := sdk.AccAddress(msg.FromAddress) + to := sdk.AccAddress(msg.ToAddress) if k.BlockedAddr(to) { return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", msg.ToAddress) } - err = k.SendCoins(ctx, from, to, msg.Amount) + err := k.SendCoins(ctx, from, to, msg.Amount) if err != nil { return nil, err } @@ -80,10 +74,7 @@ func (k msgServer) MultiSend(goCtx context.Context, msg *types.MsgMultiSend) (*t } for _, out := range msg.Outputs { - accAddr, err := sdk.AccAddressFromBech32(out.Address) - if err != nil { - panic(err) - } + accAddr := sdk.AccAddress(out.Address) if k.BlockedAddr(accAddr) { return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive transactions", out.Address) } diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index be6eef6be1..41daf37dbf 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -85,12 +85,8 @@ func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, inputs []types.Input, } for _, in := range inputs { - inAddress, err := sdk.AccAddressFromBech32(in.Address) - if err != nil { - return err - } - - err = k.SubtractCoins(ctx, inAddress, in.Coins) + inAddress := sdk.AccAddress(in.Address) + err := k.SubtractCoins(ctx, inAddress, in.Coins) if err != nil { return err } @@ -98,17 +94,14 @@ func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, inputs []types.Input, ctx.EventManager().EmitEvent( sdk.NewEvent( sdk.EventTypeMessage, - sdk.NewAttribute(types.AttributeKeySender, in.Address), + sdk.NewAttribute(types.AttributeKeySender, inAddress.String()), ), ) } for _, out := range outputs { - outAddress, err := sdk.AccAddressFromBech32(out.Address) - if err != nil { - return err - } - err = k.AddCoins(ctx, outAddress, out.Coins) + outAddress := sdk.AccAddress(out.Address) + err := k.AddCoins(ctx, outAddress, out.Coins) if err != nil { return err } @@ -116,7 +109,7 @@ func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, inputs []types.Input, ctx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypeTransfer, - sdk.NewAttribute(types.AttributeKeyRecipient, out.Address), + sdk.NewAttribute(types.AttributeKeyRecipient, outAddress.String()), sdk.NewAttribute(sdk.AttributeKeyAmount, out.Coins.String()), ), ) @@ -268,9 +261,11 @@ func (k BaseSendKeeper) SetBalance(ctx sdk.Context, addr sdk.AccAddress, balance balancesStore := prefix.NewStore(store, types.BalancesPrefix) accountStore := prefix.NewStore(balancesStore, addr.Bytes()) - bz := k.cdc.MustMarshalBinaryBare(&balance) - accountStore.Set([]byte(balance.Denom), bz) - + if bz, err := balance.Marshal(); err != nil { + return err + } else { + accountStore.Set([]byte(balance.Denom), bz) + } return nil } diff --git a/x/bank/keeper/view.go b/x/bank/keeper/view.go index 695d0d9249..3e84030907 100644 --- a/x/bank/keeper/view.go +++ b/x/bank/keeper/view.go @@ -83,7 +83,7 @@ func (k BaseViewKeeper) GetAccountsBalances(ctx sdk.Context) []types.Balance { } accountBalance := types.Balance{ - Address: addr.String(), + Address: addr, Coins: sdk.NewCoins(balance), } balances = append(balances, accountBalance) @@ -107,7 +107,9 @@ func (k BaseViewKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom s } var balance sdk.Coin - k.cdc.MustUnmarshalBinaryBare(bz, &balance) + if err := balance.Unmarshal(bz); err != nil { + panic(err) + } return balance } @@ -125,7 +127,9 @@ func (k BaseViewKeeper) IterateAccountBalances(ctx sdk.Context, addr sdk.AccAddr for ; iterator.Valid(); iterator.Next() { var balance sdk.Coin - k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &balance) + if err := balance.Unmarshal(iterator.Value()); err != nil { + panic(err) + } if cb(balance) { break @@ -147,7 +151,9 @@ func (k BaseViewKeeper) IterateAllBalances(ctx sdk.Context, cb func(sdk.AccAddre address := types.AddressFromBalancesStore(iterator.Key()) var balance sdk.Coin - k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &balance) + if err := balance.Unmarshal(iterator.Value()); err != nil { + panic(err) + } if cb(address, balance) { break diff --git a/x/bank/simulation/genesis.go b/x/bank/simulation/genesis.go index e8ff09fa01..cda7d6211b 100644 --- a/x/bank/simulation/genesis.go +++ b/x/bank/simulation/genesis.go @@ -42,7 +42,7 @@ func RandomGenesisBalances(simState *module.SimulationState) []types.Balance { for _, acc := range simState.Accounts { genesisBalances = append(genesisBalances, types.Balance{ - Address: acc.Address.String(), + Address: acc.Address, Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(simState.InitialStake))), }) } diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index e15d1e67d2..e403ffd224 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -92,11 +92,7 @@ func sendMsgSend( err error ) - from, err := sdk.AccAddressFromBech32(msg.FromAddress) - if err != nil { - return err - } - + from := sdk.AccAddress(msg.FromAddress) account := ak.GetAccount(ctx, from) spendable := bk.SpendableCoins(ctx, account.GetAddress()) @@ -233,10 +229,7 @@ func sendMsgMultiSend( sequenceNumbers := make([]uint64, len(msg.Inputs)) for i := 0; i < len(msg.Inputs); i++ { - addr, err := sdk.AccAddressFromBech32(msg.Inputs[i].Address) - if err != nil { - panic(err) - } + addr := sdk.AccAddress(msg.Inputs[i].Address) acc := ak.GetAccount(ctx, addr) accountNumbers[i] = acc.GetAccountNumber() sequenceNumbers[i] = acc.GetSequence() @@ -247,10 +240,7 @@ func sendMsgMultiSend( err error ) - addr, err := sdk.AccAddressFromBech32(msg.Inputs[0].Address) - if err != nil { - panic(err) - } + addr := sdk.AccAddress(msg.Inputs[0].Address) // feePayer is the first signer, i.e. first input address feePayer := ak.GetAccount(ctx, addr) diff --git a/x/bank/types/balance.go b/x/bank/types/balance.go index 96fcdf4189..c2f0a13e0d 100644 --- a/x/bank/types/balance.go +++ b/x/bank/types/balance.go @@ -15,12 +15,7 @@ var _ exported.GenesisBalance = (*Balance)(nil) // GetAddress returns the account address of the Balance object. func (b Balance) GetAddress() sdk.AccAddress { - addr, err := sdk.AccAddressFromBech32(b.Address) - if err != nil { - panic(fmt.Errorf("couldn't convert %q to account address: %v", b.Address, err)) - } - - return addr + return sdk.AccAddress(b.Address) } // GetCoins returns the account coins of the Balance object. @@ -30,9 +25,8 @@ func (b Balance) GetCoins() sdk.Coins { // Validate checks for address and coins correctness. func (b Balance) Validate() error { - _, err := sdk.AccAddressFromBech32(b.Address) - if err != nil { - return err + if len(b.Address) == 0 { + return fmt.Errorf("empty address") } seenDenoms := make(map[string]bool) @@ -84,10 +78,9 @@ func SanitizeGenesisBalances(balances []Balance) []Balance { adL := make([]*addrToBalance, 0, len(balances)) for _, balance := range balances { balance := balance - addr, _ := sdk.AccAddressFromBech32(balance.Address) adL = append(adL, &addrToBalance{ balance: &balance, - accAddr: []byte(addr), + accAddr: balance.Address, }) } diff --git a/x/bank/types/bank.pb.go b/x/bank/types/bank.pb.go index 23f9ab3758..eca6358eb2 100644 --- a/x/bank/types/bank.pb.go +++ b/x/bank/types/bank.pb.go @@ -133,7 +133,7 @@ func (m *SendEnabled) GetEnabled() bool { // Input models transaction input. type Input struct { - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + Address []byte `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` Coins github_com_line_lfb_sdk_types.Coins `protobuf:"bytes,2,rep,name=coins,proto3,castrepeated=github.com/line/lfb-sdk/types.Coins" json:"coins"` } @@ -172,7 +172,7 @@ var xxx_messageInfo_Input proto.InternalMessageInfo // Output models transaction outputs. type Output struct { - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + Address []byte `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` Coins github_com_line_lfb_sdk_types.Coins `protobuf:"bytes,2,rep,name=coins,proto3,castrepeated=github.com/line/lfb-sdk/types.Coins" json:"coins"` } @@ -403,43 +403,43 @@ func init() { func init() { proto.RegisterFile("lfb/bank/v1beta1/bank.proto", fileDescriptor_6d4f9a82f4a1e6b2) } var fileDescriptor_6d4f9a82f4a1e6b2 = []byte{ - // 570 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x54, 0xbf, 0x6f, 0xd3, 0x40, - 0x18, 0xf5, 0x35, 0x4d, 0x48, 0x2f, 0x20, 0x21, 0x2b, 0x42, 0x26, 0x55, 0xed, 0x60, 0x40, 0x0a, - 0x3f, 0x6a, 0x53, 0xd8, 0x22, 0x84, 0x50, 0x00, 0xa1, 0x0e, 0x08, 0xe4, 0x0a, 0x21, 0x60, 0x88, - 0xce, 0xb9, 0x4b, 0xb0, 0x7a, 0xbe, 0xb3, 0x72, 0x67, 0xd4, 0xfc, 0x03, 0xc0, 0xc8, 0xd8, 0xb1, - 0x0b, 0x0b, 0x33, 0x7f, 0x44, 0xc7, 0x88, 0x89, 0x29, 0xa0, 0x64, 0x61, 0xee, 0x5f, 0x80, 0xee, - 0xce, 0x09, 0x29, 0x50, 0xb1, 0x30, 0xb0, 0xdd, 0xf3, 0xf7, 0xee, 0x7d, 0x4f, 0xef, 0xfb, 0xce, - 0x70, 0x9d, 0xf6, 0xe3, 0x30, 0x46, 0x6c, 0x37, 0x7c, 0xbd, 0x15, 0x13, 0x89, 0xb6, 0x34, 0x08, - 0xb2, 0x21, 0x97, 0xdc, 0x3e, 0x4b, 0xfb, 0x71, 0xa0, 0x71, 0x51, 0x6c, 0xd4, 0x07, 0x7c, 0xc0, - 0x75, 0x31, 0x54, 0x27, 0xc3, 0x6b, 0x9c, 0xef, 0x71, 0x91, 0x72, 0xd1, 0x35, 0x05, 0x03, 0x8a, - 0x52, 0xa1, 0x2f, 0xc8, 0x42, 0xbf, 0xc7, 0x13, 0x66, 0x8a, 0xfe, 0x18, 0xc0, 0xca, 0x13, 0x34, - 0x44, 0xa9, 0xb0, 0x7b, 0xf0, 0xb4, 0x20, 0x0c, 0x77, 0x09, 0x43, 0x31, 0x25, 0xd8, 0x01, 0xcd, - 0x52, 0xab, 0x76, 0x73, 0x23, 0xf8, 0xd5, 0x41, 0xb0, 0x43, 0x18, 0x7e, 0x60, 0x48, 0x9d, 0x0b, - 0x47, 0x13, 0x6f, 0x63, 0x84, 0x52, 0xda, 0xf6, 0x97, 0x2f, 0x5f, 0xe7, 0x69, 0x22, 0x49, 0x9a, - 0xc9, 0x91, 0x1f, 0xd5, 0xc4, 0x4f, 0xbe, 0xfd, 0x12, 0xd6, 0x31, 0xe9, 0xa3, 0x9c, 0xca, 0xee, - 0xb1, 0x66, 0x2b, 0x4d, 0xd0, 0xaa, 0x76, 0xae, 0x1c, 0x4d, 0xbc, 0xcb, 0x46, 0xed, 0x4f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xab, 0x39, 0x3f, 0x65, 0x89, 0x3c, 0x61, 0x03, 0x1a, 0xb0, - 0xaa, 0xae, 0x31, 0xc2, 0xa4, 0x5e, 0x81, 0x33, 0xd1, 0x02, 0xeb, 0x94, 0x69, 0x82, 0x04, 0x11, - 0x4e, 0xa9, 0x59, 0xd2, 0x29, 0x1b, 0xe8, 0xef, 0x03, 0x58, 0x7d, 0x44, 0x24, 0xc2, 0x48, 0x22, - 0xbb, 0x09, 0x6b, 0x98, 0x88, 0xde, 0x30, 0xc9, 0x64, 0xc2, 0x59, 0x21, 0xbf, 0xfc, 0xc9, 0xbe, - 0xad, 0x18, 0x8c, 0xa7, 0xdd, 0x9c, 0x25, 0x72, 0x3e, 0x9a, 0xf5, 0xdf, 0x9f, 0xd4, 0xc2, 0x6c, - 0x04, 0xf1, 0xfc, 0x28, 0x6c, 0x1b, 0xae, 0xaa, 0x40, 0x9d, 0x92, 0x16, 0xd6, 0x67, 0x65, 0x0d, - 0x27, 0x22, 0xa3, 0x68, 0xe4, 0xac, 0x9a, 0x05, 0x28, 0x60, 0xe7, 0xce, 0xe1, 0xd4, 0x05, 0xe3, - 0xa9, 0x0b, 0xbe, 0x4d, 0x5d, 0xf0, 0x7e, 0xe6, 0x5a, 0xe3, 0x99, 0x6b, 0x7d, 0x99, 0xb9, 0xd6, - 0x8b, 0x4b, 0x7f, 0x89, 0x4f, 0x8f, 0x20, 0xae, 0xe8, 0x3f, 0xc2, 0xad, 0x1f, 0x01, 0x00, 0x00, - 0xff, 0xff, 0x68, 0x87, 0xba, 0xf3, 0x90, 0x04, 0x00, 0x00, + // 573 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x54, 0x3f, 0x6f, 0xd3, 0x4e, + 0x18, 0xf6, 0x35, 0x7f, 0x7e, 0xc9, 0xa5, 0x3f, 0x09, 0x59, 0x11, 0x32, 0xa9, 0x6a, 0x07, 0x03, + 0x52, 0xf8, 0x53, 0x9b, 0xc2, 0x16, 0x21, 0x84, 0x02, 0x08, 0x75, 0x40, 0x20, 0x57, 0x08, 0x01, + 0x43, 0x74, 0xce, 0x5d, 0x82, 0x55, 0xfb, 0xce, 0xca, 0x9d, 0x51, 0xf3, 0x05, 0x80, 0x91, 0xb1, + 0x63, 0x17, 0x16, 0x66, 0x3e, 0x44, 0xc7, 0x88, 0x89, 0x29, 0xa0, 0x64, 0x61, 0xee, 0x27, 0x40, + 0x77, 0x67, 0x87, 0x14, 0xa8, 0x58, 0x18, 0xd8, 0xee, 0xb9, 0xf7, 0xb9, 0xe7, 0x7d, 0xf4, 0xbc, + 0xaf, 0x0d, 0x37, 0xe2, 0x61, 0xe8, 0x87, 0x88, 0xee, 0xf9, 0xaf, 0xb6, 0x43, 0x22, 0xd0, 0xb6, + 0x02, 0x5e, 0x3a, 0x66, 0x82, 0x99, 0x67, 0xe2, 0x61, 0xe8, 0x29, 0x9c, 0x17, 0x5b, 0xcd, 0x11, + 0x1b, 0x31, 0x55, 0xf4, 0xe5, 0x49, 0xf3, 0x5a, 0xe7, 0x06, 0x8c, 0x27, 0x8c, 0xf7, 0x75, 0x41, + 0x83, 0xbc, 0x94, 0xeb, 0x73, 0xb2, 0xd4, 0x1f, 0xb0, 0x88, 0xea, 0xa2, 0x3b, 0x05, 0xb0, 0xfa, + 0x18, 0x8d, 0x51, 0xc2, 0xcd, 0x01, 0x5c, 0xe7, 0x84, 0xe2, 0x3e, 0xa1, 0x28, 0x8c, 0x09, 0xb6, + 0x40, 0xbb, 0xd4, 0x69, 0xdc, 0xd8, 0xf4, 0x7e, 0x76, 0xe0, 0xed, 0x12, 0x8a, 0xef, 0x6b, 0x52, + 0xef, 0xfc, 0xf1, 0xcc, 0xd9, 0x9c, 0xa0, 0x24, 0xee, 0xba, 0xab, 0x8f, 0xaf, 0xb1, 0x24, 0x12, + 0x24, 0x49, 0xc5, 0xc4, 0x0d, 0x1a, 0xfc, 0x07, 0xdf, 0x7c, 0x01, 0x9b, 0x98, 0x0c, 0x51, 0x16, + 0x8b, 0xfe, 0x89, 0x66, 0x6b, 0x6d, 0xd0, 0xa9, 0xf5, 0x2e, 0x1f, 0xcf, 0x9c, 0x4b, 0x5a, 0xed, + 0x77, 0xac, 0x55, 0x55, 0x33, 0x27, 0xac, 0x98, 0xe9, 0x96, 0x0f, 0x0e, 0x1d, 0xc3, 0x7d, 0x00, + 0x1b, 0x2b, 0x97, 0x66, 0x13, 0x56, 0x30, 0xa1, 0x2c, 0xb1, 0x40, 0x1b, 0x74, 0xea, 0x81, 0x06, + 0xa6, 0x05, 0xff, 0x3b, 0xd1, 0x3a, 0x28, 0x60, 0xb7, 0x26, 0x45, 0xbe, 0x1d, 0x3a, 0xc0, 0x7d, + 0x0d, 0x60, 0x65, 0x87, 0xa6, 0x99, 0x90, 0x6c, 0x84, 0xf1, 0x98, 0x70, 0xae, 0x54, 0xd6, 0x83, + 0x02, 0x9a, 0xcf, 0x60, 0x45, 0xa6, 0xc9, 0xad, 0x35, 0x95, 0xd6, 0xd9, 0x3c, 0x2d, 0x4e, 0x96, + 0x69, 0xdd, 0x65, 0x11, 0xed, 0x5d, 0x3d, 0x9a, 0x39, 0xc6, 0x87, 0x2f, 0xce, 0x85, 0x51, 0x24, + 0x5e, 0x66, 0xa1, 0x37, 0x60, 0x89, 0x1f, 0x47, 0x94, 0xf8, 0xf1, 0x30, 0xdc, 0xe2, 0x78, 0xcf, + 0x17, 0x93, 0x94, 0x70, 0xc5, 0xe5, 0x81, 0x56, 0xec, 0xd6, 0xde, 0x6a, 0x23, 0x86, 0xfb, 0x06, + 0xc0, 0xea, 0xa3, 0x4c, 0xfc, 0x03, 0x4e, 0xde, 0x03, 0x58, 0xdd, 0xcd, 0xd2, 0x34, 0x9e, 0xc8, + 0x7e, 0x82, 0x09, 0x14, 0xe7, 0x7b, 0xf2, 0x77, 0xfa, 0x29, 0xc5, 0xee, 0x1d, 0xd9, 0xaf, 0x18, + 0xc3, 0xa7, 0x8f, 0x5b, 0xd7, 0xaf, 0x9c, 0xf6, 0x78, 0x5f, 0x7f, 0x38, 0x64, 0x3f, 0x65, 0x63, + 0x41, 0xb0, 0xa7, 0xbd, 0xed, 0xb8, 0x4f, 0x61, 0xfd, 0x9e, 0x9c, 0xf3, 0x13, 0x1a, 0x89, 0x53, + 0x36, 0xa0, 0x05, 0x6b, 0xf2, 0x19, 0x25, 0x54, 0xa8, 0x15, 0xf8, 0x3f, 0x58, 0x62, 0x95, 0x72, + 0x1c, 0x21, 0x4e, 0xb8, 0x55, 0x6a, 0x97, 0x3a, 0xf5, 0xa0, 0x80, 0xee, 0x01, 0x80, 0xb5, 0x87, + 0x44, 0x20, 0x8c, 0x04, 0x32, 0xdb, 0xb0, 0x81, 0x09, 0x1f, 0x8c, 0xa3, 0x54, 0x44, 0x8c, 0xe6, + 0xf2, 0xab, 0x57, 0xe6, 0x2d, 0xc9, 0xa0, 0x2c, 0xe9, 0x67, 0x34, 0x12, 0xc5, 0x68, 0x36, 0x7e, + 0xfd, 0xa4, 0x96, 0x66, 0x03, 0x88, 0x8b, 0x23, 0x37, 0x4d, 0x58, 0x96, 0x81, 0x5a, 0x25, 0x25, + 0xac, 0xce, 0xd2, 0x1a, 0x8e, 0x78, 0x1a, 0xa3, 0x89, 0x55, 0x56, 0xd7, 0x05, 0xec, 0xdd, 0x3e, + 0x9a, 0xdb, 0x60, 0x3a, 0xb7, 0xc1, 0xd7, 0xb9, 0x0d, 0xde, 0x2d, 0x6c, 0x63, 0xba, 0xb0, 0x8d, + 0xcf, 0x0b, 0xdb, 0x78, 0x7e, 0xf1, 0x0f, 0xf1, 0xa9, 0x11, 0x84, 0x55, 0xf5, 0x47, 0xb8, 0xf9, + 0x3d, 0x00, 0x00, 0xff, 0xff, 0xec, 0x6b, 0x64, 0xfe, 0x90, 0x04, 0x00, 0x00, } func (this *SendEnabled) Equal(that interface{}) bool { @@ -1204,7 +1204,7 @@ func (m *Input) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowBank @@ -1214,23 +1214,25 @@ func (m *Input) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthBank } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthBank } if postIndex > l { return io.ErrUnexpectedEOF } - m.Address = string(dAtA[iNdEx:postIndex]) + m.Address = append(m.Address[:0], dAtA[iNdEx:postIndex]...) + if m.Address == nil { + m.Address = []byte{} + } iNdEx = postIndex case 2: if wireType != 2 { @@ -1320,7 +1322,7 @@ func (m *Output) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowBank @@ -1330,23 +1332,25 @@ func (m *Output) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthBank } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthBank } if postIndex > l { return io.ErrUnexpectedEOF } - m.Address = string(dAtA[iNdEx:postIndex]) + m.Address = append(m.Address[:0], dAtA[iNdEx:postIndex]...) + if m.Address == nil { + m.Address = []byte{} + } iNdEx = postIndex case 2: if wireType != 2 { diff --git a/x/bank/types/genesis.go b/x/bank/types/genesis.go index 31727eb519..8e20cecd3a 100644 --- a/x/bank/types/genesis.go +++ b/x/bank/types/genesis.go @@ -19,7 +19,8 @@ func (gs GenesisState) Validate() error { seenMetadatas := make(map[string]bool) for _, balance := range gs.Balances { - if seenBalances[balance.Address] { + addr := balance.GetAddress().String() + if seenBalances[addr] { return fmt.Errorf("duplicate balance for address %s", balance.Address) } @@ -27,7 +28,7 @@ func (gs GenesisState) Validate() error { return err } - seenBalances[balance.Address] = true + seenBalances[addr] = true } for _, metadata := range gs.DenomMetadata { diff --git a/x/bank/types/genesis.pb.go b/x/bank/types/genesis.pb.go index a523ff83a4..259d8d043d 100644 --- a/x/bank/types/genesis.pb.go +++ b/x/bank/types/genesis.pb.go @@ -102,7 +102,7 @@ func (m *GenesisState) GetDenomMetadata() []Metadata { // genesis state. type Balance struct { // address is the address of the balance holder. - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + Address []byte `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` // coins defines the different coins this balance holds. Coins github_com_line_lfb_sdk_types.Coins `protobuf:"bytes,2,rep,name=coins,proto3,castrepeated=github.com/line/lfb-sdk/types.Coins" json:"coins"` } @@ -167,12 +167,12 @@ var fileDescriptor_ae51259122fcca48 = []byte{ 0x1b, 0x9f, 0x9b, 0x5a, 0x92, 0x98, 0x92, 0x58, 0x92, 0x28, 0xc1, 0x02, 0xb6, 0x44, 0x0a, 0xd3, 0x7d, 0xbe, 0x50, 0x15, 0x4e, 0xb2, 0x20, 0x8b, 0x3e, 0xdd, 0x93, 0x17, 0xad, 0x4c, 0xcc, 0xcd, 0xb1, 0x52, 0x42, 0xd5, 0xaf, 0x14, 0xc4, 0x0b, 0x16, 0x80, 0xa9, 0x56, 0xea, 0x60, 0xe4, 0x62, - 0x87, 0x7a, 0x4d, 0x48, 0x82, 0x8b, 0x3d, 0x31, 0x25, 0xa5, 0x28, 0xb5, 0x18, 0x12, 0x80, 0x9c, + 0x87, 0x7a, 0x4d, 0x48, 0x82, 0x8b, 0x3d, 0x31, 0x25, 0xa5, 0x28, 0xb5, 0x18, 0x12, 0x80, 0x3c, 0x41, 0x30, 0xae, 0x50, 0x24, 0x17, 0x2b, 0x28, 0x56, 0x60, 0xc1, 0x43, 0x15, 0x3f, 0x42, 0x4c, 0xb4, 0xe2, 0xe8, 0x58, 0x20, 0xcf, 0xf0, 0x62, 0x81, 0x3c, 0x83, 0x93, 0xdd, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0xa9, 0xe0, 0x32, 0xaf, 0x02, 0x92, 0x38, 0xc0, 0xc6, - 0x26, 0xb1, 0x81, 0x93, 0x85, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xb0, 0xf6, 0xd8, 0x21, 0x9a, + 0x26, 0xb1, 0x81, 0x93, 0x85, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x39, 0x61, 0x51, 0xd1, 0x9a, 0x02, 0x00, 0x00, } @@ -578,7 +578,7 @@ func (m *Balance) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowGenesis @@ -588,23 +588,25 @@ func (m *Balance) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthGenesis } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthGenesis } if postIndex > l { return io.ErrUnexpectedEOF } - m.Address = string(dAtA[iNdEx:postIndex]) + m.Address = append(m.Address[:0], dAtA[iNdEx:postIndex]...) + if m.Address == nil { + m.Address = []byte{} + } iNdEx = postIndex case 2: if wireType != 2 { diff --git a/x/bank/types/msgs.go b/x/bank/types/msgs.go index d8a19c4dca..bac48ebdd3 100644 --- a/x/bank/types/msgs.go +++ b/x/bank/types/msgs.go @@ -16,7 +16,7 @@ var _ sdk.Msg = &MsgSend{} // NewMsgSend - construct a msg to send coins from one account to another. //nolint:interfacer func NewMsgSend(fromAddr, toAddr sdk.AccAddress, amount sdk.Coins) *MsgSend { - return &MsgSend{FromAddress: fromAddr.String(), ToAddress: toAddr.String(), Amount: amount} + return &MsgSend{FromAddress: fromAddr, ToAddress: toAddr, Amount: amount} } // Route Implements Msg. @@ -27,14 +27,11 @@ func (msg MsgSend) Type() string { return TypeMsgSend } // ValidateBasic Implements Msg. func (msg MsgSend) ValidateBasic() error { - _, err := sdk.AccAddressFromBech32(msg.FromAddress) - if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err) + if len(msg.FromAddress) == 0 { + return sdkerrors.ErrInvalidAddress } - - _, err = sdk.AccAddressFromBech32(msg.ToAddress) - if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid recipient address (%s)", err) + if len(msg.ToAddress) == 0 { + return sdkerrors.ErrInvalidAddress } if !msg.Amount.IsValid() { @@ -55,11 +52,7 @@ func (msg MsgSend) GetSignBytes() []byte { // GetSigners Implements Msg. func (msg MsgSend) GetSigners() []sdk.AccAddress { - from, err := sdk.AccAddressFromBech32(msg.FromAddress) - if err != nil { - panic(err) - } - return []sdk.AccAddress{from} + return []sdk.AccAddress{sdk.AccAddress(msg.FromAddress)} } var _ sdk.Msg = &MsgMultiSend{} @@ -99,8 +92,7 @@ func (msg MsgMultiSend) GetSignBytes() []byte { func (msg MsgMultiSend) GetSigners() []sdk.AccAddress { addrs := make([]sdk.AccAddress, len(msg.Inputs)) for i, in := range msg.Inputs { - addr, _ := sdk.AccAddressFromBech32(in.Address) - addrs[i] = addr + addrs[i] = sdk.AccAddress(in.Address) } return addrs @@ -108,9 +100,8 @@ func (msg MsgMultiSend) GetSigners() []sdk.AccAddress { // ValidateBasic - validate transaction input func (in Input) ValidateBasic() error { - _, err := sdk.AccAddressFromBech32(in.Address) - if err != nil { - return err + if len(in.Address) == 0 { + return sdkerrors.ErrInvalidAddress } if !in.Coins.IsValid() { @@ -128,16 +119,15 @@ func (in Input) ValidateBasic() error { //nolint:interfacer func NewInput(addr sdk.AccAddress, coins sdk.Coins) Input { return Input{ - Address: addr.String(), + Address: addr, Coins: coins, } } // ValidateBasic - validate transaction output func (out Output) ValidateBasic() error { - _, err := sdk.AccAddressFromBech32(out.Address) - if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid output address (%s)", err) + if len(out.Address) == 0 { + return sdkerrors.ErrInvalidAddress } if !out.Coins.IsValid() { @@ -155,7 +145,7 @@ func (out Output) ValidateBasic() error { //nolint:interfacer func NewOutput(addr sdk.AccAddress, coins sdk.Coins) Output { return Output{ - Address: addr.String(), + Address: addr, Coins: coins, } } diff --git a/x/bank/types/supply.go b/x/bank/types/supply.go index e8e76e26a6..445149cee1 100644 --- a/x/bank/types/supply.go +++ b/x/bank/types/supply.go @@ -56,3 +56,16 @@ func (supply Supply) ValidateBasic() error { return nil } + +func (supply *Supply) MarshalX() ([]byte, error) { + return supply.Marshal() +} + +func UnmarshalSupplyX(bz []byte) (exported.SupplyI, error) { + var supply Supply + + if err := supply.Unmarshal(bz); err != nil { + return nil, err + } + return &supply, nil +} diff --git a/x/bank/types/tx.pb.go b/x/bank/types/tx.pb.go index d2403c8e7c..855924f92b 100644 --- a/x/bank/types/tx.pb.go +++ b/x/bank/types/tx.pb.go @@ -32,8 +32,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // MsgSend represents a message to send coins from one account to another. type MsgSend struct { - FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty" yaml:"from_address"` - ToAddress string `protobuf:"bytes,2,opt,name=to_address,json=toAddress,proto3" json:"to_address,omitempty" yaml:"to_address"` + FromAddress []byte `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty" yaml:"from_address"` + ToAddress []byte `protobuf:"bytes,2,opt,name=to_address,json=toAddress,proto3" json:"to_address,omitempty" yaml:"to_address"` Amount github_com_line_lfb_sdk_types.Coins `protobuf:"bytes,3,rep,name=amount,proto3,castrepeated=github.com/line/lfb-sdk/types.Coins" json:"amount"` } @@ -209,7 +209,7 @@ func init() { proto.RegisterFile("lfb/bank/v1beta1/tx.proto", fileDescriptor_d7d var fileDescriptor_d7d7d23756e577ab = []byte{ // 438 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0x41, 0x8b, 0xd3, 0x40, - 0x00, 0x85, 0x33, 0xdb, 0xd2, 0xb5, 0xb3, 0x0b, 0xba, 0x71, 0xdd, 0xed, 0x46, 0x48, 0xd6, 0x28, + 0x00, 0x85, 0x33, 0xdb, 0xd2, 0x75, 0x67, 0x0b, 0xba, 0x71, 0xdd, 0xed, 0x46, 0x48, 0xd6, 0x28, 0x52, 0x10, 0x27, 0xb4, 0x2a, 0x48, 0x0e, 0x82, 0xd1, 0x8b, 0x87, 0x20, 0xa4, 0x37, 0x3d, 0x48, 0xd2, 0x4c, 0x62, 0x68, 0x32, 0x13, 0x3a, 0x13, 0x69, 0x7f, 0x80, 0xe0, 0xd1, 0x9f, 0xd0, 0xb3, 0xbf, 0xa4, 0xc7, 0x1e, 0x3d, 0x55, 0x49, 0x2f, 0x9e, 0xfb, 0x0b, 0x24, 0x93, 0xa4, 0xad, 0xd6, @@ -217,25 +217,25 @@ var fileDescriptor_d7d7d23756e577ab = []byte{ 0xf8, 0xd4, 0xf3, 0x30, 0x77, 0x7b, 0x06, 0x9f, 0xa0, 0x74, 0x4c, 0x39, 0x95, 0x6f, 0xc5, 0x81, 0x87, 0x0a, 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, + 0xe3, 0xc5, 0xec, 0xa2, 0xca, 0x25, 0xfa, 0xfb, 0xdf, 0xa3, 0x37, 0x05, 0xb7, 0x9a, 0x45, 0x17, + 0xa7, 0x12, 0xcb, 0xcf, 0xe1, 0x31, 0xcd, 0xb8, 0xf0, 0x1d, 0x09, 0x5f, 0x67, 0xdf, 0xf7, 0x56, + 0x08, 0x2a, 0x63, 0x2d, 0x37, 0x9b, 0xa2, 0xda, 0x05, 0x3c, 0xdf, 0xad, 0x51, 0xf7, 0xeb, 0xcf, + 0x00, 0x6c, 0xd8, 0x2c, 0x94, 0x5f, 0xc3, 0xa6, 0xa8, 0x77, 0xb5, 0x1f, 0x5b, 0x4d, 0x52, 0xee, + 0x1d, 0x44, 0x75, 0x9a, 0x3c, 0x80, 0x27, 0xdb, 0xa5, 0xea, 0x3f, 0xf5, 0x1b, 0xae, 0x3c, 0xfc, 0x3f, 0xaf, 0x43, 0xad, 0x17, 0xf3, 0x5c, 0x05, 0x8b, 0x5c, 0x05, 0x3f, 0x73, 0x15, 0x7c, 0x5d, 0xa9, 0xd2, 0x62, 0xa5, 0x4a, 0xdf, 0x57, 0xaa, 0xf4, 0xee, 0xc1, 0xa1, 0x6b, 0x9a, 0x94, 0xef, - 0x50, 0xdc, 0x96, 0xd7, 0x12, 0x2f, 0xf0, 0xc9, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x65, 0xb1, - 0x1d, 0x61, 0x00, 0x03, 0x00, 0x00, + 0x50, 0xdc, 0x96, 0xd7, 0x12, 0x2f, 0xf0, 0xc9, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb9, 0xf9, + 0xf5, 0xde, 0x00, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -618,7 +618,7 @@ func (m *MsgSend) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field FromAddress", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -628,29 +628,31 @@ func (m *MsgSend) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.FromAddress = string(dAtA[iNdEx:postIndex]) + m.FromAddress = append(m.FromAddress[:0], dAtA[iNdEx:postIndex]...) + if m.FromAddress == nil { + m.FromAddress = []byte{} + } iNdEx = postIndex case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field ToAddress", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -660,23 +662,25 @@ func (m *MsgSend) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.ToAddress = string(dAtA[iNdEx:postIndex]) + m.ToAddress = append(m.ToAddress[:0], dAtA[iNdEx:postIndex]...) + if m.ToAddress == nil { + m.ToAddress = []byte{} + } iNdEx = postIndex case 3: if wireType != 2 {