diff --git a/.codecov.yml b/.codecov.yml index 8fd6c94d4ad8..c10133afd9e5 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -47,6 +47,7 @@ ignore: - "*.md" - "*.rst" - "**/*.pb.go" + - "x/**/*.pb.go" - "x/**/test_common.go" - "scripts/" - "contrib" diff --git a/CHANGELOG.md b/CHANGELOG.md index 34c617d89f9c..5804dbb319d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -86,6 +86,11 @@ for JSON encoding. * Every reference of `crypto.Pubkey` in context of a `Validator` is now of type string. `GetPubKeyFromBech32` must be used to get the `crypto.Pubkey`. * The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type provided is specified by `ModuleCdc`. +* (x/slashing) [\#5627](https://github.com/cosmos/cosmos-sdk/pull/5627) Migrate the `x/slashing` module to use Protocol Buffers for state +serialization instead of Amino. The exact codec used is `codec.HybridCodec` which utilizes Protobuf for binary encoding and Amino +for JSON encoding. + * The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type + provided is specified by `ModuleCdc`. * (x/distribution) [\#5610](https://github.com/cosmos/cosmos-sdk/pull/5610) Migrate the `x/distribution` module to use Protocol Buffers for state serialization instead of Amino. The exact codec used is `codec.HybridCodec` which utilizes Protobuf for binary encoding and Amino for JSON encoding. diff --git a/Makefile b/Makefile index 2cf897fe985a..96f04d16a8f6 100644 --- a/Makefile +++ b/Makefile @@ -238,25 +238,37 @@ proto-lint: proto-check-breaking: @buf check breaking --against-input '.git#branch=master' -# Origin -# TODO: Update to the version of Tendermint that is being used in go.mod -version_branch = v0.33.0 -tendermint = https://raw.githubusercontent.com/tendermint/tendermint/$(version_branch) - -# Outputs -tmkv = third_party/proto/tendermint/libs/kv/types.proto -tmmerkle = third_party/proto/tendermint/crypto/merkle/merkle.proto -tmabci = third_party/proto/tendermint/abci/types/types.proto - -# You *only* need to run this to rebuild protobufs from the tendermint source -proto-update-tendermint: - @curl $(tendermint)/abci/types/types.proto > $(tmabci) - sed -i '' '8,9 s|github.com/tendermint|third_party/proto|g' $(tmabci) - sed -i '' '7 s|github.com/gogo/protobuf|third_party/proto|' $(tmabci) - @curl $(tendermint)/libs/kv/types.proto > $(tmkv) - sed -i '' 's|github.com/gogo/protobuf|third_party/proto|' $(tmkv) - @curl $(tendermint)/crypto/merkle/merkle.proto > $(tmmerkle) - sed -i '' '7 s|github.com/gogo/protobuf|third_party/proto|' $(tmmerkle) - - -.PHONY: proto-all proto-gen proto-lint proto-check-breaking proto-update-tendermint +TM_URL = https://raw.githubusercontent.com/tendermint/tendermint/v0.33.1 +GOGO_PROTO_URL = https://raw.githubusercontent.com/regen-network/protobuf/cosmos +COSMOS_PROTO_URL = https://raw.githubusercontent.com/regen-network/cosmos-proto/master + +TM_KV_TYPES = third_party/proto/tendermint/libs/kv +TM_MERKLE_TYPES = third_party/proto/tendermint/crypto/merkle +TM_ABCI_TYPES = third_party/proto/tendermint/abci/types +GOGO_PROTO_TYPES = third_party/proto/gogoproto +COSMOS_PROTO_TYPES = third_party/proto/cosmos-proto +SDK_PROTO_TYPES = third_party/proto/cosmos-sdk/types +AUTH_PROTO_TYPES = third_party/proto/cosmos-sdk/x/auth/types +VESTING_PROTO_TYPES = third_party/proto/cosmos-sdk/x/auth/vesting/types +SUPPLY_PROTO_TYPES = third_party/proto/cosmos-sdk/x/supply/types + +proto-update-deps: + @mkdir -p $(GOGO_PROTO_TYPES) + @curl -sSL $(GOGO_PROTO_URL)/gogoproto/gogo.proto > $(GOGO_PROTO_TYPES)/gogo.proto + + @mkdir -p $(COSMOS_PROTO_TYPES) + @curl -sSL $(COSMOS_PROTO_URL)/cosmos.proto > $(COSMOS_PROTO_TYPES)/cosmos.proto + + @mkdir -p $(TM_ABCI_TYPES) + @curl -sSL $(TM_URL)/abci/types/types.proto > $(TM_ABCI_TYPES)/types.proto + @sed -i '' '8 s|crypto/merkle/merkle.proto|third_party/proto/tendermint/crypto/merkle/merkle.proto|g' $(TM_ABCI_TYPES)/types.proto + @sed -i '' '9 s|libs/kv/types.proto|third_party/proto/tendermint/libs/kv/types.proto|g' $(TM_ABCI_TYPES)/types.proto + + @mkdir -p $(TM_KV_TYPES) + @curl -sSL $(TM_URL)/libs/kv/types.proto > $(TM_KV_TYPES)/types.proto + + @mkdir -p $(TM_MERKLE_TYPES) + @curl -sSL $(TM_URL)/crypto/merkle/merkle.proto > $(TM_MERKLE_TYPES)/merkle.proto + + +.PHONY: proto-all proto-gen proto-lint proto-check-breaking proto-update-deps diff --git a/go.mod b/go.mod index 54dc76100f07..ace0be09309c 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.6.2 - github.com/stretchr/testify v1.5.0 + github.com/stretchr/testify v1.5.1 github.com/tendermint/btcd v0.1.1 github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 github.com/tendermint/go-amino v0.15.1 diff --git a/go.sum b/go.sum index a0e82c697eff..7e0165233f77 100644 --- a/go.sum +++ b/go.sum @@ -239,6 +239,8 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.0 h1:DMOzIV76tmoDNE9pX6RSN0aDtCYeCg5VueieJaAo1uw= github.com/stretchr/testify v1.5.0/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d h1:gZZadD8H+fF+n9CmNhYL1Y0dJB+kLOmKd7FbPJLeGHs= diff --git a/simapp/app.go b/simapp/app.go index 610f0d1e8766..b1d2ca6b1624 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -176,7 +176,7 @@ func NewSimApp( appCodec, keys[auth.StoreKey], app.subspaces[auth.ModuleName], auth.ProtoBaseAccount, ) app.BankKeeper = bank.NewBaseKeeper( - app.cdc, keys[bank.StoreKey], app.AccountKeeper, app.subspaces[bank.ModuleName], app.BlacklistedAccAddrs(), + appCodec, keys[bank.StoreKey], app.AccountKeeper, app.subspaces[bank.ModuleName], app.BlacklistedAccAddrs(), ) app.SupplyKeeper = supply.NewKeeper( appCodec, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms, @@ -193,7 +193,7 @@ func NewSimApp( app.SupplyKeeper, auth.FeeCollectorName, app.ModuleAccountAddrs(), ) app.SlashingKeeper = slashing.NewKeeper( - app.cdc, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName], + appCodec, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName], ) app.CrisisKeeper = crisis.NewKeeper( app.subspaces[crisis.ModuleName], invCheckPeriod, app.SupplyKeeper, auth.FeeCollectorName, diff --git a/third_party/proto/gogoproto/gogo.proto b/third_party/proto/gogoproto/gogo.proto index 588291f0ec20..49e78f99fe57 100644 --- a/third_party/proto/gogoproto/gogo.proto +++ b/third_party/proto/gogoproto/gogo.proto @@ -142,4 +142,4 @@ extend google.protobuf.FieldOptions { optional bool wktpointer = 65012; optional string castrepeated = 65013; -} \ No newline at end of file +} diff --git a/third_party/proto/tendermint/abci/types/types.proto b/third_party/proto/tendermint/abci/types/types.proto index 6c65444b0755..7fb4b1bdb703 100644 --- a/third_party/proto/tendermint/abci/types/types.proto +++ b/third_party/proto/tendermint/abci/types/types.proto @@ -1,6 +1,6 @@ syntax = "proto3"; package tendermint.abci.types; -option go_package = "github.com/tendermint/tendermint/abci/types"; +option go_package = "github.com/tendermint/tendermint/abci/types"; // For more information on gogo.proto, see: // https://github.com/gogo/protobuf/blob/master/extensions.md @@ -14,31 +14,31 @@ import "google/protobuf/duration.proto"; // NOTE: When using custom types, mind the warnings. // https://github.com/gogo/protobuf/blob/master/custom_types.md#warnings-and-issues -option (gogoproto.marshaler_all) = true; -option (gogoproto.unmarshaler_all) = true; -option (gogoproto.sizer_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.sizer_all) = true; option (gogoproto.goproto_registration) = true; // Generate tests option (gogoproto.populate_all) = true; -option (gogoproto.equal_all) = true; -option (gogoproto.testgen_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.testgen_all) = true; //---------------------------------------- // Request types message Request { oneof value { - RequestEcho echo = 2; - RequestFlush flush = 3; - RequestInfo info = 4; - RequestSetOption set_option = 5; - RequestInitChain init_chain = 6; - RequestQuery query = 7; + RequestEcho echo = 2; + RequestFlush flush = 3; + RequestInfo info = 4; + RequestSetOption set_option = 5; + RequestInitChain init_chain = 6; + RequestQuery query = 7; RequestBeginBlock begin_block = 8; - RequestCheckTx check_tx = 9; - RequestDeliverTx deliver_tx = 19; - RequestEndBlock end_block = 11; - RequestCommit commit = 12; + RequestCheckTx check_tx = 9; + RequestDeliverTx deliver_tx = 19; + RequestEndBlock end_block = 11; + RequestCommit commit = 12; } } @@ -46,50 +46,49 @@ message RequestEcho { string message = 1; } -message RequestFlush { -} +message RequestFlush {} message RequestInfo { - string version = 1; + string version = 1; uint64 block_version = 2; - uint64 p2p_version = 3; + uint64 p2p_version = 3; } // nondeterministic message RequestSetOption { - string key = 1; + string key = 1; string value = 2; } message RequestInitChain { - google.protobuf.Timestamp time = 1 [(gogoproto.nullable)=false, (gogoproto.stdtime)=true]; - string chain_id = 2; - ConsensusParams consensus_params = 3; - repeated ValidatorUpdate validators = 4 [(gogoproto.nullable)=false]; - bytes app_state_bytes = 5; + google.protobuf.Timestamp time = 1 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; + string chain_id = 2; + ConsensusParams consensus_params = 3; + repeated ValidatorUpdate validators = 4 [(gogoproto.nullable) = false]; + bytes app_state_bytes = 5; } message RequestQuery { - bytes data = 1; - string path = 2; - int64 height = 3; - bool prove = 4; + bytes data = 1; + string path = 2; + int64 height = 3; + bool prove = 4; } message RequestBeginBlock { - bytes hash = 1; - Header header = 2 [(gogoproto.nullable)=false]; - LastCommitInfo last_commit_info = 3 [(gogoproto.nullable)=false]; - repeated Evidence byzantine_validators = 4 [(gogoproto.nullable)=false]; + bytes hash = 1; + Header header = 2 [(gogoproto.nullable) = false]; + LastCommitInfo last_commit_info = 3 [(gogoproto.nullable) = false]; + repeated Evidence byzantine_validators = 4 [(gogoproto.nullable) = false]; } enum CheckTxType { - New = 0; + New = 0; Recheck = 1; } message RequestCheckTx { - bytes tx = 1; + bytes tx = 1; CheckTxType type = 2; } @@ -101,26 +100,25 @@ message RequestEndBlock { int64 height = 1; } -message RequestCommit { -} +message RequestCommit {} //---------------------------------------- // Response types message Response { oneof value { - ResponseException exception = 1; - ResponseEcho echo = 2; - ResponseFlush flush = 3; - ResponseInfo info = 4; - ResponseSetOption set_option = 5; - ResponseInitChain init_chain = 6; - ResponseQuery query = 7; + ResponseException exception = 1; + ResponseEcho echo = 2; + ResponseFlush flush = 3; + ResponseInfo info = 4; + ResponseSetOption set_option = 5; + ResponseInitChain init_chain = 6; + ResponseQuery query = 7; ResponseBeginBlock begin_block = 8; - ResponseCheckTx check_tx = 9; - ResponseDeliverTx deliver_tx = 10; - ResponseEndBlock end_block = 11; - ResponseCommit commit = 12; + ResponseCheckTx check_tx = 9; + ResponseDeliverTx deliver_tx = 10; + ResponseEndBlock end_block = 11; + ResponseCommit commit = 12; } } @@ -133,16 +131,15 @@ message ResponseEcho { string message = 1; } -message ResponseFlush { -} +message ResponseFlush {} message ResponseInfo { string data = 1; - string version = 2; + string version = 2; uint64 app_version = 3; - int64 last_block_height = 4; + int64 last_block_height = 4; bytes last_block_app_hash = 5; } @@ -150,58 +147,62 @@ message ResponseInfo { message ResponseSetOption { uint32 code = 1; // bytes data = 2; - string log = 3; + string log = 3; string info = 4; } message ResponseInitChain { - ConsensusParams consensus_params = 1; - repeated ValidatorUpdate validators = 2 [(gogoproto.nullable)=false]; + ConsensusParams consensus_params = 1; + repeated ValidatorUpdate validators = 2 [(gogoproto.nullable) = false]; } message ResponseQuery { uint32 code = 1; // bytes data = 2; // use "value" instead. - string log = 3; // nondeterministic - string info = 4; // nondeterministic - int64 index = 5; - bytes key = 6; - bytes value = 7; - tendermint.crypto.merkle.Proof proof = 8; - int64 height = 9; - string codespace = 10; + string log = 3; // nondeterministic + string info = 4; // nondeterministic + int64 index = 5; + bytes key = 6; + bytes value = 7; + tendermint.crypto.merkle.Proof proof = 8; + int64 height = 9; + string codespace = 10; } message ResponseBeginBlock { - repeated Event events = 1 [(gogoproto.nullable)=false, (gogoproto.jsontag)="events,omitempty"]; + repeated Event events = 1 + [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; } message ResponseCheckTx { - uint32 code = 1; - bytes data = 2; - string log = 3; // nondeterministic - string info = 4; // nondeterministic - int64 gas_wanted = 5; - int64 gas_used = 6; - repeated Event events = 7 [(gogoproto.nullable)=false, (gogoproto.jsontag)="events,omitempty"]; + uint32 code = 1; + bytes data = 2; + string log = 3; // nondeterministic + string info = 4; // nondeterministic + int64 gas_wanted = 5; + int64 gas_used = 6; + repeated Event events = 7 + [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; string codespace = 8; } message ResponseDeliverTx { - uint32 code = 1; - bytes data = 2; - string log = 3; // nondeterministic - string info = 4; // nondeterministic - int64 gas_wanted = 5; - int64 gas_used = 6; - repeated Event events = 7 [(gogoproto.nullable)=false, (gogoproto.jsontag)="events,omitempty"]; + uint32 code = 1; + bytes data = 2; + string log = 3; // nondeterministic + string info = 4; // nondeterministic + int64 gas_wanted = 5; + int64 gas_used = 6; + repeated Event events = 7 + [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; string codespace = 8; } message ResponseEndBlock { - repeated ValidatorUpdate validator_updates = 1 [(gogoproto.nullable)=false]; - ConsensusParams consensus_param_updates = 2; - repeated Event events = 3 [(gogoproto.nullable)=false, (gogoproto.jsontag)="events,omitempty"]; + repeated ValidatorUpdate validator_updates = 1 [(gogoproto.nullable) = false]; + ConsensusParams consensus_param_updates = 2; + repeated Event events = 3 + [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; } message ResponseCommit { @@ -215,8 +216,8 @@ message ResponseCommit { // ConsensusParams contains all consensus-relevant parameters // that can be adjusted by the abci app message ConsensusParams { - BlockParams block = 1; - EvidenceParams evidence = 2; + BlockParams block = 1; + EvidenceParams evidence = 2; ValidatorParams validator = 3; } @@ -230,8 +231,9 @@ message BlockParams { message EvidenceParams { // Note: must be greater than 0 - int64 max_age_num_blocks = 1; - google.protobuf.Duration max_age_duration = 2 [(gogoproto.nullable)=false, (gogoproto.stdduration)=true]; + int64 max_age_num_blocks = 1; + google.protobuf.Duration max_age_duration = 2 + [(gogoproto.nullable) = false, (gogoproto.stdduration) = true]; } // ValidatorParams contains limits on validators. @@ -240,13 +242,14 @@ message ValidatorParams { } message LastCommitInfo { - int32 round = 1; - repeated VoteInfo votes = 2 [(gogoproto.nullable)=false]; + int32 round = 1; + repeated VoteInfo votes = 2 [(gogoproto.nullable) = false]; } message Event { - string type = 1; - repeated tendermint.libs.kv.Pair attributes = 2 [(gogoproto.nullable)=false, (gogoproto.jsontag)="attributes,omitempty"]; + string type = 1; + repeated tendermint.libs.kv.Pair attributes = 2 + [(gogoproto.nullable) = false, (gogoproto.jsontag) = "attributes,omitempty"]; } //---------------------------------------- @@ -254,63 +257,62 @@ message Event { message Header { // basic block info - Version version = 1 [(gogoproto.nullable)=false]; - string chain_id = 2 [(gogoproto.customname)="ChainID"]; - int64 height = 3; - google.protobuf.Timestamp time = 4 [(gogoproto.nullable)=false, (gogoproto.stdtime)=true]; + Version version = 1 [(gogoproto.nullable) = false]; + string chain_id = 2 [(gogoproto.customname) = "ChainID"]; + int64 height = 3; + google.protobuf.Timestamp time = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; // prev block info - BlockID last_block_id = 5 [(gogoproto.nullable)=false]; + BlockID last_block_id = 5 [(gogoproto.nullable) = false]; // hashes of block data - bytes last_commit_hash = 6; // commit from validators from the last block - bytes data_hash = 7; // transactions + bytes last_commit_hash = 6; // commit from validators from the last block + bytes data_hash = 7; // transactions // hashes from the app output from the prev block - bytes validators_hash = 8; // validators for the current block + bytes validators_hash = 8; // validators for the current block bytes next_validators_hash = 9; // validators for the next block - bytes consensus_hash = 10; // consensus params for current block - bytes app_hash = 11; // state after txs from the previous block - bytes last_results_hash = 12;// root hash of all results from the txs from the previous block + bytes consensus_hash = 10; // consensus params for current block + bytes app_hash = 11; // state after txs from the previous block + bytes last_results_hash = 12; // root hash of all results from the txs from the previous block // consensus info - bytes evidence_hash = 13; // evidence included in the block - bytes proposer_address = 14; // original proposer of the block + bytes evidence_hash = 13; // evidence included in the block + bytes proposer_address = 14; // original proposer of the block } message Version { uint64 Block = 1; - uint64 App = 2; + uint64 App = 2; } - message BlockID { - bytes hash = 1; - PartSetHeader parts_header = 2 [(gogoproto.nullable)=false]; + bytes hash = 1; + PartSetHeader parts_header = 2 [(gogoproto.nullable) = false]; } message PartSetHeader { int32 total = 1; - bytes hash = 2; + bytes hash = 2; } // Validator message Validator { bytes address = 1; - //PubKey pub_key = 2 [(gogoproto.nullable)=false]; + // PubKey pub_key = 2 [(gogoproto.nullable)=false]; int64 power = 3; } // ValidatorUpdate message ValidatorUpdate { - PubKey pub_key = 1 [(gogoproto.nullable)=false]; - int64 power = 2; + PubKey pub_key = 1 [(gogoproto.nullable) = false]; + int64 power = 2; } // VoteInfo message VoteInfo { - Validator validator = 1 [(gogoproto.nullable)=false]; - bool signed_last_block = 2; + Validator validator = 1 [(gogoproto.nullable) = false]; + bool signed_last_block = 2; } message PubKey { @@ -319,18 +321,18 @@ message PubKey { } message Evidence { - string type = 1; - Validator validator = 2 [(gogoproto.nullable)=false]; - int64 height = 3; - google.protobuf.Timestamp time = 4 [(gogoproto.nullable)=false, (gogoproto.stdtime)=true]; - int64 total_voting_power = 5; + string type = 1; + Validator validator = 2 [(gogoproto.nullable) = false]; + int64 height = 3; + google.protobuf.Timestamp time = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; + int64 total_voting_power = 5; } //---------------------------------------- // Service Definition service ABCIApplication { - rpc Echo(RequestEcho) returns (ResponseEcho) ; + rpc Echo(RequestEcho) returns (ResponseEcho); rpc Flush(RequestFlush) returns (ResponseFlush); rpc Info(RequestInfo) returns (ResponseInfo); rpc SetOption(RequestSetOption) returns (ResponseSetOption); diff --git a/third_party/proto/tendermint/crypto/merkle/merkle.proto b/third_party/proto/tendermint/crypto/merkle/merkle.proto index 9dbb2be074e8..159fc58c98dd 100644 --- a/third_party/proto/tendermint/crypto/merkle/merkle.proto +++ b/third_party/proto/tendermint/crypto/merkle/merkle.proto @@ -1,17 +1,17 @@ syntax = "proto3"; package tendermint.crypto.merkle; -option go_package = "github.com/tendermint/tendermint/crypto/merkle"; +option go_package = "github.com/tendermint/tendermint/crypto/merkle"; // For more information on gogo.proto, see: // https://github.com/gogo/protobuf/blob/master/extensions.md import "third_party/proto/gogoproto/gogo.proto"; -option (gogoproto.marshaler_all) = true; +option (gogoproto.marshaler_all) = true; option (gogoproto.unmarshaler_all) = true; -option (gogoproto.sizer_all) = true; +option (gogoproto.sizer_all) = true; option (gogoproto.populate_all) = true; -option (gogoproto.equal_all) = true; +option (gogoproto.equal_all) = true; //---------------------------------------- // Message types @@ -21,11 +21,11 @@ option (gogoproto.equal_all) = true; // for example neighbouring node hash message ProofOp { string type = 1; - bytes key = 2; - bytes data = 3; + bytes key = 2; + bytes data = 3; } // Proof is Merkle proof defined by the list of ProofOps message Proof { - repeated ProofOp ops = 1 [(gogoproto.nullable)=false]; + repeated ProofOp ops = 1 [(gogoproto.nullable) = false]; } diff --git a/third_party/proto/tendermint/libs/kv/types.proto b/third_party/proto/tendermint/libs/kv/types.proto index 247022798347..7e1375c21aba 100644 --- a/third_party/proto/tendermint/libs/kv/types.proto +++ b/third_party/proto/tendermint/libs/kv/types.proto @@ -1,29 +1,29 @@ syntax = "proto3"; package tendermint.libs.kv; -option go_package = "github.com/tendermint/tendermint/libs/kv"; +option go_package = "github.com/tendermint/tendermint/libs/kv"; import "third_party/proto/gogoproto/gogo.proto"; -option (gogoproto.marshaler_all) = true; -option (gogoproto.unmarshaler_all) = true; -option (gogoproto.sizer_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.sizer_all) = true; option (gogoproto.goproto_registration) = true; // Generate tests option (gogoproto.populate_all) = true; -option (gogoproto.equal_all) = true; -option (gogoproto.testgen_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.testgen_all) = true; //---------------------------------------- // Abstract types -// Define these here for compatibility but use tmlibs/common.KVPair. +// Define these here for compatibility but use tmlibs/kv.Pair. message Pair { - bytes key = 1; + bytes key = 1; bytes value = 2; } -// Define these here for compatibility but use tmlibs/common.KI64Pair. +// Define these here for compatibility but use tmlibs/kv.KI64Pair. message KI64Pair { - bytes key = 1; + bytes key = 1; int64 value = 2; } diff --git a/types/proto.go b/types/proto.go index e4cdbdc511c0..b6978c1eb9a5 100644 --- a/types/proto.go +++ b/types/proto.go @@ -1,7 +1,7 @@ package types import ( - _ "github.com/gogo/protobuf/gogoproto" // nolint + _ "github.com/gogo/protobuf/gogoproto" // nolint _ "github.com/regen-network/cosmos-proto" // nolint ) diff --git a/x/auth/types/account.go b/x/auth/types/account.go index 1c2460166e22..08b67facc3de 100644 --- a/x/auth/types/account.go +++ b/x/auth/types/account.go @@ -7,6 +7,7 @@ import ( "github.com/tendermint/tendermint/crypto" yaml "gopkg.in/yaml.v2" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/exported" ) @@ -16,17 +17,14 @@ var _ exported.GenesisAccount = (*BaseAccount)(nil) // NewBaseAccount creates a new BaseAccount object func NewBaseAccount(address sdk.AccAddress, pubKey crypto.PubKey, accountNumber, sequence uint64) *BaseAccount { - var pkStr string - if pubKey != nil { - pkStr = sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKey) - } - - return &BaseAccount{ + acc := &BaseAccount{ Address: address, - PubKey: pkStr, AccountNumber: accountNumber, Sequence: sequence, } + + acc.SetPubKey(pubKey) + return acc } // ProtoBaseAccount - a prototype function for BaseAccount @@ -57,22 +55,23 @@ func (acc *BaseAccount) SetAddress(addr sdk.AccAddress) error { } // GetPubKey - Implements sdk.Account. -func (acc BaseAccount) GetPubKey() crypto.PubKey { - if acc.PubKey == "" { +func (acc BaseAccount) GetPubKey() (pk crypto.PubKey) { + if len(acc.PubKey) == 0 { return nil } - return sdk.MustGetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, acc.PubKey) + codec.Cdc.MustUnmarshalBinaryBare(acc.PubKey, &pk) + return pk } // SetPubKey - Implements sdk.Account. func (acc *BaseAccount) SetPubKey(pubKey crypto.PubKey) error { - pkStr, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKey) - if err != nil { - return err + if pubKey == nil { + acc.PubKey = nil + } else { + acc.PubKey = pubKey.Bytes() } - acc.PubKey = pkStr return nil } @@ -100,15 +99,47 @@ func (acc *BaseAccount) SetSequence(seq uint64) error { // Validate checks for errors on the account fields func (acc BaseAccount) Validate() error { - if acc.PubKey != "" && acc.Address != nil && + if len(acc.PubKey) != 0 && acc.Address != nil && !bytes.Equal(acc.GetPubKey().Address().Bytes(), acc.Address.Bytes()) { - return errors.New("pubkey and address pair is invalid") + return errors.New("account address and pubkey address do not match") } return nil } func (acc BaseAccount) String() string { - out, _ := yaml.Marshal(acc) - return string(out) + out, _ := acc.MarshalYAML() + return out.(string) +} + +type baseAccountPretty struct { + Address sdk.AccAddress `json:"address" yaml:"address"` + PubKey string `json:"public_key" yaml:"public_key"` + AccountNumber uint64 `json:"account_number" yaml:"account_number"` + Sequence uint64 `json:"sequence" yaml:"sequence"` +} + +// MarshalYAML returns the YAML representation of an account. +func (acc BaseAccount) MarshalYAML() (interface{}, error) { + alias := baseAccountPretty{ + Address: acc.Address, + AccountNumber: acc.AccountNumber, + Sequence: acc.Sequence, + } + + if acc.PubKey != nil { + pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, acc.GetPubKey()) + if err != nil { + return nil, err + } + + alias.PubKey = pks + } + + bz, err := yaml.Marshal(alias) + if err != nil { + return nil, err + } + + return string(bz), err } diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index e86f4b5940b1..ca612f1fe188 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -1,7 +1,6 @@ package types_test import ( - "errors" "testing" "github.com/stretchr/testify/require" @@ -86,17 +85,17 @@ func TestGenesisAccountValidate(t *testing.T) { tests := []struct { name string acc exported.GenesisAccount - expErr error + expErr bool }{ { "valid base account", baseAcc, - nil, + false, }, { "invalid base valid account", types.NewBaseAccount(addr, secp256k1.GenPrivKey().PubKey(), 0, 0), - errors.New("pubkey and address pair is invalid"), + true, }, } @@ -104,8 +103,7 @@ func TestGenesisAccountValidate(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { - err := tt.acc.Validate() - require.Equal(t, tt.expErr, err) + require.Equal(t, tt.expErr, tt.acc.Validate() != nil) }) } } diff --git a/x/auth/types/types.pb.go b/x/auth/types/types.pb.go index 04705c07d3d3..6770d4eb2b2b 100644 --- a/x/auth/types/types.pb.go +++ b/x/auth/types/types.pb.go @@ -30,7 +30,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // type for additional functionality (e.g. vesting). type BaseAccount struct { Address github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=address,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"address,omitempty"` - PubKey string `protobuf:"bytes,2,opt,name=pub_key,json=pubKey,proto3" json:"pub_key,omitempty" yaml:"public_key"` + PubKey []byte `protobuf:"bytes,2,opt,name=pub_key,json=pubKey,proto3" json:"pub_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"` } @@ -207,46 +207,45 @@ func init() { func init() { proto.RegisterFile("x/auth/types/types.proto", fileDescriptor_2d526fa662daab74) } var fileDescriptor_2d526fa662daab74 = []byte{ - // 610 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x3d, 0x6f, 0xd3, 0x4e, - 0x18, 0x8f, 0xff, 0xc9, 0x3f, 0x2d, 0xd7, 0x82, 0x88, 0xfb, 0xe6, 0x46, 0xc8, 0x17, 0x79, 0x40, - 0x61, 0xa8, 0x43, 0x8a, 0x8a, 0xd4, 0x0c, 0x88, 0x3a, 0xc0, 0x52, 0xa8, 0x2a, 0x47, 0x62, 0x40, - 0x42, 0xd6, 0xf9, 0x7c, 0x38, 0x56, 0x7a, 0x39, 0xd7, 0x77, 0xae, 0xec, 0x7e, 0x02, 0x46, 0x46, - 0xc6, 0xce, 0x7c, 0x92, 0x8e, 0x1d, 0x99, 0x5c, 0x94, 0x2e, 0xcc, 0x1e, 0x99, 0x90, 0x7d, 0x69, - 0x49, 0x4b, 0x41, 0x2c, 0xc9, 0x3d, 0xcf, 0xef, 0xed, 0xee, 0xf1, 0x1d, 0xd0, 0x92, 0x0e, 0x8a, - 0xc5, 0xb0, 0x23, 0xd2, 0x90, 0x70, 0xf9, 0x6b, 0x86, 0x11, 0x13, 0x4c, 0x5d, 0xc6, 0x8c, 0x53, - 0xc6, 0x1d, 0xee, 0x8d, 0xcc, 0xc4, 0x2c, 0x48, 0xe6, 0x51, 0xb7, 0xf9, 0x50, 0x0c, 0x83, 0xc8, - 0x73, 0x42, 0x14, 0x89, 0xb4, 0x53, 0x12, 0x3b, 0x3e, 0xf3, 0xd9, 0xaf, 0x95, 0x54, 0x37, 0x1b, - 0xbf, 0x19, 0x1a, 0xb9, 0x02, 0x16, 0x2c, 0xc4, 0xc9, 0x0e, 0xc6, 0x2c, 0x1e, 0x0b, 0x75, 0x17, - 0xcc, 0x21, 0xcf, 0x8b, 0x08, 0xe7, 0x9a, 0xd2, 0x52, 0xda, 0x8b, 0x56, 0xf7, 0x47, 0x06, 0x37, - 0xfc, 0x40, 0x0c, 0x63, 0xd7, 0xc4, 0x8c, 0x76, 0xe4, 0x06, 0xa6, 0x7f, 0x1b, 0xdc, 0x1b, 0x4d, - 0xed, 0x76, 0x30, 0xde, 0x91, 0x42, 0xfb, 0xd2, 0x41, 0x35, 0xc1, 0x5c, 0x18, 0xbb, 0xce, 0x88, - 0xa4, 0xda, 0x7f, 0x2d, 0xa5, 0x7d, 0xc7, 0x5a, 0xc9, 0x33, 0xd8, 0x48, 0x11, 0x3d, 0xe8, 0x19, - 0x61, 0xec, 0x1e, 0x04, 0xb8, 0xc0, 0x0c, 0xbb, 0x1e, 0xc6, 0xee, 0x2e, 0x49, 0xd5, 0xe7, 0xe0, - 0x1e, 0x92, 0xfb, 0x70, 0xc6, 0x31, 0x75, 0x49, 0xa4, 0x55, 0x5b, 0x4a, 0xbb, 0x66, 0xad, 0xe7, - 0x19, 0x5c, 0x91, 0xb2, 0xeb, 0xb8, 0x61, 0xdf, 0x9d, 0x36, 0xf6, 0xca, 0x5a, 0x6d, 0x82, 0x79, - 0x4e, 0x0e, 0x63, 0x32, 0xc6, 0x44, 0xab, 0x15, 0x5a, 0xfb, 0xaa, 0xee, 0xcd, 0x7f, 0x3c, 0x81, - 0x95, 0xcf, 0x27, 0xb0, 0x62, 0xa4, 0xa0, 0x3e, 0x10, 0xde, 0x2b, 0x42, 0xd4, 0xf7, 0xa0, 0x8e, - 0x68, 0xa1, 0xd7, 0x94, 0x56, 0xb5, 0xbd, 0xb0, 0xb9, 0x64, 0xce, 0x0c, 0xf8, 0xa8, 0x6b, 0xf6, - 0x59, 0x30, 0xb6, 0x1e, 0x9f, 0x66, 0xb0, 0xf2, 0xe5, 0x1c, 0xb6, 0xff, 0x61, 0x0c, 0x85, 0x80, - 0xdb, 0x53, 0x53, 0xf5, 0x3e, 0xa8, 0xfa, 0x88, 0x97, 0x87, 0xaf, 0xd9, 0xc5, 0xd2, 0x38, 0xaf, - 0x82, 0xfa, 0x3e, 0x8a, 0x10, 0xe5, 0xea, 0x1e, 0x58, 0xa2, 0x28, 0x71, 0x28, 0xa1, 0xcc, 0xc1, - 0x43, 0x14, 0x21, 0x2c, 0x48, 0x24, 0xc7, 0x5e, 0xb3, 0xf4, 0x3c, 0x83, 0x4d, 0x79, 0xe4, 0x5b, - 0x48, 0x86, 0xdd, 0xa0, 0x28, 0x79, 0x43, 0x28, 0xeb, 0x5f, 0xf5, 0xd4, 0x6d, 0xb0, 0x28, 0x12, - 0x87, 0x07, 0xbe, 0x73, 0x10, 0xd0, 0x40, 0xc8, 0x54, 0x6b, 0x2d, 0xcf, 0xe0, 0x92, 0x34, 0x9a, - 0x45, 0x0d, 0x1b, 0x88, 0x64, 0x10, 0xf8, 0xaf, 0x8b, 0x42, 0xb5, 0xc1, 0x4a, 0x09, 0x1e, 0x13, - 0x07, 0x33, 0x2e, 0x9c, 0x90, 0x44, 0x8e, 0x9b, 0x0a, 0x32, 0x9d, 0x7f, 0x2b, 0xcf, 0xe0, 0x83, - 0x19, 0x8f, 0x9b, 0x34, 0xc3, 0x6e, 0x14, 0x66, 0xc7, 0xa4, 0xcf, 0xb8, 0xd8, 0x27, 0x91, 0x95, - 0x0a, 0xa2, 0x1e, 0x82, 0xb5, 0x22, 0xed, 0x88, 0x44, 0xc1, 0x87, 0x54, 0xf2, 0x89, 0xb7, 0xb9, - 0xb5, 0xd5, 0xdd, 0x96, 0x5f, 0xc6, 0xea, 0x4d, 0x32, 0xb8, 0x3c, 0x08, 0xfc, 0xb7, 0x25, 0xa3, - 0x90, 0xbe, 0x7c, 0x51, 0xe2, 0x79, 0x06, 0x75, 0x99, 0xf6, 0x07, 0x03, 0xc3, 0x5e, 0xe6, 0xd7, - 0x74, 0xb2, 0xad, 0xa6, 0x60, 0xfd, 0xa6, 0x82, 0x13, 0x1c, 0x6e, 0x6e, 0x3d, 0x1d, 0x75, 0xb5, - 0xff, 0xcb, 0xd0, 0x67, 0x93, 0x0c, 0xae, 0x5e, 0x0b, 0x1d, 0x5c, 0x32, 0xf2, 0x0c, 0xb6, 0x6e, - 0x8f, 0xbd, 0x32, 0x31, 0xec, 0x55, 0x7e, 0xab, 0xb6, 0x37, 0x5f, 0x5c, 0xac, 0xef, 0x27, 0x50, - 0xb1, 0xfa, 0xa7, 0x13, 0x5d, 0x39, 0x9b, 0xe8, 0xca, 0xb7, 0x89, 0xae, 0x7c, 0xba, 0xd0, 0x2b, - 0x67, 0x17, 0x7a, 0xe5, 0xeb, 0x85, 0x5e, 0x79, 0xf7, 0xe8, 0xaf, 0xf7, 0x67, 0xf6, 0xcd, 0xbb, - 0xf5, 0xf2, 0x75, 0x3e, 0xf9, 0x19, 0x00, 0x00, 0xff, 0xff, 0xd6, 0x52, 0x88, 0x39, 0x0a, 0x04, - 0x00, 0x00, + // 606 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x3f, 0x6f, 0xd3, 0x40, + 0x14, 0x8f, 0x49, 0x48, 0xab, 0x6b, 0x41, 0xc4, 0xfd, 0xe7, 0x46, 0xc8, 0x17, 0x79, 0x40, 0x61, + 0xa8, 0x43, 0x8a, 0x8a, 0xd4, 0x0c, 0x88, 0x3a, 0xc0, 0x52, 0xa8, 0x2a, 0x47, 0x62, 0x40, 0x42, + 0xd6, 0xf9, 0x7c, 0x38, 0x56, 0x7a, 0x39, 0xd7, 0x77, 0xae, 0xec, 0x7e, 0x02, 0x46, 0x46, 0xc6, + 0xce, 0x7c, 0x92, 0x8e, 0x1d, 0x99, 0x5c, 0x94, 0x2e, 0xcc, 0x1e, 0x99, 0x90, 0x7d, 0x69, 0x49, + 0x4b, 0x41, 0x2c, 0xc9, 0xbd, 0xf7, 0xfb, 0x77, 0xf7, 0x7c, 0x07, 0xb4, 0xa4, 0x83, 0x62, 0x31, + 0xec, 0x88, 0x34, 0x24, 0x5c, 0xfe, 0x9a, 0x61, 0xc4, 0x04, 0x53, 0x97, 0x31, 0xe3, 0x94, 0x71, + 0x87, 0x7b, 0x23, 0x33, 0x31, 0x0b, 0x92, 0x79, 0xd4, 0x6d, 0x3e, 0x12, 0xc3, 0x20, 0xf2, 0x9c, + 0x10, 0x45, 0x22, 0xed, 0x94, 0xc4, 0x8e, 0xcf, 0x7c, 0xf6, 0x7b, 0x25, 0xd5, 0xcd, 0xc6, 0x1f, + 0x86, 0x46, 0xae, 0x80, 0x05, 0x0b, 0x71, 0xb2, 0x83, 0x31, 0x8b, 0xc7, 0x42, 0xdd, 0x05, 0x73, + 0xc8, 0xf3, 0x22, 0xc2, 0xb9, 0xa6, 0xb4, 0x94, 0xf6, 0xa2, 0xd5, 0xfd, 0x99, 0xc1, 0x0d, 0x3f, + 0x10, 0xc3, 0xd8, 0x35, 0x31, 0xa3, 0x1d, 0xb9, 0x81, 0xe9, 0xdf, 0x06, 0xf7, 0x46, 0x53, 0xbb, + 0x1d, 0x8c, 0x77, 0xa4, 0xd0, 0xbe, 0x74, 0x50, 0x4d, 0x30, 0x17, 0xc6, 0xae, 0x33, 0x22, 0xa9, + 0x76, 0xa7, 0x34, 0x5b, 0xc9, 0x33, 0xd8, 0x48, 0x11, 0x3d, 0xe8, 0x19, 0x61, 0xec, 0x1e, 0x04, + 0xb8, 0xc0, 0x0c, 0xbb, 0x1e, 0xc6, 0xee, 0x2e, 0x49, 0xd5, 0x17, 0xe0, 0x3e, 0x92, 0xfb, 0x70, + 0xc6, 0x31, 0x75, 0x49, 0xa4, 0x55, 0x5b, 0x4a, 0xbb, 0x66, 0xad, 0xe7, 0x19, 0x5c, 0x91, 0xb2, + 0xeb, 0xb8, 0x61, 0xdf, 0x9b, 0x36, 0xf6, 0xca, 0x5a, 0x6d, 0x82, 0x79, 0x4e, 0x0e, 0x63, 0x32, + 0xc6, 0x44, 0xab, 0x15, 0x5a, 0xfb, 0xaa, 0xee, 0xcd, 0x7f, 0x3a, 0x81, 0x95, 0x2f, 0x27, 0xb0, + 0x62, 0xa4, 0xa0, 0x3e, 0x10, 0xde, 0x6b, 0x42, 0xd4, 0x0f, 0xa0, 0x8e, 0x68, 0xa1, 0xd7, 0x94, + 0x56, 0xb5, 0xbd, 0xb0, 0xb9, 0x64, 0xce, 0x0c, 0xf8, 0xa8, 0x6b, 0xf6, 0x59, 0x30, 0xb6, 0x9e, + 0x9c, 0x66, 0xb0, 0xf2, 0xf5, 0x1c, 0xb6, 0xff, 0x63, 0x0c, 0x85, 0x80, 0xdb, 0x53, 0x53, 0xf5, + 0x01, 0xa8, 0xfa, 0x88, 0x97, 0x87, 0xaf, 0xd9, 0xc5, 0xd2, 0x38, 0xaf, 0x82, 0xfa, 0x3e, 0x8a, + 0x10, 0xe5, 0xea, 0x1e, 0x58, 0xa2, 0x28, 0x71, 0x28, 0xa1, 0xcc, 0xc1, 0x43, 0x14, 0x21, 0x2c, + 0x48, 0x24, 0xc7, 0x5e, 0xb3, 0xf4, 0x3c, 0x83, 0x4d, 0x79, 0xe4, 0x5b, 0x48, 0x86, 0xdd, 0xa0, + 0x28, 0x79, 0x4b, 0x28, 0xeb, 0x5f, 0xf5, 0xd4, 0x6d, 0xb0, 0x28, 0x12, 0x87, 0x07, 0xbe, 0x73, + 0x10, 0xd0, 0x40, 0xc8, 0x54, 0x6b, 0x2d, 0xcf, 0xe0, 0x92, 0x34, 0x9a, 0x45, 0x0d, 0x1b, 0x88, + 0x64, 0x10, 0xf8, 0x6f, 0x8a, 0x42, 0xb5, 0xc1, 0x4a, 0x09, 0x1e, 0x13, 0x07, 0x33, 0x2e, 0x9c, + 0x90, 0x44, 0x8e, 0x9b, 0x0a, 0x32, 0x9d, 0x7f, 0x2b, 0xcf, 0xe0, 0xc3, 0x19, 0x8f, 0x9b, 0x34, + 0xc3, 0x6e, 0x14, 0x66, 0xc7, 0xa4, 0xcf, 0xb8, 0xd8, 0x27, 0x91, 0x95, 0x0a, 0xa2, 0x1e, 0x82, + 0xb5, 0x22, 0xed, 0x88, 0x44, 0xc1, 0xc7, 0x54, 0xf2, 0x89, 0xb7, 0xb9, 0xb5, 0xd5, 0xdd, 0x96, + 0x5f, 0xc6, 0xea, 0x4d, 0x32, 0xb8, 0x3c, 0x08, 0xfc, 0x77, 0x25, 0xa3, 0x90, 0xbe, 0x7a, 0x59, + 0xe2, 0x79, 0x06, 0x75, 0x99, 0xf6, 0x17, 0x03, 0xc3, 0x5e, 0xe6, 0xd7, 0x74, 0xb2, 0xad, 0xa6, + 0x60, 0xfd, 0xa6, 0x82, 0x13, 0x1c, 0x6e, 0x6e, 0x3d, 0x1b, 0x75, 0xb5, 0xbb, 0x65, 0xe8, 0xf3, + 0x49, 0x06, 0x57, 0xaf, 0x85, 0x0e, 0x2e, 0x19, 0x79, 0x06, 0x5b, 0xb7, 0xc7, 0x5e, 0x99, 0x18, + 0xf6, 0x2a, 0xbf, 0x55, 0xdb, 0x9b, 0x2f, 0x2e, 0xd6, 0x8f, 0x13, 0xa8, 0x58, 0xfd, 0xd3, 0x89, + 0xae, 0x9c, 0x4d, 0x74, 0xe5, 0xfb, 0x44, 0x57, 0x3e, 0x5f, 0xe8, 0x95, 0xb3, 0x0b, 0xbd, 0xf2, + 0xed, 0x42, 0xaf, 0xbc, 0x7f, 0xfc, 0xcf, 0xfb, 0x33, 0xfb, 0xe6, 0xdd, 0x7a, 0xf9, 0x3a, 0x9f, + 0xfe, 0x0a, 0x00, 0x00, 0xff, 0xff, 0x84, 0x2e, 0x85, 0xe8, 0x0a, 0x04, 0x00, 0x00, } func (this *Params) Equal(that interface{}) bool { @@ -571,7 +570,7 @@ func (m *BaseAccount) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field PubKey", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -581,23 +580,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 ErrInvalidLengthTypes } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - m.PubKey = string(dAtA[iNdEx:postIndex]) + m.PubKey = append(m.PubKey[:0], dAtA[iNdEx:postIndex]...) + if m.PubKey == nil { + m.PubKey = []byte{} + } iNdEx = postIndex case 3: if wireType != 0 { diff --git a/x/auth/types/types.proto b/x/auth/types/types.proto index c707eb9c55ab..8a0d6555c7c5 100644 --- a/x/auth/types/types.proto +++ b/x/auth/types/types.proto @@ -14,7 +14,7 @@ message BaseAccount { option (gogoproto.goproto_stringer) = false; bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; - string pub_key = 2 [(gogoproto.moretags) = "yaml:\"public_key\""]; + bytes pub_key = 2 [(gogoproto.moretags) = "yaml:\"public_key\""]; uint64 account_number = 3 [(gogoproto.moretags) = "yaml:\"account_number\""]; uint64 sequence = 4; } diff --git a/x/auth/vesting/types/vesting_account.go b/x/auth/vesting/types/vesting_account.go index cbbeffc03143..d4b6fc6345cf 100644 --- a/x/auth/vesting/types/vesting_account.go +++ b/x/auth/vesting/types/vesting_account.go @@ -1,10 +1,10 @@ package types import ( - "encoding/json" "errors" "time" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -164,7 +164,7 @@ func (bva BaseVestingAccount) Validate() error { return bva.BaseAccount.Validate() } -type vestingAccountPretty struct { +type vestingAccountYAML struct { Address sdk.AccAddress `json:"address" yaml:"address"` PubKey string `json:"public_key" yaml:"public_key"` AccountNumber uint64 `json:"account_number" yaml:"account_number"` @@ -179,6 +179,21 @@ type vestingAccountPretty struct { VestingPeriods Periods `json:"vesting_periods,omitempty" yaml:"vesting_periods,omitempty"` } +type vestingAccountJSON struct { + Address sdk.AccAddress `json:"address" yaml:"address"` + PubKey crypto.PubKey `json:"public_key" yaml:"public_key"` + AccountNumber uint64 `json:"account_number" yaml:"account_number"` + Sequence uint64 `json:"sequence" yaml:"sequence"` + OriginalVesting sdk.Coins `json:"original_vesting" yaml:"original_vesting"` + DelegatedFree sdk.Coins `json:"delegated_free" yaml:"delegated_free"` + DelegatedVesting sdk.Coins `json:"delegated_vesting" yaml:"delegated_vesting"` + EndTime int64 `json:"end_time" yaml:"end_time"` + + // custom fields based on concrete vesting type which can be omitted + StartTime int64 `json:"start_time,omitempty" yaml:"start_time,omitempty"` + VestingPeriods Periods `json:"vesting_periods,omitempty" yaml:"vesting_periods,omitempty"` +} + func (bva BaseVestingAccount) String() string { out, _ := bva.MarshalYAML() return out.(string) @@ -186,9 +201,8 @@ func (bva BaseVestingAccount) String() string { // MarshalYAML returns the YAML representation of a BaseVestingAccount. func (bva BaseVestingAccount) MarshalYAML() (interface{}, error) { - alias := vestingAccountPretty{ + alias := vestingAccountYAML{ Address: bva.Address, - PubKey: bva.PubKey, AccountNumber: bva.AccountNumber, Sequence: bva.Sequence, OriginalVesting: bva.OriginalVesting, @@ -197,6 +211,16 @@ func (bva BaseVestingAccount) MarshalYAML() (interface{}, error) { EndTime: bva.EndTime, } + pk := bva.GetPubKey() + if pk != nil { + pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pk) + if err != nil { + return nil, err + } + + alias.PubKey = pks + } + bz, err := yaml.Marshal(alias) if err != nil { return nil, err @@ -207,9 +231,9 @@ func (bva BaseVestingAccount) MarshalYAML() (interface{}, error) { // MarshalJSON returns the JSON representation of a BaseVestingAccount. func (bva BaseVestingAccount) MarshalJSON() ([]byte, error) { - alias := vestingAccountPretty{ + alias := vestingAccountJSON{ Address: bva.Address, - PubKey: bva.PubKey, + PubKey: bva.GetPubKey(), AccountNumber: bva.AccountNumber, Sequence: bva.Sequence, OriginalVesting: bva.OriginalVesting, @@ -218,29 +242,17 @@ func (bva BaseVestingAccount) MarshalJSON() ([]byte, error) { EndTime: bva.EndTime, } - return json.Marshal(alias) + return codec.Cdc.MarshalJSON(alias) } // UnmarshalJSON unmarshals raw JSON bytes into a BaseVestingAccount. func (bva *BaseVestingAccount) UnmarshalJSON(bz []byte) error { - var alias vestingAccountPretty - if err := json.Unmarshal(bz, &alias); err != nil { + var alias vestingAccountJSON + if err := codec.Cdc.UnmarshalJSON(bz, &alias); err != nil { return err } - var ( - pk crypto.PubKey - err error - ) - - if alias.PubKey != "" { - pk, err = sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, alias.PubKey) - if err != nil { - return err - } - } - - bva.BaseAccount = authtypes.NewBaseAccount(alias.Address, pk, alias.AccountNumber, alias.Sequence) + bva.BaseAccount = authtypes.NewBaseAccount(alias.Address, alias.PubKey, alias.AccountNumber, alias.Sequence) bva.OriginalVesting = alias.OriginalVesting bva.DelegatedFree = alias.DelegatedFree bva.DelegatedVesting = alias.DelegatedVesting @@ -344,9 +356,8 @@ func (cva ContinuousVestingAccount) String() string { // MarshalYAML returns the YAML representation of a ContinuousVestingAccount. func (cva ContinuousVestingAccount) MarshalYAML() (interface{}, error) { - alias := vestingAccountPretty{ + alias := vestingAccountYAML{ Address: cva.Address, - PubKey: cva.PubKey, AccountNumber: cva.AccountNumber, Sequence: cva.Sequence, OriginalVesting: cva.OriginalVesting, @@ -356,6 +367,16 @@ func (cva ContinuousVestingAccount) MarshalYAML() (interface{}, error) { StartTime: cva.StartTime, } + pk := cva.GetPubKey() + if pk != nil { + pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pk) + if err != nil { + return nil, err + } + + alias.PubKey = pks + } + bz, err := yaml.Marshal(alias) if err != nil { return nil, err @@ -366,9 +387,9 @@ func (cva ContinuousVestingAccount) MarshalYAML() (interface{}, error) { // MarshalJSON returns the JSON representation of a ContinuousVestingAccount. func (cva ContinuousVestingAccount) MarshalJSON() ([]byte, error) { - alias := vestingAccountPretty{ + alias := vestingAccountJSON{ Address: cva.Address, - PubKey: cva.PubKey, + PubKey: cva.GetPubKey(), AccountNumber: cva.AccountNumber, Sequence: cva.Sequence, OriginalVesting: cva.OriginalVesting, @@ -378,30 +399,18 @@ func (cva ContinuousVestingAccount) MarshalJSON() ([]byte, error) { StartTime: cva.StartTime, } - return json.Marshal(alias) + return codec.Cdc.MarshalJSON(alias) } // UnmarshalJSON unmarshals raw JSON bytes into a ContinuousVestingAccount. func (cva *ContinuousVestingAccount) UnmarshalJSON(bz []byte) error { - var alias vestingAccountPretty - if err := json.Unmarshal(bz, &alias); err != nil { + var alias vestingAccountJSON + if err := codec.Cdc.UnmarshalJSON(bz, &alias); err != nil { return err } - var ( - pk crypto.PubKey - err error - ) - - if alias.PubKey != "" { - pk, err = sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, alias.PubKey) - if err != nil { - return err - } - } - cva.BaseVestingAccount = &BaseVestingAccount{ - BaseAccount: authtypes.NewBaseAccount(alias.Address, pk, alias.AccountNumber, alias.Sequence), + BaseAccount: authtypes.NewBaseAccount(alias.Address, alias.PubKey, alias.AccountNumber, alias.Sequence), OriginalVesting: alias.OriginalVesting, DelegatedFree: alias.DelegatedFree, DelegatedVesting: alias.DelegatedVesting, @@ -536,9 +545,8 @@ func (pva PeriodicVestingAccount) String() string { // MarshalYAML returns the YAML representation of a PeriodicVestingAccount. func (pva PeriodicVestingAccount) MarshalYAML() (interface{}, error) { - alias := vestingAccountPretty{ + alias := vestingAccountYAML{ Address: pva.Address, - PubKey: pva.PubKey, AccountNumber: pva.AccountNumber, Sequence: pva.Sequence, OriginalVesting: pva.OriginalVesting, @@ -549,6 +557,16 @@ func (pva PeriodicVestingAccount) MarshalYAML() (interface{}, error) { VestingPeriods: pva.VestingPeriods, } + pk := pva.GetPubKey() + if pk != nil { + pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pk) + if err != nil { + return nil, err + } + + alias.PubKey = pks + } + bz, err := yaml.Marshal(alias) if err != nil { return nil, err @@ -559,9 +577,9 @@ func (pva PeriodicVestingAccount) MarshalYAML() (interface{}, error) { // MarshalJSON returns the JSON representation of a PeriodicVestingAccount. func (pva PeriodicVestingAccount) MarshalJSON() ([]byte, error) { - alias := vestingAccountPretty{ + alias := vestingAccountJSON{ Address: pva.Address, - PubKey: pva.PubKey, + PubKey: pva.GetPubKey(), AccountNumber: pva.AccountNumber, Sequence: pva.Sequence, OriginalVesting: pva.OriginalVesting, @@ -572,30 +590,18 @@ func (pva PeriodicVestingAccount) MarshalJSON() ([]byte, error) { VestingPeriods: pva.VestingPeriods, } - return json.Marshal(alias) + return codec.Cdc.MarshalJSON(alias) } // UnmarshalJSON unmarshals raw JSON bytes into a PeriodicVestingAccount. func (pva *PeriodicVestingAccount) UnmarshalJSON(bz []byte) error { - var alias vestingAccountPretty - if err := json.Unmarshal(bz, &alias); err != nil { + var alias vestingAccountJSON + if err := codec.Cdc.UnmarshalJSON(bz, &alias); err != nil { return err } - var ( - pk crypto.PubKey - err error - ) - - if alias.PubKey != "" { - pk, err = sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, alias.PubKey) - if err != nil { - return err - } - } - pva.BaseVestingAccount = &BaseVestingAccount{ - BaseAccount: authtypes.NewBaseAccount(alias.Address, pk, alias.AccountNumber, alias.Sequence), + BaseAccount: authtypes.NewBaseAccount(alias.Address, alias.PubKey, alias.AccountNumber, alias.Sequence), OriginalVesting: alias.OriginalVesting, DelegatedFree: alias.DelegatedFree, DelegatedVesting: alias.DelegatedVesting, @@ -676,9 +682,9 @@ func (dva DelayedVestingAccount) String() string { // MarshalJSON returns the JSON representation of a DelayedVestingAccount. func (dva DelayedVestingAccount) MarshalJSON() ([]byte, error) { - alias := vestingAccountPretty{ + alias := vestingAccountJSON{ Address: dva.Address, - PubKey: dva.PubKey, + PubKey: dva.GetPubKey(), AccountNumber: dva.AccountNumber, Sequence: dva.Sequence, OriginalVesting: dva.OriginalVesting, @@ -687,30 +693,18 @@ func (dva DelayedVestingAccount) MarshalJSON() ([]byte, error) { EndTime: dva.EndTime, } - return json.Marshal(alias) + return codec.Cdc.MarshalJSON(alias) } // UnmarshalJSON unmarshals raw JSON bytes into a DelayedVestingAccount. func (dva *DelayedVestingAccount) UnmarshalJSON(bz []byte) error { - var alias vestingAccountPretty - if err := json.Unmarshal(bz, &alias); err != nil { + var alias vestingAccountJSON + if err := codec.Cdc.UnmarshalJSON(bz, &alias); err != nil { return err } - var ( - pk crypto.PubKey - err error - ) - - if alias.PubKey != "" { - pk, err = sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, alias.PubKey) - if err != nil { - return err - } - } - dva.BaseVestingAccount = &BaseVestingAccount{ - BaseAccount: authtypes.NewBaseAccount(alias.Address, pk, alias.AccountNumber, alias.Sequence), + BaseAccount: authtypes.NewBaseAccount(alias.Address, alias.PubKey, alias.AccountNumber, alias.Sequence), OriginalVesting: alias.OriginalVesting, DelegatedFree: alias.DelegatedFree, DelegatedVesting: alias.DelegatedVesting, diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index e36661111fef..974a1f3149c2 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -2,7 +2,6 @@ package types_test import ( "encoding/json" - "errors" "testing" "time" @@ -589,58 +588,59 @@ func TestGenesisAccountValidate(t *testing.T) { tests := []struct { name string acc authexported.GenesisAccount - expErr error + expErr bool }{ { "valid base account", baseAcc, - nil, + false, }, { "invalid base valid account", authtypes.NewBaseAccount(addr, secp256k1.GenPrivKey().PubKey(), 0, 0), - errors.New("pubkey and address pair is invalid"), + true, }, { "valid base vesting account", baseVestingWithCoins, - nil, + false, }, { "valid continuous vesting account", types.NewContinuousVestingAccount(baseAcc, initialVesting, 100, 200), - nil, + false, }, { "invalid vesting times", types.NewContinuousVestingAccount(baseAcc, initialVesting, 1654668078, 1554668078), - errors.New("vesting start-time cannot be before end-time"), + true, }, { "valid periodic vesting account", types.NewPeriodicVestingAccount(baseAcc, initialVesting, 0, types.Periods{types.Period{Length: int64(100), Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}}}), - nil, + false, }, { "invalid vesting period lengths", types.NewPeriodicVestingAccountRaw( baseVestingWithCoins, 0, types.Periods{types.Period{Length: int64(50), Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}}}), - errors.New("vesting end time does not match length of all vesting periods"), + true, }, { "invalid vesting period amounts", types.NewPeriodicVestingAccountRaw( baseVestingWithCoins, 0, types.Periods{types.Period{Length: int64(100), Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 25)}}}), - errors.New("original vesting coins does not match the sum of all coins in vesting periods"), + true, }, } + for _, tt := range tests { tt := tt + t.Run(tt.name, func(t *testing.T) { - err := tt.acc.Validate() - require.Equal(t, tt.expErr, err) + require.Equal(t, tt.expErr, tt.acc.Validate() != nil) }) } } diff --git a/x/bank/alias.go b/x/bank/alias.go index 4ddeda71f50e..d28cf6c1d4cd 100644 --- a/x/bank/alias.go +++ b/x/bank/alias.go @@ -3,8 +3,8 @@ package bank // nolint import ( - "github.com/cosmos/cosmos-sdk/x/bank/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/keeper" + "github.com/cosmos/cosmos-sdk/x/bank/types" ) const ( diff --git a/x/bank/app_test.go b/x/bank/app_test.go index 46a33d3f62f6..4a36d2d8af77 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -16,7 +16,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/types" ) type ( diff --git a/x/bank/client/cli/query.go b/x/bank/client/cli/query.go index 046e84051448..e7327a091eb4 100644 --- a/x/bank/client/cli/query.go +++ b/x/bank/client/cli/query.go @@ -11,7 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/types" ) const ( diff --git a/x/bank/client/cli/tx.go b/x/bank/client/cli/tx.go index b2b36c45dbe7..0764045968a7 100644 --- a/x/bank/client/cli/tx.go +++ b/x/bank/client/cli/tx.go @@ -12,7 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/types" ) // GetTxCmd returns the transaction commands for this module diff --git a/x/bank/client/rest/query.go b/x/bank/client/rest/query.go index eb1f3463b7a6..99b3680bbb16 100644 --- a/x/bank/client/rest/query.go +++ b/x/bank/client/rest/query.go @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/types" ) // QueryBalancesRequestHandlerFn returns a REST handler that queries for all diff --git a/x/bank/client/rest/tx.go b/x/bank/client/rest/tx.go index 52fa9f25136b..30178166bb5f 100644 --- a/x/bank/client/rest/tx.go +++ b/x/bank/client/rest/tx.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/types" ) // SendReq defines the properties of a send request's body. diff --git a/x/bank/handler.go b/x/bank/handler.go index 3c83ec4c2af4..30341ab47b57 100644 --- a/x/bank/handler.go +++ b/x/bank/handler.go @@ -3,8 +3,8 @@ package bank import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/bank/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/keeper" + "github.com/cosmos/cosmos-sdk/x/bank/types" ) // NewHandler returns a handler for "bank" type messages. diff --git a/x/bank/internal/types/codec.go b/x/bank/internal/types/codec.go deleted file mode 100644 index 6d4d49adc118..000000000000 --- a/x/bank/internal/types/codec.go +++ /dev/null @@ -1,20 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/codec" -) - -// Register concrete types on codec codec -func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterConcrete(MsgSend{}, "cosmos-sdk/MsgSend", nil) - cdc.RegisterConcrete(MsgMultiSend{}, "cosmos-sdk/MsgMultiSend", nil) -} - -// module codec -var ModuleCdc *codec.Codec - -func init() { - ModuleCdc = codec.New() - RegisterCodec(ModuleCdc) - ModuleCdc.Seal() -} diff --git a/x/bank/internal/keeper/invariants.go b/x/bank/keeper/invariants.go similarity index 94% rename from x/bank/internal/keeper/invariants.go rename to x/bank/keeper/invariants.go index 65730451261b..3833c034d3df 100644 --- a/x/bank/internal/keeper/invariants.go +++ b/x/bank/keeper/invariants.go @@ -4,7 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/types" ) // RegisterInvariants registers the bank module invariants diff --git a/x/bank/internal/keeper/keeper.go b/x/bank/keeper/keeper.go similarity index 97% rename from x/bank/internal/keeper/keeper.go rename to x/bank/keeper/keeper.go index 9a1d16305e35..97a7dabdd6bd 100644 --- a/x/bank/internal/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -11,7 +11,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) @@ -35,7 +35,7 @@ type BaseKeeper struct { } func NewBaseKeeper( - cdc *codec.Codec, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blacklistedAddrs map[string]bool, + cdc codec.Marshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blacklistedAddrs map[string]bool, ) BaseKeeper { // set KeyTable if it has not already been set @@ -150,7 +150,7 @@ var _ SendKeeper = (*BaseSendKeeper)(nil) type BaseSendKeeper struct { BaseViewKeeper - cdc *codec.Codec + cdc codec.Marshaler ak types.AccountKeeper storeKey sdk.StoreKey paramSpace paramtypes.Subspace @@ -160,7 +160,7 @@ type BaseSendKeeper struct { } func NewBaseSendKeeper( - cdc *codec.Codec, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blacklistedAddrs map[string]bool, + cdc codec.Marshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blacklistedAddrs map[string]bool, ) BaseSendKeeper { return BaseSendKeeper{ @@ -345,7 +345,7 @@ 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) + bz := k.cdc.MustMarshalBinaryBare(&balance) accountStore.Set([]byte(balance.Denom), bz) return nil @@ -389,13 +389,13 @@ type ViewKeeper interface { // BaseViewKeeper implements a read only keeper implementation of ViewKeeper. type BaseViewKeeper struct { - cdc *codec.Codec + cdc codec.Marshaler storeKey sdk.StoreKey ak types.AccountKeeper } // NewBaseViewKeeper returns a new BaseViewKeeper. -func NewBaseViewKeeper(cdc *codec.Codec, storeKey sdk.StoreKey, ak types.AccountKeeper) BaseViewKeeper { +func NewBaseViewKeeper(cdc codec.Marshaler, storeKey sdk.StoreKey, ak types.AccountKeeper) BaseViewKeeper { return BaseViewKeeper{ cdc: cdc, storeKey: storeKey, diff --git a/x/bank/internal/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go similarity index 99% rename from x/bank/internal/keeper/keeper_test.go rename to x/bank/keeper/keeper_test.go index d71f1274f1d2..472fe39972d5 100644 --- a/x/bank/internal/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -13,7 +13,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/vesting" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/types" ) const ( diff --git a/x/bank/internal/keeper/querier.go b/x/bank/keeper/querier.go similarity index 96% rename from x/bank/internal/keeper/querier.go rename to x/bank/keeper/querier.go index 072511b2d2a8..be17b371629a 100644 --- a/x/bank/internal/keeper/querier.go +++ b/x/bank/keeper/querier.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/types" ) // NewQuerier returns a new sdk.Keeper instance. diff --git a/x/bank/internal/keeper/querier_test.go b/x/bank/keeper/querier_test.go similarity index 96% rename from x/bank/internal/keeper/querier_test.go rename to x/bank/keeper/querier_test.go index 643f7b1798cf..3732aaa74429 100644 --- a/x/bank/internal/keeper/querier_test.go +++ b/x/bank/keeper/querier_test.go @@ -7,8 +7,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/bank/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/keeper" + "github.com/cosmos/cosmos-sdk/x/bank/types" ) func (suite *IntegrationTestSuite) TestQuerier_QueryBalance() { diff --git a/x/bank/module.go b/x/bank/module.go index dfde67f4a85e..7cb86714272c 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -16,9 +16,9 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/bank/client/cli" "github.com/cosmos/cosmos-sdk/x/bank/client/rest" - "github.com/cosmos/cosmos-sdk/x/bank/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/keeper" "github.com/cosmos/cosmos-sdk/x/bank/simulation" + "github.com/cosmos/cosmos-sdk/x/bank/types" sim "github.com/cosmos/cosmos-sdk/x/simulation" ) diff --git a/x/bank/simulation/genesis.go b/x/bank/simulation/genesis.go index b593fa05b070..97716bd2fa6c 100644 --- a/x/bank/simulation/genesis.go +++ b/x/bank/simulation/genesis.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/types" ) // Simulation parameter constants diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 2d9e8468359a..c3ff22f9ceed 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -10,8 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/simapp/helpers" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/keeper" + "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/simulation" ) diff --git a/x/bank/simulation/params.go b/x/bank/simulation/params.go index f5aa25bf6a0c..458a8a09a16e 100644 --- a/x/bank/simulation/params.go +++ b/x/bank/simulation/params.go @@ -6,7 +6,7 @@ import ( "fmt" "math/rand" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/simulation" ) diff --git a/x/bank/types/codec.go b/x/bank/types/codec.go new file mode 100644 index 000000000000..652fb3f2fe23 --- /dev/null +++ b/x/bank/types/codec.go @@ -0,0 +1,28 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" +) + +// Register concrete types on codec codec +func RegisterCodec(cdc *codec.Codec) { + cdc.RegisterConcrete(MsgSend{}, "cosmos-sdk/MsgSend", nil) + cdc.RegisterConcrete(MsgMultiSend{}, "cosmos-sdk/MsgMultiSend", nil) +} + +var ( + amino = codec.New() + + // ModuleCdc references the global x/staking module codec. Note, the codec should + // ONLY be used in certain instances of tests and for JSON encoding as Amino is + // still used for that purpose. + // + // The actual codec used for serialization should be provided to x/staking and + // defined at the application level. + ModuleCdc = codec.NewHybridCodec(amino) +) + +func init() { + RegisterCodec(amino) + amino.Seal() +} diff --git a/x/bank/internal/types/errors.go b/x/bank/types/errors.go similarity index 100% rename from x/bank/internal/types/errors.go rename to x/bank/types/errors.go diff --git a/x/bank/internal/types/events.go b/x/bank/types/events.go similarity index 100% rename from x/bank/internal/types/events.go rename to x/bank/types/events.go diff --git a/x/bank/internal/types/expected_keepers.go b/x/bank/types/expected_keepers.go similarity index 100% rename from x/bank/internal/types/expected_keepers.go rename to x/bank/types/expected_keepers.go diff --git a/x/bank/internal/types/genesis.go b/x/bank/types/genesis.go similarity index 100% rename from x/bank/internal/types/genesis.go rename to x/bank/types/genesis.go diff --git a/x/bank/internal/types/key.go b/x/bank/types/key.go similarity index 100% rename from x/bank/internal/types/key.go rename to x/bank/types/key.go diff --git a/x/bank/internal/types/key_test.go b/x/bank/types/key_test.go similarity index 91% rename from x/bank/internal/types/key_test.go rename to x/bank/types/key_test.go index a16a22381d6e..b1e5a7614106 100644 --- a/x/bank/internal/types/key_test.go +++ b/x/bank/types/key_test.go @@ -4,7 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/internal/types" + "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/stretchr/testify/require" ) diff --git a/x/bank/internal/types/msgs.go b/x/bank/types/msgs.go similarity index 84% rename from x/bank/internal/types/msgs.go rename to x/bank/types/msgs.go index 83db26aaefd1..3dab0c6bb538 100644 --- a/x/bank/internal/types/msgs.go +++ b/x/bank/types/msgs.go @@ -5,13 +5,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// MsgSend - high level transaction of the coin module -type MsgSend struct { - FromAddress sdk.AccAddress `json:"from_address" yaml:"from_address"` - ToAddress sdk.AccAddress `json:"to_address" yaml:"to_address"` - Amount sdk.Coins `json:"amount" yaml:"amount"` -} - var _ sdk.Msg = MsgSend{} // NewMsgSend - construct arbitrary multi-in, multi-out send msg. @@ -52,12 +45,6 @@ func (msg MsgSend) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.FromAddress} } -// MsgMultiSend - high level transaction of the coin module -type MsgMultiSend struct { - Inputs []Input `json:"inputs" yaml:"inputs"` - Outputs []Output `json:"outputs" yaml:"outputs"` -} - var _ sdk.Msg = MsgMultiSend{} // NewMsgMultiSend - construct arbitrary multi-in, multi-out send msg. @@ -99,12 +86,6 @@ func (msg MsgMultiSend) GetSigners() []sdk.AccAddress { return addrs } -// Input models transaction input -type Input struct { - Address sdk.AccAddress `json:"address" yaml:"address"` - Coins sdk.Coins `json:"coins" yaml:"coins"` -} - // ValidateBasic - validate transaction input func (in Input) ValidateBasic() error { if len(in.Address) == 0 { @@ -127,12 +108,6 @@ func NewInput(addr sdk.AccAddress, coins sdk.Coins) Input { } } -// Output models transaction outputs -type Output struct { - Address sdk.AccAddress `json:"address" yaml:"address"` - Coins sdk.Coins `json:"coins" yaml:"coins"` -} - // ValidateBasic - validate transaction output func (out Output) ValidateBasic() error { if len(out.Address) == 0 { diff --git a/x/bank/internal/types/msgs_test.go b/x/bank/types/msgs_test.go similarity index 100% rename from x/bank/internal/types/msgs_test.go rename to x/bank/types/msgs_test.go diff --git a/x/bank/internal/types/params.go b/x/bank/types/params.go similarity index 100% rename from x/bank/internal/types/params.go rename to x/bank/types/params.go diff --git a/x/bank/internal/types/querier.go b/x/bank/types/querier.go similarity index 100% rename from x/bank/internal/types/querier.go rename to x/bank/types/querier.go diff --git a/x/bank/types/types.pb.go b/x/bank/types/types.pb.go new file mode 100644 index 000000000000..0de721984735 --- /dev/null +++ b/x/bank/types/types.pb.go @@ -0,0 +1,1177 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: x/bank/types/types.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MsgSend - high level transaction of the coin module +type MsgSend struct { + FromAddress github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"from_address,omitempty" yaml:"from_address"` + ToAddress github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,2,opt,name=to_address,json=toAddress,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"to_address,omitempty" yaml:"to_address"` + Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount"` +} + +func (m *MsgSend) Reset() { *m = MsgSend{} } +func (m *MsgSend) String() string { return proto.CompactTextString(m) } +func (*MsgSend) ProtoMessage() {} +func (*MsgSend) Descriptor() ([]byte, []int) { + return fileDescriptor_934ff6b24d3432e2, []int{0} +} +func (m *MsgSend) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSend) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSend.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgSend) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSend.Merge(m, src) +} +func (m *MsgSend) XXX_Size() int { + return m.Size() +} +func (m *MsgSend) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSend.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSend proto.InternalMessageInfo + +func (m *MsgSend) GetFromAddress() github_com_cosmos_cosmos_sdk_types.AccAddress { + if m != nil { + return m.FromAddress + } + return nil +} + +func (m *MsgSend) GetToAddress() github_com_cosmos_cosmos_sdk_types.AccAddress { + if m != nil { + return m.ToAddress + } + return nil +} + +func (m *MsgSend) GetAmount() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Amount + } + return nil +} + +// Input models transaction input +type Input struct { + Address github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=address,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"address,omitempty"` + Coins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=coins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"coins"` +} + +func (m *Input) Reset() { *m = Input{} } +func (m *Input) String() string { return proto.CompactTextString(m) } +func (*Input) ProtoMessage() {} +func (*Input) Descriptor() ([]byte, []int) { + return fileDescriptor_934ff6b24d3432e2, []int{1} +} +func (m *Input) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Input) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Input.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Input) XXX_Merge(src proto.Message) { + xxx_messageInfo_Input.Merge(m, src) +} +func (m *Input) XXX_Size() int { + return m.Size() +} +func (m *Input) XXX_DiscardUnknown() { + xxx_messageInfo_Input.DiscardUnknown(m) +} + +var xxx_messageInfo_Input proto.InternalMessageInfo + +func (m *Input) GetAddress() github_com_cosmos_cosmos_sdk_types.AccAddress { + if m != nil { + return m.Address + } + return nil +} + +func (m *Input) GetCoins() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Coins + } + return nil +} + +// Output models transaction outputs +type Output struct { + Address github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=address,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"address,omitempty"` + Coins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=coins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"coins"` +} + +func (m *Output) Reset() { *m = Output{} } +func (m *Output) String() string { return proto.CompactTextString(m) } +func (*Output) ProtoMessage() {} +func (*Output) Descriptor() ([]byte, []int) { + return fileDescriptor_934ff6b24d3432e2, []int{2} +} +func (m *Output) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Output) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Output.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Output) XXX_Merge(src proto.Message) { + xxx_messageInfo_Output.Merge(m, src) +} +func (m *Output) XXX_Size() int { + return m.Size() +} +func (m *Output) XXX_DiscardUnknown() { + xxx_messageInfo_Output.DiscardUnknown(m) +} + +var xxx_messageInfo_Output proto.InternalMessageInfo + +func (m *Output) GetAddress() github_com_cosmos_cosmos_sdk_types.AccAddress { + if m != nil { + return m.Address + } + return nil +} + +func (m *Output) GetCoins() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Coins + } + return nil +} + +// MsgMultiSend - high level transaction of the coin module +type MsgMultiSend struct { + Inputs []Input `protobuf:"bytes,1,rep,name=inputs,proto3" json:"inputs"` + Outputs []Output `protobuf:"bytes,2,rep,name=outputs,proto3" json:"outputs"` +} + +func (m *MsgMultiSend) Reset() { *m = MsgMultiSend{} } +func (m *MsgMultiSend) String() string { return proto.CompactTextString(m) } +func (*MsgMultiSend) ProtoMessage() {} +func (*MsgMultiSend) Descriptor() ([]byte, []int) { + return fileDescriptor_934ff6b24d3432e2, []int{3} +} +func (m *MsgMultiSend) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgMultiSend) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgMultiSend.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgMultiSend) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgMultiSend.Merge(m, src) +} +func (m *MsgMultiSend) XXX_Size() int { + return m.Size() +} +func (m *MsgMultiSend) XXX_DiscardUnknown() { + xxx_messageInfo_MsgMultiSend.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgMultiSend proto.InternalMessageInfo + +func (m *MsgMultiSend) GetInputs() []Input { + if m != nil { + return m.Inputs + } + return nil +} + +func (m *MsgMultiSend) GetOutputs() []Output { + if m != nil { + return m.Outputs + } + return nil +} + +func init() { + proto.RegisterType((*MsgSend)(nil), "cosmos_sdk.x.bank.v1.MsgSend") + proto.RegisterType((*Input)(nil), "cosmos_sdk.x.bank.v1.Input") + proto.RegisterType((*Output)(nil), "cosmos_sdk.x.bank.v1.Output") + proto.RegisterType((*MsgMultiSend)(nil), "cosmos_sdk.x.bank.v1.MsgMultiSend") +} + +func init() { proto.RegisterFile("x/bank/types/types.proto", fileDescriptor_934ff6b24d3432e2) } + +var fileDescriptor_934ff6b24d3432e2 = []byte{ + // 403 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xa8, 0xd0, 0x4f, 0x4a, + 0xcc, 0xcb, 0xd6, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, + 0x42, 0x22, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, 0x7a, 0x20, + 0x45, 0x7a, 0x65, 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, 0x25, + 0x95, 0xfa, 0x60, 0x85, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0x44, 0xb7, 0x94, 0x20, 0x86, + 0x81, 0x4a, 0x7b, 0x98, 0xb8, 0xd8, 0x7d, 0x8b, 0xd3, 0x83, 0x53, 0xf3, 0x52, 0x84, 0xb2, 0xb9, + 0x78, 0xd2, 0x8a, 0xf2, 0x73, 0xe3, 0x13, 0x53, 0x52, 0x8a, 0x52, 0x8b, 0x8b, 0x25, 0x18, 0x15, + 0x18, 0x35, 0x78, 0x9c, 0x3c, 0x3e, 0xdd, 0x93, 0x17, 0xae, 0x4c, 0xcc, 0xcd, 0xb1, 0x52, 0x42, + 0x96, 0x55, 0xfa, 0x75, 0x4f, 0x5e, 0x37, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, + 0x57, 0x1f, 0xe2, 0x30, 0x28, 0xa5, 0x5b, 0x9c, 0x02, 0x75, 0xbd, 0x9e, 0x63, 0x72, 0xb2, 0x23, + 0x44, 0x47, 0x10, 0x37, 0x48, 0x3f, 0x94, 0x23, 0x94, 0xca, 0xc5, 0x55, 0x92, 0x0f, 0xb7, 0x8a, + 0x09, 0x6c, 0x95, 0xdb, 0xa7, 0x7b, 0xf2, 0x82, 0x10, 0xab, 0x10, 0x72, 0x64, 0x58, 0xc4, 0x59, + 0x92, 0x0f, 0xb3, 0x26, 0x96, 0x8b, 0x2d, 0x31, 0x37, 0xbf, 0x34, 0xaf, 0x44, 0x82, 0x59, 0x81, + 0x59, 0x83, 0xdb, 0x48, 0x58, 0x0f, 0x29, 0x04, 0xcb, 0x0c, 0xf5, 0x9c, 0xf3, 0x33, 0xf3, 0x9c, + 0x0c, 0x4e, 0xdc, 0x93, 0x67, 0x58, 0x75, 0x5f, 0x5e, 0x83, 0x08, 0x6b, 0x40, 0x1a, 0x8a, 0x83, + 0xa0, 0x86, 0x2a, 0x6d, 0x64, 0xe4, 0x62, 0xf5, 0xcc, 0x2b, 0x28, 0x2d, 0x11, 0xf2, 0xe6, 0x62, + 0x47, 0x0d, 0x37, 0x43, 0xd2, 0xdd, 0x0d, 0x33, 0x41, 0x28, 0x9a, 0x8b, 0x35, 0x19, 0x64, 0x8f, + 0x04, 0x13, 0x35, 0x1d, 0x0d, 0x31, 0x53, 0x69, 0x13, 0x23, 0x17, 0x9b, 0x7f, 0x69, 0xc9, 0xd0, + 0x72, 0x74, 0x3b, 0x23, 0x17, 0x8f, 0x6f, 0x71, 0xba, 0x6f, 0x69, 0x4e, 0x49, 0x26, 0x38, 0xb1, + 0x5a, 0x72, 0xb1, 0x65, 0x82, 0x02, 0x1e, 0xe4, 0x72, 0x90, 0x75, 0xd2, 0x7a, 0xd8, 0xb2, 0x86, + 0x1e, 0x38, 0x72, 0x9c, 0x58, 0x40, 0xd6, 0x06, 0x41, 0x35, 0x08, 0xd9, 0x70, 0xb1, 0xe7, 0x83, + 0xfd, 0x0f, 0x73, 0xaa, 0x0c, 0x76, 0xbd, 0x90, 0x40, 0x82, 0x6a, 0x86, 0x69, 0x71, 0x72, 0x3e, + 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, + 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x4d, 0xbc, 0x9e, 0x42, 0xce, 0xd3, + 0x49, 0x6c, 0xe0, 0xdc, 0x67, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x64, 0xad, 0xc1, 0x15, 0xea, + 0x03, 0x00, 0x00, +} + +func (m *MsgSend) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgSend) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSend) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Amount) > 0 { + for iNdEx := len(m.Amount) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Amount[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.ToAddress) > 0 { + i -= len(m.ToAddress) + copy(dAtA[i:], m.ToAddress) + i = encodeVarintTypes(dAtA, i, uint64(len(m.ToAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.FromAddress) > 0 { + i -= len(m.FromAddress) + copy(dAtA[i:], m.FromAddress) + i = encodeVarintTypes(dAtA, i, uint64(len(m.FromAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Input) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Input) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Input) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Coins) > 0 { + for iNdEx := len(m.Coins) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Coins[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Output) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Output) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Output) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Coins) > 0 { + for iNdEx := len(m.Coins) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Coins[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgMultiSend) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgMultiSend) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgMultiSend) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Outputs) > 0 { + for iNdEx := len(m.Outputs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Outputs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Inputs) > 0 { + for iNdEx := len(m.Inputs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Inputs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgSend) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.FromAddress) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.ToAddress) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.Amount) > 0 { + for _, e := range m.Amount { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *Input) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.Coins) > 0 { + for _, e := range m.Coins { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *Output) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.Coins) > 0 { + for _, e := range m.Coins { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *MsgMultiSend) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Inputs) > 0 { + for _, e := range m.Inputs { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + if len(m.Outputs) > 0 { + for _, e := range m.Outputs { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgSend) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgSend: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSend: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FromAddress", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + 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 byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ToAddress = append(m.ToAddress[:0], dAtA[iNdEx:postIndex]...) + if m.ToAddress == nil { + m.ToAddress = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Amount = append(m.Amount, types.Coin{}) + if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Input) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Input: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Input: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = append(m.Address[:0], dAtA[iNdEx:postIndex]...) + if m.Address == nil { + m.Address = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Coins", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Coins = append(m.Coins, types.Coin{}) + if err := m.Coins[len(m.Coins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Output) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Output: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Output: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = append(m.Address[:0], dAtA[iNdEx:postIndex]...) + if m.Address == nil { + m.Address = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Coins", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Coins = append(m.Coins, types.Coin{}) + if err := m.Coins[len(m.Coins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgMultiSend) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgMultiSend: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgMultiSend: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Inputs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Inputs = append(m.Inputs, Input{}) + if err := m.Inputs[len(m.Inputs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Outputs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Outputs = append(m.Outputs, Output{}) + if err := m.Outputs[len(m.Outputs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTypes(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTypes + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTypes + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTypes + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/bank/types/types.proto b/x/bank/types/types.proto new file mode 100644 index 000000000000..9aee8d22a319 --- /dev/null +++ b/x/bank/types/types.proto @@ -0,0 +1,48 @@ +syntax = "proto3"; + +package cosmos_sdk.x.bank.v1; + +option go_package = "github.com/cosmos/cosmos-sdk/x/bank/types"; + +import "third_party/proto/gogoproto/gogo.proto"; +import "types/types.proto"; + +// MsgSend - high level transaction of the coin module +message MsgSend { + bytes from_address = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", + (gogoproto.moretags) = "yaml:\"from_address\"" + ]; + bytes to_address = 2 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", + (gogoproto.moretags) = "yaml:\"to_address\"" + ]; + repeated cosmos_sdk.v1.Coin amount = 3 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} + +// Input models transaction input +message Input { + bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; + repeated cosmos_sdk.v1.Coin coins = 2 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} + +// Output models transaction outputs +message Output { + bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; + repeated cosmos_sdk.v1.Coin coins = 2 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} + +// MsgMultiSend - high level transaction of the coin module +message MsgMultiSend { + repeated Input inputs = 1 [(gogoproto.nullable) = false]; + repeated Output outputs = 2 [(gogoproto.nullable) = false]; +} diff --git a/x/distribution/keeper/test_common.go b/x/distribution/keeper/test_common.go index a60b36985a4b..0c18e9249525 100644 --- a/x/distribution/keeper/test_common.go +++ b/x/distribution/keeper/test_common.go @@ -132,7 +132,7 @@ func CreateTestInputAdvanced( ctx := sdk.NewContext(ms, abci.Header{ChainID: "foochainid"}, isCheckTx, log.NewNopLogger()) accountKeeper := auth.NewAccountKeeper(appCodec, keyAcc, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) - bankKeeper := bank.NewBaseKeeper(cdc, keyBank, accountKeeper, pk.Subspace(bank.DefaultParamspace), blacklistedAddrs) + bankKeeper := bank.NewBaseKeeper(appCodec, keyBank, accountKeeper, pk.Subspace(bank.DefaultParamspace), blacklistedAddrs) maccPerms := map[string][]string{ auth.FeeCollectorName: nil, types.ModuleName: nil, diff --git a/x/gov/keeper/test_common.go b/x/gov/keeper/test_common.go index d521b10bef3b..84df63afb549 100644 --- a/x/gov/keeper/test_common.go +++ b/x/gov/keeper/test_common.go @@ -151,7 +151,7 @@ func createTestInput( pk := keeper.NewKeeper(appCodec, keyParams, tkeyParams) accountKeeper := auth.NewAccountKeeper(appCodec, keyAcc, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) - bankKeeper := bank.NewBaseKeeper(cdc, keyBank, accountKeeper, pk.Subspace(bank.DefaultParamspace), blacklistedAddrs) + bankKeeper := bank.NewBaseKeeper(appCodec, keyBank, accountKeeper, pk.Subspace(bank.DefaultParamspace), blacklistedAddrs) supplyKeeper := supply.NewKeeper(appCodec, keySupply, accountKeeper, bankKeeper, maccPerms) sk := staking.NewKeeper(staking.ModuleCdc, keyStaking, bankKeeper, supplyKeeper, pk.Subspace(staking.DefaultParamspace)) diff --git a/x/slashing/abci_test.go b/x/slashing/abci_test.go index a6a14c885b3d..c1b0f62fffb4 100644 --- a/x/slashing/abci_test.go +++ b/x/slashing/abci_test.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing" - slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/internal/keeper" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" "github.com/cosmos/cosmos-sdk/x/staking" ) diff --git a/x/slashing/alias.go b/x/slashing/alias.go index 38d556a6e492..9ebdd29edf35 100644 --- a/x/slashing/alias.go +++ b/x/slashing/alias.go @@ -3,8 +3,8 @@ package slashing // nolint import ( - "github.com/cosmos/cosmos-sdk/x/slashing/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) const ( diff --git a/x/slashing/client/cli/query.go b/x/slashing/client/cli/query.go index 71f404230758..c661b589f1d0 100644 --- a/x/slashing/client/cli/query.go +++ b/x/slashing/client/cli/query.go @@ -12,7 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // GetQueryCmd returns the cli query commands for this module @@ -68,7 +68,11 @@ $ query slashing signing-info cosmosvalconspub1zcjduepqfhvwcmt7p06fvdge } var signingInfo types.ValidatorSigningInfo - cdc.MustUnmarshalBinaryLengthPrefixed(res, &signingInfo) + signingInfo, err = types.UnmarshalValSigningInfo(types.ModuleCdc, res) + if err != nil { + return err + } + return cliCtx.PrintOutput(signingInfo) }, } diff --git a/x/slashing/client/cli/tx.go b/x/slashing/client/cli/tx.go index 117e216a957a..4233d5c7a072 100644 --- a/x/slashing/client/cli/tx.go +++ b/x/slashing/client/cli/tx.go @@ -12,7 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // GetTxCmd returns the transaction commands for this module diff --git a/x/slashing/client/rest/query.go b/x/slashing/client/rest/query.go index 751fe648dc45..2d3d9bfab798 100644 --- a/x/slashing/client/rest/query.go +++ b/x/slashing/client/rest/query.go @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) { diff --git a/x/slashing/client/rest/tx.go b/x/slashing/client/rest/tx.go index 1257b8e105a5..9498ea8ba5ff 100644 --- a/x/slashing/client/rest/tx.go +++ b/x/slashing/client/rest/tx.go @@ -10,7 +10,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) { diff --git a/x/slashing/genesis.go b/x/slashing/genesis.go index 8b959c8a0bac..a5d2eb0f1350 100644 --- a/x/slashing/genesis.go +++ b/x/slashing/genesis.go @@ -2,7 +2,7 @@ package slashing import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking/exported" ) diff --git a/x/slashing/handler.go b/x/slashing/handler.go index fe4ef7cb7c2e..629a92dde29e 100644 --- a/x/slashing/handler.go +++ b/x/slashing/handler.go @@ -3,7 +3,7 @@ package slashing import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // NewHandler creates an sdk.Handler for all the slashing type messages diff --git a/x/slashing/handler_test.go b/x/slashing/handler_test.go index c168f8052ffb..abd5e52559fd 100644 --- a/x/slashing/handler_test.go +++ b/x/slashing/handler_test.go @@ -11,8 +11,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing" - slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" ) diff --git a/x/slashing/internal/types/codec.go b/x/slashing/internal/types/codec.go deleted file mode 100644 index 34790d54d630..000000000000 --- a/x/slashing/internal/types/codec.go +++ /dev/null @@ -1,20 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/codec" -) - -// RegisterCodec registers concrete types on codec -func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterConcrete(MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil) -} - -// ModuleCdc defines the module codec -var ModuleCdc *codec.Codec - -func init() { - ModuleCdc = codec.New() - RegisterCodec(ModuleCdc) - codec.RegisterCrypto(ModuleCdc) - ModuleCdc.Seal() -} diff --git a/x/slashing/internal/keeper/hooks.go b/x/slashing/keeper/hooks.go similarity index 97% rename from x/slashing/internal/keeper/hooks.go rename to x/slashing/keeper/hooks.go index a8ef6e093e15..e6374a87f990 100644 --- a/x/slashing/internal/keeper/hooks.go +++ b/x/slashing/keeper/hooks.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tendermint/crypto" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) func (k Keeper) AfterValidatorBonded(ctx sdk.Context, address sdk.ConsAddress, _ sdk.ValAddress) { diff --git a/x/slashing/internal/keeper/infractions.go b/x/slashing/keeper/infractions.go similarity index 98% rename from x/slashing/internal/keeper/infractions.go rename to x/slashing/keeper/infractions.go index a10b6f945b3a..a8e349b75be8 100644 --- a/x/slashing/internal/keeper/infractions.go +++ b/x/slashing/keeper/infractions.go @@ -6,7 +6,7 @@ import ( "github.com/tendermint/tendermint/crypto" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // HandleValidatorSignature handles a validator signature, must be called once per validator per block. diff --git a/x/slashing/internal/keeper/keeper.go b/x/slashing/keeper/keeper.go similarity index 77% rename from x/slashing/internal/keeper/keeper.go rename to x/slashing/keeper/keeper.go index 6aedd7aee273..3616a7cd3dab 100644 --- a/x/slashing/internal/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -3,30 +3,26 @@ package keeper import ( "fmt" + gogotypes "github.com/gogo/protobuf/types" + "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // Keeper of the slashing store type Keeper struct { storeKey sdk.StoreKey - cdc *codec.Codec + cdc codec.Marshaler sk types.StakingKeeper paramspace types.ParamSubspace } // NewKeeper creates a slashing keeper -func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, sk types.StakingKeeper, paramspace types.ParamSubspace) Keeper { - - // set KeyTable if it has not already been set - if !paramspace.HasKeyTable() { - paramspace = paramspace.WithKeyTable(types.ParamKeyTable()) - } - +func NewKeeper(cdc codec.Marshaler, key sdk.StoreKey, sk types.StakingKeeper, paramspace types.ParamSubspace) Keeper { return Keeper{ storeKey: key, cdc: cdc, @@ -43,18 +39,31 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { // AddPubkey sets a address-pubkey relation func (k Keeper) AddPubkey(ctx sdk.Context, pubkey crypto.PubKey) { addr := pubkey.Address() - k.setAddrPubkeyRelation(ctx, addr, pubkey) + + pkStr, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pubkey) + if err != nil { + panic(fmt.Errorf("error while setting address-pubkey relation: %s", addr)) + } + + k.setAddrPubkeyRelation(ctx, addr, pkStr) } // GetPubkey returns the pubkey from the adddress-pubkey relation func (k Keeper) GetPubkey(ctx sdk.Context, address crypto.Address) (crypto.PubKey, error) { store := ctx.KVStore(k.storeKey) - var pubkey crypto.PubKey + + var pubkey gogotypes.StringValue err := k.cdc.UnmarshalBinaryLengthPrefixed(store.Get(types.GetAddrPubkeyRelationKey(address)), &pubkey) if err != nil { return nil, fmt.Errorf("address %s not found", sdk.ConsAddress(address)) } - return pubkey, nil + + pkStr, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, pubkey.Value) + if err != nil { + return pkStr, err + } + + return pkStr, nil } // Slash attempts to slash a validator. The slash is delegated to the staking @@ -85,9 +94,10 @@ func (k Keeper) Jail(ctx sdk.Context, consAddr sdk.ConsAddress) { k.sk.Jail(ctx, consAddr) } -func (k Keeper) setAddrPubkeyRelation(ctx sdk.Context, addr crypto.Address, pubkey crypto.PubKey) { +func (k Keeper) setAddrPubkeyRelation(ctx sdk.Context, addr crypto.Address, pubkey string) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(pubkey) + + bz := k.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.StringValue{Value: pubkey}) store.Set(types.GetAddrPubkeyRelationKey(addr), bz) } diff --git a/x/slashing/internal/keeper/keeper_test.go b/x/slashing/keeper/keeper_test.go similarity index 99% rename from x/slashing/internal/keeper/keeper_test.go rename to x/slashing/keeper/keeper_test.go index fdf50a261e27..4f4f555bbffc 100644 --- a/x/slashing/internal/keeper/keeper_test.go +++ b/x/slashing/keeper/keeper_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" ) diff --git a/x/slashing/internal/keeper/params.go b/x/slashing/keeper/params.go similarity index 96% rename from x/slashing/internal/keeper/params.go rename to x/slashing/keeper/params.go index 82fe991cccc1..8ece97a687ad 100644 --- a/x/slashing/internal/keeper/params.go +++ b/x/slashing/keeper/params.go @@ -4,7 +4,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // SignedBlocksWindow - sliding window for downtime slashing diff --git a/x/slashing/internal/keeper/querier.go b/x/slashing/keeper/querier.go similarity index 97% rename from x/slashing/internal/keeper/querier.go rename to x/slashing/keeper/querier.go index 11b365e1ee1b..1eab719a63f7 100644 --- a/x/slashing/internal/keeper/querier.go +++ b/x/slashing/keeper/querier.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // NewQuerier creates a new querier for slashing clients. diff --git a/x/slashing/internal/keeper/querier_test.go b/x/slashing/keeper/querier_test.go similarity index 92% rename from x/slashing/internal/keeper/querier_test.go rename to x/slashing/keeper/querier_test.go index ea4095dc61b1..fd924bc8e823 100644 --- a/x/slashing/internal/keeper/querier_test.go +++ b/x/slashing/keeper/querier_test.go @@ -7,7 +7,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) func TestNewQuerier(t *testing.T) { diff --git a/x/slashing/internal/keeper/signing_info.go b/x/slashing/keeper/signing_info.go similarity index 91% rename from x/slashing/internal/keeper/signing_info.go rename to x/slashing/keeper/signing_info.go index 1162c258f35a..0e1a82c62fa2 100644 --- a/x/slashing/internal/keeper/signing_info.go +++ b/x/slashing/keeper/signing_info.go @@ -3,8 +3,10 @@ package keeper import ( "time" + gogotypes "github.com/gogo/protobuf/types" + sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // GetValidatorSigningInfo retruns the ValidatorSigningInfo for a specific validator @@ -31,7 +33,7 @@ func (k Keeper) HasValidatorSigningInfo(ctx sdk.Context, consAddr sdk.ConsAddres // SetValidatorSigningInfo sets the validator signing info to a consensus address key func (k Keeper) SetValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress, info types.ValidatorSigningInfo) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(info) + bz := k.cdc.MustMarshalBinaryLengthPrefixed(&info) store.Set(types.GetValidatorSigningInfoKey(address), bz) } @@ -53,16 +55,17 @@ func (k Keeper) IterateValidatorSigningInfos(ctx sdk.Context, } // GetValidatorMissedBlockBitArray gets the bit for the missed blocks array -func (k Keeper) GetValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64) (missed bool) { +func (k Keeper) GetValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64) bool { store := ctx.KVStore(k.storeKey) bz := store.Get(types.GetValidatorMissedBlockBitArrayKey(address, index)) + var missed gogotypes.BoolValue if bz == nil { // lazy: treat empty key as not missed - missed = false - return + return false } k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &missed) - return + + return missed.Value } // IterateValidatorMissedBlockBitArray iterates over the signed blocks window @@ -74,13 +77,14 @@ func (k Keeper) IterateValidatorMissedBlockBitArray(ctx sdk.Context, index := int64(0) // Array may be sparse for ; index < k.SignedBlocksWindow(ctx); index++ { - var missed bool + var missed gogotypes.BoolValue bz := store.Get(types.GetValidatorMissedBlockBitArrayKey(address, index)) if bz == nil { continue } + k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &missed) - if handler(index, missed) { + if handler(index, missed.Value) { break } } @@ -128,7 +132,7 @@ func (k Keeper) IsTombstoned(ctx sdk.Context, consAddr sdk.ConsAddress) bool { // missed a block in the current window func (k Keeper) SetValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64, missed bool) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(missed) + bz := k.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.BoolValue{Value: missed}) store.Set(types.GetValidatorMissedBlockBitArrayKey(address, index), bz) } diff --git a/x/slashing/internal/keeper/signing_info_test.go b/x/slashing/keeper/signing_info_test.go similarity index 97% rename from x/slashing/internal/keeper/signing_info_test.go rename to x/slashing/keeper/signing_info_test.go index 7d9e7c56e526..ac8c5075276f 100644 --- a/x/slashing/internal/keeper/signing_info_test.go +++ b/x/slashing/keeper/signing_info_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) func TestGetSetValidatorSigningInfo(t *testing.T) { diff --git a/x/slashing/internal/keeper/test_common.go b/x/slashing/keeper/test_common.go similarity index 95% rename from x/slashing/internal/keeper/test_common.go rename to x/slashing/keeper/test_common.go index ca388dd24d18..d80c68b7ed9e 100644 --- a/x/slashing/internal/keeper/test_common.go +++ b/x/slashing/keeper/test_common.go @@ -24,7 +24,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/params/keeper" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/supply" ) @@ -96,7 +96,7 @@ func CreateTestInput(t *testing.T, defaults types.Params) (sdk.Context, bank.Kee paramsKeeper := keeper.NewKeeper(appCodec, keyParams, tkeyParams) accountKeeper := auth.NewAccountKeeper(appCodec, keyAcc, paramsKeeper.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) - bk := bank.NewBaseKeeper(cdc, keyBank, accountKeeper, paramsKeeper.Subspace(bank.DefaultParamspace), blacklistedAddrs) + bk := bank.NewBaseKeeper(appCodec, keyBank, accountKeeper, paramsKeeper.Subspace(bank.DefaultParamspace), blacklistedAddrs) maccPerms := map[string][]string{ auth.FeeCollectorName: nil, staking.NotBondedPoolName: {supply.Burner, supply.Staking}, @@ -124,7 +124,7 @@ func CreateTestInput(t *testing.T, defaults types.Params) (sdk.Context, bank.Kee } paramstore := paramsKeeper.Subspace(types.DefaultParamspace) - keeper := NewKeeper(cdc, keySlashing, &sk, paramstore) + keeper := NewKeeper(types.ModuleCdc, keySlashing, &sk, paramstore) keeper.SetParams(ctx, defaults) sk.SetHooks(keeper.Hooks()) diff --git a/x/slashing/internal/keeper/unjail.go b/x/slashing/keeper/unjail.go similarity index 95% rename from x/slashing/internal/keeper/unjail.go rename to x/slashing/keeper/unjail.go index 51fda4855382..cf57c1e71c4a 100644 --- a/x/slashing/internal/keeper/unjail.go +++ b/x/slashing/keeper/unjail.go @@ -2,7 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // Unjail calls the staking Unjail function to unjail a validator if the diff --git a/x/slashing/module.go b/x/slashing/module.go index 3e4c0b7a99e8..b404b8c4ecde 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -17,8 +17,8 @@ import ( sim "github.com/cosmos/cosmos-sdk/x/simulation" "github.com/cosmos/cosmos-sdk/x/slashing/client/cli" "github.com/cosmos/cosmos-sdk/x/slashing/client/rest" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" "github.com/cosmos/cosmos-sdk/x/slashing/simulation" + "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" ) diff --git a/x/slashing/simulation/decoder.go b/x/slashing/simulation/decoder.go index 9aea5f701b15..48a12705a780 100644 --- a/x/slashing/simulation/decoder.go +++ b/x/slashing/simulation/decoder.go @@ -4,12 +4,13 @@ import ( "bytes" "fmt" + gogotypes "github.com/gogo/protobuf/types" "github.com/tendermint/tendermint/crypto" tmkv "github.com/tendermint/tendermint/libs/kv" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // DecodeStore unmarshals the KVPair's Value to the corresponding slashing type @@ -22,10 +23,10 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { return fmt.Sprintf("%v\n%v", infoA, infoB) case bytes.Equal(kvA.Key[:1], types.ValidatorMissedBlockBitArrayKey): - var missedA, missedB bool + var missedA, missedB gogotypes.BoolValue cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &missedA) cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &missedB) - return fmt.Sprintf("missedA: %v\nmissedB: %v", missedA, missedB) + return fmt.Sprintf("missedA: %v\nmissedB: %v", missedA.Value, missedB.Value) case bytes.Equal(kvA.Key[:1], types.AddrPubkeyRelationKey): var pubKeyA, pubKeyB crypto.PubKey diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index acd3be67c62f..522bff74750d 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + gogotypes "github.com/gogo/protobuf/types" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/ed25519" @@ -12,7 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // nolint:deadcode,unused,varcheck @@ -36,11 +38,11 @@ func TestDecodeStore(t *testing.T) { info := types.NewValidatorSigningInfo(consAddr1, 0, 1, time.Now().UTC(), false, 0) bechPK := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, delPk1) - missed := true + missed := gogotypes.BoolValue{Value: true} kvPairs := tmkv.Pairs{ tmkv.Pair{Key: types.GetValidatorSigningInfoKey(consAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(info)}, - tmkv.Pair{Key: types.GetValidatorMissedBlockBitArrayKey(consAddr1, 6), Value: cdc.MustMarshalBinaryLengthPrefixed(missed)}, + tmkv.Pair{Key: types.GetValidatorMissedBlockBitArrayKey(consAddr1, 6), Value: cdc.MustMarshalBinaryLengthPrefixed(&missed)}, tmkv.Pair{Key: types.GetAddrPubkeyRelationKey(delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(delPk1)}, tmkv.Pair{Key: []byte{0x99}, Value: []byte{0x99}}, } @@ -50,7 +52,7 @@ func TestDecodeStore(t *testing.T) { expectedLog string }{ {"ValidatorSigningInfo", fmt.Sprintf("%v\n%v", info, info)}, - {"ValidatorMissedBlockBitArray", fmt.Sprintf("missedA: %v\nmissedB: %v", missed, missed)}, + {"ValidatorMissedBlockBitArray", fmt.Sprintf("missedA: %v\nmissedB: %v", missed.Value, missed.Value)}, {"AddrPubkeyRelation", fmt.Sprintf("PubKeyA: %s\nPubKeyB: %s", bechPK, bechPK)}, {"other", ""}, } diff --git a/x/slashing/simulation/genesis.go b/x/slashing/simulation/genesis.go index a26a626642b7..d9dae7cd3d7b 100644 --- a/x/slashing/simulation/genesis.go +++ b/x/slashing/simulation/genesis.go @@ -12,7 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // Simulation parameter constants diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 8b7124609c09..c0f0b94554f6 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -10,8 +10,8 @@ import ( simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" ) diff --git a/x/slashing/simulation/params.go b/x/slashing/simulation/params.go index 6679928d8fc4..72048f2264bd 100644 --- a/x/slashing/simulation/params.go +++ b/x/slashing/simulation/params.go @@ -7,7 +7,7 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) const ( diff --git a/x/slashing/types/codec.go b/x/slashing/types/codec.go new file mode 100644 index 000000000000..04114f1465a1 --- /dev/null +++ b/x/slashing/types/codec.go @@ -0,0 +1,28 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" +) + +// RegisterCodec registers concrete types on codec +func RegisterCodec(cdc *codec.Codec) { + cdc.RegisterConcrete(MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil) +} + +var ( + amino = codec.New() + + // ModuleCdc references the global x/slashing module codec. Note, the codec + // should ONLY be used in certain instances of tests and for JSON encoding as Amino + // is still used for that purpose. + // + // The actual codec used for serialization should be provided to x/slashing and + // defined at the application level. + ModuleCdc = codec.NewHybridCodec(amino) +) + +func init() { + RegisterCodec(amino) + codec.RegisterCrypto(amino) + amino.Seal() +} diff --git a/x/slashing/internal/types/errors.go b/x/slashing/types/errors.go similarity index 100% rename from x/slashing/internal/types/errors.go rename to x/slashing/types/errors.go diff --git a/x/slashing/internal/types/events.go b/x/slashing/types/events.go similarity index 100% rename from x/slashing/internal/types/events.go rename to x/slashing/types/events.go diff --git a/x/slashing/internal/types/expected_keepers.go b/x/slashing/types/expected_keepers.go similarity index 100% rename from x/slashing/internal/types/expected_keepers.go rename to x/slashing/types/expected_keepers.go diff --git a/x/slashing/internal/types/genesis.go b/x/slashing/types/genesis.go similarity index 100% rename from x/slashing/internal/types/genesis.go rename to x/slashing/types/genesis.go diff --git a/x/slashing/internal/types/keys.go b/x/slashing/types/keys.go similarity index 100% rename from x/slashing/internal/types/keys.go rename to x/slashing/types/keys.go diff --git a/x/slashing/internal/types/msg.go b/x/slashing/types/msg.go similarity index 83% rename from x/slashing/internal/types/msg.go rename to x/slashing/types/msg.go index b2ccdce173ba..a9798615f6ad 100644 --- a/x/slashing/internal/types/msg.go +++ b/x/slashing/types/msg.go @@ -7,11 +7,6 @@ import ( // verify interface at compile time var _ sdk.Msg = &MsgUnjail{} -// MsgUnjail - struct for unjailing jailed validator -type MsgUnjail struct { - ValidatorAddr sdk.ValAddress `json:"address" yaml:"address"` // address of the validator operator -} - // NewMsgUnjail creates a new MsgUnjail instance func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail { return MsgUnjail{ @@ -37,5 +32,6 @@ func (msg MsgUnjail) ValidateBasic() error { if msg.ValidatorAddr.Empty() { return ErrBadValidatorAddr } + return nil } diff --git a/x/slashing/internal/types/msg_test.go b/x/slashing/types/msg_test.go similarity index 100% rename from x/slashing/internal/types/msg_test.go rename to x/slashing/types/msg_test.go diff --git a/x/slashing/internal/types/params.go b/x/slashing/types/params.go similarity index 100% rename from x/slashing/internal/types/params.go rename to x/slashing/types/params.go diff --git a/x/slashing/internal/types/querier.go b/x/slashing/types/querier.go similarity index 100% rename from x/slashing/internal/types/querier.go rename to x/slashing/types/querier.go diff --git a/x/slashing/internal/types/signing_info.go b/x/slashing/types/signing_info.go similarity index 50% rename from x/slashing/internal/types/signing_info.go rename to x/slashing/types/signing_info.go index 431658c2241a..315cac792c56 100644 --- a/x/slashing/internal/types/signing_info.go +++ b/x/slashing/types/signing_info.go @@ -4,19 +4,11 @@ import ( "fmt" "time" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" ) -// ValidatorSigningInfo defines the signing info for a validator -type ValidatorSigningInfo struct { - Address sdk.ConsAddress `json:"address" yaml:"address"` // validator consensus address - StartHeight int64 `json:"start_height" yaml:"start_height"` // height at which validator was first a candidate OR was unjailed - IndexOffset int64 `json:"index_offset" yaml:"index_offset"` // index offset into signed block bit array - JailedUntil time.Time `json:"jailed_until" yaml:"jailed_until"` // timestamp validator cannot be unjailed until - Tombstoned bool `json:"tombstoned" yaml:"tombstoned"` // whether or not a validator has been tombstoned (killed out of validator set) - MissedBlocksCounter int64 `json:"missed_blocks_counter" yaml:"missed_blocks_counter"` // missed blocks counter (to avoid scanning the array every time) -} - // NewValidatorSigningInfo creates a new ValidatorSigningInfo instance func NewValidatorSigningInfo( condAddr sdk.ConsAddress, startHeight, indexOffset int64, @@ -45,3 +37,9 @@ func (i ValidatorSigningInfo) String() string { i.Address, i.StartHeight, i.IndexOffset, i.JailedUntil, i.Tombstoned, i.MissedBlocksCounter) } + +// unmarshal a validator signing info from a store value +func UnmarshalValSigningInfo(cdc codec.Marshaler, value []byte) (signingInfo ValidatorSigningInfo, err error) { + err = cdc.UnmarshalBinaryLengthPrefixed(value, &signingInfo) + return signingInfo, err +} diff --git a/x/slashing/types/types.pb.go b/x/slashing/types/types.pb.go new file mode 100644 index 000000000000..a5444def9e35 --- /dev/null +++ b/x/slashing/types/types.pb.go @@ -0,0 +1,764 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: x/slashing/types/types.proto + +package types + +import ( + bytes "bytes" + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "github.com/golang/protobuf/ptypes/timestamp" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MsgUnjail - struct for unjailing jailed validator +type MsgUnjail struct { + ValidatorAddr github_com_cosmos_cosmos_sdk_types.ValAddress `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ValAddress" json:"address" yaml:"address"` +} + +func (m *MsgUnjail) Reset() { *m = MsgUnjail{} } +func (m *MsgUnjail) String() string { return proto.CompactTextString(m) } +func (*MsgUnjail) ProtoMessage() {} +func (*MsgUnjail) Descriptor() ([]byte, []int) { + return fileDescriptor_57cb37764f972476, []int{0} +} +func (m *MsgUnjail) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUnjail) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUnjail.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUnjail) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUnjail.Merge(m, src) +} +func (m *MsgUnjail) XXX_Size() int { + return m.Size() +} +func (m *MsgUnjail) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUnjail.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUnjail proto.InternalMessageInfo + +func (m *MsgUnjail) GetValidatorAddr() github_com_cosmos_cosmos_sdk_types.ValAddress { + if m != nil { + return m.ValidatorAddr + } + return nil +} + +// ValidatorSigningInfo defines the signing info for a validator +type ValidatorSigningInfo struct { + Address github_com_cosmos_cosmos_sdk_types.ConsAddress `protobuf:"bytes,1,opt,name=address,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ConsAddress" json:"address,omitempty"` + // height at which validator was first a candidate OR was unjailed + StartHeight int64 `protobuf:"varint,2,opt,name=start_height,json=startHeight,proto3" json:"start_height,omitempty" yaml:"start_height"` + // index offset into signed block bit array + IndexOffset int64 `protobuf:"varint,3,opt,name=index_offset,json=indexOffset,proto3" json:"index_offset,omitempty" yaml:"index_offset"` + // timestamp validator cannot be unjailed until + JailedUntil time.Time `protobuf:"bytes,4,opt,name=jailed_until,json=jailedUntil,proto3,stdtime" json:"jailed_until" yaml:"jailed_until"` + // whether or not a validator has been tombstoned (killed out of validator set) + Tombstoned bool `protobuf:"varint,5,opt,name=tombstoned,proto3" json:"tombstoned,omitempty"` + // missed blocks counter (to avoid scanning the array every time) + MissedBlocksCounter int64 `protobuf:"varint,6,opt,name=missed_blocks_counter,json=missedBlocksCounter,proto3" json:"missed_blocks_counter,omitempty" yaml:"missed_blocks_counter"` +} + +func (m *ValidatorSigningInfo) Reset() { *m = ValidatorSigningInfo{} } +func (*ValidatorSigningInfo) ProtoMessage() {} +func (*ValidatorSigningInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_57cb37764f972476, []int{1} +} +func (m *ValidatorSigningInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorSigningInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorSigningInfo.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ValidatorSigningInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorSigningInfo.Merge(m, src) +} +func (m *ValidatorSigningInfo) XXX_Size() int { + return m.Size() +} +func (m *ValidatorSigningInfo) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorSigningInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorSigningInfo proto.InternalMessageInfo + +func (m *ValidatorSigningInfo) GetAddress() github_com_cosmos_cosmos_sdk_types.ConsAddress { + if m != nil { + return m.Address + } + return nil +} + +func (m *ValidatorSigningInfo) GetStartHeight() int64 { + if m != nil { + return m.StartHeight + } + return 0 +} + +func (m *ValidatorSigningInfo) GetIndexOffset() int64 { + if m != nil { + return m.IndexOffset + } + return 0 +} + +func (m *ValidatorSigningInfo) GetJailedUntil() time.Time { + if m != nil { + return m.JailedUntil + } + return time.Time{} +} + +func (m *ValidatorSigningInfo) GetTombstoned() bool { + if m != nil { + return m.Tombstoned + } + return false +} + +func (m *ValidatorSigningInfo) GetMissedBlocksCounter() int64 { + if m != nil { + return m.MissedBlocksCounter + } + return 0 +} + +func init() { + proto.RegisterType((*MsgUnjail)(nil), "cosmos_sdk.x.slashing.v1.MsgUnjail") + proto.RegisterType((*ValidatorSigningInfo)(nil), "cosmos_sdk.x.slashing.v1.ValidatorSigningInfo") +} + +func init() { proto.RegisterFile("x/slashing/types/types.proto", fileDescriptor_57cb37764f972476) } + +var fileDescriptor_57cb37764f972476 = []byte{ + // 488 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xbf, 0x6f, 0xd3, 0x40, + 0x14, 0xc7, 0x73, 0x04, 0x4a, 0xb9, 0x84, 0x0e, 0x2e, 0x08, 0x2b, 0xaa, 0x7c, 0x91, 0x07, 0x94, + 0xa5, 0xb6, 0x28, 0x5b, 0x36, 0xdc, 0x01, 0x90, 0xf8, 0x21, 0x99, 0xb6, 0x03, 0x03, 0xd6, 0x39, + 0x77, 0x39, 0x1f, 0xb1, 0xef, 0x22, 0xdf, 0xb9, 0x4a, 0x56, 0xfe, 0x82, 0x8e, 0x8c, 0xfd, 0x43, + 0xf8, 0x03, 0x3a, 0x76, 0x64, 0x32, 0x28, 0x59, 0x10, 0x63, 0xc6, 0x4e, 0xc8, 0xbe, 0x98, 0x46, + 0x15, 0x42, 0x5d, 0xec, 0x7b, 0x9f, 0xfb, 0xbe, 0xf7, 0xbd, 0x77, 0xef, 0xe0, 0xde, 0xcc, 0x57, + 0x29, 0x56, 0x09, 0x17, 0xcc, 0xd7, 0xf3, 0x29, 0x55, 0xe6, 0xeb, 0x4d, 0x73, 0xa9, 0xa5, 0x65, + 0x8f, 0xa4, 0xca, 0xa4, 0x8a, 0x14, 0x99, 0x78, 0x33, 0xaf, 0x11, 0x7a, 0xa7, 0xcf, 0x7a, 0x4f, + 0x75, 0xc2, 0x73, 0x12, 0x4d, 0x71, 0xae, 0xe7, 0x7e, 0x2d, 0xf6, 0x99, 0x64, 0xf2, 0x7a, 0x65, + 0x2a, 0xf4, 0x10, 0x93, 0x92, 0xa5, 0xd4, 0x48, 0xe2, 0x62, 0xec, 0x6b, 0x9e, 0x51, 0xa5, 0x71, + 0x36, 0x35, 0x02, 0xf7, 0x0b, 0x80, 0x0f, 0xde, 0x2a, 0x76, 0x2c, 0x3e, 0x63, 0x9e, 0x5a, 0x05, + 0xdc, 0x39, 0xc5, 0x29, 0x27, 0x58, 0xcb, 0x3c, 0xc2, 0x84, 0xe4, 0x36, 0xe8, 0x83, 0x41, 0x37, + 0x78, 0xf7, 0xbb, 0x44, 0xf7, 0xab, 0x98, 0x2a, 0xb5, 0x2a, 0xd1, 0xce, 0x1c, 0x67, 0xe9, 0xd0, + 0x5d, 0x03, 0xf7, 0xaa, 0x44, 0xfb, 0x8c, 0xeb, 0xa4, 0x88, 0xbd, 0x91, 0xcc, 0x7c, 0x73, 0xe8, + 0xf5, 0x6f, 0x5f, 0x91, 0xc9, 0xba, 0xa7, 0x13, 0x9c, 0xbe, 0x30, 0x19, 0xe1, 0xc3, 0xbf, 0x2e, + 0x15, 0x71, 0xbf, 0xb5, 0xe1, 0xa3, 0x93, 0x86, 0x7c, 0xe0, 0x4c, 0x70, 0xc1, 0x5e, 0x8b, 0xb1, + 0xb4, 0xde, 0xc0, 0xc6, 0x75, 0x7d, 0x90, 0x83, 0xab, 0x12, 0x79, 0xb7, 0xf0, 0x3a, 0x94, 0x42, + 0x35, 0x66, 0x4d, 0x09, 0x6b, 0x08, 0xbb, 0x4a, 0xe3, 0x5c, 0x47, 0x09, 0xe5, 0x2c, 0xd1, 0xf6, + 0x9d, 0x3e, 0x18, 0xb4, 0x83, 0x27, 0xab, 0x12, 0xed, 0x9a, 0x86, 0x36, 0x77, 0xdd, 0xb0, 0x53, + 0x87, 0xaf, 0xea, 0xa8, 0xca, 0xe5, 0x82, 0xd0, 0x59, 0x24, 0xc7, 0x63, 0x45, 0xb5, 0xdd, 0xbe, + 0x99, 0xbb, 0xb9, 0xeb, 0x86, 0x9d, 0x3a, 0x7c, 0x5f, 0x47, 0xd6, 0x27, 0xd8, 0xad, 0x6e, 0x97, + 0x92, 0xa8, 0x10, 0x9a, 0xa7, 0xf6, 0xdd, 0x3e, 0x18, 0x74, 0x0e, 0x7a, 0x9e, 0x99, 0x8d, 0xd7, + 0xcc, 0xc6, 0x3b, 0x6a, 0x66, 0x13, 0xa0, 0x8b, 0x12, 0xb5, 0xae, 0x6b, 0x6f, 0x66, 0xbb, 0x67, + 0x3f, 0x10, 0x08, 0x3b, 0x06, 0x1d, 0x57, 0xc4, 0x72, 0x20, 0xd4, 0x32, 0x8b, 0x95, 0x96, 0x82, + 0x12, 0xfb, 0x5e, 0x1f, 0x0c, 0xb6, 0xc3, 0x0d, 0x62, 0x1d, 0xc1, 0xc7, 0x19, 0x57, 0x8a, 0x92, + 0x28, 0x4e, 0xe5, 0x68, 0xa2, 0xa2, 0x91, 0x2c, 0x84, 0xa6, 0xb9, 0xbd, 0x55, 0x37, 0xd1, 0x5f, + 0x95, 0x68, 0xcf, 0x18, 0xfd, 0x53, 0xe6, 0x86, 0xbb, 0x86, 0x07, 0x35, 0x3e, 0x34, 0x74, 0xb8, + 0xfd, 0xf5, 0x1c, 0xb5, 0x7e, 0x9d, 0x23, 0x10, 0xbc, 0xbc, 0x58, 0x38, 0xe0, 0x72, 0xe1, 0x80, + 0x9f, 0x0b, 0x07, 0x9c, 0x2d, 0x9d, 0xd6, 0xe5, 0xd2, 0x69, 0x7d, 0x5f, 0x3a, 0xad, 0x8f, 0xff, + 0x7f, 0x16, 0x37, 0xdf, 0x7e, 0xbc, 0x55, 0x5f, 0xc5, 0xf3, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, + 0xf7, 0x43, 0x16, 0x33, 0x16, 0x03, 0x00, 0x00, +} + +func (this *ValidatorSigningInfo) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ValidatorSigningInfo) + if !ok { + that2, ok := that.(ValidatorSigningInfo) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.Address, that1.Address) { + return false + } + if this.StartHeight != that1.StartHeight { + return false + } + if this.IndexOffset != that1.IndexOffset { + return false + } + if !this.JailedUntil.Equal(that1.JailedUntil) { + return false + } + if this.Tombstoned != that1.Tombstoned { + return false + } + if this.MissedBlocksCounter != that1.MissedBlocksCounter { + return false + } + return true +} +func (m *MsgUnjail) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUnjail) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUnjail) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ValidatorAddr) > 0 { + i -= len(m.ValidatorAddr) + copy(dAtA[i:], m.ValidatorAddr) + i = encodeVarintTypes(dAtA, i, uint64(len(m.ValidatorAddr))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ValidatorSigningInfo) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ValidatorSigningInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorSigningInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.MissedBlocksCounter != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.MissedBlocksCounter)) + i-- + dAtA[i] = 0x30 + } + if m.Tombstoned { + i-- + if m.Tombstoned { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x28 + } + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.JailedUntil, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.JailedUntil):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintTypes(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x22 + if m.IndexOffset != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.IndexOffset)) + i-- + dAtA[i] = 0x18 + } + if m.StartHeight != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.StartHeight)) + i-- + dAtA[i] = 0x10 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgUnjail) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddr) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *ValidatorSigningInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.StartHeight != 0 { + n += 1 + sovTypes(uint64(m.StartHeight)) + } + if m.IndexOffset != 0 { + n += 1 + sovTypes(uint64(m.IndexOffset)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.JailedUntil) + n += 1 + l + sovTypes(uint64(l)) + if m.Tombstoned { + n += 2 + } + if m.MissedBlocksCounter != 0 { + n += 1 + sovTypes(uint64(m.MissedBlocksCounter)) + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgUnjail) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUnjail: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUnjail: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddr", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddr = append(m.ValidatorAddr[:0], dAtA[iNdEx:postIndex]...) + if m.ValidatorAddr == nil { + m.ValidatorAddr = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorSigningInfo) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValidatorSigningInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorSigningInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = append(m.Address[:0], dAtA[iNdEx:postIndex]...) + if m.Address == nil { + m.Address = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StartHeight", wireType) + } + m.StartHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StartHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IndexOffset", wireType) + } + m.IndexOffset = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.IndexOffset |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field JailedUntil", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.JailedUntil, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Tombstoned", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Tombstoned = bool(v != 0) + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MissedBlocksCounter", wireType) + } + m.MissedBlocksCounter = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MissedBlocksCounter |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTypes(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTypes + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTypes + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTypes + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/slashing/types/types.proto b/x/slashing/types/types.proto new file mode 100644 index 000000000000..dfd7cf75dbe4 --- /dev/null +++ b/x/slashing/types/types.proto @@ -0,0 +1,41 @@ +syntax = "proto3"; +package cosmos_sdk.x.slashing.v1; + +option go_package = "github.com/cosmos/cosmos-sdk/x/slashing/types"; + +import "third_party/proto/gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; + +// MsgUnjail - struct for unjailing jailed validator +message MsgUnjail { + bytes validator_addr = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress", + (gogoproto.moretags) = "yaml:\"address\"", + (gogoproto.jsontag) = "address" + ]; +} + +// ValidatorSigningInfo defines the signing info for a validator +message ValidatorSigningInfo { + option (gogoproto.equal) = true; + option (gogoproto.goproto_stringer) = false; + + bytes address = 1 [ + (gogoproto.casttype) = + "github.com/cosmos/cosmos-sdk/types.ConsAddress" // validator consensus address + ]; + // height at which validator was first a candidate OR was unjailed + int64 start_height = 2 [(gogoproto.moretags) = "yaml:\"start_height\""]; + // index offset into signed block bit array + int64 index_offset = 3 [(gogoproto.moretags) = "yaml:\"index_offset\""]; + // timestamp validator cannot be unjailed until + google.protobuf.Timestamp jailed_until = 4 [ + (gogoproto.moretags) = "yaml:\"jailed_until\"", + (gogoproto.stdtime) = true, + (gogoproto.nullable) = false + ]; + // whether or not a validator has been tombstoned (killed out of validator set) + bool tombstoned = 5; + // missed blocks counter (to avoid scanning the array every time) + int64 missed_blocks_counter = 6 [(gogoproto.moretags) = "yaml:\"missed_blocks_counter\""]; +} diff --git a/x/staking/keeper/test_common.go b/x/staking/keeper/test_common.go index 18a0dfc509ca..3e83a310bf64 100644 --- a/x/staking/keeper/test_common.go +++ b/x/staking/keeper/test_common.go @@ -133,7 +133,7 @@ func CreateTestInput(t *testing.T, isCheckTx bool, initPower int64) (sdk.Context ) bk := bank.NewBaseKeeper( - cdc, + appCodec, bankKey, accountKeeper, pk.Subspace(bank.DefaultParamspace),