diff --git a/.codecov.yml b/.codecov.yml index 8fd6c94d4a..c10133afd9 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 5c6b57be3e..7e9979d326 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,12 @@ flushed to disk or kept as a snapshot. Note, `KeepRecent` is automatically infer and provided directly the IAVL store. * (modules) [\#5555](https://github.com/cosmos/cosmos-sdk/pull/5555) Move x/auth/client/utils/ types and functions to x/auth/client/. * (modules) [\#5572](https://github.com/cosmos/cosmos-sdk/pull/5572) Move account balance logic and APIs from `x/auth` to `x/bank`. +* (types) [\#5533](https://github.com/cosmos/cosmos-sdk/pull/5533) Refactored `AppModuleBasic` and `AppModuleGenesis` +to now accept a `codec.JSONMarshaler` for modular serialization of genesis state. + +### Features + +* (x/ibc) [\#5588](https://github.com/cosmos/cosmos-sdk/pull/5588) Add [ICS 024 - Host State Machine Requirements](https://github.com/cosmos/ics/tree/master/spec/ics-024-host-requirements) subpackage to `x/ibc` module. ### Bug Fixes @@ -72,7 +78,7 @@ and provided directly the IAVL store. * Callers to `NewBaseVestingAccount` are responsible for verifying account balance in relation to the original vesting amount. * The `SendKeeper` and `ViewKeeper` interfaces in `x/bank` have been modified to account for changes. -* (staking) [\#5600](https://github.com/cosmos/cosmos-sdk/pull/5600) Migrate the `x/staking` module to use Protocol Buffer for state +* (x/staking) [\#5600](https://github.com/cosmos/cosmos-sdk/pull/5600) Migrate the `x/staking` 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. * `BondStatus` is now of type `int32` instead of `byte`. @@ -80,7 +86,12 @@ 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`. -* (distr) [\#5610](https://github.com/cosmos/cosmos-sdk/pull/5610) Migrate the `x/distribution` module to use Protocol Buffer for state +* (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. * `ValidatorHistoricalRewards.ReferenceCount` is now of types `uint32` instead of `uint16`. @@ -89,6 +100,36 @@ for JSON encoding. * `ValidatorAccumulatedCommission` is now a struct with `commission`. * The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type provided is specified by `ModuleCdc`. +* (x/auth) [\#5533](https://github.com/cosmos/cosmos-sdk/pull/5533) Migrate the `x/auth` module to use Protocol Buffers for state +serialization instead of Amino. + * The `BaseAccount.PubKey` field is now represented as a Bech32 string instead of a `crypto.Pubkey`. + * `NewBaseAccountWithAddress` now returns a reference to a `BaseAccount`. + * The `x/auth` module now accepts a `Codec` interface which extends the `codec.Marshaler` interface by + requiring a concrete codec to know how to serialize accounts. + * The `AccountRetriever` type now accepts a `Codec` in its constructor in order to know how to + serialize accounts. +* (x/supply) [\#5533](https://github.com/cosmos/cosmos-sdk/pull/5533) Migrate the `x/supply` module to use Protocol Buffers for state +serialization instead of Amino. + * The `internal` sub-package has been removed in order to expose the types proto file. + * The `x/supply` module now accepts a `Codec` interface which extends the `codec.Marshaler` interface by + requiring a concrete codec to know how to serialize `SupplyI` types. + * The `SupplyI` interface has been modified to no longer return `SupplyI` on methods. Instead the + concrete type's receiver should modify the type. +* (x/mint) [\#5634](https://github.com/cosmos/cosmos-sdk/pull/5634) Migrate the `x/mint` module to use Protocol Buffers for state +serialization instead of Amino. + * The `internal` sub-package has been removed in order to expose the types proto file. +* (x/evidence) [\#5634](https://github.com/cosmos/cosmos-sdk/pull/5634) Migrate the `x/evidence` module to use Protocol Buffers for state +serialization instead of Amino. + * The `internal` sub-package has been removed in order to expose the types proto file. + * The module now accepts a `Codec` interface which extends the `codec.Marshaler` interface by + requiring a concrete codec to know how to serialize `Evidence` types. + * The `MsgSubmitEvidence` message has been removed in favor of `MsgSubmitEvidenceBase`. The application-level + codec must now define the concrete `MsgSubmitEvidence` type which must implement the module's `MsgSubmitEvidence` + interface. +* (x/upgrade) [\#5659](https://github.com/cosmos/cosmos-sdk/pull/5659) Migrate the `x/upgrade` module to use Protocol +Buffers for state serialization instead of Amino. + * The `internal` sub-package has been removed in order to expose the types proto file. + * The `x/upgrade` module now accepts a `codec.Marshaler` interface. ### Improvements diff --git a/Makefile b/Makefile index 2cf897fe98..96f04d16a8 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) +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 -# 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 +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 -# 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) +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-tendermint +.PHONY: proto-all proto-gen proto-lint proto-check-breaking proto-update-deps diff --git a/client/flags/flags.go b/client/flags/flags.go index 64dc2f25a3..746b512b06 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -68,6 +68,7 @@ const ( FlagKeyringBackend = "keyring-backend" FlagPage = "page" FlagLimit = "limit" + FlagUnsafeCORS = "unsafe-cors" ) // LineBreak can be included in a command list to provide a blank line @@ -141,6 +142,7 @@ func RegisterRestServerFlags(cmd *cobra.Command) *cobra.Command { cmd.Flags().Uint(FlagMaxOpenConnections, 1000, "The number of maximum open connections") cmd.Flags().Uint(FlagRPCReadTimeout, 10, "The RPC read timeout (in seconds)") cmd.Flags().Uint(FlagRPCWriteTimeout, 10, "The RPC write timeout (in seconds)") + cmd.Flags().Bool(FlagUnsafeCORS, false, "Allows CORS requests from all domains. For development purposes only, use it at your own risk.") return cmd } diff --git a/client/lcd/root.go b/client/lcd/root.go index 12697944c0..29bae3ba3c 100644 --- a/client/lcd/root.go +++ b/client/lcd/root.go @@ -7,6 +7,7 @@ import ( "os" "time" + "github.com/gorilla/handlers" "github.com/gorilla/mux" "github.com/rakyll/statik/fs" "github.com/spf13/cobra" @@ -46,7 +47,7 @@ func NewRestServer(cdc *codec.Codec) *RestServer { } // Start starts the rest server -func (rs *RestServer) Start(listenAddr string, maxOpen int, readTimeout, writeTimeout uint) (err error) { +func (rs *RestServer) Start(listenAddr string, maxOpen int, readTimeout, writeTimeout uint, cors bool) (err error) { server.TrapSignal(func() { err := rs.listener.Close() rs.log.Error("error closing listener", "err", err) @@ -68,6 +69,11 @@ func (rs *RestServer) Start(listenAddr string, maxOpen int, readTimeout, writeTi ), ) + var h http.Handler = rs.Mux + if cors { + return rpcserver.StartHTTPServer(rs.listener, handlers.CORS()(h), rs.log, cfg) + } + return rpcserver.StartHTTPServer(rs.listener, rs.Mux, rs.log, cfg) } @@ -90,6 +96,7 @@ func ServeCommand(cdc *codec.Codec, registerRoutesFn func(*RestServer)) *cobra.C viper.GetInt(flags.FlagMaxOpenConnections), uint(viper.GetInt(flags.FlagRPCReadTimeout)), uint(viper.GetInt(flags.FlagRPCWriteTimeout)), + viper.GetBool(flags.FlagUnsafeCORS), ) return err diff --git a/docs/architecture/adr-019-protobuf-state-encoding.md b/docs/architecture/adr-019-protobuf-state-encoding.md index f43c53e815..d090528665 100644 --- a/docs/architecture/adr-019-protobuf-state-encoding.md +++ b/docs/architecture/adr-019-protobuf-state-encoding.md @@ -3,6 +3,7 @@ ## Changelog - 2020 Feb 15: Initial Draft +- 2020 Feb 24: Updates to handle messages with interface fields ## Status @@ -143,19 +144,6 @@ message Account { ```go // app/codec/codec.go -import ( - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/supply" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" - // ... -) - -var ( - _ auth.Codec = (*Codec)(nil) - // ... -) - type Codec struct { codec.Marshaler @@ -192,10 +180,91 @@ about all the required types. Note, the use of `interface_type` allows us to avo amount of code boilerplate when implementing the `Codec`. A similar concept is to be applied for messages that contain interfaces fields. The module will -define a "base" concrete message type (e.g. `MsgSubmitProposalBase`) that the application-level codec -will extend via `oneof` (e.g. `MsgSubmitProposal`) that fulfills the required interface -(e.g. `MsgSubmitProposalI`). Note, however, the module's message handler must now switch on the -interface rather than the concrete type for this particular message. +define a "base" concrete message type that the application-level codec will extend via `oneof` that +fulfills the required message interface. + +Example: + +The `MsgSubmitEvidence` defined by the `x/evidence` module contains a field `Evidence` which is an +interface. + +```go +type MsgSubmitEvidence struct { + Evidence exported.Evidence + Submitter sdk.AccAddress +} +``` + +Instead, we will implement a "base" message type and an interface which the concrete message type +must implement. + +```protobuf +// x/evidence/types/types.proto + +message MsgSubmitEvidenceBase { + bytes submitter = 1 + [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress" + ]; +} +``` + +```go +// x/evidence/exported/evidence.go + +type MsgSubmitEvidence interface { + sdk.Msg + + GetEvidence() Evidence + GetSubmitter() sdk.AccAddress +} +``` + +Notice the `MsgSubmitEvidence` interface extends `sdk.Msg` and allows for the `Evidence` interface +to be retrieved from the concrete message type. + +Now, the application-level codec will define the concrete `MsgSubmitEvidence` type and will have it +fulfill the `MsgSubmitEvidence` interface defined by `x/evidence`. + +```protobuf +// app/codec/codec.proto + +message Evidence { + option (gogoproto.equal) = true; + option (cosmos_proto.interface_type) = "github.com/cosmos/cosmos-sdk/x/evidence/exported.Evidence"; + + oneof sum { + cosmos_sdk.x.evidence.v1.Equivocation equivocation = 1; + } +} + +message MsgSubmitEvidence { + option (gogoproto.equal) = true; + option (gogoproto.goproto_getters) = false; + + Evidence evidence = 1; + cosmos_sdk.x.evidence.v1.MsgSubmitEvidenceBase base = 2 + [ + (gogoproto.nullable) = false, + (gogoproto.embed) = true + ]; +} +``` + +```go +// app/codec/msgs.go + +func (msg MsgSubmitEvidence) GetEvidence() eviexported.Evidence { + return msg.Evidence.GetEvidence() +} + +func (msg MsgSubmitEvidence) GetSubmitter() sdk.AccAddress { + return msg.Submitter +} +``` + +Note, however, the module's message handler must now handle the interface `MsgSubmitEvidence` in +addition to any concrete types. ### Why Wasn't X Chosen Instead diff --git a/docs/building-modules/README.md b/docs/building-modules/README.md index f23a129e7b..15a2f0c464 100644 --- a/docs/building-modules/README.md +++ b/docs/building-modules/README.md @@ -19,3 +19,4 @@ This repository contains documentation on concepts developers need to know in or 9. [Genesis](./genesis.md) 10. [Module Interfaces](./module-interfaces.md) 11. [Standard Module Structure](./structure.md) +12. [Errors](./errors.md) diff --git a/docs/building-modules/errors.md b/docs/building-modules/errors.md new file mode 100644 index 0000000000..426a9d6d91 --- /dev/null +++ b/docs/building-modules/errors.md @@ -0,0 +1,53 @@ + + +# Errors + +Modules are encouraged to define and register their own errors to provide better +context on failed message or handler execution. Typically, these errors should be +common or general errors which can be further wrapped to provide additional specific +execution context. + +## Registration + +Modules should define and register their custom errors in `x/{module}/types/errors.go`. Registration +of errors is handled via the `types/errors` package. + +Example: + ++++ https://github.com/cosmos/cosmos-sdk/blob/v0.38.1/x/distribution/types/errors.go#L1-L21 + +Each custom module error must provide the codespace, which is typically the module name +(e.g. "distribution") and is unique per module, and a uint32 code. Together, the codespace and code +provide a globally unique SDK error. Typically, the code is monotonically increasing but does not +necessarily have to be. The only restrictions on error codes are the following: + +* Must be greater than one, as a code value of one is reserved for internal errors. +* Must be unique within the module. + +Note, the SDK provides a core set of *common* errors. These errors are defined in `types/errors/errors.go`. + +## Wrapping + +The custom module errors can be returned as their concrete type as they already fulfill the `error` +interface. However, module errors can be wrapped to provide further context and meaning to failed +execution. + +Example: + ++++ https://github.com/cosmos/cosmos-sdk/blob/v0.38.1/x/distribution/keeper/querier.go#L62-L80 + +Regardless if an error is wrapped or not, the SDK's `errors` package provides an API to determine if +an error is of a particular kind via `Is`. + +## ABCI + +If a module error is registered, the SDK `errors` package allows ABCI information to be extracted +through the `ABCIInfo` API. The package also provides `ResponseCheckTx` and `ResponseDeliverTx` as +auxiliary APIs to automatically get `CheckTx` and `DeliverTx` responses from an error. + +## Next {hide} + +Learn about [interfaces](../interfaces/interfaces-intro.md) {hide} diff --git a/docs/building-modules/structure.md b/docs/building-modules/structure.md index 47d9a82b19..bb20c9945e 100644 --- a/docs/building-modules/structure.md +++ b/docs/building-modules/structure.md @@ -85,9 +85,9 @@ allows for greater freedom of development while maintaining API stability. - `module.go`: The module's implementation of the `AppModule` and `AppModuleBasic` interfaces. - `simulation/`: The module's simulation package defines all the required functions -used on the blockchain simulator: randomized genesis state, parameters, weigthed +used on the blockchain simulator: randomized genesis state, parameters, weighted operations, proposal contents and types decoders. ## Next {hide} -Learn about [interfaces](../interfaces/interfaces-intro.md) {hide} +Learn about [Errors](./errors.md) {hide} diff --git a/docs/interfaces/rest.md b/docs/interfaces/rest.md index 75e5a78dc3..9ba57ffb2a 100644 --- a/docs/interfaces/rest.md +++ b/docs/interfaces/rest.md @@ -7,10 +7,10 @@ synopsis: "This document describes how to create a REST interface for an SDK **a ## Prerequisites {hide} -* [Query Lifecycle](./query-lifecycle.md) {prereq} -* [Application CLI](./cli.md) {prereq} +- [Query Lifecycle](./query-lifecycle.md) {prereq} +- [Application CLI](./cli.md) {prereq} -## Application REST Interface +## Application REST Interface Building the REST Interface for an application is done by [aggregating REST Routes](#registering-routes) defined in the application's modules. This interface is served by a REST Server [REST server](#rest-server), which route requests and output responses in the application itself. The SDK comes with its own REST Server by default. To enable it, the `rest.ServeCommand` command needs to be added as a subcommand of the `rootCmd` in the `main()` function of the [CLI interface](./cli.md): @@ -24,19 +24,19 @@ Users will then be able to use the application CLI to start a new REST server, a appcli rest-server --chain-id --trust-node ``` -Note that if `trust-node` is set to `false`, the REST server will verify the query proof against the merkle root (contained in the block header). +Note that if `trust-node` is set to `false`, the REST server will verify the query proof against the merkle root (contained in the block header). ## REST Server A REST Server is used to receive and route HTTP Requests, obtain the results from the application, and return a response to the user. The REST Server defined by the SDK `rest` package contains the following: -* **Router:** A router for HTTP requests. A new router can be instantiated for an application and used to match routes based on path, request method, headers, etc. The SDK uses the [Gorilla Mux Router](https://github.com/gorilla/mux). -* **CLIContext:** A [`CLIContext`](./query-lifecycle.md#clicontext) created for a user interaction. -* **Keybase:** A [Keybase](../basics/accounts.md#keybase) is a key manager. -* **Logger:** A logger from Tendermint `Log`, a log package structured around key-value pairs that allows logging level to be set differently for different keys. The logger takes `Debug()`, `Info()`, and `Error()`s. -* **Listener:** A [listener](https://golang.org/pkg/net/#Listener) from the net package. +- **Router:** A router for HTTP requests. A new router can be instantiated for an application and used to match routes based on path, request method, headers, etc. The SDK uses the [Gorilla Mux Router](https://github.com/gorilla/mux). +- **CLIContext:** A [`CLIContext`](./query-lifecycle.md#clicontext) created for a user interaction. +- **Keybase:** A [Keybase](../basics/accounts.md#keybase) is a key manager. +- **Logger:** A logger from Tendermint `Log`, a log package structured around key-value pairs that allows logging level to be set differently for different keys. The logger takes `Debug()`, `Info()`, and `Error()`s. +- **Listener:** A [listener](https://golang.org/pkg/net/#Listener) from the net package. -Of the five, the only attribute that application developers need interact with is the `router`: they need to add routes to it so that the REST server can properly handle queries. See the next section for more information on registering routes. +Of the five, the only attribute that application developers need interact with is the `router`: they need to add routes to it so that the REST server can properly handle queries. See the next section for more information on registering routes. In order to enable the REST Server in an SDK application, the `rest.ServeCommand` needs to be added to the application's command-line interface. See the [above section](#application-rest-interface) for more information. @@ -44,7 +44,7 @@ In order to enable the REST Server in an SDK application, the `rest.ServeCommand To include routes for each module in an application, the CLI must have some kind of function to register routes in its REST Server. This function is called `RegisterRoutes()`, and is utilized by the `ServeCommand` and must include routes for each of the application's modules. Since each module used by an SDK application implements a [`RegisterRESTRoutes`](../building-modules/module-interfaces.md#rest) function, application developers simply use the [Module Manager](../building-modules/module-manager.md) to call this function for each module (this is done in the [application's constructor](../basics/app-anatomy.md#constructor-function)). -At the bare minimum, a `RegisterRoutes()` function should use the SDK client package `RegisterRoutes()` function to be able to route RPC calls, and instruct the application Module Manager to call `RegisterRESTRoutes()` for all of its modules. This is done in the `main.go` file of the CLI (typically located in `./cmd/appcli/main.go`). +At the bare minimum, a `RegisterRoutes()` function should use the SDK client package `RegisterRoutes()` function to be able to route RPC calls, and instruct the application Module Manager to call `RegisterRESTRoutes()` for all of its modules. This is done in the `main.go` file of the CLI (typically located in `./cmd/appcli/main.go`). ```go func registerRoutes(rs *rest.RestServer) { @@ -58,3 +58,14 @@ This function is specific to the application and passed in to the `ServeCommand` ```go rootCmd.AddCommand(rest.ServeCommand(cdc, registerRoutes)) ``` + +## Cross-Origin Resource Sharing (CORS) + +[CORS policies](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) are not enabled by default to help with security. If you would like to use the rest-server in a public environment we recommend you provide a reverse proxy, this can be done with [nginx](https://www.nginx.com/). For testing and development purposes there is an `unsafe_cors` flag that can be passed to the cmd to enable accepting cors from everyone. + +```sh +gaiacli rest-server --chain-id=test \ + --laddr=tcp://localhost:1317 \ + --node tcp://localhost:26657 \ + --trust-node=true --unsafe-cors +``` diff --git a/go.mod b/go.mod index 47579d904e..ad82af5e20 100644 --- a/go.mod +++ b/go.mod @@ -10,19 +10,20 @@ require ( github.com/gogo/protobuf v1.3.1 github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129 github.com/golang/protobuf v1.3.3 + github.com/gorilla/handlers v1.4.2 github.com/gorilla/mux v1.7.4 github.com/hashicorp/golang-lru v0.5.4 github.com/mattn/go-isatty v0.0.12 github.com/pelletier/go-toml v1.6.0 github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.6 - github.com/regen-network/cosmos-proto v0.1.0 + github.com/regen-network/cosmos-proto v0.1.1-0.20200213154359-02baa11ea7c2 github.com/spf13/afero v1.2.1 // indirect - github.com/spf13/cobra v0.0.5 + github.com/spf13/cobra v0.0.6 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.4.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 8177d91a3f..55185f3f08 100644 --- a/go.sum +++ b/go.sum @@ -46,6 +46,7 @@ github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0W github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI= github.com/cosmos/ledger-go v0.9.2/go.mod h1:oZJ2hHAZROdlHiwTg4t7kP+GKIIkBT+o6c9QWFanOyI= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/danieljoos/wincred v1.0.2 h1:zf4bhty2iLuwgjgpraD2E9UbvO+fe54XXGJbOwe23fU= github.com/danieljoos/wincred v1.0.2/go.mod h1:SnuYRW9lp1oJrZX/dXJqr0cPK5gYXqx3EJbmjhLdK9U= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -91,7 +92,6 @@ github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129/go.mod h1:sBzyDLLjw3 github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= @@ -105,6 +105,8 @@ github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/handlers v1.4.2 h1:0QniY0USkHQ1RGCLfKxeNHK9bkDHGRYGNDFBCS+YARg= +github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc= github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= @@ -196,14 +198,16 @@ github.com/rakyll/statik v0.1.6 h1:uICcfUXpgqtw2VopbIncslhAmE5hwc4g20TEyEENBNs= github.com/rakyll/statik v0.1.6/go.mod h1:OEi9wJV/fMUAGx1eNjq75DKDsJVuEv1U0oYdX6GX8Zs= github.com/rcrowley/go-metrics v0.0.0-20180503174638-e2704e165165 h1:nkcn14uNmFEuGCb2mBZbBb24RdNRL08b/wb+xBOYpuk= github.com/rcrowley/go-metrics v0.0.0-20180503174638-e2704e165165/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/regen-network/cosmos-proto v0.1.0 h1:gsV+YO2kMvY430zQn8ioPXRxEJgb/ms0iMPeWo3VEyY= -github.com/regen-network/cosmos-proto v0.1.0/go.mod h1:+r7jN10xXCypD4yBgzKOa+vgLz0riqYMHeDcKekxPvA= +github.com/regen-network/cosmos-proto v0.1.1-0.20200213154359-02baa11ea7c2 h1:jQK1YoH972Aptd22YKgtNu5jM2X2xMGkyIENOAc71to= +github.com/regen-network/cosmos-proto v0.1.1-0.20200213154359-02baa11ea7c2/go.mod h1:+r7jN10xXCypD4yBgzKOa+vgLz0riqYMHeDcKekxPvA= github.com/regen-network/protobuf v1.3.2-alpha.regen.1 h1:YdeZbBS0lG1D13COb7b57+nM/RGgIs8WF9DwitU6EBM= github.com/regen-network/protobuf v1.3.2-alpha.regen.1/go.mod h1:lye6mqhOn/GCw1zRl3uPD5VP8rC+LPMyTyPAyQV872U= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= @@ -220,6 +224,8 @@ github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU github.com/spf13/cobra v0.0.1/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/cobra v0.0.6 h1:breEStsVwemnKh2/s6gMvSdMEkwW0sK8vGStnlVBMCs= +github.com/spf13/cobra v0.0.6/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= @@ -227,6 +233,7 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= github.com/spf13/viper v1.6.1/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k= github.com/spf13/viper v1.6.2 h1:7aKfF+e8/k68gda3LOjo5RxiUqddoFxVq4BKBPrxk5E= github.com/spf13/viper v1.6.2/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k= @@ -238,6 +245,10 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= 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= @@ -253,7 +264,6 @@ github.com/tendermint/go-amino v0.15.1 h1:D2uk35eT4iTsvJd9jWIetzthE5C0/k2QmMFkCN github.com/tendermint/go-amino v0.15.1/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= github.com/tendermint/iavl v0.13.0 h1:r2sINvNFlJsLlLhGoqlqPlREWYkuK26BvMfkBt+XQnA= github.com/tendermint/iavl v0.13.0/go.mod h1:7nSUPdrsHEZ2nNZa+9gaIrcJciWd1jCQZXtcyARU82k= -github.com/tendermint/tendermint v0.33.0 h1:TW1g9sQs3YSqKM8o1+opL3/VmBy4Ke/VKV9MxYpqNbI= github.com/tendermint/tendermint v0.33.0/go.mod h1:s5UoymnPIY+GcA3mMte4P9gpMP8vS7UH7HBXikT1pHI= github.com/tendermint/tendermint v0.33.1 h1:8f68LUBz8yhISZvaLFP4siXXrLWsWeoYfelbdNtmvm4= github.com/tendermint/tendermint v0.33.1/go.mod h1:fBOKyrlXOETqQ+heL8x/TZgSdmItON54csyabvktBp0= @@ -341,7 +351,6 @@ google.golang.org/genproto v0.0.0-20200108215221-bd8f9a0ef82f/go.mod h1:n3cpQtvx google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.1 h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk= google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= diff --git a/simapp/app.go b/simapp/app.go index 20215e8486..e7253c9a78 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -11,6 +11,7 @@ import ( bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" @@ -25,6 +26,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/mint" "github.com/cosmos/cosmos-sdk/x/params" paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" + paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" "github.com/cosmos/cosmos-sdk/x/slashing" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/supply" @@ -78,7 +80,6 @@ var ( } ) -// Verify app interface at compile time var _ App = (*SimApp)(nil) // SimApp extends an ABCI application, but with most of its parameters exported. @@ -124,10 +125,10 @@ func NewSimApp( invCheckPeriod uint, baseAppOptions ...func(*bam.BaseApp), ) *SimApp { - appCodec := NewAppCodec() - // TODO: Remove cdc in favor of appCodec once all modules are migrated. - cdc := MakeCodec() + cdc := simappcodec.MakeCodec(ModuleBasics) + + appCodec := simappcodec.NewAppCodec(cdc) bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) @@ -150,7 +151,7 @@ func NewSimApp( } // init params keeper and subspaces - app.ParamsKeeper = params.NewKeeper(appCodec.Params, keys[params.StoreKey], tkeys[params.TStoreKey]) + app.ParamsKeeper = params.NewKeeper(appCodec, keys[params.StoreKey], tkeys[params.TStoreKey]) app.subspaces[auth.ModuleName] = app.ParamsKeeper.Subspace(auth.DefaultParamspace) app.subspaces[bank.ModuleName] = app.ParamsKeeper.Subspace(bank.DefaultParamspace) app.subspaces[staking.ModuleName] = app.ParamsKeeper.Subspace(staking.DefaultParamspace) @@ -163,36 +164,36 @@ func NewSimApp( // add keepers app.AccountKeeper = auth.NewAccountKeeper( - app.cdc, keys[auth.StoreKey], app.subspaces[auth.ModuleName], auth.ProtoBaseAccount, + 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( - app.cdc, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms, + appCodec, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms, ) stakingKeeper := staking.NewKeeper( - appCodec.Staking, keys[staking.StoreKey], app.BankKeeper, app.SupplyKeeper, app.subspaces[staking.ModuleName], + appCodec, keys[staking.StoreKey], app.BankKeeper, app.SupplyKeeper, app.subspaces[staking.ModuleName], ) app.MintKeeper = mint.NewKeeper( - app.cdc, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper, + appCodec, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper, app.SupplyKeeper, auth.FeeCollectorName, ) app.DistrKeeper = distr.NewKeeper( - appCodec.Distribution, keys[distr.StoreKey], app.subspaces[distr.ModuleName], app.BankKeeper, &stakingKeeper, + appCodec, keys[distr.StoreKey], app.subspaces[distr.ModuleName], app.BankKeeper, &stakingKeeper, 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, ) - app.UpgradeKeeper = upgrade.NewKeeper(skipUpgradeHeights, keys[upgrade.StoreKey], app.cdc) + app.UpgradeKeeper = upgrade.NewKeeper(skipUpgradeHeights, keys[upgrade.StoreKey], appCodec) // create evidence keeper with router evidenceKeeper := evidence.NewKeeper( - app.cdc, keys[evidence.StoreKey], app.subspaces[evidence.ModuleName], &app.StakingKeeper, app.SlashingKeeper, + appCodec, keys[evidence.StoreKey], app.subspaces[evidence.ModuleName], &app.StakingKeeper, app.SlashingKeeper, ) evidenceRouter := evidence.NewRouter() // TODO: Register evidence routes. @@ -202,7 +203,7 @@ func NewSimApp( // register the proposal types govRouter := gov.NewRouter() govRouter.AddRoute(gov.RouterKey, gov.ProposalHandler). - AddRoute(params.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)). + AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)). AddRoute(distr.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)). AddRoute(upgrade.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)) app.GovKeeper = gov.NewKeeper( @@ -305,7 +306,7 @@ func (app *SimApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Re func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { var genesisState GenesisState app.cdc.MustUnmarshalJSON(req.AppStateBytes, &genesisState) - return app.mm.InitGenesis(ctx, genesisState) + return app.mm.InitGenesis(ctx, app.cdc, genesisState) } // LoadHeight loads a particular height diff --git a/simapp/codec.go b/simapp/codec.go deleted file mode 100644 index 0e8aabe15c..0000000000 --- a/simapp/codec.go +++ /dev/null @@ -1,46 +0,0 @@ -package simapp - -import ( - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/vesting" - distr "github.com/cosmos/cosmos-sdk/x/distribution" - "github.com/cosmos/cosmos-sdk/x/params" - "github.com/cosmos/cosmos-sdk/x/staking" -) - -// AppCodec defines the application-level codec. This codec contains all the -// required module-specific codecs that are to be provided upon initialization. -type AppCodec struct { - amino *codec.Codec - - Params *params.Codec - Staking *staking.Codec - Distribution *distr.Codec -} - -func NewAppCodec() *AppCodec { - amino := MakeCodec() - - return &AppCodec{ - amino: amino, - Params: params.NewCodec(amino), - Staking: staking.NewCodec(amino), - Distribution: distr.NewCodec(amino), - } -} - -// MakeCodec creates and returns a reference to an Amino codec that has all the -// necessary types and interfaces registered. This codec is provided to all the -// modules the application depends on. -// -// NOTE: This codec will be deprecated in favor of AppCodec once all modules are -// migrated. -func MakeCodec() *codec.Codec { - var cdc = codec.New() - ModuleBasics.RegisterCodec(cdc) - vesting.RegisterCodec(cdc) - sdk.RegisterCodec(cdc) - codec.RegisterCrypto(cdc) - return cdc -} diff --git a/simapp/codec/codec.go b/simapp/codec/codec.go new file mode 100644 index 0000000000..abcd8752d2 --- /dev/null +++ b/simapp/codec/codec.go @@ -0,0 +1,169 @@ +package codec + +import ( + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/auth" + authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/x/auth/vesting" + "github.com/cosmos/cosmos-sdk/x/evidence" + eviexported "github.com/cosmos/cosmos-sdk/x/evidence/exported" + "github.com/cosmos/cosmos-sdk/x/supply" + supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported" +) + +var ( + _ auth.Codec = (*Codec)(nil) + _ supply.Codec = (*Codec)(nil) + _ evidence.Codec = (*Codec)(nil) +) + +// Codec defines the application-level codec. This codec contains all the +// required module-specific codecs that are to be provided upon initialization. +type Codec struct { + codec.Marshaler + + // Keep reference to the amino codec to allow backwards compatibility along + // with type, and interface registration. + amino *codec.Codec +} + +func NewAppCodec(amino *codec.Codec) *Codec { + return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino} +} + +// MarshalAccount marshals an Account interface. If the given type implements +// the Marshaler interface, it is treated as a Proto-defined message and +// serialized that way. Otherwise, it falls back on the internal Amino codec. +func (c *Codec) MarshalAccount(accI authexported.Account) ([]byte, error) { + acc := &Account{} + if err := acc.SetAccount(accI); err != nil { + return nil, err + } + + return c.Marshaler.MarshalBinaryLengthPrefixed(acc) +} + +// UnmarshalAccount returns an Account interface from raw encoded account bytes +// of a Proto-based Account type. An error is returned upon decoding failure. +func (c *Codec) UnmarshalAccount(bz []byte) (authexported.Account, error) { + acc := &Account{} + if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, acc); err != nil { + return nil, err + } + + return acc.GetAccount(), nil +} + +// MarshalAccountJSON JSON encodes an account object implementing the Account +// interface. +func (c *Codec) MarshalAccountJSON(acc authexported.Account) ([]byte, error) { + return c.Marshaler.MarshalJSON(acc) +} + +// UnmarshalAccountJSON returns an Account from JSON encoded bytes. +func (c *Codec) UnmarshalAccountJSON(bz []byte) (authexported.Account, error) { + acc := &Account{} + if err := c.Marshaler.UnmarshalJSON(bz, acc); err != nil { + return nil, err + } + + return acc.GetAccount(), nil +} + +// MarshalSupply marshals a SupplyI interface. If the given type implements +// the Marshaler interface, it is treated as a Proto-defined message and +// serialized that way. Otherwise, it falls back on the internal Amino codec. +func (c *Codec) MarshalSupply(supplyI supplyexported.SupplyI) ([]byte, error) { + supply := &Supply{} + if err := supply.SetSupplyI(supplyI); err != nil { + return nil, err + } + + return c.Marshaler.MarshalBinaryLengthPrefixed(supply) +} + +// UnmarshalSupply returns a SupplyI interface from raw encoded account bytes +// of a Proto-based SupplyI type. An error is returned upon decoding failure. +func (c *Codec) UnmarshalSupply(bz []byte) (supplyexported.SupplyI, error) { + supply := &Supply{} + if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, supply); err != nil { + return nil, err + } + + return supply.GetSupplyI(), nil +} + +// MarshalSupplyJSON JSON encodes a supply object implementing the SupplyI +// interface. +func (c *Codec) MarshalSupplyJSON(supply supplyexported.SupplyI) ([]byte, error) { + return c.Marshaler.MarshalJSON(supply) +} + +// UnmarshalSupplyJSON returns a SupplyI from JSON encoded bytes. +func (c *Codec) UnmarshalSupplyJSON(bz []byte) (supplyexported.SupplyI, error) { + supply := &Supply{} + if err := c.Marshaler.UnmarshalJSON(bz, supply); err != nil { + return nil, err + } + + return supply.GetSupplyI(), nil +} + +// MarshalEvidence marshals an Evidence interface. If the given type implements +// the Marshaler interface, it is treated as a Proto-defined message and +// serialized that way. Otherwise, it falls back on the internal Amino codec. +func (c *Codec) MarshalEvidence(evidenceI eviexported.Evidence) ([]byte, error) { + evidence := &Evidence{} + if err := evidence.SetEvidence(evidenceI); err != nil { + return nil, err + } + + return c.Marshaler.MarshalBinaryLengthPrefixed(evidence) +} + +// UnmarshalEvidence returns an Evidence interface from raw encoded evidence +// bytes of a Proto-based Evidence type. An error is returned upon decoding +// failure. +func (c *Codec) UnmarshalEvidence(bz []byte) (eviexported.Evidence, error) { + evidence := &Evidence{} + if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, evidence); err != nil { + return nil, err + } + + return evidence.GetEvidence(), nil +} + +// MarshalEvidenceJSON JSON encodes an evidence object implementing the Evidence +// interface. +func (c *Codec) MarshalEvidenceJSON(evidence eviexported.Evidence) ([]byte, error) { + return c.Marshaler.MarshalJSON(evidence) +} + +// UnmarshalEvidenceJSON returns an Evidence from JSON encoded bytes +func (c *Codec) UnmarshalEvidenceJSON(bz []byte) (eviexported.Evidence, error) { + evidence := &Evidence{} + if err := c.Marshaler.UnmarshalJSON(bz, evidence); err != nil { + return nil, err + } + + return evidence.GetEvidence(), nil +} + +// ---------------------------------------------------------------------------- +// necessary types and interfaces registered. This codec is provided to all the +// modules the application depends on. +// +// NOTE: This codec will be deprecated in favor of AppCodec once all modules are +// migrated. +func MakeCodec(bm module.BasicManager) *codec.Codec { + cdc := codec.New() + + bm.RegisterCodec(cdc) + vesting.RegisterCodec(cdc) + sdk.RegisterCodec(cdc) + codec.RegisterCrypto(cdc) + + return cdc +} diff --git a/simapp/codec/codec.pb.go b/simapp/codec/codec.pb.go new file mode 100644 index 0000000000..b222403b46 --- /dev/null +++ b/simapp/codec/codec.pb.go @@ -0,0 +1,1676 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: simapp/codec/codec.proto + +package codec + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_x_auth_exported "github.com/cosmos/cosmos-sdk/x/auth/exported" + types "github.com/cosmos/cosmos-sdk/x/auth/types" + types1 "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" + github_com_cosmos_cosmos_sdk_x_evidence_exported "github.com/cosmos/cosmos-sdk/x/evidence/exported" + types3 "github.com/cosmos/cosmos-sdk/x/evidence/types" + github_com_cosmos_cosmos_sdk_x_supply_exported "github.com/cosmos/cosmos-sdk/x/supply/exported" + types2 "github.com/cosmos/cosmos-sdk/x/supply/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + _ "github.com/regen-network/cosmos-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 + +// Account defines the application-level Account type. +type Account struct { + // sum defines a list of all acceptable concrete Account implementations. + // + // Types that are valid to be assigned to Sum: + // *Account_BaseAccount + // *Account_ContinuousVestingAccount + // *Account_DelayedVestingAccount + // *Account_PeriodicVestingAccount + // *Account_ModuleAccount + Sum isAccount_Sum `protobuf_oneof:"sum"` +} + +func (m *Account) Reset() { *m = Account{} } +func (m *Account) String() string { return proto.CompactTextString(m) } +func (*Account) ProtoMessage() {} +func (*Account) Descriptor() ([]byte, []int) { + return fileDescriptor_3c6d4085e4065f5a, []int{0} +} +func (m *Account) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Account) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Account.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 *Account) XXX_Merge(src proto.Message) { + xxx_messageInfo_Account.Merge(m, src) +} +func (m *Account) XXX_Size() int { + return m.Size() +} +func (m *Account) XXX_DiscardUnknown() { + xxx_messageInfo_Account.DiscardUnknown(m) +} + +var xxx_messageInfo_Account proto.InternalMessageInfo + +type isAccount_Sum interface { + isAccount_Sum() + MarshalTo([]byte) (int, error) + Size() int +} + +type Account_BaseAccount struct { + BaseAccount *types.BaseAccount `protobuf:"bytes,1,opt,name=base_account,json=baseAccount,proto3,oneof" json:"base_account,omitempty"` +} +type Account_ContinuousVestingAccount struct { + ContinuousVestingAccount *types1.ContinuousVestingAccount `protobuf:"bytes,2,opt,name=continuous_vesting_account,json=continuousVestingAccount,proto3,oneof" json:"continuous_vesting_account,omitempty"` +} +type Account_DelayedVestingAccount struct { + DelayedVestingAccount *types1.DelayedVestingAccount `protobuf:"bytes,3,opt,name=delayed_vesting_account,json=delayedVestingAccount,proto3,oneof" json:"delayed_vesting_account,omitempty"` +} +type Account_PeriodicVestingAccount struct { + PeriodicVestingAccount *types1.PeriodicVestingAccount `protobuf:"bytes,4,opt,name=periodic_vesting_account,json=periodicVestingAccount,proto3,oneof" json:"periodic_vesting_account,omitempty"` +} +type Account_ModuleAccount struct { + ModuleAccount *types2.ModuleAccount `protobuf:"bytes,5,opt,name=module_account,json=moduleAccount,proto3,oneof" json:"module_account,omitempty"` +} + +func (*Account_BaseAccount) isAccount_Sum() {} +func (*Account_ContinuousVestingAccount) isAccount_Sum() {} +func (*Account_DelayedVestingAccount) isAccount_Sum() {} +func (*Account_PeriodicVestingAccount) isAccount_Sum() {} +func (*Account_ModuleAccount) isAccount_Sum() {} + +func (m *Account) GetSum() isAccount_Sum { + if m != nil { + return m.Sum + } + return nil +} + +func (m *Account) GetBaseAccount() *types.BaseAccount { + if x, ok := m.GetSum().(*Account_BaseAccount); ok { + return x.BaseAccount + } + return nil +} + +func (m *Account) GetContinuousVestingAccount() *types1.ContinuousVestingAccount { + if x, ok := m.GetSum().(*Account_ContinuousVestingAccount); ok { + return x.ContinuousVestingAccount + } + return nil +} + +func (m *Account) GetDelayedVestingAccount() *types1.DelayedVestingAccount { + if x, ok := m.GetSum().(*Account_DelayedVestingAccount); ok { + return x.DelayedVestingAccount + } + return nil +} + +func (m *Account) GetPeriodicVestingAccount() *types1.PeriodicVestingAccount { + if x, ok := m.GetSum().(*Account_PeriodicVestingAccount); ok { + return x.PeriodicVestingAccount + } + return nil +} + +func (m *Account) GetModuleAccount() *types2.ModuleAccount { + if x, ok := m.GetSum().(*Account_ModuleAccount); ok { + return x.ModuleAccount + } + return nil +} + +// XXX_OneofWrappers is for the internal use of the proto package. +func (*Account) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*Account_BaseAccount)(nil), + (*Account_ContinuousVestingAccount)(nil), + (*Account_DelayedVestingAccount)(nil), + (*Account_PeriodicVestingAccount)(nil), + (*Account_ModuleAccount)(nil), + } +} + +// Supply defines the application-level Supply type. +type Supply struct { + // sum defines a set of all acceptable concrete Supply implementations. + // + // Types that are valid to be assigned to Sum: + // *Supply_Supply + Sum isSupply_Sum `protobuf_oneof:"sum"` +} + +func (m *Supply) Reset() { *m = Supply{} } +func (m *Supply) String() string { return proto.CompactTextString(m) } +func (*Supply) ProtoMessage() {} +func (*Supply) Descriptor() ([]byte, []int) { + return fileDescriptor_3c6d4085e4065f5a, []int{1} +} +func (m *Supply) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Supply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Supply.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 *Supply) XXX_Merge(src proto.Message) { + xxx_messageInfo_Supply.Merge(m, src) +} +func (m *Supply) XXX_Size() int { + return m.Size() +} +func (m *Supply) XXX_DiscardUnknown() { + xxx_messageInfo_Supply.DiscardUnknown(m) +} + +var xxx_messageInfo_Supply proto.InternalMessageInfo + +type isSupply_Sum interface { + isSupply_Sum() + Equal(interface{}) bool + MarshalTo([]byte) (int, error) + Size() int +} + +type Supply_Supply struct { + Supply *types2.Supply `protobuf:"bytes,1,opt,name=supply,proto3,oneof" json:"supply,omitempty"` +} + +func (*Supply_Supply) isSupply_Sum() {} + +func (m *Supply) GetSum() isSupply_Sum { + if m != nil { + return m.Sum + } + return nil +} + +func (m *Supply) GetSupply() *types2.Supply { + if x, ok := m.GetSum().(*Supply_Supply); ok { + return x.Supply + } + return nil +} + +// XXX_OneofWrappers is for the internal use of the proto package. +func (*Supply) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*Supply_Supply)(nil), + } +} + +// Evidence defines the application-level allowed Evidence to be submitted via a +// MsgSubmitEvidence message. +type Evidence struct { + // sum defines a set of all acceptable concrete Evidence implementations. + // + // Types that are valid to be assigned to Sum: + // *Evidence_Equivocation + Sum isEvidence_Sum `protobuf_oneof:"sum"` +} + +func (m *Evidence) Reset() { *m = Evidence{} } +func (m *Evidence) String() string { return proto.CompactTextString(m) } +func (*Evidence) ProtoMessage() {} +func (*Evidence) Descriptor() ([]byte, []int) { + return fileDescriptor_3c6d4085e4065f5a, []int{2} +} +func (m *Evidence) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Evidence) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Evidence.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 *Evidence) XXX_Merge(src proto.Message) { + xxx_messageInfo_Evidence.Merge(m, src) +} +func (m *Evidence) XXX_Size() int { + return m.Size() +} +func (m *Evidence) XXX_DiscardUnknown() { + xxx_messageInfo_Evidence.DiscardUnknown(m) +} + +var xxx_messageInfo_Evidence proto.InternalMessageInfo + +type isEvidence_Sum interface { + isEvidence_Sum() + Equal(interface{}) bool + MarshalTo([]byte) (int, error) + Size() int +} + +type Evidence_Equivocation struct { + Equivocation *types3.Equivocation `protobuf:"bytes,1,opt,name=equivocation,proto3,oneof" json:"equivocation,omitempty"` +} + +func (*Evidence_Equivocation) isEvidence_Sum() {} + +func (m *Evidence) GetSum() isEvidence_Sum { + if m != nil { + return m.Sum + } + return nil +} + +func (m *Evidence) GetEquivocation() *types3.Equivocation { + if x, ok := m.GetSum().(*Evidence_Equivocation); ok { + return x.Equivocation + } + return nil +} + +// XXX_OneofWrappers is for the internal use of the proto package. +func (*Evidence) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*Evidence_Equivocation)(nil), + } +} + +// MsgSubmitEvidence defines the application-level message type for handling +// evidence submission. +type MsgSubmitEvidence struct { + Evidence *Evidence `protobuf:"bytes,1,opt,name=evidence,proto3" json:"evidence,omitempty"` + types3.MsgSubmitEvidenceBase `protobuf:"bytes,2,opt,name=base,proto3,embedded=base" json:"base"` +} + +func (m *MsgSubmitEvidence) Reset() { *m = MsgSubmitEvidence{} } +func (m *MsgSubmitEvidence) String() string { return proto.CompactTextString(m) } +func (*MsgSubmitEvidence) ProtoMessage() {} +func (*MsgSubmitEvidence) Descriptor() ([]byte, []int) { + return fileDescriptor_3c6d4085e4065f5a, []int{3} +} +func (m *MsgSubmitEvidence) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSubmitEvidence) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSubmitEvidence.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 *MsgSubmitEvidence) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSubmitEvidence.Merge(m, src) +} +func (m *MsgSubmitEvidence) XXX_Size() int { + return m.Size() +} +func (m *MsgSubmitEvidence) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSubmitEvidence.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSubmitEvidence proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Account)(nil), "cosmos_sdk.simapp.codec.v1.Account") + proto.RegisterType((*Supply)(nil), "cosmos_sdk.simapp.codec.v1.Supply") + proto.RegisterType((*Evidence)(nil), "cosmos_sdk.simapp.codec.v1.Evidence") + proto.RegisterType((*MsgSubmitEvidence)(nil), "cosmos_sdk.simapp.codec.v1.MsgSubmitEvidence") +} + +func init() { proto.RegisterFile("simapp/codec/codec.proto", fileDescriptor_3c6d4085e4065f5a) } + +var fileDescriptor_3c6d4085e4065f5a = []byte{ + // 593 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x54, 0x4d, 0x6f, 0xd3, 0x3e, + 0x18, 0x4f, 0xfe, 0xeb, 0xfa, 0xaf, 0xbc, 0x81, 0x44, 0x24, 0xa0, 0xaa, 0x50, 0x3a, 0x26, 0x98, + 0x78, 0x51, 0x13, 0x8d, 0xf1, 0xb6, 0x5e, 0x60, 0x1d, 0x43, 0x45, 0xa2, 0x08, 0x75, 0x12, 0x07, + 0x2e, 0x55, 0x6a, 0x5b, 0xad, 0xb5, 0x26, 0x36, 0xb5, 0x1d, 0xb5, 0xdf, 0x00, 0x71, 0xe2, 0x23, + 0x4c, 0x7c, 0x00, 0x4e, 0x3b, 0xf2, 0x01, 0xa6, 0x9d, 0x7a, 0xe4, 0x34, 0xa1, 0xf6, 0xc2, 0xc7, + 0x40, 0x89, 0x9d, 0xb4, 0x55, 0xda, 0xee, 0x12, 0xd5, 0x7e, 0x7e, 0x6f, 0x76, 0x9f, 0xc7, 0xa0, + 0xc8, 0x89, 0xef, 0x31, 0xe6, 0x42, 0x8a, 0x30, 0x54, 0x5f, 0x87, 0xf5, 0xa9, 0xa0, 0x56, 0x09, + 0x52, 0xee, 0x53, 0xde, 0xe2, 0xe8, 0xc4, 0x51, 0x20, 0x47, 0x95, 0xc3, 0xdd, 0xd2, 0x63, 0xd1, + 0x25, 0x7d, 0xd4, 0x62, 0x5e, 0x5f, 0x0c, 0xdd, 0x18, 0xee, 0x2a, 0x74, 0x65, 0x76, 0xa1, 0x84, + 0x4a, 0x3b, 0x59, 0x70, 0x87, 0x76, 0xe8, 0xf4, 0x97, 0xc6, 0x15, 0x07, 0xae, 0x27, 0x45, 0xd7, + 0x15, 0x43, 0x86, 0xb9, 0xfa, 0xea, 0xca, 0x96, 0xae, 0x84, 0x98, 0x0b, 0x12, 0x74, 0x16, 0x20, + 0x4a, 0x03, 0x97, 0x4b, 0xc6, 0x7a, 0xc3, 0x05, 0xb5, 0x3b, 0x03, 0x17, 0x87, 0x04, 0xe1, 0x00, + 0xe2, 0x6c, 0x75, 0xfb, 0x57, 0x0e, 0xfc, 0x7f, 0x00, 0x21, 0x95, 0x81, 0xb0, 0xde, 0x82, 0xcd, + 0xb6, 0xc7, 0x71, 0xcb, 0x53, 0xeb, 0xa2, 0xb9, 0x65, 0x3e, 0xd8, 0x78, 0x72, 0xd7, 0x99, 0xb9, + 0x89, 0x81, 0x13, 0x25, 0x71, 0xc2, 0x5d, 0xa7, 0xe6, 0x71, 0xac, 0x89, 0x75, 0xa3, 0xb9, 0xd1, + 0x9e, 0x2e, 0xad, 0x10, 0x94, 0x20, 0x0d, 0x04, 0x09, 0x24, 0x95, 0xbc, 0xa5, 0x53, 0xa7, 0xaa, + 0xff, 0xc5, 0xaa, 0xcf, 0x17, 0xa9, 0x2a, 0x64, 0xa4, 0x7e, 0x98, 0xf2, 0x3f, 0xa9, 0xcd, 0xa9, + 0x55, 0x11, 0x2e, 0xa9, 0x59, 0x3e, 0xb8, 0x8d, 0x70, 0xcf, 0x1b, 0x62, 0x94, 0x31, 0x5d, 0x8b, + 0x4d, 0xf7, 0x56, 0x9b, 0xbe, 0x51, 0xe4, 0x8c, 0xe3, 0x4d, 0xb4, 0xa8, 0x60, 0x31, 0x50, 0x64, + 0xb8, 0x4f, 0x28, 0x22, 0x30, 0xe3, 0x97, 0x8b, 0xfd, 0x9e, 0xae, 0xf6, 0xfb, 0xa8, 0xd9, 0x19, + 0xc3, 0x5b, 0x6c, 0x61, 0xc5, 0xfa, 0x00, 0xae, 0xfb, 0x14, 0xc9, 0xde, 0xf4, 0x2f, 0x5a, 0x8f, + 0x7d, 0xee, 0xcf, 0xfb, 0xa8, 0x56, 0x88, 0x1c, 0x1a, 0x31, 0x7a, 0x2a, 0x7c, 0xcd, 0x9f, 0xdd, + 0xa8, 0xee, 0x5f, 0x9c, 0x55, 0x9e, 0x3d, 0xea, 0x10, 0xd1, 0x95, 0x6d, 0x07, 0x52, 0x5f, 0x37, + 0x6e, 0xd2, 0xcc, 0x1c, 0x9d, 0xb8, 0xba, 0xf5, 0xf0, 0x80, 0xd1, 0xbe, 0xc0, 0xc8, 0xd1, 0xd4, + 0xda, 0x3a, 0x58, 0xe3, 0xd2, 0xdf, 0xfe, 0x66, 0x82, 0xfc, 0x71, 0x6c, 0x67, 0xbd, 0x04, 0x79, + 0x65, 0xac, 0xfb, 0xc6, 0x5e, 0x16, 0x4a, 0xe1, 0xeb, 0x46, 0x53, 0xe3, 0xab, 0xaf, 0xfe, 0x9e, + 0x96, 0xcd, 0x8b, 0xb3, 0xca, 0x8b, 0xab, 0xa2, 0xe8, 0x1e, 0x4f, 0xc3, 0x28, 0xa5, 0x77, 0x49, + 0x98, 0x1f, 0x26, 0x28, 0x1c, 0xe9, 0x56, 0xb7, 0xde, 0x83, 0x4d, 0xfc, 0x45, 0x92, 0x90, 0x42, + 0x4f, 0x10, 0x1a, 0xe8, 0x50, 0x3b, 0xf3, 0xa1, 0x92, 0xc1, 0x88, 0x62, 0x1d, 0xcd, 0xa0, 0xeb, + 0x46, 0x73, 0x8e, 0x5d, 0x3d, 0xd0, 0x11, 0xf7, 0xaf, 0x48, 0x98, 0x4e, 0x5a, 0x9a, 0x31, 0x09, + 0x94, 0x84, 0xfc, 0x69, 0x82, 0x1b, 0x0d, 0xde, 0x39, 0x96, 0x6d, 0x9f, 0x88, 0x34, 0xed, 0x6b, + 0x50, 0x48, 0xa8, 0x3a, 0xe9, 0x3d, 0x67, 0xf9, 0x03, 0x94, 0x8a, 0x36, 0x53, 0x96, 0xd5, 0x00, + 0xb9, 0x68, 0x06, 0xf5, 0x78, 0xb9, 0xcb, 0xcf, 0x99, 0x31, 0x8f, 0x26, 0xb9, 0x56, 0x38, 0xbf, + 0x2c, 0x1b, 0xa3, 0xcb, 0xb2, 0xd9, 0x8c, 0x65, 0xaa, 0x85, 0xaf, 0xa7, 0x65, 0x23, 0x3a, 0x74, + 0xed, 0xf0, 0x7c, 0x6c, 0x9b, 0xa3, 0xb1, 0x6d, 0xfe, 0x19, 0xdb, 0xe6, 0xf7, 0x89, 0x6d, 0x8c, + 0x26, 0xb6, 0xf1, 0x7b, 0x62, 0x1b, 0x9f, 0x1f, 0xae, 0xbc, 0x8c, 0xd9, 0x97, 0xb5, 0x9d, 0x8f, + 0x5f, 0x9b, 0xbd, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x57, 0xb9, 0x47, 0x37, 0x70, 0x05, 0x00, + 0x00, +} + +func (this *Supply) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Supply) + if !ok { + that2, ok := that.(Supply) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if that1.Sum == nil { + if this.Sum != nil { + return false + } + } else if this.Sum == nil { + return false + } else if !this.Sum.Equal(that1.Sum) { + return false + } + return true +} +func (this *Supply_Supply) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Supply_Supply) + if !ok { + that2, ok := that.(Supply_Supply) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.Supply.Equal(that1.Supply) { + return false + } + return true +} +func (this *Evidence) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Evidence) + if !ok { + that2, ok := that.(Evidence) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if that1.Sum == nil { + if this.Sum != nil { + return false + } + } else if this.Sum == nil { + return false + } else if !this.Sum.Equal(that1.Sum) { + return false + } + return true +} +func (this *Evidence_Equivocation) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Evidence_Equivocation) + if !ok { + that2, ok := that.(Evidence_Equivocation) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.Equivocation.Equal(that1.Equivocation) { + return false + } + return true +} +func (this *MsgSubmitEvidence) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgSubmitEvidence) + if !ok { + that2, ok := that.(MsgSubmitEvidence) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.Evidence.Equal(that1.Evidence) { + return false + } + if !this.MsgSubmitEvidenceBase.Equal(&that1.MsgSubmitEvidenceBase) { + return false + } + return true +} +func (this *Account) GetAccount() github_com_cosmos_cosmos_sdk_x_auth_exported.Account { + if x := this.GetBaseAccount(); x != nil { + return x + } + if x := this.GetContinuousVestingAccount(); x != nil { + return x + } + if x := this.GetDelayedVestingAccount(); x != nil { + return x + } + if x := this.GetPeriodicVestingAccount(); x != nil { + return x + } + if x := this.GetModuleAccount(); x != nil { + return x + } + return nil +} + +func (this *Account) SetAccount(value github_com_cosmos_cosmos_sdk_x_auth_exported.Account) error { + if value == nil { + this.Sum = nil + return nil + } + switch vt := value.(type) { + case *types.BaseAccount: + this.Sum = &Account_BaseAccount{vt} + return nil + case *types1.ContinuousVestingAccount: + this.Sum = &Account_ContinuousVestingAccount{vt} + return nil + case *types1.DelayedVestingAccount: + this.Sum = &Account_DelayedVestingAccount{vt} + return nil + case *types1.PeriodicVestingAccount: + this.Sum = &Account_PeriodicVestingAccount{vt} + return nil + case *types2.ModuleAccount: + this.Sum = &Account_ModuleAccount{vt} + return nil + } + return fmt.Errorf("can't encode value of type %T as message Account", value) +} + +func (this *Supply) GetSupplyI() github_com_cosmos_cosmos_sdk_x_supply_exported.SupplyI { + if x := this.GetSupply(); x != nil { + return x + } + return nil +} + +func (this *Supply) SetSupplyI(value github_com_cosmos_cosmos_sdk_x_supply_exported.SupplyI) error { + if value == nil { + this.Sum = nil + return nil + } + switch vt := value.(type) { + case *types2.Supply: + this.Sum = &Supply_Supply{vt} + return nil + } + return fmt.Errorf("can't encode value of type %T as message Supply", value) +} + +func (this *Evidence) GetEvidence() github_com_cosmos_cosmos_sdk_x_evidence_exported.Evidence { + if x := this.GetEquivocation(); x != nil { + return x + } + return nil +} + +func (this *Evidence) SetEvidence(value github_com_cosmos_cosmos_sdk_x_evidence_exported.Evidence) error { + if value == nil { + this.Sum = nil + return nil + } + switch vt := value.(type) { + case *types3.Equivocation: + this.Sum = &Evidence_Equivocation{vt} + return nil + case types3.Equivocation: + this.Sum = &Evidence_Equivocation{&vt} + return nil + } + return fmt.Errorf("can't encode value of type %T as message Evidence", value) +} + +func (m *Account) 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 *Account) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Account) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sum != nil { + { + size := m.Sum.Size() + i -= size + if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } + } + return len(dAtA) - i, nil +} + +func (m *Account_BaseAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Account_BaseAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.BaseAccount != nil { + { + size, err := m.BaseAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} +func (m *Account_ContinuousVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Account_ContinuousVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.ContinuousVestingAccount != nil { + { + size, err := m.ContinuousVestingAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + return len(dAtA) - i, nil +} +func (m *Account_DelayedVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Account_DelayedVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.DelayedVestingAccount != nil { + { + size, err := m.DelayedVestingAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + return len(dAtA) - i, nil +} +func (m *Account_PeriodicVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Account_PeriodicVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.PeriodicVestingAccount != nil { + { + size, err := m.PeriodicVestingAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + return len(dAtA) - i, nil +} +func (m *Account_ModuleAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Account_ModuleAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.ModuleAccount != nil { + { + size, err := m.ModuleAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + return len(dAtA) - i, nil +} +func (m *Supply) 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 *Supply) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Supply) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sum != nil { + { + size := m.Sum.Size() + i -= size + if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } + } + return len(dAtA) - i, nil +} + +func (m *Supply_Supply) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Supply_Supply) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.Supply != nil { + { + size, err := m.Supply.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} +func (m *Evidence) 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 *Evidence) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Evidence) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sum != nil { + { + size := m.Sum.Size() + i -= size + if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } + } + return len(dAtA) - i, nil +} + +func (m *Evidence_Equivocation) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Evidence_Equivocation) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.Equivocation != nil { + { + size, err := m.Equivocation.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} +func (m *MsgSubmitEvidence) 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 *MsgSubmitEvidence) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSubmitEvidence) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.MsgSubmitEvidenceBase.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if m.Evidence != nil { + { + size, err := m.Evidence.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintCodec(dAtA []byte, offset int, v uint64) int { + offset -= sovCodec(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Account) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Sum != nil { + n += m.Sum.Size() + } + return n +} + +func (m *Account_BaseAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BaseAccount != nil { + l = m.BaseAccount.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} +func (m *Account_ContinuousVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ContinuousVestingAccount != nil { + l = m.ContinuousVestingAccount.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} +func (m *Account_DelayedVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.DelayedVestingAccount != nil { + l = m.DelayedVestingAccount.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} +func (m *Account_PeriodicVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PeriodicVestingAccount != nil { + l = m.PeriodicVestingAccount.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} +func (m *Account_ModuleAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ModuleAccount != nil { + l = m.ModuleAccount.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} +func (m *Supply) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Sum != nil { + n += m.Sum.Size() + } + return n +} + +func (m *Supply_Supply) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Supply != nil { + l = m.Supply.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} +func (m *Evidence) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Sum != nil { + n += m.Sum.Size() + } + return n +} + +func (m *Evidence_Equivocation) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Equivocation != nil { + l = m.Equivocation.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} +func (m *MsgSubmitEvidence) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Evidence != nil { + l = m.Evidence.Size() + n += 1 + l + sovCodec(uint64(l)) + } + l = m.MsgSubmitEvidenceBase.Size() + n += 1 + l + sovCodec(uint64(l)) + return n +} + +func sovCodec(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozCodec(x uint64) (n int) { + return sovCodec(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Account) 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 ErrIntOverflowCodec + } + 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: Account: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Account: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCodec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCodec + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCodec + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &types.BaseAccount{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Account_BaseAccount{v} + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ContinuousVestingAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCodec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCodec + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCodec + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &types1.ContinuousVestingAccount{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Account_ContinuousVestingAccount{v} + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelayedVestingAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCodec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCodec + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCodec + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &types1.DelayedVestingAccount{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Account_DelayedVestingAccount{v} + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PeriodicVestingAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCodec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCodec + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCodec + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &types1.PeriodicVestingAccount{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Account_PeriodicVestingAccount{v} + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ModuleAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCodec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCodec + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCodec + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &types2.ModuleAccount{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Account_ModuleAccount{v} + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCodec(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCodec + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCodec + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Supply) 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 ErrIntOverflowCodec + } + 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: Supply: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Supply: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Supply", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCodec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCodec + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCodec + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &types2.Supply{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Supply_Supply{v} + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCodec(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCodec + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCodec + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Evidence) 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 ErrIntOverflowCodec + } + 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: Evidence: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Evidence: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Equivocation", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCodec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCodec + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCodec + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &types3.Equivocation{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Evidence_Equivocation{v} + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCodec(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCodec + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCodec + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgSubmitEvidence) 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 ErrIntOverflowCodec + } + 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: MsgSubmitEvidence: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSubmitEvidence: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Evidence", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCodec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCodec + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCodec + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Evidence == nil { + m.Evidence = &Evidence{} + } + if err := m.Evidence.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgSubmitEvidenceBase", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCodec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCodec + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCodec + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MsgSubmitEvidenceBase.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCodec(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCodec + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCodec + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipCodec(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, ErrIntOverflowCodec + } + 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, ErrIntOverflowCodec + } + 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, ErrIntOverflowCodec + } + 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, ErrInvalidLengthCodec + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupCodec + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthCodec + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthCodec = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowCodec = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupCodec = fmt.Errorf("proto: unexpected end of group") +) diff --git a/simapp/codec/codec.proto b/simapp/codec/codec.proto new file mode 100644 index 0000000000..2b68c487a6 --- /dev/null +++ b/simapp/codec/codec.proto @@ -0,0 +1,58 @@ +syntax = "proto3"; +package cosmos_sdk.simapp.codec.v1; + +import "third_party/proto/cosmos-proto/cosmos.proto"; +import "third_party/proto/gogoproto/gogo.proto"; +import "x/auth/types/types.proto"; +import "x/auth/vesting/types/types.proto"; +import "x/supply/types/types.proto"; +import "x/evidence/types/types.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/simapp/codec"; + +// Account defines the application-level Account type. +message Account { + option (cosmos_proto.interface_type) = "*github.com/cosmos/cosmos-sdk/x/auth/exported.Account"; + + // sum defines a list of all acceptable concrete Account implementations. + oneof sum { + cosmos_sdk.x.auth.v1.BaseAccount base_account = 1; + cosmos_sdk.x.auth.vesting.v1.ContinuousVestingAccount continuous_vesting_account = 2; + cosmos_sdk.x.auth.vesting.v1.DelayedVestingAccount delayed_vesting_account = 3; + cosmos_sdk.x.auth.vesting.v1.PeriodicVestingAccount periodic_vesting_account = 4; + cosmos_sdk.x.supply.v1.ModuleAccount module_account = 5; + } +} + +// Supply defines the application-level Supply type. +message Supply { + option (gogoproto.equal) = true; + option (cosmos_proto.interface_type) = "*github.com/cosmos/cosmos-sdk/x/supply/exported.SupplyI"; + + // sum defines a set of all acceptable concrete Supply implementations. + oneof sum { + cosmos_sdk.x.supply.v1.Supply supply = 1; + } +} + +// Evidence defines the application-level allowed Evidence to be submitted via a +// MsgSubmitEvidence message. +message Evidence { + option (gogoproto.equal) = true; + option (cosmos_proto.interface_type) = "github.com/cosmos/cosmos-sdk/x/evidence/exported.Evidence"; + + // sum defines a set of all acceptable concrete Evidence implementations. + oneof sum { + cosmos_sdk.x.evidence.v1.Equivocation equivocation = 1; + } +} + +// MsgSubmitEvidence defines the application-level message type for handling +// evidence submission. +message MsgSubmitEvidence { + option (gogoproto.equal) = true; + option (gogoproto.goproto_getters) = false; + + Evidence evidence = 1; + cosmos_sdk.x.evidence.v1.MsgSubmitEvidenceBase base = 2 [(gogoproto.nullable) = false, (gogoproto.embed) = true]; +} diff --git a/simapp/codec/msgs.go b/simapp/codec/msgs.go new file mode 100644 index 0000000000..d6390261be --- /dev/null +++ b/simapp/codec/msgs.go @@ -0,0 +1,38 @@ +package codec + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/evidence" + eviexported "github.com/cosmos/cosmos-sdk/x/evidence/exported" +) + +var _ eviexported.MsgSubmitEvidence = MsgSubmitEvidence{} + +// NewMsgSubmitEvidence returns a new MsgSubmitEvidence. +func NewMsgSubmitEvidence(evidenceI eviexported.Evidence, s sdk.AccAddress) MsgSubmitEvidence { + e := &Evidence{} + e.SetEvidence(evidenceI) + + return MsgSubmitEvidence{Evidence: e, MsgSubmitEvidenceBase: evidence.NewMsgSubmitEvidenceBase(s)} +} + +// ValidateBasic performs basic (non-state-dependant) validation on a +// MsgSubmitEvidence. +func (msg MsgSubmitEvidence) ValidateBasic() error { + if err := msg.MsgSubmitEvidenceBase.ValidateBasic(); err != nil { + return nil + } + if msg.Evidence == nil { + return sdkerrors.Wrap(evidence.ErrInvalidEvidence, "missing evidence") + } + if err := msg.Evidence.GetEvidence().ValidateBasic(); err != nil { + return err + } + + return nil +} + +// nolint +func (msg MsgSubmitEvidence) GetEvidence() eviexported.Evidence { return msg.Evidence.GetEvidence() } +func (msg MsgSubmitEvidence) GetSubmitter() sdk.AccAddress { return msg.Submitter } diff --git a/simapp/export.go b/simapp/export.go index 39cf18586f..23a2352792 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -27,7 +27,7 @@ func (app *SimApp) ExportAppStateAndValidators( app.prepForZeroHeightGenesis(ctx, jailWhiteList) } - genState := app.mm.ExportGenesis(ctx) + genState := app.mm.ExportGenesis(ctx, app.cdc) appState, err = codec.MarshalJSONIndent(app.cdc, genState) if err != nil { return nil, nil, err diff --git a/simapp/genesis.go b/simapp/genesis.go index d96c6feec9..1a760e3e49 100644 --- a/simapp/genesis.go +++ b/simapp/genesis.go @@ -2,6 +2,8 @@ package simapp import ( "encoding/json" + + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" ) // The genesis state of the blockchain is represented here as a map of raw json @@ -15,5 +17,7 @@ type GenesisState map[string]json.RawMessage // NewDefaultGenesisState generates the default state for the application. func NewDefaultGenesisState() GenesisState { - return ModuleBasics.DefaultGenesis() + cdc := simappcodec.MakeCodec(ModuleBasics) + + return ModuleBasics.DefaultGenesis(cdc) } diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 3d41fa3b84..18cb24a894 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" @@ -20,7 +21,7 @@ import ( distr "github.com/cosmos/cosmos-sdk/x/distribution" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/mint" - "github.com/cosmos/cosmos-sdk/x/params" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/simulation" "github.com/cosmos/cosmos-sdk/x/slashing" "github.com/cosmos/cosmos-sdk/x/staking" @@ -137,7 +138,7 @@ func TestAppImportExport(t *testing.T) { ctxA := app.NewContext(true, abci.Header{Height: app.LastBlockHeight()}) ctxB := newApp.NewContext(true, abci.Header{Height: app.LastBlockHeight()}) - newApp.mm.InitGenesis(ctxB, genesisState) + newApp.mm.InitGenesis(ctxB, app.Codec(), genesisState) fmt.Printf("comparing stores...\n") @@ -152,7 +153,7 @@ func TestAppImportExport(t *testing.T) { {app.keys[mint.StoreKey], newApp.keys[mint.StoreKey], [][]byte{}}, {app.keys[distr.StoreKey], newApp.keys[distr.StoreKey], [][]byte{}}, {app.keys[supply.StoreKey], newApp.keys[supply.StoreKey], [][]byte{}}, - {app.keys[params.StoreKey], newApp.keys[params.StoreKey], [][]byte{}}, + {app.keys[paramtypes.StoreKey], newApp.keys[paramtypes.StoreKey], [][]byte{}}, {app.keys[gov.StoreKey], newApp.keys[gov.StoreKey], [][]byte{}}, } diff --git a/simapp/utils_test.go b/simapp/utils_test.go index 9cadfff0da..b6d5fa1f35 100644 --- a/simapp/utils_test.go +++ b/simapp/utils_test.go @@ -8,12 +8,13 @@ import ( tmkv "github.com/tendermint/tendermint/libs/kv" "github.com/cosmos/cosmos-sdk/codec" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" ) func TestGetSimulationLog(t *testing.T) { - cdc := MakeCodec() + cdc := simappcodec.MakeCodec(ModuleBasics) decoders := make(sdk.StoreDecoderRegistry) decoders[auth.StoreKey] = func(cdc *codec.Codec, kvAs, kvBs tmkv.Pair) string { return "10" } diff --git a/third_party/proto/gogoproto/gogo.proto b/third_party/proto/gogoproto/gogo.proto index 588291f0ec..49e78f99fe 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 6c65444b07..7fb4b1bdb7 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 9dbb2be074..159fc58c98 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 2470227983..7e1375c21a 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/errors/abci.go b/types/errors/abci.go index cc56335431..04ba8413d3 100644 --- a/types/errors/abci.go +++ b/types/errors/abci.go @@ -154,10 +154,9 @@ func errIsNil(err error) bool { return false } -// Redact replace all errors that do not initialize with a weave error with a -// generic internal error instance. This function is supposed to hide -// implementation details errors and leave only those that weave framework -// originates. +// Redact replaces an error that is not initialized as an ABCI Error with a +// generic internal error instance. If the error is an ABCI Error, that error is +// simply returned. func Redact(err error) error { if ErrPanic.Is(err) { return errors.New(internalABCILog) diff --git a/types/module/module.go b/types/module/module.go index 924c998342..0b1633e3cd 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -48,9 +48,8 @@ type AppModuleBasic interface { Name() string RegisterCodec(*codec.Codec) - // genesis - DefaultGenesis() json.RawMessage - ValidateGenesis(json.RawMessage) error + DefaultGenesis(codec.JSONMarshaler) json.RawMessage + ValidateGenesis(codec.JSONMarshaler, json.RawMessage) error // client functionality RegisterRESTRoutes(context.CLIContext, *mux.Router) @@ -78,21 +77,23 @@ func (bm BasicManager) RegisterCodec(cdc *codec.Codec) { } // DefaultGenesis provides default genesis information for all modules -func (bm BasicManager) DefaultGenesis() map[string]json.RawMessage { +func (bm BasicManager) DefaultGenesis(cdc codec.JSONMarshaler) map[string]json.RawMessage { genesis := make(map[string]json.RawMessage) for _, b := range bm { - genesis[b.Name()] = b.DefaultGenesis() + genesis[b.Name()] = b.DefaultGenesis(cdc) } + return genesis } // ValidateGenesis performs genesis state validation for all modules -func (bm BasicManager) ValidateGenesis(genesis map[string]json.RawMessage) error { +func (bm BasicManager) ValidateGenesis(cdc codec.JSONMarshaler, genesis map[string]json.RawMessage) error { for _, b := range bm { - if err := b.ValidateGenesis(genesis[b.Name()]); err != nil { + if err := b.ValidateGenesis(cdc, genesis[b.Name()]); err != nil { return err } } + return nil } @@ -126,8 +127,9 @@ func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command, cdc *codec. // AppModuleGenesis is the standard form for an application module genesis functions type AppModuleGenesis interface { AppModuleBasic - InitGenesis(sdk.Context, json.RawMessage) []abci.ValidatorUpdate - ExportGenesis(sdk.Context) json.RawMessage + + InitGenesis(sdk.Context, codec.JSONMarshaler, json.RawMessage) []abci.ValidatorUpdate + ExportGenesis(sdk.Context, codec.JSONMarshaler) json.RawMessage } // AppModule is the standard form for an application module @@ -256,13 +258,14 @@ func (m *Manager) RegisterRoutes(router sdk.Router, queryRouter sdk.QueryRouter) } // InitGenesis performs init genesis functionality for modules -func (m *Manager) InitGenesis(ctx sdk.Context, genesisData map[string]json.RawMessage) abci.ResponseInitChain { +func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, genesisData map[string]json.RawMessage) abci.ResponseInitChain { var validatorUpdates []abci.ValidatorUpdate for _, moduleName := range m.OrderInitGenesis { if genesisData[moduleName] == nil { continue } - moduleValUpdates := m.Modules[moduleName].InitGenesis(ctx, genesisData[moduleName]) + + moduleValUpdates := m.Modules[moduleName].InitGenesis(ctx, cdc, genesisData[moduleName]) // use these validator updates if provided, the module manager assumes // only one module will update the validator set @@ -273,17 +276,19 @@ func (m *Manager) InitGenesis(ctx sdk.Context, genesisData map[string]json.RawMe validatorUpdates = moduleValUpdates } } + return abci.ResponseInitChain{ Validators: validatorUpdates, } } // ExportGenesis performs export genesis functionality for modules -func (m *Manager) ExportGenesis(ctx sdk.Context) map[string]json.RawMessage { +func (m *Manager) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) map[string]json.RawMessage { genesisData := make(map[string]json.RawMessage) for _, moduleName := range m.OrderExportGenesis { - genesisData[moduleName] = m.Modules[moduleName].ExportGenesis(ctx) + genesisData[moduleName] = m.Modules[moduleName].ExportGenesis(ctx, cdc) } + return genesisData } diff --git a/types/proto.go b/types/proto.go index e4cdbdc511..b6978c1eb9 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/types/router.go b/types/router.go index f3593f5530..12d0455f80 100644 --- a/types/router.go +++ b/types/router.go @@ -2,9 +2,27 @@ package types import "regexp" -// IsAlphaNumeric defines a regular expression for matching against alpha-numeric -// values. -var IsAlphaNumeric = regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString +var ( + // IsAlphaNumeric defines a regular expression for matching against alpha-numeric + // values. + IsAlphaNumeric = regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString + + // IsAlphaLower defines regular expression to check if the string has lowercase + // alphabetic characters only. + IsAlphaLower = regexp.MustCompile(`^[a-z]+$`).MatchString + + // IsAlphaUpper defines regular expression to check if the string has uppercase + // alphabetic characters only. + IsAlphaUpper = regexp.MustCompile(`^[A-Z]+$`).MatchString + + // IsAlpha defines regular expression to check if the string has alphabetic + // characters only. + IsAlpha = regexp.MustCompile(`^[a-zA-Z]+$`).MatchString + + // IsNumeric defines regular expression to check if the string has numeric + // characters only. + IsNumeric = regexp.MustCompile(`^[0-9]+$`).MatchString +) // Router provides handlers for each transaction type. type Router interface { diff --git a/types/types.pb.go b/types/types.pb.go index 4d2136c0a0..845bf267ba 100644 --- a/types/types.pb.go +++ b/types/types.pb.go @@ -250,28 +250,83 @@ func init() { func init() { proto.RegisterFile("types/types.proto", fileDescriptor_2c0f90c600ad7e2e) } var fileDescriptor_2c0f90c600ad7e2e = []byte{ - // 298 bytes of a gzipped FileDescriptorProto + // 305 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2c, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x07, 0x93, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xbc, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x65, 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, 0x25, 0x95, 0xfa, 0x60, 0x15, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, - 0x44, 0x9b, 0x92, 0x23, 0x17, 0x8b, 0x73, 0x7e, 0x66, 0x9e, 0x90, 0x08, 0x17, 0x6b, 0x4a, 0x6a, + 0x44, 0x9b, 0x92, 0x3b, 0x17, 0x8b, 0x73, 0x7e, 0x66, 0x9e, 0x90, 0x08, 0x17, 0x6b, 0x4a, 0x6a, 0x5e, 0x7e, 0xae, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x84, 0x23, 0xa4, 0xcc, 0xc5, 0x96, 0x98, 0x9b, 0x5f, 0x9a, 0x57, 0x22, 0xc1, 0x04, 0x12, 0x76, 0xe2, 0x3e, 0x71, 0x4f, 0x9e, 0xe1, - 0xd6, 0x3d, 0x79, 0x66, 0xcf, 0xbc, 0x92, 0x20, 0xa8, 0x94, 0x92, 0x0b, 0x17, 0xbb, 0x4b, 0x6a, - 0x32, 0x39, 0xa6, 0xb8, 0xa4, 0x26, 0xc3, 0x4d, 0xd1, 0xe4, 0xe2, 0xf0, 0xcc, 0x2b, 0x09, 0x00, - 0xfb, 0x45, 0x96, 0x8b, 0x39, 0x33, 0xaf, 0x04, 0x62, 0x08, 0xaa, 0x9d, 0x20, 0x71, 0x90, 0x52, - 0x97, 0xd4, 0x64, 0xb8, 0xd2, 0x94, 0xd4, 0x64, 0x74, 0xa5, 0x20, 0x83, 0x41, 0xe2, 0x4a, 0x4e, - 0x5c, 0x3c, 0x61, 0x89, 0x39, 0x8e, 0x29, 0x29, 0x45, 0xa9, 0xc5, 0xc5, 0xa9, 0xc5, 0x42, 0x3a, - 0x5c, 0x9c, 0x89, 0x30, 0x8e, 0x04, 0xa3, 0x02, 0xb3, 0x06, 0x8f, 0x13, 0xdf, 0xaf, 0x7b, 0xf2, - 0x5c, 0x08, 0x45, 0x41, 0x08, 0x05, 0x56, 0x2c, 0x0d, 0x77, 0x14, 0x18, 0x9d, 0x5c, 0x6e, 0x3c, - 0x94, 0x63, 0x68, 0x78, 0x24, 0xc7, 0x70, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, - 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, - 0x51, 0x4a, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x90, 0x68, 0x80, - 0x52, 0xba, 0xc5, 0x29, 0xd9, 0x90, 0x58, 0x4a, 0x62, 0x03, 0x87, 0xb7, 0x31, 0x20, 0x00, 0x00, - 0xff, 0xff, 0xd6, 0x08, 0x09, 0x0f, 0xbb, 0x01, 0x00, 0x00, + 0xd6, 0x3d, 0x79, 0x66, 0xcf, 0xbc, 0x92, 0x20, 0xa8, 0x94, 0x15, 0xcb, 0x8b, 0x05, 0xf2, 0x8c, + 0x4a, 0x5e, 0x5c, 0xec, 0x2e, 0xa9, 0xc9, 0xe4, 0x98, 0xe5, 0x92, 0x9a, 0x8c, 0x66, 0x96, 0x26, + 0x17, 0x87, 0x67, 0x5e, 0x49, 0x00, 0xd8, 0x5f, 0xb2, 0x5c, 0xcc, 0x99, 0x79, 0x25, 0x10, 0xa3, + 0x50, 0xed, 0x07, 0x89, 0x83, 0x94, 0xba, 0xa4, 0x26, 0xc3, 0x95, 0xa6, 0xa4, 0x26, 0xa3, 0x2b, + 0x05, 0x19, 0x0f, 0x12, 0x57, 0x72, 0xe2, 0xe2, 0x09, 0x4b, 0xcc, 0x71, 0x4c, 0x49, 0x29, 0x4a, + 0x2d, 0x2e, 0x4e, 0x2d, 0x16, 0xd2, 0xe1, 0xe2, 0x4c, 0x84, 0x71, 0x24, 0x18, 0x15, 0x98, 0x35, + 0x78, 0x9c, 0xf8, 0x7e, 0xdd, 0x93, 0xe7, 0x42, 0x28, 0x0a, 0x42, 0x28, 0xb0, 0x62, 0x69, 0xb8, + 0xa3, 0xc0, 0xe8, 0xe4, 0x72, 0xe3, 0xa1, 0x1c, 0x43, 0xc3, 0x23, 0x39, 0x86, 0x13, 0x8f, 0xe4, + 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, + 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x52, 0x4a, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, + 0xce, 0xcf, 0xd5, 0x87, 0x44, 0x09, 0x94, 0xd2, 0x2d, 0x4e, 0xc9, 0x86, 0xc4, 0x58, 0x12, 0x1b, + 0x38, 0xec, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xa7, 0x40, 0xd2, 0x04, 0xc7, 0x01, 0x00, + 0x00, } +func (this *Coin) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Coin) + if !ok { + that2, ok := that.(Coin) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Denom != that1.Denom { + return false + } + if !this.Amount.Equal(that1.Amount) { + return false + } + return true +} +func (this *DecCoin) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*DecCoin) + if !ok { + that2, ok := that.(DecCoin) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Denom != that1.Denom { + return false + } + if !this.Amount.Equal(that1.Amount) { + return false + } + return true +} func (m *Coin) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) diff --git a/types/types.proto b/types/types.proto index 590d21ccd9..7fff608b9c 100644 --- a/types/types.proto +++ b/types/types.proto @@ -3,18 +3,19 @@ package cosmos_sdk.v1; import "third_party/proto/gogoproto/gogo.proto"; -option go_package = "github.com/cosmos/cosmos-sdk/types"; +option go_package = "github.com/cosmos/cosmos-sdk/types"; option (gogoproto.goproto_stringer_all) = false; -option (gogoproto.stringer_all) = false; +option (gogoproto.stringer_all) = false; // Coin defines a token with a denomination and an amount. // // NOTE: The amount field is an Int which implements the custom method // signatures required by gogoproto. message Coin { - string denom = 1; - string amount = 2 - [ (gogoproto.customtype) = "Int", (gogoproto.nullable) = false ]; + option (gogoproto.equal) = true; + + string denom = 1; + string amount = 2 [(gogoproto.customtype) = "Int", (gogoproto.nullable) = false]; } // DecCoin defines a token with a denomination and a decimal amount. @@ -22,26 +23,25 @@ message Coin { // NOTE: The amount field is an Dec which implements the custom method // signatures required by gogoproto. message DecCoin { - string denom = 1; - string amount = 2 - [ (gogoproto.customtype) = "Dec", (gogoproto.nullable) = false ]; + option (gogoproto.equal) = true; + + string denom = 1; + string amount = 2 [(gogoproto.customtype) = "Dec", (gogoproto.nullable) = false]; } // IntProto defines a Protobuf wrapper around an Int object. message IntProto { - string int = 1 - [ (gogoproto.customtype) = "Int", (gogoproto.nullable) = false ]; + string int = 1 [(gogoproto.customtype) = "Int", (gogoproto.nullable) = false]; } // DecProto defines a Protobuf wrapper around a Dec object. message DecProto { - string dec = 1 - [ (gogoproto.customtype) = "Dec", (gogoproto.nullable) = false ]; + string dec = 1 [(gogoproto.customtype) = "Dec", (gogoproto.nullable) = false]; } // ValAddresses defines a repeated set of validator addresses. message ValAddresses { option (gogoproto.stringer) = true; - repeated bytes addresses = 1 [ (gogoproto.casttype) = "ValAddress" ]; -} \ No newline at end of file + repeated bytes addresses = 1 [(gogoproto.casttype) = "ValAddress"]; +} diff --git a/x/auth/alias.go b/x/auth/alias.go index 01b20a68f3..b5d5516352 100644 --- a/x/auth/alias.go +++ b/x/auth/alias.go @@ -1,9 +1,3 @@ -// nolint -// autogenerated code using github.com/rigelrozanski/multitool -// aliases generated for the following subdirectories: -// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/ante -// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/keeper -// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/types package auth import ( @@ -12,6 +6,9 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/types" ) +// DONTCOVER +// nolint + const ( ModuleName = types.ModuleName StoreKey = types.StoreKey @@ -40,7 +37,6 @@ var ( NewBaseAccountWithAddress = types.NewBaseAccountWithAddress NewAccountRetriever = types.NewAccountRetriever RegisterCodec = types.RegisterCodec - RegisterAccountTypeCodec = types.RegisterAccountTypeCodec NewGenesisState = types.NewGenesisState DefaultGenesisState = types.DefaultGenesisState ValidateGenesis = types.ValidateGenesis @@ -89,4 +85,5 @@ type ( StdSignature = types.StdSignature TxBuilder = types.TxBuilder GenesisAccountIterator = types.GenesisAccountIterator + Codec = types.Codec ) diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 0e999a9d47..05e570ca28 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -1,6 +1,7 @@ package ante import ( + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" err "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -112,21 +113,24 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim if sigs[i] != nil { continue } - acc := cgts.ak.GetAccount(ctx, signer) var pubkey crypto.PubKey + acc := cgts.ak.GetAccount(ctx, signer) + // use placeholder simSecp256k1Pubkey if sig is nil if acc == nil || acc.GetPubKey() == nil { pubkey = simSecp256k1Pubkey } else { pubkey = acc.GetPubKey() } + // use stdsignature to mock the size of a full signature simSig := types.StdSignature{ Signature: simSecp256k1Sig[:], PubKey: pubkey, } - sigBz := types.ModuleCdc.MustMarshalBinaryLengthPrefixed(simSig) + + sigBz := codec.Cdc.MustMarshalBinaryLengthPrefixed(simSig) cost := sdk.Gas(len(sigBz) + 6) // If the pubkey is a multi-signature pubkey, then we estimate for the maximum diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 4498b432d7..895be5373c 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -299,6 +299,7 @@ func (vscd ValidateSigCountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim func DefaultSigVerificationGasConsumer( meter sdk.GasMeter, sig []byte, pubkey crypto.PubKey, params types.Params, ) error { + switch pubkey := pubkey.(type) { case ed25519.PubKeyEd25519: meter.ConsumeGas(params.SigVerifyCostED25519, "ante verify: ed25519") @@ -321,11 +322,13 @@ func DefaultSigVerificationGasConsumer( } // ConsumeMultisignatureVerificationGas consumes gas from a GasMeter for verifying a multisig pubkey signature -func ConsumeMultisignatureVerificationGas(meter sdk.GasMeter, - sig multisig.Multisignature, pubkey multisig.PubKeyMultisigThreshold, - params types.Params) { +func ConsumeMultisignatureVerificationGas( + meter sdk.GasMeter, sig multisig.Multisignature, pubkey multisig.PubKeyMultisigThreshold, params types.Params, +) { + size := sig.BitArray.Size() sigIndex := 0 + for i := 0; i < size; i++ { if sig.BitArray.GetIndex(i) { DefaultSigVerificationGasConsumer(meter, sig.Sigs[sigIndex], pubkey.PubKeys[i], params) @@ -340,5 +343,6 @@ func GetSignerAcc(ctx sdk.Context, ak keeper.AccountKeeper, addr sdk.AccAddress) if acc := ak.GetAccount(ctx, addr); acc != nil { return acc, nil } + return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr) } diff --git a/x/auth/client/cli/query.go b/x/auth/client/cli/query.go index af9f00b4dd..ebb5f3f508 100644 --- a/x/auth/client/cli/query.go +++ b/x/auth/client/cli/query.go @@ -50,7 +50,7 @@ func GetAccountCmd(cdc *codec.Codec) *cobra.Command { Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) - accGetter := types.NewAccountRetriever(cliCtx) + accGetter := types.NewAccountRetriever(authclient.Codec, cliCtx) key, err := sdk.AccAddressFromBech32(args[0]) if err != nil { diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index b46192925d..f1ea091d0b 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -86,7 +86,7 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) txBldr := types.NewTxBuilderFromCLI(inBuf) if !viper.GetBool(flagOffline) { - accnum, seq, err := types.NewAccountRetriever(cliCtx).GetAccountNumberSequence(multisigInfo.GetAddress()) + accnum, seq, err := types.NewAccountRetriever(client.Codec, cliCtx).GetAccountNumberSequence(multisigInfo.GetAddress()) if err != nil { return err } diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index ebbe936a78..a6434be7ef 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -224,7 +224,7 @@ func printAndValidateSigs( // Validate the actual signature over the transaction bytes since we can // reach out to a full node to query accounts. if !offline && success { - acc, err := types.NewAccountRetriever(cliCtx).GetAccount(sigAddr) + acc, err := types.NewAccountRetriever(client.Codec, cliCtx).GetAccount(sigAddr) if err != nil { fmt.Printf("failed to get account: %s\n", sigAddr) return false diff --git a/x/auth/client/rest/query.go b/x/auth/client/rest/query.go index 44f1bbb5b0..6f245e40a2 100644 --- a/x/auth/client/rest/query.go +++ b/x/auth/client/rest/query.go @@ -33,7 +33,7 @@ func QueryAccountRequestHandlerFn(storeName string, cliCtx context.CLIContext) h return } - accGetter := types.NewAccountRetriever(cliCtx) + accGetter := types.NewAccountRetriever(client.Codec, cliCtx) account, height, err := accGetter.GetAccountWithHeight(addr) if err != nil { diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index 12d50a65ab..3c35aebe61 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -19,6 +19,15 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) +// Codec defines the x/auth account codec to be used for use with the +// AccountRetriever. The application must be sure to set this to their respective +// codec that implements the Codec interface and must be the same codec that +// passed to the x/auth module. +// +// TODO:/XXX: Using a package-level global isn't ideal and we should consider +// refactoring the module manager to allow passing in the correct module codec. +var Codec authtypes.Codec + // GasEstimateResponse defines a response definition for tx gas estimation. type GasEstimateResponse struct { GasEstimate uint64 `json:"gas_estimate" yaml:"gas_estimate"` @@ -198,9 +207,10 @@ func SignStdTx( // SignStdTxWithSignerAddress attaches a signature to a StdTx and returns a copy of a it. // Don't perform online validation or lookups if offline is true, else // populate account and sequence numbers from a foreign account. -func SignStdTxWithSignerAddress(txBldr authtypes.TxBuilder, cliCtx context.CLIContext, - addr sdk.AccAddress, name string, stdTx authtypes.StdTx, - offline bool) (signedStdTx authtypes.StdTx, err error) { +func SignStdTxWithSignerAddress( + txBldr authtypes.TxBuilder, cliCtx context.CLIContext, + addr sdk.AccAddress, name string, stdTx authtypes.StdTx, offline bool, +) (signedStdTx authtypes.StdTx, err error) { // check whether the address is a signer if !isTxSigner(addr, stdTx.GetSigners()) { @@ -242,7 +252,7 @@ func populateAccountFromState( txBldr authtypes.TxBuilder, cliCtx context.CLIContext, addr sdk.AccAddress, ) (authtypes.TxBuilder, error) { - num, seq, err := authtypes.NewAccountRetriever(cliCtx).GetAccountNumberSequence(addr) + num, seq, err := authtypes.NewAccountRetriever(Codec, cliCtx).GetAccountNumberSequence(addr) if err != nil { return txBldr, err } @@ -290,7 +300,7 @@ func parseQueryResponse(cdc *codec.Codec, rawRes []byte) (uint64, error) { func PrepareTxBuilder(txBldr authtypes.TxBuilder, cliCtx context.CLIContext) (authtypes.TxBuilder, error) { from := cliCtx.GetFromAddress() - accGetter := authtypes.NewAccountRetriever(cliCtx) + accGetter := authtypes.NewAccountRetriever(Codec, cliCtx) if err := accGetter.EnsureExists(from); err != nil { return txBldr, err } @@ -299,7 +309,7 @@ func PrepareTxBuilder(txBldr authtypes.TxBuilder, cliCtx context.CLIContext) (au // TODO: (ref #1903) Allow for user supplied account number without // automatically doing a manual lookup. if txbldrAccNum == 0 || txbldrAccSeq == 0 { - num, seq, err := authtypes.NewAccountRetriever(cliCtx).GetAccountNumberSequence(from) + num, seq, err := authtypes.NewAccountRetriever(Codec, cliCtx).GetAccountNumberSequence(from) if err != nil { return txBldr, err } diff --git a/x/auth/keeper/account.go b/x/auth/keeper/account.go index 8417a4a34d..f2e9292b47 100644 --- a/x/auth/keeper/account.go +++ b/x/auth/keeper/account.go @@ -13,6 +13,7 @@ func (ak AccountKeeper) NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddre if err != nil { panic(err) } + return ak.NewAccount(ctx, acc) } @@ -21,6 +22,7 @@ func (ak AccountKeeper) NewAccount(ctx sdk.Context, acc exported.Account) export if err := acc.SetAccountNumber(ak.GetNextAccountNumber(ctx)); err != nil { panic(err) } + return acc } @@ -31,17 +33,17 @@ func (ak AccountKeeper) GetAccount(ctx sdk.Context, addr sdk.AccAddress) exporte if bz == nil { return nil } - acc := ak.decodeAccount(bz) - return acc + + return ak.decodeAccount(bz) } // GetAllAccounts returns all accounts in the accountKeeper. func (ak AccountKeeper) GetAllAccounts(ctx sdk.Context) (accounts []exported.Account) { - ak.IterateAccounts(ctx, - func(acc exported.Account) (stop bool) { - accounts = append(accounts, acc) - return false - }) + ak.IterateAccounts(ctx, func(acc exported.Account) (stop bool) { + accounts = append(accounts, acc) + return false + }) + return accounts } @@ -49,10 +51,12 @@ func (ak AccountKeeper) GetAllAccounts(ctx sdk.Context) (accounts []exported.Acc func (ak AccountKeeper) SetAccount(ctx sdk.Context, acc exported.Account) { addr := acc.GetAddress() store := ctx.KVStore(ak.key) - bz, err := ak.cdc.MarshalBinaryBare(acc) + + bz, err := ak.cdc.MarshalAccount(acc) if err != nil { panic(err) } + store.Set(types.AddressStoreKey(addr), bz) } diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 244dec7c19..df5228fa7f 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -3,37 +3,32 @@ 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" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/params/subspace" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) // AccountKeeper encodes/decodes accounts using the go-amino (binary) // encoding/decoding library. type AccountKeeper struct { - // The (unexposed) key used to access the store from the Context. - key sdk.StoreKey + key sdk.StoreKey + cdc types.Codec + paramSubspace paramtypes.Subspace // The prototypical Account constructor. proto func() exported.Account - - // The codec codec for binary encoding/decoding of accounts. - cdc *codec.Codec - - paramSubspace subspace.Subspace } // NewAccountKeeper returns a new sdk.AccountKeeper that uses go-amino to // (binary) encode and decode concrete sdk.Accounts. -// nolint func NewAccountKeeper( - cdc *codec.Codec, key sdk.StoreKey, paramstore subspace.Subspace, proto func() exported.Account, + cdc types.Codec, key sdk.StoreKey, paramstore paramtypes.Subspace, proto func() exported.Account, ) AccountKeeper { return AccountKeeper{ @@ -55,6 +50,7 @@ func (ak AccountKeeper) GetPubKey(ctx sdk.Context, addr sdk.AccAddress) (crypto. if acc == nil { return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr) } + return acc.GetPubKey(), nil } @@ -64,6 +60,7 @@ func (ak AccountKeeper) GetSequence(ctx sdk.Context, addr sdk.AccAddress) (uint6 if acc == nil { return 0, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr) } + return acc.GetSequence(), nil } @@ -72,30 +69,33 @@ func (ak AccountKeeper) GetSequence(ctx sdk.Context, addr sdk.AccAddress) (uint6 func (ak AccountKeeper) GetNextAccountNumber(ctx sdk.Context) uint64 { var accNumber uint64 store := ctx.KVStore(ak.key) + bz := store.Get(types.GlobalAccountNumberKey) if bz == nil { // initialize the account numbers accNumber = 0 } else { - err := ak.cdc.UnmarshalBinaryLengthPrefixed(bz, &accNumber) + val := gogotypes.UInt64Value{} + + err := ak.cdc.UnmarshalBinaryLengthPrefixed(bz, &val) if err != nil { panic(err) } + + accNumber = val.GetValue() } - bz = ak.cdc.MustMarshalBinaryLengthPrefixed(accNumber + 1) + bz = ak.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.UInt64Value{Value: accNumber + 1}) store.Set(types.GlobalAccountNumberKey, bz) return accNumber } -// ----------------------------------------------------------------------------- -// Misc. - -func (ak AccountKeeper) decodeAccount(bz []byte) (acc exported.Account) { - err := ak.cdc.UnmarshalBinaryBare(bz, &acc) +func (ak AccountKeeper) decodeAccount(bz []byte) exported.Account { + acc, err := ak.cdc.UnmarshalAccount(bz) if err != nil { panic(err) } - return + + return acc } diff --git a/x/auth/module.go b/x/auth/module.go index d3cf501e4f..c5adc58113 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -41,14 +41,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { // DefaultGenesis returns default genesis state as raw bytes for the auth // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return types.ModuleCdc.MustMarshalJSON(types.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the auth module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data types.GenesisState - if err := types.ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) } @@ -113,18 +113,18 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { // InitGenesis performs genesis initialization for the auth module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - types.ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.accountKeeper, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the auth // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, am.accountKeeper) - return types.ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock returns the begin blocker for the auth module. diff --git a/x/auth/simulation/decoder.go b/x/auth/simulation/decoder.go index 725d82fc0a..d157aab943 100644 --- a/x/auth/simulation/decoder.go +++ b/x/auth/simulation/decoder.go @@ -19,11 +19,13 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { cdc.MustUnmarshalBinaryBare(kvA.Value, &accA) cdc.MustUnmarshalBinaryBare(kvB.Value, &accB) return fmt.Sprintf("%v\n%v", accA, accB) + case bytes.Equal(kvA.Key, types.GlobalAccountNumberKey): var globalAccNumberA, globalAccNumberB uint64 cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &globalAccNumberA) cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &globalAccNumberB) return fmt.Sprintf("GlobalAccNumberA: %d\nGlobalAccNumberB: %d", globalAccNumberA, globalAccNumberB) + default: panic(fmt.Sprintf("invalid account key %X", kvA.Key)) } diff --git a/x/auth/simulation/genesis.go b/x/auth/simulation/genesis.go index 94fd8ec5ff..f809042d14 100644 --- a/x/auth/simulation/genesis.go +++ b/x/auth/simulation/genesis.go @@ -98,7 +98,7 @@ func RandomizedGenState(simState *module.SimulationState) { func RandomGenesisAccounts(simState *module.SimulationState) (genesisAccs exported.GenesisAccounts) { for i, acc := range simState.Accounts { bacc := types.NewBaseAccountWithAddress(acc.Address) - var gacc exported.GenesisAccount = &bacc + var gacc exported.GenesisAccount = bacc // Only consider making a vesting account once the initial bonded validator // set is exhausted due to needing to track DelegatedVesting. @@ -115,7 +115,7 @@ func RandomGenesisAccounts(simState *module.SimulationState) (genesisAccs export endTime = int64(simulation.RandIntBetween(simState.Rand, int(startTime)+1, int(startTime+(60*60*12)))) } - bva := vestingtypes.NewBaseVestingAccount(&bacc, initialVesting, endTime) + bva := vestingtypes.NewBaseVestingAccount(bacc, initialVesting, endTime) if simState.Rand.Intn(100) < 50 { gacc = vestingtypes.NewContinuousVestingAccountRaw(bva, startTime) diff --git a/x/auth/types/account.go b/x/auth/types/account.go index 643c33abd2..08b67facc3 100644 --- a/x/auth/types/account.go +++ b/x/auth/types/account.go @@ -2,41 +2,29 @@ package types import ( "bytes" - "encoding/json" "errors" "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" ) -//----------------------------------------------------------------------------- -// BaseAccount - var _ exported.Account = (*BaseAccount)(nil) var _ exported.GenesisAccount = (*BaseAccount)(nil) -// BaseAccount - a base account structure. -// This can be extended by embedding within in your AppAccount. -// However one doesn't have to use BaseAccount as long as your struct -// implements Account. -type BaseAccount 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"` -} - // NewBaseAccount creates a new BaseAccount object func NewBaseAccount(address sdk.AccAddress, pubKey crypto.PubKey, accountNumber, sequence uint64) *BaseAccount { - return &BaseAccount{ + acc := &BaseAccount{ Address: address, - PubKey: pubKey, AccountNumber: accountNumber, Sequence: sequence, } + + acc.SetPubKey(pubKey) + return acc } // ProtoBaseAccount - a prototype function for BaseAccount @@ -45,8 +33,8 @@ func ProtoBaseAccount() exported.Account { } // NewBaseAccountWithAddress - returns a new base account with a given address -func NewBaseAccountWithAddress(addr sdk.AccAddress) BaseAccount { - return BaseAccount{ +func NewBaseAccountWithAddress(addr sdk.AccAddress) *BaseAccount { + return &BaseAccount{ Address: addr, } } @@ -61,23 +49,34 @@ func (acc *BaseAccount) SetAddress(addr sdk.AccAddress) error { if len(acc.Address) != 0 { return errors.New("cannot override BaseAccount address") } + acc.Address = addr return nil } // GetPubKey - Implements sdk.Account. -func (acc BaseAccount) GetPubKey() crypto.PubKey { - return acc.PubKey +func (acc BaseAccount) GetPubKey() (pk crypto.PubKey) { + if len(acc.PubKey) == 0 { + return nil + } + + codec.Cdc.MustUnmarshalBinaryBare(acc.PubKey, &pk) + return pk } // SetPubKey - Implements sdk.Account. func (acc *BaseAccount) SetPubKey(pubKey crypto.PubKey) error { - acc.PubKey = pubKey + if pubKey == nil { + acc.PubKey = nil + } else { + acc.PubKey = pubKey.Bytes() + } + return nil } // GetAccountNumber - Implements Account -func (acc *BaseAccount) GetAccountNumber() uint64 { +func (acc BaseAccount) GetAccountNumber() uint64 { return acc.AccountNumber } @@ -88,7 +87,7 @@ func (acc *BaseAccount) SetAccountNumber(accNumber uint64) error { } // GetSequence - Implements sdk.Account. -func (acc *BaseAccount) GetSequence() uint64 { +func (acc BaseAccount) GetSequence() uint64 { return acc.Sequence } @@ -100,14 +99,19 @@ func (acc *BaseAccount) SetSequence(seq uint64) error { // Validate checks for errors on the account fields func (acc BaseAccount) Validate() error { - if acc.PubKey != nil && acc.Address != nil && - !bytes.Equal(acc.PubKey.Address().Bytes(), acc.Address.Bytes()) { - return errors.New("pubkey and address pair is invalid") + if len(acc.PubKey) != 0 && acc.Address != nil && + !bytes.Equal(acc.GetPubKey().Address().Bytes(), acc.Address.Bytes()) { + return errors.New("account address and pubkey address do not match") } return nil } +func (acc BaseAccount) String() string { + out, _ := acc.MarshalYAML() + return out.(string) +} + type baseAccountPretty struct { Address sdk.AccAddress `json:"address" yaml:"address"` PubKey string `json:"public_key" yaml:"public_key"` @@ -115,11 +119,6 @@ type baseAccountPretty struct { Sequence uint64 `json:"sequence" yaml:"sequence"` } -func (acc BaseAccount) String() string { - out, _ := acc.MarshalYAML() - return out.(string) -} - // MarshalYAML returns the YAML representation of an account. func (acc BaseAccount) MarshalYAML() (interface{}, error) { alias := baseAccountPretty{ @@ -129,7 +128,7 @@ func (acc BaseAccount) MarshalYAML() (interface{}, error) { } if acc.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, acc.PubKey) + pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, acc.GetPubKey()) if err != nil { return nil, err } @@ -144,46 +143,3 @@ func (acc BaseAccount) MarshalYAML() (interface{}, error) { return string(bz), err } - -// MarshalJSON returns the JSON representation of a BaseAccount. -func (acc BaseAccount) MarshalJSON() ([]byte, error) { - alias := baseAccountPretty{ - Address: acc.Address, - AccountNumber: acc.AccountNumber, - Sequence: acc.Sequence, - } - - if acc.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, acc.PubKey) - if err != nil { - return nil, err - } - - alias.PubKey = pks - } - - return json.Marshal(alias) -} - -// UnmarshalJSON unmarshals raw JSON bytes into a BaseAccount. -func (acc *BaseAccount) UnmarshalJSON(bz []byte) error { - var alias baseAccountPretty - if err := json.Unmarshal(bz, &alias); err != nil { - return err - } - - if alias.PubKey != "" { - pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, alias.PubKey) - if err != nil { - return err - } - - acc.PubKey = pk - } - - acc.Address = alias.Address - acc.AccountNumber = alias.AccountNumber - acc.Sequence = alias.Sequence - - return nil -} diff --git a/x/auth/types/account_retriever.go b/x/auth/types/account_retriever.go index ab87e3259b..bc24b4a9c4 100644 --- a/x/auth/types/account_retriever.go +++ b/x/auth/types/account_retriever.go @@ -18,12 +18,13 @@ type NodeQuerier interface { // AccountRetriever defines the properties of a type that can be used to // retrieve accounts. type AccountRetriever struct { + codec Codec querier NodeQuerier } // NewAccountRetriever initialises a new AccountRetriever instance. -func NewAccountRetriever(querier NodeQuerier) AccountRetriever { - return AccountRetriever{querier: querier} +func NewAccountRetriever(codec Codec, querier NodeQuerier) AccountRetriever { + return AccountRetriever{codec: codec, querier: querier} } // GetAccount queries for an account given an address and a block height. An @@ -37,18 +38,18 @@ func (ar AccountRetriever) GetAccount(addr sdk.AccAddress) (exported.Account, er // height of the query with the account. An error is returned if the query // or decoding fails. func (ar AccountRetriever) GetAccountWithHeight(addr sdk.AccAddress) (exported.Account, int64, error) { - bs, err := ModuleCdc.MarshalJSON(NewQueryAccountParams(addr)) + bs, err := ar.codec.MarshalJSON(NewQueryAccountParams(addr)) if err != nil { return nil, 0, err } - res, height, err := ar.querier.QueryWithData(fmt.Sprintf("custom/%s/%s", QuerierRoute, QueryAccount), bs) + bz, height, err := ar.querier.QueryWithData(fmt.Sprintf("custom/%s/%s", QuerierRoute, QueryAccount), bs) if err != nil { return nil, height, err } var account exported.Account - if err := ModuleCdc.UnmarshalJSON(res, &account); err != nil { + if err := ar.codec.UnmarshalJSON(bz, &account); err != nil { return nil, height, err } diff --git a/x/auth/types/account_retriever_test.go b/x/auth/types/account_retriever_test.go index 76126db115..0481e00b26 100644 --- a/x/auth/types/account_retriever_test.go +++ b/x/auth/types/account_retriever_test.go @@ -1,4 +1,4 @@ -package types +package types_test import ( "errors" @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/tests/mocks" + "github.com/cosmos/cosmos-sdk/x/auth/types" ) var errFoo = errors.New("dummy") @@ -17,9 +18,9 @@ func TestAccountRetriever(t *testing.T) { defer mockCtrl.Finish() mockNodeQuerier := mocks.NewMockNodeQuerier(mockCtrl) - accRetr := NewAccountRetriever(mockNodeQuerier) + accRetr := types.NewAccountRetriever(appCodec, mockNodeQuerier) addr := []byte("test") - bs, err := ModuleCdc.MarshalJSON(NewQueryAccountParams(addr)) + bs, err := appCodec.MarshalJSON(types.NewQueryAccountParams(addr)) require.NoError(t, err) mockNodeQuerier.EXPECT().QueryWithData(gomock.Eq("custom/acc/account"), diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index 90a4dacb0c..ca612f1fe1 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -1,22 +1,20 @@ -package types +package types_test import ( - "encoding/json" - "errors" "testing" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/secp256k1" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/x/auth/types" ) func TestBaseAddressPubKey(t *testing.T) { - _, pub1, addr1 := KeyTestPubAddr() - _, pub2, addr2 := KeyTestPubAddr() - acc := NewBaseAccountWithAddress(addr1) + _, pub1, addr1 := types.KeyTestPubAddr() + _, pub2, addr2 := types.KeyTestPubAddr() + acc := types.NewBaseAccountWithAddress(addr1) // check the address (set) and pubkey (not set) require.EqualValues(t, addr1, acc.GetAddress()) @@ -40,16 +38,15 @@ func TestBaseAddressPubKey(t *testing.T) { //------------------------------------ // can set address on empty account - acc2 := BaseAccount{} + acc2 := types.BaseAccount{} err = acc2.SetAddress(addr2) require.Nil(t, err) require.EqualValues(t, addr2, acc2.GetAddress()) } func TestBaseAccountSequence(t *testing.T) { - _, _, addr := KeyTestPubAddr() - acc := NewBaseAccountWithAddress(addr) - + _, _, addr := types.KeyTestPubAddr() + acc := types.NewBaseAccountWithAddress(addr) seq := uint64(7) err := acc.SetSequence(seq) @@ -58,9 +55,8 @@ func TestBaseAccountSequence(t *testing.T) { } func TestBaseAccountMarshal(t *testing.T) { - _, pub, addr := KeyTestPubAddr() - acc := NewBaseAccountWithAddress(addr) - + _, pub, addr := types.KeyTestPubAddr() + acc := types.NewBaseAccountWithAddress(addr) seq := uint64(7) // set everything on the account @@ -69,73 +65,45 @@ func TestBaseAccountMarshal(t *testing.T) { err = acc.SetSequence(seq) require.Nil(t, err) - // need a codec for marshaling - cdc := codec.New() - codec.RegisterCrypto(cdc) - - b, err := cdc.MarshalBinaryLengthPrefixed(acc) + bz, err := appCodec.MarshalAccount(acc) require.Nil(t, err) - acc2 := BaseAccount{} - err = cdc.UnmarshalBinaryLengthPrefixed(b, &acc2) + acc2, err := appCodec.UnmarshalAccount(bz) require.Nil(t, err) require.Equal(t, acc, acc2) // error on bad bytes - acc2 = BaseAccount{} - err = cdc.UnmarshalBinaryLengthPrefixed(b[:len(b)/2], &acc2) + _, err = appCodec.UnmarshalAccount(bz[:len(bz)/2]) require.NotNil(t, err) } func TestGenesisAccountValidate(t *testing.T) { pubkey := secp256k1.GenPrivKey().PubKey() addr := sdk.AccAddress(pubkey.Address()) - baseAcc := NewBaseAccount(addr, pubkey, 0, 0) + baseAcc := types.NewBaseAccount(addr, pubkey, 0, 0) + tests := []struct { name string acc exported.GenesisAccount - expErr error + expErr bool }{ { "valid base account", baseAcc, - nil, + false, }, { "invalid base valid account", - NewBaseAccount(addr, secp256k1.GenPrivKey().PubKey(), 0, 0), - errors.New("pubkey and address pair is invalid"), + types.NewBaseAccount(addr, secp256k1.GenPrivKey().PubKey(), 0, 0), + 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) }) } } - -func TestBaseAccountJSON(t *testing.T) { - pubkey := secp256k1.GenPrivKey().PubKey() - addr := sdk.AccAddress(pubkey.Address()) - baseAcc := NewBaseAccount(addr, pubkey, 10, 50) - - bz, err := json.Marshal(baseAcc) - require.NoError(t, err) - - bz1, err := baseAcc.MarshalJSON() - require.NoError(t, err) - require.Equal(t, string(bz1), string(bz)) - - var a BaseAccount - require.NoError(t, json.Unmarshal(bz, &a)) - require.Equal(t, baseAcc.String(), a.String()) - - bz, err = ModuleCdc.MarshalJSON(baseAcc) - require.NoError(t, err) - - var b BaseAccount - require.NoError(t, ModuleCdc.UnmarshalJSON(bz, &b)) - require.Equal(t, baseAcc.String(), b.String()) -} diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index c6be8883f7..be7f21b3f1 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -5,10 +5,20 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/exported" ) -// ModuleCdc auth module wide codec -var ModuleCdc = codec.New() +// Codec defines the interface needed to serialize x/auth state. It must be +// aware of all concrete account types. +type Codec interface { + codec.Marshaler -// RegisterCodec registers concrete types on the codec + MarshalAccount(acc exported.Account) ([]byte, error) + UnmarshalAccount(bz []byte) (exported.Account, error) + + MarshalAccountJSON(acc exported.Account) ([]byte, error) + UnmarshalAccountJSON(bz []byte) (exported.Account, error) +} + +// RegisterCodec registers the account interfaces and concrete types on the +// provided Amino codec. func RegisterCodec(cdc *codec.Codec) { cdc.RegisterInterface((*exported.GenesisAccount)(nil), nil) cdc.RegisterInterface((*exported.Account)(nil), nil) @@ -16,13 +26,20 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(StdTx{}, "cosmos-sdk/StdTx", nil) } -// RegisterAccountTypeCodec registers an external account type defined in -// another module for the internal ModuleCdc. -func RegisterAccountTypeCodec(o interface{}, name string) { - ModuleCdc.RegisterConcrete(o, name, nil) -} +var ( + amino = codec.New() + + // ModuleCdc references the global x/auth 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/auth and + // defined at the application level. + ModuleCdc = codec.NewHybridCodec(amino) +) func init() { - RegisterCodec(ModuleCdc) - codec.RegisterCrypto(ModuleCdc) + RegisterCodec(amino) + codec.RegisterCrypto(amino) + amino.Seal() } diff --git a/x/auth/types/common_test.go b/x/auth/types/common_test.go new file mode 100644 index 0000000000..02b80ac6aa --- /dev/null +++ b/x/auth/types/common_test.go @@ -0,0 +1,11 @@ +package types_test + +import ( + "github.com/cosmos/cosmos-sdk/simapp" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" +) + +var ( + app = simapp.Setup(false) + appCodec = simappcodec.NewAppCodec(app.Codec()) +) diff --git a/x/auth/types/errors.go b/x/auth/types/errors.go index 3333cc8a46..8e765ceb98 100644 --- a/x/auth/types/errors.go +++ b/x/auth/types/errors.go @@ -1,8 +1,10 @@ package types -import "errors" +import ( + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) var ( - ErrorInvalidSigner = errors.New("tx intended signer does not match the given signer") - ErrorInvalidGasAdjustment = errors.New("invalid gas adjustment") + ErrorInvalidSigner = sdkerrors.Register(ModuleName, 2, "tx intended signer does not match the given signer") + ErrorInvalidGasAdjustment = sdkerrors.Register(ModuleName, 3, "invalid gas adjustment") ) diff --git a/x/auth/types/genesis.go b/x/auth/types/genesis.go index 89999db447..1b83380e35 100644 --- a/x/auth/types/genesis.go +++ b/x/auth/types/genesis.go @@ -5,7 +5,6 @@ import ( "fmt" "sort" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth/exported" ) @@ -30,7 +29,7 @@ func DefaultGenesisState() GenesisState { // GetGenesisStateFromAppState returns x/auth GenesisState given raw application // genesis state. -func GetGenesisStateFromAppState(cdc *codec.Codec, appState map[string]json.RawMessage) GenesisState { +func GetGenesisStateFromAppState(cdc Codec, appState map[string]json.RawMessage) GenesisState { var genesisState GenesisState if appState[ModuleName] != nil { cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState) @@ -86,7 +85,7 @@ type GenesisAccountIterator struct{} // appGenesis and invokes a callback on each genesis account. If any call // returns true, iteration stops. func (GenesisAccountIterator) IterateGenesisAccounts( - cdc *codec.Codec, appGenesis map[string]json.RawMessage, cb func(exported.Account) (stop bool), + cdc Codec, appGenesis map[string]json.RawMessage, cb func(exported.Account) (stop bool), ) { for _, genAcc := range GetGenesisStateFromAppState(cdc, appGenesis).Accounts { diff --git a/x/auth/types/genesis_test.go b/x/auth/types/genesis_test.go index 3b892f4803..c5e482cf03 100644 --- a/x/auth/types/genesis_test.go +++ b/x/auth/types/genesis_test.go @@ -1,4 +1,4 @@ -package types +package types_test import ( "encoding/json" @@ -9,21 +9,22 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/x/auth/types" ) func TestSanitize(t *testing.T) { addr1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) - authAcc1 := NewBaseAccountWithAddress(addr1) + authAcc1 := types.NewBaseAccountWithAddress(addr1) authAcc1.SetAccountNumber(1) addr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) - authAcc2 := NewBaseAccountWithAddress(addr2) + authAcc2 := types.NewBaseAccountWithAddress(addr2) - genAccs := exported.GenesisAccounts{&authAcc1, &authAcc2} + genAccs := exported.GenesisAccounts{authAcc1, authAcc2} require.True(t, genAccs[0].GetAccountNumber() > genAccs[1].GetAccountNumber()) require.Equal(t, genAccs[1].GetAddress(), addr2) - genAccs = SanitizeGenesisAccounts(genAccs) + genAccs = types.SanitizeGenesisAccounts(genAccs) require.False(t, genAccs[0].GetAccountNumber() > genAccs[1].GetAccountNumber()) require.Equal(t, genAccs[1].GetAddress(), addr1) @@ -38,34 +39,33 @@ var ( // require duplicate accounts fails validation func TestValidateGenesisDuplicateAccounts(t *testing.T) { - acc1 := NewBaseAccountWithAddress(sdk.AccAddress(addr1)) + acc1 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr1)) genAccs := make(exported.GenesisAccounts, 2) - genAccs[0] = &acc1 - genAccs[1] = &acc1 + genAccs[0] = acc1 + genAccs[1] = acc1 - require.Error(t, ValidateGenAccounts(genAccs)) + require.Error(t, types.ValidateGenAccounts(genAccs)) } func TestGenesisAccountIterator(t *testing.T) { - acc1 := NewBaseAccountWithAddress(sdk.AccAddress(addr1)) + acc1 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr1)) + acc2 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr2)) - acc2 := NewBaseAccountWithAddress(sdk.AccAddress(addr2)) + genAccounts := exported.GenesisAccounts{acc1, acc2} - genAccounts := exported.GenesisAccounts{&acc1, &acc2} - - authGenState := DefaultGenesisState() + authGenState := types.DefaultGenesisState() authGenState.Accounts = genAccounts appGenesis := make(map[string]json.RawMessage) - authGenStateBz, err := ModuleCdc.MarshalJSON(authGenState) + authGenStateBz, err := appCodec.MarshalJSON(authGenState) require.NoError(t, err) - appGenesis[ModuleName] = authGenStateBz + appGenesis[types.ModuleName] = authGenStateBz var addresses []sdk.AccAddress - GenesisAccountIterator{}.IterateGenesisAccounts( - ModuleCdc, appGenesis, func(acc exported.Account) (stop bool) { + types.GenesisAccountIterator{}.IterateGenesisAccounts( + appCodec, appGenesis, func(acc exported.Account) (stop bool) { addresses = append(addresses, acc.GetAddress()) return false }, diff --git a/x/auth/types/params.go b/x/auth/types/params.go index 2f994ef7ee..f2347e299b 100644 --- a/x/auth/types/params.go +++ b/x/auth/types/params.go @@ -1,12 +1,11 @@ package types import ( - "bytes" "fmt" - "strings" - "github.com/cosmos/cosmos-sdk/x/params" - "github.com/cosmos/cosmos-sdk/x/params/subspace" + yaml "gopkg.in/yaml.v2" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) // DefaultParamspace defines the default auth module parameter subspace @@ -30,20 +29,12 @@ var ( KeySigVerifyCostSecp256k1 = []byte("SigVerifyCostSecp256k1") ) -var _ subspace.ParamSet = &Params{} - -// Params defines the parameters for the auth module. -type Params struct { - MaxMemoCharacters uint64 `json:"max_memo_characters" yaml:"max_memo_characters"` - TxSigLimit uint64 `json:"tx_sig_limit" yaml:"tx_sig_limit"` - TxSizeCostPerByte uint64 `json:"tx_size_cost_per_byte" yaml:"tx_size_cost_per_byte"` - SigVerifyCostED25519 uint64 `json:"sig_verify_cost_ed25519" yaml:"sig_verify_cost_ed25519"` - SigVerifyCostSecp256k1 uint64 `json:"sig_verify_cost_secp256k1" yaml:"sig_verify_cost_secp256k1"` -} +var _ paramtypes.ParamSet = &Params{} // NewParams creates a new Params object -func NewParams(maxMemoCharacters, txSigLimit, txSizeCostPerByte, - sigVerifyCostED25519, sigVerifyCostSecp256k1 uint64) Params { +func NewParams( + maxMemoCharacters, txSigLimit, txSizeCostPerByte, sigVerifyCostED25519, sigVerifyCostSecp256k1 uint64, +) Params { return Params{ MaxMemoCharacters: maxMemoCharacters, @@ -55,30 +46,23 @@ func NewParams(maxMemoCharacters, txSigLimit, txSizeCostPerByte, } // ParamKeyTable for auth module -func ParamKeyTable() subspace.KeyTable { - return subspace.NewKeyTable().RegisterParamSet(&Params{}) +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) } // ParamSetPairs implements the ParamSet interface and returns all the key/value pairs // pairs of auth module's parameters. // nolint -func (p *Params) ParamSetPairs() subspace.ParamSetPairs { - return subspace.ParamSetPairs{ - params.NewParamSetPair(KeyMaxMemoCharacters, &p.MaxMemoCharacters, validateMaxMemoCharacters), - params.NewParamSetPair(KeyTxSigLimit, &p.TxSigLimit, validateTxSigLimit), - params.NewParamSetPair(KeyTxSizeCostPerByte, &p.TxSizeCostPerByte, validateTxSizeCostPerByte), - params.NewParamSetPair(KeySigVerifyCostED25519, &p.SigVerifyCostED25519, validateSigVerifyCostED25519), - params.NewParamSetPair(KeySigVerifyCostSecp256k1, &p.SigVerifyCostSecp256k1, validateSigVerifyCostSecp256k1), +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyMaxMemoCharacters, &p.MaxMemoCharacters, validateMaxMemoCharacters), + paramtypes.NewParamSetPair(KeyTxSigLimit, &p.TxSigLimit, validateTxSigLimit), + paramtypes.NewParamSetPair(KeyTxSizeCostPerByte, &p.TxSizeCostPerByte, validateTxSizeCostPerByte), + paramtypes.NewParamSetPair(KeySigVerifyCostED25519, &p.SigVerifyCostED25519, validateSigVerifyCostED25519), + paramtypes.NewParamSetPair(KeySigVerifyCostSecp256k1, &p.SigVerifyCostSecp256k1, validateSigVerifyCostSecp256k1), } } -// Equal returns a boolean determining if two Params types are identical. -func (p Params) Equal(p2 Params) bool { - bz1 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&p) - bz2 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&p2) - return bytes.Equal(bz1, bz2) -} - // DefaultParams returns a default set of parameters. func DefaultParams() Params { return Params{ @@ -92,14 +76,8 @@ func DefaultParams() Params { // String implements the stringer interface. func (p Params) String() string { - var sb strings.Builder - sb.WriteString("Params: \n") - sb.WriteString(fmt.Sprintf("MaxMemoCharacters: %d\n", p.MaxMemoCharacters)) - sb.WriteString(fmt.Sprintf("TxSigLimit: %d\n", p.TxSigLimit)) - sb.WriteString(fmt.Sprintf("TxSizeCostPerByte: %d\n", p.TxSizeCostPerByte)) - sb.WriteString(fmt.Sprintf("SigVerifyCostED25519: %d\n", p.SigVerifyCostED25519)) - sb.WriteString(fmt.Sprintf("SigVerifyCostSecp256k1: %d\n", p.SigVerifyCostSecp256k1)) - return sb.String() + out, _ := yaml.Marshal(p) + return string(out) } func validateTxSigLimit(i interface{}) error { diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index a37408f9e9..a9a6cd3e9d 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -163,16 +163,6 @@ func (tx StdTx) FeePayer() sdk.AccAddress { return sdk.AccAddress{} } -//__________________________________________________________ - -// StdFee includes the amount of coins paid in fees and the maximum -// gas to be used by the transaction. The ratio yields an effective "gasprice", -// which must be above some miminum to be accepted into the mempool. -type StdFee struct { - Amount sdk.Coins `json:"amount" yaml:"amount"` - Gas uint64 `json:"gas" yaml:"gas"` -} - // NewStdFee returns a new instance of StdFee func NewStdFee(gas uint64, amount sdk.Coins) StdFee { return StdFee{ @@ -190,10 +180,12 @@ func (fee StdFee) Bytes() []byte { if len(fee.Amount) == 0 { fee.Amount = sdk.NewCoins() } - bz, err := ModuleCdc.MarshalJSON(fee) // TODO + + bz, err := codec.Cdc.MarshalJSON(fee) // TODO if err != nil { panic(err) } + return bz } @@ -228,7 +220,8 @@ func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, ms for _, msg := range msgs { msgsBytes = append(msgsBytes, json.RawMessage(msg.GetSignBytes())) } - bz, err := ModuleCdc.MarshalJSON(StdSignDoc{ + + bz, err := codec.Cdc.MarshalJSON(StdSignDoc{ AccountNumber: accnum, ChainID: chainID, Fee: json.RawMessage(fee.Bytes()), @@ -236,9 +229,11 @@ func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, ms Msgs: msgsBytes, Sequence: sequence, }) + if err != nil { panic(err) } + return sdk.MustSortJSON(bz) } diff --git a/x/auth/types/test_common.go b/x/auth/types/test_utils.go similarity index 100% rename from x/auth/types/test_common.go rename to x/auth/types/test_utils.go diff --git a/x/auth/types/txbuilder.go b/x/auth/types/txbuilder.go index 533596ccb6..4ffd327d66 100644 --- a/x/auth/types/txbuilder.go +++ b/x/auth/types/txbuilder.go @@ -59,8 +59,8 @@ func NewTxBuilderFromCLI(input io.Reader) TxBuilder { } txbldr := TxBuilder{ keybase: kb, - accountNumber: uint64(viper.GetInt64(flags.FlagAccountNumber)), - sequence: uint64(viper.GetInt64(flags.FlagSequence)), + accountNumber: viper.GetUint64(flags.FlagAccountNumber), + sequence: viper.GetUint64(flags.FlagSequence), gas: flags.GasFlagVar.Gas, gasAdjustment: viper.GetFloat64(flags.FlagGasAdjustment), simulateAndExecute: flags.GasFlagVar.Simulate, diff --git a/x/auth/types/types.pb.go b/x/auth/types/types.pb.go new file mode 100644 index 0000000000..d4aaf520d2 --- /dev/null +++ b/x/auth/types/types.pb.go @@ -0,0 +1,1035 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: x/auth/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 + +// BaseAccount defines a base account type. It contains all the necessary fields +// for basic account functionality. Any custom account type should extend this +// 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 []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"` +} + +func (m *BaseAccount) Reset() { *m = BaseAccount{} } +func (*BaseAccount) ProtoMessage() {} +func (*BaseAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_2d526fa662daab74, []int{0} +} +func (m *BaseAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BaseAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BaseAccount.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 *BaseAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_BaseAccount.Merge(m, src) +} +func (m *BaseAccount) XXX_Size() int { + return m.Size() +} +func (m *BaseAccount) XXX_DiscardUnknown() { + xxx_messageInfo_BaseAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_BaseAccount proto.InternalMessageInfo + +// StdFee includes the amount of coins paid in fees and the maximum +// gas to be used by the transaction. The ratio yields an effective "gasprice", +// which must be above some miminum to be accepted into the mempool. +type StdFee struct { + Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount"` + Gas uint64 `protobuf:"varint,2,opt,name=gas,proto3" json:"gas,omitempty"` +} + +func (m *StdFee) Reset() { *m = StdFee{} } +func (m *StdFee) String() string { return proto.CompactTextString(m) } +func (*StdFee) ProtoMessage() {} +func (*StdFee) Descriptor() ([]byte, []int) { + return fileDescriptor_2d526fa662daab74, []int{1} +} +func (m *StdFee) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StdFee) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StdFee.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 *StdFee) XXX_Merge(src proto.Message) { + xxx_messageInfo_StdFee.Merge(m, src) +} +func (m *StdFee) XXX_Size() int { + return m.Size() +} +func (m *StdFee) XXX_DiscardUnknown() { + xxx_messageInfo_StdFee.DiscardUnknown(m) +} + +var xxx_messageInfo_StdFee proto.InternalMessageInfo + +func (m *StdFee) GetAmount() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Amount + } + return nil +} + +func (m *StdFee) GetGas() uint64 { + if m != nil { + return m.Gas + } + return 0 +} + +// Params defines the parameters for the auth module. +type Params struct { + MaxMemoCharacters uint64 `protobuf:"varint,1,opt,name=max_memo_characters,json=maxMemoCharacters,proto3" json:"max_memo_characters,omitempty" yaml:"max_memo_characters"` + TxSigLimit uint64 `protobuf:"varint,2,opt,name=tx_sig_limit,json=txSigLimit,proto3" json:"tx_sig_limit,omitempty" yaml:"tx_sig_limit"` + TxSizeCostPerByte uint64 `protobuf:"varint,3,opt,name=tx_size_cost_per_byte,json=txSizeCostPerByte,proto3" json:"tx_size_cost_per_byte,omitempty" yaml:"tx_size_cost_per_byte"` + SigVerifyCostED25519 uint64 `protobuf:"varint,4,opt,name=sig_verify_cost_ed25519,json=sigVerifyCostEd25519,proto3" json:"sig_verify_cost_ed25519,omitempty" yaml:"sig_verify_cost_ed25519"` + SigVerifyCostSecp256k1 uint64 `protobuf:"varint,5,opt,name=sig_verify_cost_secp256k1,json=sigVerifyCostSecp256k1,proto3" json:"sig_verify_cost_secp256k1,omitempty" yaml:"sig_verify_cost_secp256k1"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_2d526fa662daab74, []int{2} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetMaxMemoCharacters() uint64 { + if m != nil { + return m.MaxMemoCharacters + } + return 0 +} + +func (m *Params) GetTxSigLimit() uint64 { + if m != nil { + return m.TxSigLimit + } + return 0 +} + +func (m *Params) GetTxSizeCostPerByte() uint64 { + if m != nil { + return m.TxSizeCostPerByte + } + return 0 +} + +func (m *Params) GetSigVerifyCostED25519() uint64 { + if m != nil { + return m.SigVerifyCostED25519 + } + return 0 +} + +func (m *Params) GetSigVerifyCostSecp256k1() uint64 { + if m != nil { + return m.SigVerifyCostSecp256k1 + } + return 0 +} + +func init() { + proto.RegisterType((*BaseAccount)(nil), "cosmos_sdk.x.auth.v1.BaseAccount") + proto.RegisterType((*StdFee)(nil), "cosmos_sdk.x.auth.v1.StdFee") + proto.RegisterType((*Params)(nil), "cosmos_sdk.x.auth.v1.Params") +} + +func init() { proto.RegisterFile("x/auth/types/types.proto", fileDescriptor_2d526fa662daab74) } + +var fileDescriptor_2d526fa662daab74 = []byte{ + // 613 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xbf, 0x6f, 0xd3, 0x4e, + 0x14, 0x8f, 0xbf, 0xc9, 0x37, 0xad, 0xae, 0x05, 0x11, 0xf7, 0x97, 0x1b, 0x21, 0x5f, 0xe4, 0x01, + 0x85, 0xa1, 0x0e, 0x29, 0x2a, 0x52, 0x33, 0x20, 0xea, 0x00, 0x4b, 0xa1, 0xaa, 0x1c, 0x89, 0x01, + 0x09, 0x59, 0x67, 0xfb, 0x70, 0xac, 0xf4, 0x72, 0xae, 0xef, 0x5c, 0xd9, 0x5d, 0x58, 0x19, 0x19, + 0x19, 0x3b, 0xf3, 0x97, 0x74, 0xec, 0xc8, 0xe4, 0xa2, 0x74, 0x61, 0xf6, 0xc8, 0x84, 0xce, 0x97, + 0x96, 0xb4, 0x14, 0xc4, 0x62, 0xdf, 0x7b, 0xef, 0xf3, 0xe3, 0xee, 0xbd, 0x3b, 0xa0, 0xa5, 0x1d, + 0x94, 0xf0, 0x61, 0x87, 0x67, 0x11, 0x66, 0xf2, 0x6b, 0x46, 0x31, 0xe5, 0x54, 0x5d, 0xf6, 0x28, + 0x23, 0x94, 0x39, 0xcc, 0x1f, 0x99, 0xa9, 0x29, 0x40, 0xe6, 0x51, 0xb7, 0xf9, 0x80, 0x0f, 0xc3, + 0xd8, 0x77, 0x22, 0x14, 0xf3, 0xac, 0x53, 0x02, 0x3b, 0x01, 0x0d, 0xe8, 0xaf, 0x95, 0x64, 0x37, + 0x1b, 0xbf, 0x09, 0x1a, 0x85, 0x02, 0x16, 0x2c, 0xc4, 0xf0, 0x8e, 0xe7, 0xd1, 0x64, 0xcc, 0xd5, + 0x5d, 0x30, 0x87, 0x7c, 0x3f, 0xc6, 0x8c, 0x69, 0x4a, 0x4b, 0x69, 0x2f, 0x5a, 0xdd, 0x1f, 0x39, + 0xdc, 0x08, 0x42, 0x3e, 0x4c, 0x5c, 0xd3, 0xa3, 0xa4, 0x23, 0x37, 0x30, 0xfd, 0x6d, 0x30, 0x7f, + 0x34, 0x95, 0xdb, 0xf1, 0xbc, 0x1d, 0x49, 0xb4, 0x2f, 0x15, 0x54, 0x13, 0xcc, 0x45, 0x89, 0xeb, + 0x8c, 0x70, 0xa6, 0xfd, 0x57, 0x8a, 0xad, 0x14, 0x39, 0x6c, 0x64, 0x88, 0x1c, 0xf4, 0x8c, 0x28, + 0x71, 0x0f, 0x42, 0x4f, 0xd4, 0x0c, 0xbb, 0x1e, 0x25, 0xee, 0x2e, 0xce, 0xd4, 0x67, 0xe0, 0x2e, + 0x92, 0xfb, 0x70, 0xc6, 0x09, 0x71, 0x71, 0xac, 0x55, 0x5b, 0x4a, 0xbb, 0x66, 0xad, 0x17, 0x39, + 0x5c, 0x91, 0xb4, 0xeb, 0x75, 0xc3, 0xbe, 0x33, 0x4d, 0xec, 0x95, 0xb1, 0xda, 0x04, 0xf3, 0x0c, + 0x1f, 0x26, 0x78, 0xec, 0x61, 0xad, 0x26, 0xb8, 0xf6, 0x55, 0xdc, 0x9b, 0xff, 0x78, 0x02, 0x2b, + 0x9f, 0x4f, 0x60, 0xc5, 0xf8, 0x00, 0xea, 0x03, 0xee, 0xbf, 0xc4, 0x58, 0x7d, 0x07, 0xea, 0x88, + 0x08, 0xbe, 0xa6, 0xb4, 0xaa, 0xed, 0x85, 0xcd, 0x25, 0x73, 0xa6, 0xc1, 0x47, 0x5d, 0xb3, 0x4f, + 0xc3, 0xb1, 0xf5, 0xe8, 0x34, 0x87, 0x95, 0x2f, 0xe7, 0xb0, 0xfd, 0x0f, 0x6d, 0x10, 0x04, 0x66, + 0x4f, 0x45, 0xd5, 0x7b, 0xa0, 0x1a, 0x20, 0x56, 0x1e, 0xbe, 0x66, 0x8b, 0x65, 0xaf, 0xf6, 0xfd, + 0x04, 0x2a, 0xc6, 0x79, 0x15, 0xd4, 0xf7, 0x51, 0x8c, 0x08, 0x53, 0xf7, 0xc0, 0x12, 0x41, 0xa9, + 0x43, 0x30, 0xa1, 0x8e, 0x37, 0x44, 0x31, 0xf2, 0x38, 0x8e, 0x65, 0xf3, 0x6b, 0x96, 0x5e, 0xe4, + 0xb0, 0x29, 0x0f, 0x7e, 0x0b, 0xc8, 0xb0, 0x1b, 0x04, 0xa5, 0xaf, 0x31, 0xa1, 0xfd, 0xab, 0x9c, + 0xba, 0x0d, 0x16, 0x79, 0xea, 0xb0, 0x30, 0x70, 0x0e, 0x42, 0x12, 0x72, 0xe9, 0x6d, 0xad, 0x15, + 0x39, 0x5c, 0x92, 0x42, 0xb3, 0x55, 0xc3, 0x06, 0x3c, 0x1d, 0x84, 0xc1, 0x2b, 0x11, 0xa8, 0x36, + 0x58, 0x29, 0x8b, 0xc7, 0xd8, 0xf1, 0x28, 0xe3, 0x4e, 0x84, 0x63, 0xc7, 0xcd, 0x38, 0x9e, 0x4e, + 0xa1, 0x55, 0xe4, 0xf0, 0xfe, 0x8c, 0xc6, 0x4d, 0x98, 0x61, 0x37, 0x84, 0xd8, 0x31, 0xee, 0x53, + 0xc6, 0xf7, 0x71, 0x6c, 0x65, 0x1c, 0xab, 0x87, 0x60, 0x4d, 0xb8, 0x1d, 0xe1, 0x38, 0x7c, 0x9f, + 0x49, 0x3c, 0xf6, 0x37, 0xb7, 0xb6, 0xba, 0xdb, 0x72, 0x3e, 0x56, 0x6f, 0x92, 0xc3, 0xe5, 0x41, + 0x18, 0xbc, 0x29, 0x11, 0x82, 0xfa, 0xe2, 0x79, 0x59, 0x2f, 0x72, 0xa8, 0x4b, 0xb7, 0x3f, 0x08, + 0x18, 0xf6, 0x32, 0xbb, 0xc6, 0x93, 0x69, 0x35, 0x03, 0xeb, 0x37, 0x19, 0x0c, 0x7b, 0xd1, 0xe6, + 0xd6, 0x93, 0x51, 0x57, 0xfb, 0xbf, 0x34, 0x7d, 0x3a, 0xc9, 0xe1, 0xea, 0x35, 0xd3, 0xc1, 0x25, + 0xa2, 0xc8, 0x61, 0xeb, 0x76, 0xdb, 0x2b, 0x11, 0xc3, 0x5e, 0x65, 0xb7, 0x72, 0x7b, 0xf3, 0xe2, + 0x7a, 0x89, 0x09, 0x5b, 0xfd, 0xd3, 0x89, 0xae, 0x9c, 0x4d, 0x74, 0xe5, 0xdb, 0x44, 0x57, 0x3e, + 0x5d, 0xe8, 0x95, 0xb3, 0x0b, 0xbd, 0xf2, 0xf5, 0x42, 0xaf, 0xbc, 0x7d, 0xf8, 0xd7, 0x5b, 0x34, + 0xfb, 0xf2, 0xdd, 0x7a, 0xf9, 0x46, 0x1f, 0xff, 0x0c, 0x00, 0x00, 0xff, 0xff, 0xa8, 0xcb, 0x64, + 0x0b, 0x10, 0x04, 0x00, 0x00, +} + +func (this *StdFee) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*StdFee) + if !ok { + that2, ok := that.(StdFee) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Amount) != len(that1.Amount) { + return false + } + for i := range this.Amount { + if !this.Amount[i].Equal(&that1.Amount[i]) { + return false + } + } + if this.Gas != that1.Gas { + return false + } + return true +} +func (this *Params) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Params) + if !ok { + that2, ok := that.(Params) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.MaxMemoCharacters != that1.MaxMemoCharacters { + return false + } + if this.TxSigLimit != that1.TxSigLimit { + return false + } + if this.TxSizeCostPerByte != that1.TxSizeCostPerByte { + return false + } + if this.SigVerifyCostED25519 != that1.SigVerifyCostED25519 { + return false + } + if this.SigVerifyCostSecp256k1 != that1.SigVerifyCostSecp256k1 { + return false + } + return true +} +func (m *BaseAccount) 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 *BaseAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BaseAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sequence != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x20 + } + if m.AccountNumber != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.AccountNumber)) + i-- + dAtA[i] = 0x18 + } + if len(m.PubKey) > 0 { + i -= len(m.PubKey) + copy(dAtA[i:], m.PubKey) + i = encodeVarintTypes(dAtA, i, uint64(len(m.PubKey))) + 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 *StdFee) 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 *StdFee) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StdFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Gas != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Gas)) + i-- + dAtA[i] = 0x10 + } + 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] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.SigVerifyCostSecp256k1 != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.SigVerifyCostSecp256k1)) + i-- + dAtA[i] = 0x28 + } + if m.SigVerifyCostED25519 != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.SigVerifyCostED25519)) + i-- + dAtA[i] = 0x20 + } + if m.TxSizeCostPerByte != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.TxSizeCostPerByte)) + i-- + dAtA[i] = 0x18 + } + if m.TxSigLimit != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.TxSigLimit)) + i-- + dAtA[i] = 0x10 + } + if m.MaxMemoCharacters != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.MaxMemoCharacters)) + i-- + dAtA[i] = 0x8 + } + 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 *BaseAccount) 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)) + } + l = len(m.PubKey) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.AccountNumber != 0 { + n += 1 + sovTypes(uint64(m.AccountNumber)) + } + if m.Sequence != 0 { + n += 1 + sovTypes(uint64(m.Sequence)) + } + return n +} + +func (m *StdFee) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Amount) > 0 { + for _, e := range m.Amount { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + if m.Gas != 0 { + n += 1 + sovTypes(uint64(m.Gas)) + } + return n +} + +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.MaxMemoCharacters != 0 { + n += 1 + sovTypes(uint64(m.MaxMemoCharacters)) + } + if m.TxSigLimit != 0 { + n += 1 + sovTypes(uint64(m.TxSigLimit)) + } + if m.TxSizeCostPerByte != 0 { + n += 1 + sovTypes(uint64(m.TxSizeCostPerByte)) + } + if m.SigVerifyCostED25519 != 0 { + n += 1 + sovTypes(uint64(m.SigVerifyCostED25519)) + } + if m.SigVerifyCostSecp256k1 != 0 { + n += 1 + sovTypes(uint64(m.SigVerifyCostSecp256k1)) + } + 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 *BaseAccount) 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: BaseAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BaseAccount: 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 PubKey", 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.PubKey = append(m.PubKey[:0], dAtA[iNdEx:postIndex]...) + if m.PubKey == nil { + m.PubKey = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AccountNumber", wireType) + } + m.AccountNumber = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AccountNumber |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) + } + m.Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Sequence |= uint64(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 (m *StdFee) 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: StdFee: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: StdFee: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Gas", wireType) + } + m.Gas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Gas |= uint64(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 (m *Params) 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: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxMemoCharacters", wireType) + } + m.MaxMemoCharacters = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxMemoCharacters |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TxSigLimit", wireType) + } + m.TxSigLimit = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TxSigLimit |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TxSizeCostPerByte", wireType) + } + m.TxSizeCostPerByte = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TxSizeCostPerByte |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SigVerifyCostED25519", wireType) + } + m.SigVerifyCostED25519 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SigVerifyCostED25519 |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SigVerifyCostSecp256k1", wireType) + } + m.SigVerifyCostSecp256k1 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SigVerifyCostSecp256k1 |= uint64(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/auth/types/types.proto b/x/auth/types/types.proto new file mode 100644 index 0000000000..99bf50bc85 --- /dev/null +++ b/x/auth/types/types.proto @@ -0,0 +1,45 @@ +syntax = "proto3"; +package cosmos_sdk.x.auth.v1; + +import "third_party/proto/gogoproto/gogo.proto"; +import "types/types.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/auth/types"; + +// BaseAccount defines a base account type. It contains all the necessary fields +// for basic account functionality. Any custom account type should extend this +// type for additional functionality (e.g. vesting). +message BaseAccount { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; + bytes pub_key = 2 [(gogoproto.moretags) = "yaml:\"public_key\""]; + uint64 account_number = 3 [(gogoproto.moretags) = "yaml:\"account_number\""]; + uint64 sequence = 4; +} + +// StdFee includes the amount of coins paid in fees and the maximum +// gas to be used by the transaction. The ratio yields an effective "gasprice", +// which must be above some miminum to be accepted into the mempool. +message StdFee { + option (gogoproto.equal) = true; + + repeated cosmos_sdk.v1.Coin amount = 1 + [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; + uint64 gas = 2; +} + +// Params defines the parameters for the auth module. +message Params { + option (gogoproto.equal) = true; + option (gogoproto.goproto_stringer) = false; + + uint64 max_memo_characters = 1 [(gogoproto.moretags) = "yaml:\"max_memo_characters\""]; + uint64 tx_sig_limit = 2 [(gogoproto.moretags) = "yaml:\"tx_sig_limit\""]; + uint64 tx_size_cost_per_byte = 3 [(gogoproto.moretags) = "yaml:\"tx_size_cost_per_byte\""]; + uint64 sig_verify_cost_ed25519 = 4 + [(gogoproto.customname) = "SigVerifyCostED25519", (gogoproto.moretags) = "yaml:\"sig_verify_cost_ed25519\""]; + uint64 sig_verify_cost_secp256k1 = 5 + [(gogoproto.customname) = "SigVerifyCostSecp256k1", (gogoproto.moretags) = "yaml:\"sig_verify_cost_secp256k1\""]; +} diff --git a/x/auth/vesting/alias.go b/x/auth/vesting/alias.go index 387ca51e51..9591aa12a0 100644 --- a/x/auth/vesting/alias.go +++ b/x/auth/vesting/alias.go @@ -1,15 +1,13 @@ -// nolint -// autogenerated code using github.com/rigelrozanski/multitool -// aliases generated for the following subdirectories: -// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/vesting/types/ package vesting +// DONTCOVER +// nolint + import ( "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" ) var ( - // functions aliases RegisterCodec = types.RegisterCodec NewBaseVestingAccount = types.NewBaseVestingAccount NewContinuousVestingAccountRaw = types.NewContinuousVestingAccountRaw @@ -18,9 +16,6 @@ var ( NewPeriodicVestingAccount = types.NewPeriodicVestingAccount NewDelayedVestingAccountRaw = types.NewDelayedVestingAccountRaw NewDelayedVestingAccount = types.NewDelayedVestingAccount - - // variable aliases - VestingCdc = types.VestingCdc ) type ( diff --git a/x/auth/vesting/types/codec.go b/x/auth/vesting/types/codec.go index 556e711178..c0b938e2e1 100644 --- a/x/auth/vesting/types/codec.go +++ b/x/auth/vesting/types/codec.go @@ -5,7 +5,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" ) -// RegisterCodec registers concrete types on the codec +// RegisterCodec registers the vesting interfaces and concrete types on the +// provided Amino codec. func RegisterCodec(cdc *codec.Codec) { cdc.RegisterInterface((*exported.VestingAccount)(nil), nil) cdc.RegisterConcrete(&BaseVestingAccount{}, "cosmos-sdk/BaseVestingAccount", nil) @@ -13,12 +14,3 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(&DelayedVestingAccount{}, "cosmos-sdk/DelayedVestingAccount", nil) cdc.RegisterConcrete(&PeriodicVestingAccount{}, "cosmos-sdk/PeriodicVestingAccount", nil) } - -// VestingCdc module wide codec -var VestingCdc *codec.Codec - -func init() { - VestingCdc = codec.New() - RegisterCodec(VestingCdc) - VestingCdc.Seal() -} diff --git a/x/auth/vesting/types/common_test.go b/x/auth/vesting/types/common_test.go new file mode 100644 index 0000000000..02b80ac6aa --- /dev/null +++ b/x/auth/vesting/types/common_test.go @@ -0,0 +1,11 @@ +package types_test + +import ( + "github.com/cosmos/cosmos-sdk/simapp" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" +) + +var ( + app = simapp.Setup(false) + appCodec = simappcodec.NewAppCodec(app.Codec()) +) diff --git a/x/auth/vesting/types/genesis_test.go b/x/auth/vesting/types/genesis_test.go index 7a9781eb70..fb3fea0a2f 100644 --- a/x/auth/vesting/types/genesis_test.go +++ b/x/auth/vesting/types/genesis_test.go @@ -22,7 +22,7 @@ var ( func TestValidateGenesisInvalidAccounts(t *testing.T) { acc1 := authtypes.NewBaseAccountWithAddress(sdk.AccAddress(addr1)) acc1Balance := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 150)) - baseVestingAcc := NewBaseVestingAccount(&acc1, acc1Balance, 1548775410) + baseVestingAcc := NewBaseVestingAccount(acc1, acc1Balance, 1548775410) // invalid delegated vesting baseVestingAcc.DelegatedVesting = acc1Balance.Add(acc1Balance...) @@ -32,7 +32,7 @@ func TestValidateGenesisInvalidAccounts(t *testing.T) { genAccs := make([]exported.GenesisAccount, 2) genAccs[0] = baseVestingAcc - genAccs[1] = &acc2 + genAccs[1] = acc2 require.Error(t, authtypes.ValidateGenAccounts(genAccs)) baseVestingAcc.DelegatedVesting = acc1Balance diff --git a/x/auth/vesting/types/period.go b/x/auth/vesting/types/period.go index 1c4a5e2f47..27b7a65c75 100644 --- a/x/auth/vesting/types/period.go +++ b/x/auth/vesting/types/period.go @@ -4,22 +4,16 @@ import ( "fmt" "strings" - sdk "github.com/cosmos/cosmos-sdk/types" + "gopkg.in/yaml.v2" ) -// Period defines a length of time and amount of coins that will vest -type Period struct { - Length int64 `json:"length" yaml:"length"` // length of the period, in seconds - Amount sdk.Coins `json:"amount" yaml:"amount"` // amount of coins vesting during this period -} - // Periods stores all vesting periods passed as part of a PeriodicVestingAccount type Periods []Period // String Period implements stringer interface func (p Period) String() string { - return fmt.Sprintf(`Length: %d - Amount: %s`, p.Length, p.Amount) + out, _ := yaml.Marshal(p) + return string(out) } // String Periods implements stringer interface @@ -28,6 +22,7 @@ func (vp Periods) String() string { for _, period := range vp { periodsListString = append(periodsListString, period.String()) } + return strings.TrimSpace(fmt.Sprintf(`Vesting Periods: %s`, strings.Join(periodsListString, ", "))) } diff --git a/x/auth/vesting/types/types.pb.go b/x/auth/vesting/types/types.pb.go new file mode 100644 index 0000000000..adfa4af2ee --- /dev/null +++ b/x/auth/vesting/types/types.pb.go @@ -0,0 +1,1404 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: x/auth/vesting/types/types.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types1 "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/x/auth/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 + +// BaseVestingAccount implements the VestingAccount interface. It contains all +// the necessary fields needed for any vesting account implementation. +type BaseVestingAccount struct { + *types.BaseAccount `protobuf:"bytes,1,opt,name=base_account,json=baseAccount,proto3,embedded=base_account" json:"base_account,omitempty"` + OriginalVesting github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=original_vesting,json=originalVesting,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"original_vesting" yaml:"original_vesting"` + DelegatedFree github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=delegated_free,json=delegatedFree,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"delegated_free" yaml:"delegated_free"` + DelegatedVesting github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,4,rep,name=delegated_vesting,json=delegatedVesting,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"delegated_vesting" yaml:"delegated_vesting"` + EndTime int64 `protobuf:"varint,5,opt,name=end_time,json=endTime,proto3" json:"end_time,omitempty" yaml:"end_time"` +} + +func (m *BaseVestingAccount) Reset() { *m = BaseVestingAccount{} } +func (*BaseVestingAccount) ProtoMessage() {} +func (*BaseVestingAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_b7f744d63a45e116, []int{0} +} +func (m *BaseVestingAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BaseVestingAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BaseVestingAccount.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 *BaseVestingAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_BaseVestingAccount.Merge(m, src) +} +func (m *BaseVestingAccount) XXX_Size() int { + return m.Size() +} +func (m *BaseVestingAccount) XXX_DiscardUnknown() { + xxx_messageInfo_BaseVestingAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_BaseVestingAccount proto.InternalMessageInfo + +// ContinuousVestingAccount implements the VestingAccount interface. It +// continuously vests by unlocking coins linearly with respect to time. +type ContinuousVestingAccount struct { + *BaseVestingAccount `protobuf:"bytes,1,opt,name=base_vesting_account,json=baseVestingAccount,proto3,embedded=base_vesting_account" json:"base_vesting_account,omitempty"` + StartTime int64 `protobuf:"varint,2,opt,name=start_time,json=startTime,proto3" json:"start_time,omitempty" yaml:"start_time"` +} + +func (m *ContinuousVestingAccount) Reset() { *m = ContinuousVestingAccount{} } +func (*ContinuousVestingAccount) ProtoMessage() {} +func (*ContinuousVestingAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_b7f744d63a45e116, []int{1} +} +func (m *ContinuousVestingAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ContinuousVestingAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ContinuousVestingAccount.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 *ContinuousVestingAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_ContinuousVestingAccount.Merge(m, src) +} +func (m *ContinuousVestingAccount) XXX_Size() int { + return m.Size() +} +func (m *ContinuousVestingAccount) XXX_DiscardUnknown() { + xxx_messageInfo_ContinuousVestingAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_ContinuousVestingAccount proto.InternalMessageInfo + +// DelayedVestingAccount implements the VestingAccount interface. It vests all +// coins after a specific time, but non prior. In other words, it keeps them +// locked until a specified time. +type DelayedVestingAccount struct { + *BaseVestingAccount `protobuf:"bytes,1,opt,name=base_vesting_account,json=baseVestingAccount,proto3,embedded=base_vesting_account" json:"base_vesting_account,omitempty"` +} + +func (m *DelayedVestingAccount) Reset() { *m = DelayedVestingAccount{} } +func (*DelayedVestingAccount) ProtoMessage() {} +func (*DelayedVestingAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_b7f744d63a45e116, []int{2} +} +func (m *DelayedVestingAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DelayedVestingAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DelayedVestingAccount.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 *DelayedVestingAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_DelayedVestingAccount.Merge(m, src) +} +func (m *DelayedVestingAccount) XXX_Size() int { + return m.Size() +} +func (m *DelayedVestingAccount) XXX_DiscardUnknown() { + xxx_messageInfo_DelayedVestingAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_DelayedVestingAccount proto.InternalMessageInfo + +// Period defines a length of time and amount of coins that will vest +type Period struct { + Length int64 `protobuf:"varint,1,opt,name=length,proto3" json:"length,omitempty"` + Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount"` +} + +func (m *Period) Reset() { *m = Period{} } +func (*Period) ProtoMessage() {} +func (*Period) Descriptor() ([]byte, []int) { + return fileDescriptor_b7f744d63a45e116, []int{3} +} +func (m *Period) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Period) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Period.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 *Period) XXX_Merge(src proto.Message) { + xxx_messageInfo_Period.Merge(m, src) +} +func (m *Period) XXX_Size() int { + return m.Size() +} +func (m *Period) XXX_DiscardUnknown() { + xxx_messageInfo_Period.DiscardUnknown(m) +} + +var xxx_messageInfo_Period proto.InternalMessageInfo + +func (m *Period) GetLength() int64 { + if m != nil { + return m.Length + } + return 0 +} + +func (m *Period) GetAmount() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Amount + } + return nil +} + +// PeriodicVestingAccount implements the VestingAccount interface. It +// periodically vests by unlocking coins during each specified period +type PeriodicVestingAccount struct { + *BaseVestingAccount `protobuf:"bytes,1,opt,name=base_vesting_account,json=baseVestingAccount,proto3,embedded=base_vesting_account" json:"base_vesting_account,omitempty"` + StartTime int64 `protobuf:"varint,2,opt,name=start_time,json=startTime,proto3" json:"start_time,omitempty" yaml:"start_time"` + VestingPeriods []Period `protobuf:"bytes,3,rep,name=vesting_periods,json=vestingPeriods,proto3" json:"vesting_periods" yaml:"vesting_periods"` +} + +func (m *PeriodicVestingAccount) Reset() { *m = PeriodicVestingAccount{} } +func (*PeriodicVestingAccount) ProtoMessage() {} +func (*PeriodicVestingAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_b7f744d63a45e116, []int{4} +} +func (m *PeriodicVestingAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PeriodicVestingAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PeriodicVestingAccount.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 *PeriodicVestingAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_PeriodicVestingAccount.Merge(m, src) +} +func (m *PeriodicVestingAccount) XXX_Size() int { + return m.Size() +} +func (m *PeriodicVestingAccount) XXX_DiscardUnknown() { + xxx_messageInfo_PeriodicVestingAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_PeriodicVestingAccount proto.InternalMessageInfo + +func init() { + proto.RegisterType((*BaseVestingAccount)(nil), "cosmos_sdk.x.auth.vesting.v1.BaseVestingAccount") + proto.RegisterType((*ContinuousVestingAccount)(nil), "cosmos_sdk.x.auth.vesting.v1.ContinuousVestingAccount") + proto.RegisterType((*DelayedVestingAccount)(nil), "cosmos_sdk.x.auth.vesting.v1.DelayedVestingAccount") + proto.RegisterType((*Period)(nil), "cosmos_sdk.x.auth.vesting.v1.Period") + proto.RegisterType((*PeriodicVestingAccount)(nil), "cosmos_sdk.x.auth.vesting.v1.PeriodicVestingAccount") +} + +func init() { proto.RegisterFile("x/auth/vesting/types/types.proto", fileDescriptor_b7f744d63a45e116) } + +var fileDescriptor_b7f744d63a45e116 = []byte{ + // 593 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x55, 0x4f, 0x8f, 0xd2, 0x40, + 0x1c, 0xed, 0x2c, 0x88, 0xeb, 0xa0, 0xcb, 0xd2, 0x15, 0x6c, 0x88, 0x69, 0xb1, 0x31, 0x86, 0x8b, + 0xd3, 0x65, 0xf5, 0xc4, 0xcd, 0xae, 0x31, 0xd1, 0xf5, 0x60, 0x1a, 0xe3, 0xc1, 0xc4, 0x34, 0x85, + 0x8e, 0x65, 0xb2, 0xb4, 0x43, 0x3a, 0x03, 0x59, 0x3e, 0xc0, 0x26, 0x26, 0x9b, 0x18, 0x8f, 0x1e, + 0xf7, 0xec, 0xcd, 0x8f, 0x60, 0xe2, 0x61, 0x8f, 0x1c, 0x3d, 0xa1, 0x81, 0x6f, 0xc0, 0x27, 0x30, + 0x74, 0x06, 0x58, 0xcb, 0x2e, 0xc9, 0x7a, 0x30, 0xf1, 0x02, 0x9d, 0x3f, 0xef, 0xfd, 0xde, 0xfb, + 0xcd, 0x9b, 0x16, 0x56, 0x8f, 0x2c, 0xaf, 0xc7, 0xdb, 0x56, 0x1f, 0x33, 0x4e, 0xa2, 0xc0, 0xe2, + 0x83, 0x2e, 0x66, 0xe2, 0x17, 0x75, 0x63, 0xca, 0xa9, 0x7a, 0xb7, 0x45, 0x59, 0x48, 0x99, 0xcb, + 0xfc, 0x43, 0x74, 0x84, 0x66, 0x9b, 0x91, 0xdc, 0x8c, 0xfa, 0xf5, 0xca, 0x03, 0xde, 0x26, 0xb1, + 0xef, 0x76, 0xbd, 0x98, 0x0f, 0xac, 0x04, 0x60, 0x05, 0x34, 0xa0, 0xcb, 0x27, 0xc1, 0x52, 0x29, + 0xae, 0x10, 0x57, 0x34, 0x59, 0x7a, 0x65, 0xc5, 0xfc, 0x96, 0x85, 0xaa, 0xed, 0x31, 0xfc, 0x46, + 0xd4, 0x79, 0xd2, 0x6a, 0xd1, 0x5e, 0xc4, 0xd5, 0x17, 0xf0, 0x66, 0xd3, 0x63, 0xd8, 0xf5, 0xc4, + 0x58, 0x03, 0x55, 0x50, 0xcb, 0xef, 0xdd, 0x43, 0x17, 0x08, 0xac, 0xa3, 0x19, 0x5e, 0x02, 0xed, + 0xec, 0x70, 0x64, 0x00, 0x27, 0xdf, 0x5c, 0x4e, 0xa9, 0x27, 0x00, 0x6e, 0xd3, 0x98, 0x04, 0x24, + 0xf2, 0x3a, 0xae, 0xf4, 0xa3, 0x6d, 0x54, 0x33, 0xb5, 0xfc, 0xde, 0xce, 0x79, 0xc2, 0x7e, 0x1d, + 0xed, 0x53, 0x12, 0xd9, 0x07, 0x67, 0x23, 0x43, 0x99, 0x8e, 0x8c, 0x3b, 0x03, 0x2f, 0xec, 0x34, + 0xcc, 0x34, 0xd4, 0xfc, 0xf2, 0xd3, 0xa8, 0x05, 0x84, 0xb7, 0x7b, 0x4d, 0xd4, 0xa2, 0xa1, 0x25, + 0x18, 0xe4, 0xdf, 0x43, 0xe6, 0x1f, 0x4a, 0x7f, 0x33, 0x2e, 0xe6, 0x14, 0xe6, 0x70, 0x69, 0x50, + 0x3d, 0x06, 0x70, 0xcb, 0xc7, 0x1d, 0x1c, 0x78, 0x1c, 0xfb, 0xee, 0xfb, 0x18, 0x63, 0x2d, 0x73, + 0xb9, 0x96, 0xe7, 0x52, 0x4b, 0x49, 0x68, 0xf9, 0x13, 0x78, 0x35, 0x25, 0xb7, 0x16, 0xe0, 0x67, + 0x31, 0xc6, 0xea, 0x47, 0x00, 0x8b, 0x4b, 0xba, 0x79, 0x5b, 0xb2, 0x97, 0x4b, 0x79, 0x29, 0xa5, + 0x68, 0x69, 0x29, 0x7f, 0xd5, 0x97, 0xed, 0x05, 0x7e, 0xde, 0x18, 0x04, 0x37, 0x71, 0xe4, 0xbb, + 0x9c, 0x84, 0x58, 0xbb, 0x56, 0x05, 0xb5, 0x8c, 0xbd, 0x33, 0x1d, 0x19, 0x05, 0x51, 0x6d, 0xbe, + 0x62, 0x3a, 0xd7, 0x71, 0xe4, 0xbf, 0x26, 0x21, 0x6e, 0x6c, 0x7e, 0x38, 0x35, 0x94, 0xcf, 0xa7, + 0x86, 0x62, 0x7e, 0x07, 0x50, 0xdb, 0xa7, 0x11, 0x27, 0x51, 0x8f, 0xf6, 0x58, 0x2a, 0x49, 0x6d, + 0x78, 0x3b, 0x49, 0x92, 0x54, 0x99, 0x4a, 0xd4, 0x2e, 0x5a, 0x17, 0x79, 0xb4, 0x9a, 0x4c, 0x19, + 0x30, 0xb5, 0xb9, 0x9a, 0xd9, 0xc7, 0x10, 0x32, 0xee, 0xc5, 0x5c, 0x58, 0xd8, 0x48, 0x2c, 0x94, + 0xa6, 0x23, 0xa3, 0x28, 0x2c, 0x2c, 0xd7, 0x4c, 0xe7, 0x46, 0x32, 0x48, 0xd9, 0x38, 0x01, 0xb0, + 0xf4, 0x14, 0x77, 0xbc, 0xc1, 0xa2, 0x27, 0xff, 0xdc, 0xc3, 0x39, 0x35, 0xc7, 0x00, 0xe6, 0x5e, + 0xe1, 0x98, 0x50, 0x5f, 0x2d, 0xc3, 0x5c, 0x07, 0x47, 0x01, 0x6f, 0x27, 0x05, 0x33, 0x8e, 0x1c, + 0xa9, 0xef, 0x60, 0xce, 0x0b, 0x13, 0x21, 0x6b, 0x6e, 0xd3, 0xee, 0x2c, 0x36, 0x57, 0x8a, 0x86, + 0x24, 0x6d, 0x64, 0x13, 0x1d, 0x5f, 0x37, 0x60, 0x59, 0xe8, 0x20, 0xad, 0xff, 0xeb, 0x68, 0xd5, + 0x10, 0x16, 0xe6, 0xd2, 0xba, 0x89, 0x03, 0x26, 0xaf, 0xfa, 0xfd, 0xf5, 0xd2, 0x84, 0x5d, 0x5b, + 0x97, 0x17, 0xae, 0x2c, 0x8a, 0xa4, 0xa8, 0x4c, 0x67, 0x4b, 0xce, 0x88, 0xed, 0x6c, 0x79, 0x76, + 0xf6, 0xc1, 0xd9, 0x58, 0x07, 0xc3, 0xb1, 0x0e, 0x7e, 0x8d, 0x75, 0xf0, 0x69, 0xa2, 0x2b, 0xc3, + 0x89, 0xae, 0xfc, 0x98, 0xe8, 0xca, 0xdb, 0xfa, 0xda, 0x53, 0xb8, 0xe8, 0x03, 0xd1, 0xcc, 0x25, + 0x2f, 0xea, 0x47, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x89, 0x54, 0xae, 0x4f, 0x3f, 0x06, 0x00, + 0x00, +} + +func (m *BaseVestingAccount) 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 *BaseVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BaseVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.EndTime != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.EndTime)) + i-- + dAtA[i] = 0x28 + } + if len(m.DelegatedVesting) > 0 { + for iNdEx := len(m.DelegatedVesting) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.DelegatedVesting[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + if len(m.DelegatedFree) > 0 { + for iNdEx := len(m.DelegatedFree) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.DelegatedFree[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.OriginalVesting) > 0 { + for iNdEx := len(m.OriginalVesting) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.OriginalVesting[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if m.BaseAccount != nil { + { + size, err := m.BaseAccount.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 (m *ContinuousVestingAccount) 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 *ContinuousVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ContinuousVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.StartTime != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.StartTime)) + i-- + dAtA[i] = 0x10 + } + if m.BaseVestingAccount != nil { + { + size, err := m.BaseVestingAccount.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 (m *DelayedVestingAccount) 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 *DelayedVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DelayedVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BaseVestingAccount != nil { + { + size, err := m.BaseVestingAccount.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 (m *Period) 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 *Period) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Period) 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] = 0x12 + } + } + if m.Length != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Length)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *PeriodicVestingAccount) 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 *PeriodicVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PeriodicVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.VestingPeriods) > 0 { + for iNdEx := len(m.VestingPeriods) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.VestingPeriods[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.StartTime != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.StartTime)) + i-- + dAtA[i] = 0x10 + } + if m.BaseVestingAccount != nil { + { + size, err := m.BaseVestingAccount.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 *BaseVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BaseAccount != nil { + l = m.BaseAccount.Size() + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.OriginalVesting) > 0 { + for _, e := range m.OriginalVesting { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + if len(m.DelegatedFree) > 0 { + for _, e := range m.DelegatedFree { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + if len(m.DelegatedVesting) > 0 { + for _, e := range m.DelegatedVesting { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + if m.EndTime != 0 { + n += 1 + sovTypes(uint64(m.EndTime)) + } + return n +} + +func (m *ContinuousVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BaseVestingAccount != nil { + l = m.BaseVestingAccount.Size() + n += 1 + l + sovTypes(uint64(l)) + } + if m.StartTime != 0 { + n += 1 + sovTypes(uint64(m.StartTime)) + } + return n +} + +func (m *DelayedVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BaseVestingAccount != nil { + l = m.BaseVestingAccount.Size() + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *Period) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Length != 0 { + n += 1 + sovTypes(uint64(m.Length)) + } + if len(m.Amount) > 0 { + for _, e := range m.Amount { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *PeriodicVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BaseVestingAccount != nil { + l = m.BaseVestingAccount.Size() + n += 1 + l + sovTypes(uint64(l)) + } + if m.StartTime != 0 { + n += 1 + sovTypes(uint64(m.StartTime)) + } + if len(m.VestingPeriods) > 0 { + for _, e := range m.VestingPeriods { + 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 *BaseVestingAccount) 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: BaseVestingAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BaseVestingAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseAccount", 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 m.BaseAccount == nil { + m.BaseAccount = &types.BaseAccount{} + } + if err := m.BaseAccount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OriginalVesting", 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.OriginalVesting = append(m.OriginalVesting, types1.Coin{}) + if err := m.OriginalVesting[len(m.OriginalVesting)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatedFree", 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.DelegatedFree = append(m.DelegatedFree, types1.Coin{}) + if err := m.DelegatedFree[len(m.DelegatedFree)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatedVesting", 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.DelegatedVesting = append(m.DelegatedVesting, types1.Coin{}) + if err := m.DelegatedVesting[len(m.DelegatedVesting)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EndTime", wireType) + } + m.EndTime = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EndTime |= 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 (m *ContinuousVestingAccount) 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: ContinuousVestingAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ContinuousVestingAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseVestingAccount", 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 m.BaseVestingAccount == nil { + m.BaseVestingAccount = &BaseVestingAccount{} + } + if err := m.BaseVestingAccount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) + } + m.StartTime = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StartTime |= 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 (m *DelayedVestingAccount) 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: DelayedVestingAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DelayedVestingAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseVestingAccount", 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 m.BaseVestingAccount == nil { + m.BaseVestingAccount = &BaseVestingAccount{} + } + if err := m.BaseVestingAccount.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 *Period) 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: Period: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Period: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Length", wireType) + } + m.Length = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Length |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + 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, types1.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 *PeriodicVestingAccount) 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: PeriodicVestingAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PeriodicVestingAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseVestingAccount", 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 m.BaseVestingAccount == nil { + m.BaseVestingAccount = &BaseVestingAccount{} + } + if err := m.BaseVestingAccount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) + } + m.StartTime = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StartTime |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VestingPeriods", 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.VestingPeriods = append(m.VestingPeriods, Period{}) + if err := m.VestingPeriods[len(m.VestingPeriods)-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/auth/vesting/types/types.proto b/x/auth/vesting/types/types.proto new file mode 100644 index 0000000000..7ce1295532 --- /dev/null +++ b/x/auth/vesting/types/types.proto @@ -0,0 +1,76 @@ +syntax = "proto3"; +package cosmos_sdk.x.auth.vesting.v1; + +import "third_party/proto/gogoproto/gogo.proto"; +import "types/types.proto"; +import "x/auth/types/types.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"; + +// BaseVestingAccount implements the VestingAccount interface. It contains all +// the necessary fields needed for any vesting account implementation. +message BaseVestingAccount { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + cosmos_sdk.x.auth.v1.BaseAccount base_account = 1 [(gogoproto.embed) = true]; + repeated cosmos_sdk.v1.Coin original_vesting = 2 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", + (gogoproto.moretags) = "yaml:\"original_vesting\"" + ]; + repeated cosmos_sdk.v1.Coin delegated_free = 3 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", + (gogoproto.moretags) = "yaml:\"delegated_free\"" + ]; + repeated cosmos_sdk.v1.Coin delegated_vesting = 4 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", + (gogoproto.moretags) = "yaml:\"delegated_vesting\"" + ]; + int64 end_time = 5 [(gogoproto.moretags) = "yaml:\"end_time\""]; +} + +// ContinuousVestingAccount implements the VestingAccount interface. It +// continuously vests by unlocking coins linearly with respect to time. +message ContinuousVestingAccount { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + BaseVestingAccount base_vesting_account = 1 [(gogoproto.embed) = true]; + int64 start_time = 2 [(gogoproto.moretags) = "yaml:\"start_time\""]; +} + +// DelayedVestingAccount implements the VestingAccount interface. It vests all +// coins after a specific time, but non prior. In other words, it keeps them +// locked until a specified time. +message DelayedVestingAccount { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + BaseVestingAccount base_vesting_account = 1 [(gogoproto.embed) = true]; +} + +// Period defines a length of time and amount of coins that will vest +message Period { + option (gogoproto.goproto_stringer) = false; + + int64 length = 1; + repeated cosmos_sdk.v1.Coin amount = 2 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} + +// PeriodicVestingAccount implements the VestingAccount interface. It +// periodically vests by unlocking coins during each specified period +message PeriodicVestingAccount { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + BaseVestingAccount base_vesting_account = 1 [(gogoproto.embed) = true]; + int64 start_time = 2 [(gogoproto.moretags) = "yaml:\"start_time\""]; + repeated Period vesting_periods = 3 + [(gogoproto.moretags) = "yaml:\"vesting_periods\"", (gogoproto.nullable) = false]; +} diff --git a/x/auth/vesting/types/vesting_account.go b/x/auth/vesting/types/vesting_account.go index 70efad2b33..d4b6fc6345 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" @@ -22,24 +22,8 @@ var ( _ vestexported.VestingAccount = (*DelayedVestingAccount)(nil) ) -// Register the vesting account types on the auth module codec -func init() { - authtypes.RegisterAccountTypeCodec(&BaseVestingAccount{}, "cosmos-sdk/BaseVestingAccount") - authtypes.RegisterAccountTypeCodec(&ContinuousVestingAccount{}, "cosmos-sdk/ContinuousVestingAccount") - authtypes.RegisterAccountTypeCodec(&DelayedVestingAccount{}, "cosmos-sdk/DelayedVestingAccount") - authtypes.RegisterAccountTypeCodec(&PeriodicVestingAccount{}, "cosmos-sdk/PeriodicVestingAccount") -} - -// BaseVestingAccount implements the VestingAccount interface. It contains all -// the necessary fields needed for any vesting account implementation. -type BaseVestingAccount struct { - *authtypes.BaseAccount - - OriginalVesting sdk.Coins `json:"original_vesting" yaml:"original_vesting"` // coins in account upon initialization - DelegatedFree sdk.Coins `json:"delegated_free" yaml:"delegated_free"` // coins that are vested and delegated - DelegatedVesting sdk.Coins `json:"delegated_vesting" yaml:"delegated_vesting"` // coins that vesting and delegated - EndTime int64 `json:"end_time" yaml:"end_time"` // when the coins become unlocked -} +//----------------------------------------------------------------------------- +// Base Vesting Account // NewBaseVestingAccount creates a new BaseVestingAccount object. It is the // callers responsibility to ensure the base account has sufficient funds with @@ -180,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"` @@ -195,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) @@ -202,7 +201,7 @@ 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, AccountNumber: bva.AccountNumber, Sequence: bva.Sequence, @@ -212,8 +211,9 @@ func (bva BaseVestingAccount) MarshalYAML() (interface{}, error) { EndTime: bva.EndTime, } - if bva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, bva.PubKey) + pk := bva.GetPubKey() + if pk != nil { + pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pk) if err != nil { return nil, err } @@ -231,8 +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.GetPubKey(), AccountNumber: bva.AccountNumber, Sequence: bva.Sequence, OriginalVesting: bva.OriginalVesting, @@ -241,38 +242,17 @@ func (bva BaseVestingAccount) MarshalJSON() ([]byte, error) { EndTime: bva.EndTime, } - if bva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, bva.PubKey) - if err != nil { - return nil, err - } - - alias.PubKey = pks - } - - 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 @@ -287,14 +267,6 @@ func (bva *BaseVestingAccount) UnmarshalJSON(bz []byte) error { var _ vestexported.VestingAccount = (*ContinuousVestingAccount)(nil) var _ authexported.GenesisAccount = (*ContinuousVestingAccount)(nil) -// ContinuousVestingAccount implements the VestingAccount interface. It -// continuously vests by unlocking coins linearly with respect to time. -type ContinuousVestingAccount struct { - *BaseVestingAccount - - StartTime int64 `json:"start_time" yaml:"start_time"` // when the coins start to vest -} - // NewContinuousVestingAccountRaw creates a new ContinuousVestingAccount object from BaseVestingAccount func NewContinuousVestingAccountRaw(bva *BaseVestingAccount, startTime int64) *ContinuousVestingAccount { return &ContinuousVestingAccount{ @@ -384,7 +356,7 @@ 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, AccountNumber: cva.AccountNumber, Sequence: cva.Sequence, @@ -395,8 +367,9 @@ func (cva ContinuousVestingAccount) MarshalYAML() (interface{}, error) { StartTime: cva.StartTime, } - if cva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, cva.PubKey) + pk := cva.GetPubKey() + if pk != nil { + pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pk) if err != nil { return nil, err } @@ -414,8 +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.GetPubKey(), AccountNumber: cva.AccountNumber, Sequence: cva.Sequence, OriginalVesting: cva.OriginalVesting, @@ -425,39 +399,18 @@ func (cva ContinuousVestingAccount) MarshalJSON() ([]byte, error) { StartTime: cva.StartTime, } - if cva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, cva.PubKey) - if err != nil { - return nil, err - } - - alias.PubKey = pks - } - - 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, @@ -474,14 +427,6 @@ func (cva *ContinuousVestingAccount) UnmarshalJSON(bz []byte) error { var _ vestexported.VestingAccount = (*PeriodicVestingAccount)(nil) var _ authexported.GenesisAccount = (*PeriodicVestingAccount)(nil) -// PeriodicVestingAccount implements the VestingAccount interface. It -// periodically vests by unlocking coins during each specified period -type PeriodicVestingAccount struct { - *BaseVestingAccount - StartTime int64 `json:"start_time" yaml:"start_time"` // when the coins start to vest - VestingPeriods Periods `json:"vesting_periods" yaml:"vesting_periods"` // the vesting schedule -} - // NewPeriodicVestingAccountRaw creates a new PeriodicVestingAccount object from BaseVestingAccount func NewPeriodicVestingAccountRaw(bva *BaseVestingAccount, startTime int64, periods Periods) *PeriodicVestingAccount { return &PeriodicVestingAccount{ @@ -600,7 +545,7 @@ 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, AccountNumber: pva.AccountNumber, Sequence: pva.Sequence, @@ -612,8 +557,9 @@ func (pva PeriodicVestingAccount) MarshalYAML() (interface{}, error) { VestingPeriods: pva.VestingPeriods, } - if pva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pva.PubKey) + pk := pva.GetPubKey() + if pk != nil { + pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pk) if err != nil { return nil, err } @@ -631,8 +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.GetPubKey(), AccountNumber: pva.AccountNumber, Sequence: pva.Sequence, OriginalVesting: pva.OriginalVesting, @@ -643,39 +590,18 @@ func (pva PeriodicVestingAccount) MarshalJSON() ([]byte, error) { VestingPeriods: pva.VestingPeriods, } - if pva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pva.PubKey) - if err != nil { - return nil, err - } - - alias.PubKey = pks - } - - 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, @@ -693,13 +619,6 @@ func (pva *PeriodicVestingAccount) UnmarshalJSON(bz []byte) error { var _ vestexported.VestingAccount = (*DelayedVestingAccount)(nil) var _ authexported.GenesisAccount = (*DelayedVestingAccount)(nil) -// DelayedVestingAccount implements the VestingAccount interface. It vests all -// coins after a specific time, but non prior. In other words, it keeps them -// locked until a specified time. -type DelayedVestingAccount struct { - *BaseVestingAccount -} - // NewDelayedVestingAccountRaw creates a new DelayedVestingAccount object from BaseVestingAccount func NewDelayedVestingAccountRaw(bva *BaseVestingAccount) *DelayedVestingAccount { return &DelayedVestingAccount{ @@ -756,10 +675,16 @@ func (dva DelayedVestingAccount) Validate() error { return dva.BaseVestingAccount.Validate() } +func (dva DelayedVestingAccount) String() string { + out, _ := dva.MarshalYAML() + return out.(string) +} + // MarshalJSON returns the JSON representation of a DelayedVestingAccount. func (dva DelayedVestingAccount) MarshalJSON() ([]byte, error) { - alias := vestingAccountPretty{ + alias := vestingAccountJSON{ Address: dva.Address, + PubKey: dva.GetPubKey(), AccountNumber: dva.AccountNumber, Sequence: dva.Sequence, OriginalVesting: dva.OriginalVesting, @@ -768,39 +693,18 @@ func (dva DelayedVestingAccount) MarshalJSON() ([]byte, error) { EndTime: dva.EndTime, } - if dva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, dva.PubKey) - if err != nil { - return nil, err - } - - alias.PubKey = pks - } - - 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 4555d329e6..974a1f3149 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -1,8 +1,7 @@ -package types +package types_test import ( "encoding/json" - "errors" "testing" "time" @@ -13,6 +12,7 @@ import ( 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" + "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" ) var ( @@ -24,10 +24,10 @@ func TestGetVestedCoinsContVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) - cva := NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) // require no coins vested in the very beginning of the vesting schedule vestedCoins := cva.GetVestedCoins(now) @@ -50,10 +50,10 @@ func TestGetVestingCoinsContVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) - cva := NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) // require all coins vesting in the beginning of the vesting schedule vestingCoins := cva.GetVestingCoins(now) @@ -72,11 +72,11 @@ func TestSpendableCoinsContVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) - cva := NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) // require that all original coins are locked at the end of the vesting // schedule @@ -100,24 +100,24 @@ func TestTrackDelegationContVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require the ability to delegate all vesting coins - cva := NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) cva.TrackDelegation(now, origCoins, origCoins) require.Equal(t, origCoins, cva.DelegatedVesting) require.Nil(t, cva.DelegatedFree) // require the ability to delegate all vested coins - cva = NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) cva.TrackDelegation(endTime, origCoins, origCoins) require.Nil(t, cva.DelegatedVesting) require.Equal(t, origCoins, cva.DelegatedFree) // require the ability to delegate all vesting coins (50%) and all vested coins (50%) - cva = NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) cva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, cva.DelegatedVesting) require.Nil(t, cva.DelegatedFree) @@ -127,7 +127,7 @@ func TestTrackDelegationContVestingAcc(t *testing.T) { require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, cva.DelegatedFree) // require no modifications when delegation amount is zero or not enough funds - cva = NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) require.Panics(t, func() { cva.TrackDelegation(endTime, origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 1000000)}) }) @@ -139,19 +139,19 @@ func TestTrackUndelegationContVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require the ability to undelegate all vesting coins - cva := NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) cva.TrackDelegation(now, origCoins, origCoins) cva.TrackUndelegation(origCoins) require.Nil(t, cva.DelegatedFree) require.Nil(t, cva.DelegatedVesting) // require the ability to undelegate all vested coins - cva = NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) cva.TrackDelegation(endTime, origCoins, origCoins) cva.TrackUndelegation(origCoins) @@ -159,7 +159,7 @@ func TestTrackUndelegationContVestingAcc(t *testing.T) { require.Nil(t, cva.DelegatedVesting) // require no modifications when the undelegation amount is zero - cva = NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) require.Panics(t, func() { cva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 0)}) @@ -168,7 +168,7 @@ func TestTrackUndelegationContVestingAcc(t *testing.T) { require.Nil(t, cva.DelegatedVesting) // vest 50% and delegate to two validators - cva = NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + cva = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) cva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) cva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) @@ -187,12 +187,12 @@ func TestGetVestedCoinsDelVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require no coins are vested until schedule maturation - dva := NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) vestedCoins := dva.GetVestedCoins(now) require.Nil(t, vestedCoins) @@ -205,12 +205,12 @@ func TestGetVestingCoinsDelVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require all coins vesting at the beginning of the schedule - dva := NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) vestingCoins := dva.GetVestingCoins(now) require.Equal(t, origCoins, vestingCoins) @@ -223,13 +223,13 @@ func TestSpendableCoinsDelVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require that all coins are locked in the beginning of the vesting // schedule - dva := NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) lockedCoins := dva.LockedCoins(now) require.True(t, lockedCoins.IsEqual(origCoins)) @@ -260,31 +260,31 @@ func TestTrackDelegationDelVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require the ability to delegate all vesting coins - dva := NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) dva.TrackDelegation(now, origCoins, origCoins) require.Equal(t, origCoins, dva.DelegatedVesting) require.Nil(t, dva.DelegatedFree) // require the ability to delegate all vested coins - dva = NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) dva.TrackDelegation(endTime, origCoins, origCoins) require.Nil(t, dva.DelegatedVesting) require.Equal(t, origCoins, dva.DelegatedFree) // require the ability to delegate all coins half way through the vesting // schedule - dva = NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) dva.TrackDelegation(now.Add(12*time.Hour), origCoins, origCoins) require.Equal(t, origCoins, dva.DelegatedVesting) require.Nil(t, dva.DelegatedFree) // require no modifications when delegation amount is zero or not enough funds - dva = NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) require.Panics(t, func() { dva.TrackDelegation(endTime, origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 1000000)}) @@ -297,26 +297,26 @@ func TestTrackUndelegationDelVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require the ability to undelegate all vesting coins - dva := NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) dva.TrackDelegation(now, origCoins, origCoins) dva.TrackUndelegation(origCoins) require.Nil(t, dva.DelegatedFree) require.Nil(t, dva.DelegatedVesting) // require the ability to undelegate all vested coins - dva = NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) dva.TrackDelegation(endTime, origCoins, origCoins) dva.TrackUndelegation(origCoins) require.Nil(t, dva.DelegatedFree) require.Nil(t, dva.DelegatedVesting) // require no modifications when the undelegation amount is zero - dva = NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) require.Panics(t, func() { dva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 0)}) @@ -325,7 +325,7 @@ func TestTrackUndelegationDelVestingAcc(t *testing.T) { require.Nil(t, dva.DelegatedVesting) // vest 50% and delegate to two validators - dva = NewDelayedVestingAccount(&bacc, origCoins, endTime.Unix()) + dva = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) dva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) dva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) @@ -344,16 +344,16 @@ func TestTrackUndelegationDelVestingAcc(t *testing.T) { func TestGetVestedCoinsPeriodicVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - periods := Periods{ - Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + periods := types.Periods{ + types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, } - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) - pva := NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) // require no coins vested at the beginning of the vesting schedule vestedCoins := pva.GetVestedCoins(now) @@ -389,17 +389,17 @@ func TestGetVestedCoinsPeriodicVestingAcc(t *testing.T) { func TestGetVestingCoinsPeriodicVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - periods := Periods{ - Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + periods := types.Periods{ + types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, } - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{ sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) - pva := NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) // require all coins vesting at the beginning of the vesting schedule vestingCoins := pva.GetVestingCoins(now) @@ -429,17 +429,17 @@ func TestGetVestingCoinsPeriodicVestingAcc(t *testing.T) { func TestSpendableCoinsPeriodicVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - periods := Periods{ - Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + periods := types.Periods{ + types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, } - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{ sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) - pva := NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) // require that there exist no spendable coins at the beginning of the // vesting schedule @@ -464,44 +464,44 @@ func TestSpendableCoinsPeriodicVestingAcc(t *testing.T) { func TestTrackDelegationPeriodicVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - periods := Periods{ - Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + periods := types.Periods{ + types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, } - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require the ability to delegate all vesting coins - pva := NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(now, origCoins, origCoins) require.Equal(t, origCoins, pva.DelegatedVesting) require.Nil(t, pva.DelegatedFree) // require the ability to delegate all vested coins - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(endTime, origCoins, origCoins) require.Nil(t, pva.DelegatedVesting) require.Equal(t, origCoins, pva.DelegatedFree) // delegate half of vesting coins - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(now, origCoins, periods[0].Amount) // require that all delegated coins are delegated vesting require.Equal(t, pva.DelegatedVesting, periods[0].Amount) require.Nil(t, pva.DelegatedFree) // delegate 75% of coins, split between vested and vesting - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(now.Add(12*time.Hour), origCoins, periods[0].Amount.Add(periods[1].Amount...)) // require that the maximum possible amount of vesting coins are chosen for delegation. require.Equal(t, pva.DelegatedFree, periods[1].Amount) require.Equal(t, pva.DelegatedVesting, periods[0].Amount) // require the ability to delegate all vesting coins (50%) and all vested coins (50%) - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, pva.DelegatedVesting) require.Nil(t, pva.DelegatedFree) @@ -511,7 +511,7 @@ func TestTrackDelegationPeriodicVestingAcc(t *testing.T) { require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, pva.DelegatedFree) // require no modifications when delegation amount is zero or not enough funds - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) require.Panics(t, func() { pva.TrackDelegation(endTime, origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 1000000)}) }) @@ -522,25 +522,25 @@ func TestTrackDelegationPeriodicVestingAcc(t *testing.T) { func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { now := tmtime.Now() endTime := now.Add(24 * time.Hour) - periods := Periods{ - Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, - Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + periods := types.Periods{ + types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, } - _, _, addr := KeyTestPubAddr() + _, _, addr := authtypes.KeyTestPubAddr() origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} bacc := authtypes.NewBaseAccountWithAddress(addr) // require the ability to undelegate all vesting coins at the beginning of vesting - pva := NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(now, origCoins, origCoins) pva.TrackUndelegation(origCoins) require.Nil(t, pva.DelegatedFree) require.Nil(t, pva.DelegatedVesting) // require the ability to undelegate all vested coins at the end of vesting - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(endTime, origCoins, origCoins) pva.TrackUndelegation(origCoins) @@ -548,14 +548,14 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { require.Nil(t, pva.DelegatedVesting) // require the ability to undelegate half of coins - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(endTime, origCoins, periods[0].Amount) pva.TrackUndelegation(periods[0].Amount) require.Nil(t, pva.DelegatedFree) require.Nil(t, pva.DelegatedVesting) // require no modifications when the undelegation amount is zero - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) require.Panics(t, func() { pva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 0)}) @@ -564,7 +564,7 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { require.Nil(t, pva.DelegatedVesting) // vest 50% and delegate to two validators - pva = NewPeriodicVestingAccount(&bacc, origCoins, now.Unix(), periods) + pva = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) pva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) pva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) @@ -579,97 +579,68 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 25)}, pva.DelegatedVesting) } -// TODO: Move test to bank -// func TestNewBaseVestingAccount(t *testing.T) { -// pubkey := secp256k1.GenPrivKey().PubKey() -// addr := sdk.AccAddress(pubkey.Address()) -// _, err := NewBaseVestingAccount( -// authtypes.NewBaseAccount(addr, sdk.NewCoins(), pubkey, 0, 0), -// sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}, 100, -// ) -// require.Equal(t, errors.New("vesting amount cannot be greater than total amount"), err) - -// _, err = NewBaseVestingAccount( -// authtypes.NewBaseAccount(addr, sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 10)), pubkey, 0, 0), -// sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}, 100, -// ) -// require.Equal(t, errors.New("vesting amount cannot be greater than total amount"), err) - -// _, err = NewBaseVestingAccount( -// authtypes.NewBaseAccount(addr, sdk.NewCoins(sdk.NewInt64Coin("uatom", 50), sdk.NewInt64Coin("eth", 50)), pubkey, 0, 0), -// sdk.NewCoins(sdk.NewInt64Coin("uatom", 100), sdk.NewInt64Coin("eth", 20)), 100, -// ) -// require.Equal(t, errors.New("vesting amount cannot be greater than total amount"), err) - -// _, err = NewBaseVestingAccount( -// authtypes.NewBaseAccount(addr, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}, pubkey, 0, 0), -// sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}, 100, -// ) -// require.NoError(t, err) - -// } - func TestGenesisAccountValidate(t *testing.T) { pubkey := secp256k1.GenPrivKey().PubKey() addr := sdk.AccAddress(pubkey.Address()) baseAcc := authtypes.NewBaseAccount(addr, pubkey, 0, 0) initialVesting := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)) - baseVestingWithCoins := NewBaseVestingAccount(baseAcc, initialVesting, 100) + baseVestingWithCoins := types.NewBaseVestingAccount(baseAcc, initialVesting, 100) 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", - NewContinuousVestingAccount(baseAcc, initialVesting, 100, 200), - nil, + types.NewContinuousVestingAccount(baseAcc, initialVesting, 100, 200), + false, }, { "invalid vesting times", - NewContinuousVestingAccount(baseAcc, initialVesting, 1654668078, 1554668078), - errors.New("vesting start-time cannot be before end-time"), + types.NewContinuousVestingAccount(baseAcc, initialVesting, 1654668078, 1554668078), + true, }, { "valid periodic vesting account", - NewPeriodicVestingAccount(baseAcc, initialVesting, 0, Periods{Period{Length: int64(100), Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}}}), - nil, + types.NewPeriodicVestingAccount(baseAcc, initialVesting, 0, types.Periods{types.Period{Length: int64(100), Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}}}), + false, }, { "invalid vesting period lengths", - NewPeriodicVestingAccountRaw( + types.NewPeriodicVestingAccountRaw( baseVestingWithCoins, - 0, Periods{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"), + 0, types.Periods{types.Period{Length: int64(50), Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}}}), + true, }, { "invalid vesting period amounts", - NewPeriodicVestingAccountRaw( + types.NewPeriodicVestingAccountRaw( baseVestingWithCoins, - 0, Periods{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"), + 0, types.Periods{types.Period{Length: int64(100), Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 25)}}}), + 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) }) } } @@ -680,7 +651,7 @@ func TestBaseVestingAccountJSON(t *testing.T) { coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5)) baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50) - acc := NewBaseVestingAccount(baseAcc, coins, time.Now().Unix()) + acc := types.NewBaseVestingAccount(baseAcc, coins, time.Now().Unix()) bz, err := json.Marshal(acc) require.NoError(t, err) @@ -689,19 +660,41 @@ func TestBaseVestingAccountJSON(t *testing.T) { require.NoError(t, err) require.Equal(t, string(bz1), string(bz)) - var a BaseVestingAccount + var a types.BaseVestingAccount require.NoError(t, json.Unmarshal(bz, &a)) require.Equal(t, acc.String(), a.String()) } +func TestContinuousVestingAccountMarshal(t *testing.T) { + pubkey := secp256k1.GenPrivKey().PubKey() + addr := sdk.AccAddress(pubkey.Address()) + coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5)) + baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50) + + baseVesting := types.NewBaseVestingAccount(baseAcc, coins, time.Now().Unix()) + acc := types.NewContinuousVestingAccountRaw(baseVesting, baseVesting.EndTime) + + bz, err := appCodec.MarshalAccount(acc) + require.Nil(t, err) + + acc2, err := appCodec.UnmarshalAccount(bz) + require.Nil(t, err) + require.IsType(t, &types.ContinuousVestingAccount{}, acc2) + require.Equal(t, acc.String(), acc2.String()) + + // error on bad bytes + _, err = appCodec.UnmarshalAccount(bz[:len(bz)/2]) + require.NotNil(t, err) +} + func TestContinuousVestingAccountJSON(t *testing.T) { pubkey := secp256k1.GenPrivKey().PubKey() addr := sdk.AccAddress(pubkey.Address()) coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5)) baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50) - baseVesting := NewBaseVestingAccount(baseAcc, coins, time.Now().Unix()) - acc := NewContinuousVestingAccountRaw(baseVesting, baseVesting.EndTime) + baseVesting := types.NewBaseVestingAccount(baseAcc, coins, time.Now().Unix()) + acc := types.NewContinuousVestingAccountRaw(baseVesting, baseVesting.EndTime) bz, err := json.Marshal(acc) require.NoError(t, err) @@ -710,18 +703,39 @@ func TestContinuousVestingAccountJSON(t *testing.T) { require.NoError(t, err) require.Equal(t, string(bz1), string(bz)) - var a ContinuousVestingAccount + var a types.ContinuousVestingAccount require.NoError(t, json.Unmarshal(bz, &a)) require.Equal(t, acc.String(), a.String()) } +func TestPeriodicVestingAccountMarshal(t *testing.T) { + pubkey := secp256k1.GenPrivKey().PubKey() + addr := sdk.AccAddress(pubkey.Address()) + coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5)) + baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50) + + acc := types.NewPeriodicVestingAccount(baseAcc, coins, time.Now().Unix(), types.Periods{types.Period{3600, coins}}) + + bz, err := appCodec.MarshalAccount(acc) + require.Nil(t, err) + + acc2, err := appCodec.UnmarshalAccount(bz) + require.Nil(t, err) + require.IsType(t, &types.PeriodicVestingAccount{}, acc2) + require.Equal(t, acc.String(), acc2.String()) + + // error on bad bytes + _, err = appCodec.UnmarshalAccount(bz[:len(bz)/2]) + require.NotNil(t, err) +} + func TestPeriodicVestingAccountJSON(t *testing.T) { pubkey := secp256k1.GenPrivKey().PubKey() addr := sdk.AccAddress(pubkey.Address()) coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5)) baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50) - acc := NewPeriodicVestingAccount(baseAcc, coins, time.Now().Unix(), Periods{Period{3600, coins}}) + acc := types.NewPeriodicVestingAccount(baseAcc, coins, time.Now().Unix(), types.Periods{types.Period{3600, coins}}) bz, err := json.Marshal(acc) require.NoError(t, err) @@ -730,18 +744,39 @@ func TestPeriodicVestingAccountJSON(t *testing.T) { require.NoError(t, err) require.Equal(t, string(bz1), string(bz)) - var a PeriodicVestingAccount + var a types.PeriodicVestingAccount require.NoError(t, json.Unmarshal(bz, &a)) require.Equal(t, acc.String(), a.String()) } +func TestDelayedVestingAccountMarshal(t *testing.T) { + pubkey := secp256k1.GenPrivKey().PubKey() + addr := sdk.AccAddress(pubkey.Address()) + coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5)) + baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50) + + acc := types.NewDelayedVestingAccount(baseAcc, coins, time.Now().Unix()) + + bz, err := appCodec.MarshalAccount(acc) + require.Nil(t, err) + + acc2, err := appCodec.UnmarshalAccount(bz) + require.Nil(t, err) + require.IsType(t, &types.DelayedVestingAccount{}, acc2) + require.Equal(t, acc.String(), acc2.String()) + + // error on bad bytes + _, err = appCodec.UnmarshalAccount(bz[:len(bz)/2]) + require.NotNil(t, err) +} + func TestDelayedVestingAccountJSON(t *testing.T) { pubkey := secp256k1.GenPrivKey().PubKey() addr := sdk.AccAddress(pubkey.Address()) coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5)) baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50) - acc := NewDelayedVestingAccount(baseAcc, coins, time.Now().Unix()) + acc := types.NewDelayedVestingAccount(baseAcc, coins, time.Now().Unix()) bz, err := json.Marshal(acc) require.NoError(t, err) @@ -750,7 +785,7 @@ func TestDelayedVestingAccountJSON(t *testing.T) { require.NoError(t, err) require.Equal(t, string(bz1), string(bz)) - var a DelayedVestingAccount + var a types.DelayedVestingAccount require.NoError(t, json.Unmarshal(bz, &a)) require.Equal(t, acc.String(), a.String()) } diff --git a/x/bank/alias.go b/x/bank/alias.go index faa59aa3fd..9811c9e001 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 e124baaeef..4a36d2d8af 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 ( @@ -356,7 +356,7 @@ func TestMsgMultiSendDependent(t *testing.T) { err := acc2.SetAccountNumber(1) require.NoError(t, err) - genAccs := []authexported.GenesisAccount{&acc1, &acc2} + genAccs := []authexported.GenesisAccount{acc1, acc2} app := simapp.SetupWithGenesisAccounts(genAccs) ctx := app.BaseApp.NewContext(false, abci.Header{}) diff --git a/x/bank/client/cli/query.go b/x/bank/client/cli/query.go index 046e840514..e7327a091e 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 b2b36c45db..0764045968 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 eb1f3463b7..99b3680bbb 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 52fa9f2513..30178166bb 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 3c83ec4c2a..30341ab47b 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 6d4d49adc1..0000000000 --- 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/types/errors.go b/x/bank/internal/types/errors.go deleted file mode 100644 index 157408c941..0000000000 --- a/x/bank/internal/types/errors.go +++ /dev/null @@ -1,13 +0,0 @@ -package types - -import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -// x/bank module sentinel errors -var ( - ErrNoInputs = sdkerrors.Register(ModuleName, 1, "no inputs to send transaction") - ErrNoOutputs = sdkerrors.Register(ModuleName, 2, "no outputs to send transaction") - ErrInputOutputMismatch = sdkerrors.Register(ModuleName, 3, "sum inputs != sum outputs") - ErrSendDisabled = sdkerrors.Register(ModuleName, 4, "send transactions are disabled") -) 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 6573045126..3833c034d3 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 96% rename from x/bank/internal/keeper/keeper.go rename to x/bank/keeper/keeper.go index 3f8529ad79..b1b2bdfa7a 100644 --- a/x/bank/internal/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -11,8 +11,8 @@ 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/params" + "github.com/cosmos/cosmos-sdk/x/bank/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) var _ Keeper = (*BaseKeeper)(nil) @@ -31,11 +31,11 @@ type BaseKeeper struct { BaseSendKeeper ak types.AccountKeeper - paramSpace params.Subspace + paramSpace paramtypes.Subspace } func NewBaseKeeper( - cdc *codec.Codec, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace params.Subspace, blacklistedAddrs map[string]bool, + cdc codec.Marshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blacklistedAddrs map[string]bool, ) BaseKeeper { ps := paramSpace.WithKeyTable(types.ParamKeyTable()) @@ -146,17 +146,17 @@ var _ SendKeeper = (*BaseSendKeeper)(nil) type BaseSendKeeper struct { BaseViewKeeper - cdc *codec.Codec + cdc codec.Marshaler ak types.AccountKeeper storeKey sdk.StoreKey - paramSpace params.Subspace + paramSpace paramtypes.Subspace // list of addresses that are restricted from receiving transactions blacklistedAddrs map[string]bool } func NewBaseSendKeeper( - cdc *codec.Codec, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace params.Subspace, blacklistedAddrs map[string]bool, + cdc codec.Marshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blacklistedAddrs map[string]bool, ) BaseSendKeeper { return BaseSendKeeper{ @@ -341,7 +341,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 @@ -385,13 +385,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 96% rename from x/bank/internal/keeper/keeper_test.go rename to x/bank/keeper/keeper_test.go index fbe41870f7..472fe39972 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 ( @@ -171,7 +171,7 @@ func (suite *IntegrationTestSuite) TestValidateBalance() { suite.Require().NoError(app.BankKeeper.ValidateBalance(ctx, addr1)) bacc := auth.NewBaseAccountWithAddress(addr2) - vacc := vesting.NewContinuousVestingAccount(&bacc, balances.Add(balances...), now.Unix(), endTime.Unix()) + vacc := vesting.NewContinuousVestingAccount(bacc, balances.Add(balances...), now.Unix(), endTime.Unix()) app.AccountKeeper.SetAccount(ctx, vacc) suite.Require().NoError(app.BankKeeper.SetBalances(ctx, addr2, balances)) @@ -392,7 +392,7 @@ func (suite *IntegrationTestSuite) TestSpendableCoins() { macc := app.AccountKeeper.NewAccountWithAddress(ctx, addrModule) bacc := auth.NewBaseAccountWithAddress(addr1) - vacc := vesting.NewContinuousVestingAccount(&bacc, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) + vacc := vesting.NewContinuousVestingAccount(bacc, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr2) app.AccountKeeper.SetAccount(ctx, macc) @@ -421,7 +421,7 @@ func (suite *IntegrationTestSuite) TestVestingAccountSend() { addr2 := sdk.AccAddress([]byte("addr2")) bacc := auth.NewBaseAccountWithAddress(addr1) - vacc := vesting.NewContinuousVestingAccount(&bacc, origCoins, now.Unix(), endTime.Unix()) + vacc := vesting.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) app.AccountKeeper.SetAccount(ctx, vacc) suite.Require().NoError(app.BankKeeper.SetBalances(ctx, addr1, origCoins)) @@ -454,7 +454,7 @@ func (suite *IntegrationTestSuite) TestPeriodicVestingAccountSend() { } bacc := auth.NewBaseAccountWithAddress(addr1) - vacc := vesting.NewPeriodicVestingAccount(&bacc, origCoins, ctx.BlockHeader().Time.Unix(), periods) + vacc := vesting.NewPeriodicVestingAccount(bacc, origCoins, ctx.BlockHeader().Time.Unix(), periods) app.AccountKeeper.SetAccount(ctx, vacc) suite.Require().NoError(app.BankKeeper.SetBalances(ctx, addr1, origCoins)) @@ -484,7 +484,7 @@ func (suite *IntegrationTestSuite) TestVestingAccountReceive() { addr2 := sdk.AccAddress([]byte("addr2")) bacc := auth.NewBaseAccountWithAddress(addr1) - vacc := vesting.NewContinuousVestingAccount(&bacc, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) + vacc := vesting.NewContinuousVestingAccount(bacc, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr2) app.AccountKeeper.SetAccount(ctx, vacc) @@ -523,7 +523,7 @@ func (suite *IntegrationTestSuite) TestPeriodicVestingAccountReceive() { vesting.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin("stake", 25)}}, } - vacc := vesting.NewPeriodicVestingAccount(&bacc, origCoins, ctx.BlockHeader().Time.Unix(), periods) + vacc := vesting.NewPeriodicVestingAccount(bacc, origCoins, ctx.BlockHeader().Time.Unix(), periods) acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr2) app.AccountKeeper.SetAccount(ctx, vacc) @@ -560,7 +560,7 @@ func (suite *IntegrationTestSuite) TestDelegateCoins() { macc := app.AccountKeeper.NewAccountWithAddress(ctx, addrModule) // we don't need to define an actual module account bc we just need the address for testing acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr2) bacc := auth.NewBaseAccountWithAddress(addr1) - vacc := vesting.NewContinuousVestingAccount(&bacc, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) + vacc := vesting.NewContinuousVestingAccount(bacc, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) app.AccountKeeper.SetAccount(ctx, vacc) app.AccountKeeper.SetAccount(ctx, acc) @@ -620,7 +620,7 @@ func (suite *IntegrationTestSuite) TestUndelegateCoins() { bacc := auth.NewBaseAccountWithAddress(addr1) macc := app.AccountKeeper.NewAccountWithAddress(ctx, addrModule) // we don't need to define an actual module account bc we just need the address for testing - vacc := vesting.NewContinuousVestingAccount(&bacc, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) + vacc := vesting.NewContinuousVestingAccount(bacc, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr2) app.AccountKeeper.SetAccount(ctx, vacc) 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 072511b2d2..be17b37162 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 643f7b1798..3732aaa744 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 72afda6862..7cb8671427 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" ) @@ -39,14 +39,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { RegisterCodec(cdc) } // DefaultGenesis returns default genesis state as raw bytes for the bank // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the bank module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) } @@ -111,18 +111,18 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { // InitGenesis performs genesis initialization for the bank module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.keeper, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the bank // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, am.keeper) - return ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock performs a no-op. diff --git a/x/bank/simulation/genesis.go b/x/bank/simulation/genesis.go index b593fa05b0..97716bd2fa 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 2d9e846835..c3ff22f9ce 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 f5aa25bf6a..458a8a09a1 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 0000000000..652fb3f2fe --- /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/types/errors.go b/x/bank/types/errors.go new file mode 100644 index 0000000000..dce69d0ac6 --- /dev/null +++ b/x/bank/types/errors.go @@ -0,0 +1,13 @@ +package types + +import ( + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +// x/bank module sentinel errors +var ( + ErrNoInputs = sdkerrors.Register(ModuleName, 2, "no inputs to send transaction") + ErrNoOutputs = sdkerrors.Register(ModuleName, 3, "no outputs to send transaction") + ErrInputOutputMismatch = sdkerrors.Register(ModuleName, 4, "sum inputs != sum outputs") + ErrSendDisabled = sdkerrors.Register(ModuleName, 5, "send transactions are disabled") +) 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 a16a22381d..b1e5a76141 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 83db26aaef..3dab0c6bb5 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 69% rename from x/bank/internal/types/params.go rename to x/bank/types/params.go index cdd6aff84f..68a8fcd498 100644 --- a/x/bank/internal/types/params.go +++ b/x/bank/types/params.go @@ -3,7 +3,7 @@ package types import ( "fmt" - "github.com/cosmos/cosmos-sdk/x/params" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) const ( @@ -17,9 +17,9 @@ const ( var ParamStoreKeySendEnabled = []byte("sendenabled") // ParamKeyTable type declaration for parameters -func ParamKeyTable() params.KeyTable { - return params.NewKeyTable( - params.NewParamSetPair(ParamStoreKeySendEnabled, false, validateSendEnabled), +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable( + paramtypes.NewParamSetPair(ParamStoreKeySendEnabled, false, validateSendEnabled), ) } 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 0000000000..b5a5c12883 --- /dev/null +++ b/x/bank/types/types.pb.go @@ -0,0 +1,1314 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: x/bank/types/types.proto + +package types + +import ( + bytes "bytes" + 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{ + // 413 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, 0x87, 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, 0x5a, 0xb1, 0xbc, 0x58, 0x20, 0xcf, 0xa8, 0xb4, 0x9d, 0x91, 0x8b, 0xd5, 0x33, 0xaf, + 0xa0, 0xb4, 0x44, 0xc8, 0x9b, 0x8b, 0x1d, 0x35, 0xf4, 0x0c, 0x49, 0x77, 0x3d, 0xcc, 0x04, 0xa1, + 0x68, 0x2e, 0xd6, 0x64, 0x90, 0x6d, 0x12, 0x4c, 0xd4, 0x74, 0x3a, 0xc4, 0x4c, 0xa8, 0xcb, 0x77, + 0x30, 0x72, 0xb1, 0xf9, 0x97, 0x96, 0x0c, 0x45, 0xa7, 0xf7, 0x32, 0x72, 0xf1, 0xf8, 0x16, 0xa7, + 0xfb, 0x96, 0xe6, 0x94, 0x64, 0x82, 0x93, 0xaf, 0x25, 0x17, 0x5b, 0x26, 0x28, 0x12, 0x40, 0xee, + 0x07, 0x59, 0x2a, 0xad, 0x87, 0x2d, 0xb3, 0xe8, 0x81, 0x23, 0xca, 0x89, 0x05, 0x64, 0x79, 0x10, + 0x54, 0x83, 0x90, 0x0d, 0x17, 0x7b, 0x3e, 0x38, 0x14, 0x60, 0x0e, 0x96, 0xc1, 0xae, 0x17, 0x12, + 0x54, 0x50, 0xcd, 0x30, 0x2d, 0x10, 0xf7, 0x38, 0x39, 0x9f, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, + 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, + 0xb1, 0x1c, 0x43, 0x94, 0x26, 0x5e, 0x0f, 0x22, 0xe7, 0xf5, 0x24, 0x36, 0x70, 0xae, 0x34, 0x06, + 0x04, 0x00, 0x00, 0xff, 0xff, 0x57, 0x42, 0x17, 0x1f, 0x02, 0x04, 0x00, 0x00, +} + +func (this *MsgSend) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgSend) + if !ok { + that2, ok := that.(MsgSend) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.FromAddress, that1.FromAddress) { + return false + } + if !bytes.Equal(this.ToAddress, that1.ToAddress) { + return false + } + if len(this.Amount) != len(that1.Amount) { + return false + } + for i := range this.Amount { + if !this.Amount[i].Equal(&that1.Amount[i]) { + return false + } + } + return true +} +func (this *Input) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Input) + if !ok { + that2, ok := that.(Input) + 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 len(this.Coins) != len(that1.Coins) { + return false + } + for i := range this.Coins { + if !this.Coins[i].Equal(&that1.Coins[i]) { + return false + } + } + return true +} +func (this *Output) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Output) + if !ok { + that2, ok := that.(Output) + 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 len(this.Coins) != len(that1.Coins) { + return false + } + for i := range this.Coins { + if !this.Coins[i].Equal(&that1.Coins[i]) { + return false + } + } + return true +} +func (this *MsgMultiSend) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgMultiSend) + if !ok { + that2, ok := that.(MsgMultiSend) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Inputs) != len(that1.Inputs) { + return false + } + for i := range this.Inputs { + if !this.Inputs[i].Equal(&that1.Inputs[i]) { + return false + } + } + if len(this.Outputs) != len(that1.Outputs) { + return false + } + for i := range this.Outputs { + if !this.Outputs[i].Equal(&that1.Outputs[i]) { + return false + } + } + return true +} +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 0000000000..ceb9903149 --- /dev/null +++ b/x/bank/types/types.proto @@ -0,0 +1,56 @@ +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 { + option (gogoproto.equal) = true; + + 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 { + option (gogoproto.equal) = true; + + 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 { + option (gogoproto.equal) = true; + + 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 { + option (gogoproto.equal) = true; + + repeated Input inputs = 1 [(gogoproto.nullable) = false]; + repeated Output outputs = 2 [(gogoproto.nullable) = false]; +} diff --git a/x/crisis/internal/keeper/keeper.go b/x/crisis/internal/keeper/keeper.go index f4c8163bb7..d57030ed6c 100644 --- a/x/crisis/internal/keeper/keeper.go +++ b/x/crisis/internal/keeper/keeper.go @@ -8,13 +8,13 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/crisis/internal/types" - "github.com/cosmos/cosmos-sdk/x/params" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) // Keeper - crisis keeper type Keeper struct { routes []types.InvarRoute - paramSpace params.Subspace + paramSpace paramtypes.Subspace invCheckPeriod uint supplyKeeper types.SupplyKeeper @@ -24,7 +24,7 @@ type Keeper struct { // NewKeeper creates a new Keeper object func NewKeeper( - paramSpace params.Subspace, invCheckPeriod uint, supplyKeeper types.SupplyKeeper, + paramSpace paramtypes.Subspace, invCheckPeriod uint, supplyKeeper types.SupplyKeeper, feeCollectorName string, ) Keeper { diff --git a/x/crisis/internal/types/codec.go b/x/crisis/internal/types/codec.go index fc9178eb38..b7906953cf 100644 --- a/x/crisis/internal/types/codec.go +++ b/x/crisis/internal/types/codec.go @@ -4,32 +4,26 @@ import ( "github.com/cosmos/cosmos-sdk/codec" ) -type Codec struct { - codec.Marshaler - - // Keep reference to the amino codec to allow backwards compatibility along - // with type, and interface registration. - amino *codec.Codec -} - -func NewCodec(amino *codec.Codec) *Codec { - return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino} -} - -// ---------------------------------------------------------------------------- - -// RegisterCodec registers all the necessary crisis module concrete types and -// interfaces with the provided codec reference. +// RegisterCodec registers the necessary x/crisis interfaces and concrete types +// on the provided Amino codec. These types are used for Amino JSON serialization. func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgVerifyInvariant{}, "cosmos-sdk/MsgVerifyInvariant", nil) } -// ModuleCdc defines a crisis module global Amino codec. -var ModuleCdc *Codec +var ( + amino = codec.New() + + // ModuleCdc references the global x/crisis 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/crisis and + // defined at the application level. + ModuleCdc = codec.NewHybridCodec(amino) +) func init() { - ModuleCdc = NewCodec(codec.New()) - RegisterCodec(ModuleCdc.amino) - codec.RegisterCrypto(ModuleCdc.amino) - ModuleCdc.amino.Seal() + RegisterCodec(amino) + codec.RegisterCrypto(amino) + amino.Seal() } diff --git a/x/crisis/internal/types/errors.go b/x/crisis/internal/types/errors.go index ac63f3ff43..cf8c4901b3 100644 --- a/x/crisis/internal/types/errors.go +++ b/x/crisis/internal/types/errors.go @@ -6,6 +6,6 @@ import ( // x/crisis module sentinel errors var ( - ErrNoSender = sdkerrors.Register(ModuleName, 1, "sender address is empty") - ErrUnknownInvariant = sdkerrors.Register(ModuleName, 2, "unknown invariant") + ErrNoSender = sdkerrors.Register(ModuleName, 2, "sender address is empty") + ErrUnknownInvariant = sdkerrors.Register(ModuleName, 3, "unknown invariant") ) diff --git a/x/crisis/internal/types/params.go b/x/crisis/internal/types/params.go index 5749c9192e..90aacd98ad 100644 --- a/x/crisis/internal/types/params.go +++ b/x/crisis/internal/types/params.go @@ -4,7 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/params" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) // Default parameter namespace @@ -18,9 +18,9 @@ var ( ) // type declaration for parameters -func ParamKeyTable() params.KeyTable { - return params.NewKeyTable( - params.NewParamSetPair(ParamStoreKeyConstantFee, sdk.Coin{}, validateConstantFee), +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable( + paramtypes.NewParamSetPair(ParamStoreKeyConstantFee, sdk.Coin{}, validateConstantFee), ) } diff --git a/x/crisis/internal/types/types.pb.go b/x/crisis/internal/types/types.pb.go index bf584c3844..6e9507e1ac 100644 --- a/x/crisis/internal/types/types.pb.go +++ b/x/crisis/internal/types/types.pb.go @@ -4,6 +4,7 @@ package types import ( + bytes "bytes" fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" @@ -94,28 +95,59 @@ func init() { } var fileDescriptor_df1c0b8e580cce76 = []byte{ - // 301 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0xcf, 0x4a, 0xfb, 0x30, - 0x00, 0x80, 0x97, 0xdf, 0x0f, 0x07, 0x16, 0x51, 0xa8, 0x38, 0xc6, 0x90, 0x74, 0x54, 0x90, 0x5d, - 0xd6, 0x30, 0xbc, 0x79, 0xdb, 0x3c, 0xed, 0x30, 0x0f, 0x45, 0x3c, 0x78, 0x29, 0x59, 0x13, 0xbb, - 0xb0, 0x25, 0x29, 0x49, 0x3a, 0xd6, 0xb7, 0xf0, 0xb1, 0x3c, 0xee, 0xe8, 0xa9, 0x48, 0xfb, 0x06, - 0x3b, 0xee, 0x24, 0xa6, 0x75, 0x03, 0xf1, 0x92, 0x84, 0x8f, 0x2f, 0x5f, 0xfe, 0x38, 0x37, 0x1b, - 0x14, 0x2b, 0xa6, 0x99, 0x46, 0x4c, 0x18, 0xaa, 0x04, 0x5e, 0x21, 0x93, 0xa7, 0x54, 0xd7, 0x63, - 0x90, 0x2a, 0x69, 0xa4, 0xdb, 0x89, 0xa5, 0xe6, 0x52, 0x47, 0x9a, 0x2c, 0x83, 0x4d, 0x50, 0xfb, - 0xc1, 0x7a, 0xd4, 0xbb, 0x35, 0x0b, 0xa6, 0x48, 0x94, 0x62, 0x65, 0x72, 0x64, 0x55, 0x94, 0xc8, - 0x44, 0x1e, 0x57, 0xf5, 0x7e, 0x7f, 0x0f, 0x1c, 0x77, 0xa6, 0x93, 0x67, 0xaa, 0xd8, 0x6b, 0x3e, - 0x15, 0x6b, 0xac, 0x18, 0x16, 0xc6, 0x9d, 0x3a, 0x6d, 0x4d, 0x05, 0xa1, 0xaa, 0x0b, 0xfa, 0x60, - 0x70, 0x36, 0x19, 0xed, 0x0b, 0x6f, 0x98, 0x30, 0xb3, 0xc8, 0xe6, 0x41, 0x2c, 0x39, 0xaa, 0x4f, - 0x6d, 0xa6, 0xa1, 0x26, 0xcb, 0xe6, 0x52, 0xe3, 0x38, 0x1e, 0x13, 0xa2, 0xa8, 0xd6, 0x61, 0x13, - 0x70, 0x9f, 0x9c, 0x2b, 0xf6, 0xd3, 0x8d, 0xb8, 0x24, 0xd9, 0x8a, 0x46, 0x02, 0x73, 0xda, 0xfd, - 0xd7, 0x07, 0x83, 0xd3, 0x49, 0x7f, 0x57, 0x78, 0xd7, 0x39, 0xe6, 0xab, 0x7b, 0xff, 0x4f, 0xcd, - 0x0f, 0x2f, 0x0f, 0x7c, 0x66, 0xf1, 0x23, 0xe6, 0xd4, 0x7d, 0x70, 0x2e, 0x8e, 0xba, 0x92, 0x99, - 0xa1, 0xdd, 0xff, 0xb6, 0xd7, 0xdb, 0x15, 0x5e, 0xe7, 0x77, 0xcf, 0x0a, 0x7e, 0x78, 0x7e, 0x20, - 0xe1, 0x37, 0x98, 0x78, 0xef, 0x25, 0x04, 0xdb, 0x12, 0x82, 0xcf, 0x12, 0x82, 0xb7, 0x0a, 0xb6, - 0xb6, 0x15, 0x6c, 0x7d, 0x54, 0xb0, 0xf5, 0x72, 0x62, 0x9f, 0x33, 0x6f, 0xdb, 0x4f, 0xba, 0xfb, - 0x0a, 0x00, 0x00, 0xff, 0xff, 0xa7, 0xed, 0x2c, 0x98, 0x8b, 0x01, 0x00, 0x00, + // 308 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xae, 0xd0, 0x4f, 0x2e, + 0xca, 0x2c, 0xce, 0x2c, 0xd6, 0xcf, 0xcc, 0x2b, 0x49, 0x2d, 0xca, 0x4b, 0xcc, 0xd1, 0x2f, 0xa9, + 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x62, 0xc9, 0xf9, 0xc5, + 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, 0x7a, 0x10, 0xf5, 0x7a, 0x65, 0x86, 0x52, + 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, 0x25, 0x95, 0xfa, 0x60, 0xa5, 0xfa, + 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0x44, 0xbf, 0x52, 0x03, 0x13, 0x97, 0x90, 0x6f, 0x71, 0x7a, + 0x58, 0x6a, 0x51, 0x66, 0x5a, 0xa5, 0x67, 0x5e, 0x59, 0x62, 0x51, 0x66, 0x62, 0x5e, 0x89, 0x90, + 0x27, 0x17, 0x5b, 0x71, 0x6a, 0x5e, 0x4a, 0x6a, 0x91, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x8f, 0x93, + 0xe1, 0xaf, 0x7b, 0xf2, 0xba, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, + 0x10, 0x5b, 0xa1, 0x94, 0x6e, 0x71, 0x4a, 0x36, 0xd4, 0x51, 0x8e, 0xc9, 0xc9, 0x8e, 0x29, 0x29, + 0x45, 0xa9, 0xc5, 0xc5, 0x41, 0x50, 0x03, 0x84, 0x42, 0xb8, 0x44, 0x33, 0x61, 0xe6, 0xc6, 0xe7, + 0xe6, 0xa7, 0x94, 0xe6, 0xa4, 0xc6, 0xe7, 0x25, 0xe6, 0xa6, 0x4a, 0x30, 0x29, 0x30, 0x6a, 0x70, + 0x3a, 0x29, 0x7c, 0xba, 0x27, 0x2f, 0x53, 0x99, 0x98, 0x9b, 0x63, 0xa5, 0x84, 0x55, 0x99, 0x52, + 0x90, 0x30, 0x5c, 0xdc, 0x17, 0x2c, 0xec, 0x97, 0x98, 0x9b, 0x2a, 0xe4, 0xcc, 0xc5, 0x8f, 0x50, + 0x5e, 0x94, 0x5f, 0x5a, 0x92, 0x2a, 0xc1, 0x0c, 0x36, 0x4f, 0xea, 0xd3, 0x3d, 0x79, 0x31, 0x74, + 0xf3, 0xc0, 0x0a, 0x94, 0x82, 0xf8, 0xe0, 0x22, 0x41, 0x20, 0x01, 0x2b, 0x96, 0x17, 0x0b, 0xe4, + 0x19, 0x9d, 0xe4, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, + 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x8a, 0x15, 0xec, + 0xa9, 0x24, 0x36, 0x70, 0x50, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x46, 0x5c, 0xba, 0xa4, + 0x91, 0x01, 0x00, 0x00, } +func (this *MsgVerifyInvariant) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgVerifyInvariant) + if !ok { + that2, ok := that.(MsgVerifyInvariant) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.Sender, that1.Sender) { + return false + } + if this.InvariantModuleName != that1.InvariantModuleName { + return false + } + if this.InvariantRoute != that1.InvariantRoute { + return false + } + return true +} func (m *MsgVerifyInvariant) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) diff --git a/x/crisis/internal/types/types.proto b/x/crisis/internal/types/types.proto index 64b4c5fc60..c691035f92 100644 --- a/x/crisis/internal/types/types.proto +++ b/x/crisis/internal/types/types.proto @@ -7,6 +7,8 @@ import "third_party/proto/gogoproto/gogo.proto"; // MsgVerifyInvariant - message struct to verify a particular invariance message MsgVerifyInvariant { + option (gogoproto.equal) = true; + bytes sender = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; string invariant_module_name = 2 [(gogoproto.moretags) = "yaml:\"invariant_module_name\""]; string invariant_route = 3 [(gogoproto.moretags) = "yaml:\"invariant_route\""]; diff --git a/x/crisis/module.go b/x/crisis/module.go index 1885f69ade..dd7ae36772 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -38,14 +38,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { // DefaultGenesis returns default genesis state as raw bytes for the crisis // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return types.ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the crisis module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data types.GenesisState - if err := types.ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) } @@ -109,9 +109,9 @@ func (AppModule) NewQuerierHandler() sdk.Querier { return nil } // InitGenesis performs genesis initialization for the crisis module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - types.ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, *am.keeper, genesisState) am.keeper.AssertInvariants(ctx) @@ -120,9 +120,9 @@ func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.Va // ExportGenesis returns the exported genesis state as raw bytes for the crisis // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, *am.keeper) - return types.ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock performs a no-op. diff --git a/x/distribution/alias.go b/x/distribution/alias.go index ba16c5f47f..47143d995c 100644 --- a/x/distribution/alias.go +++ b/x/distribution/alias.go @@ -111,7 +111,6 @@ var ( ParamStoreKeyBonusProposerReward = types.ParamStoreKeyBonusProposerReward ParamStoreKeyWithdrawAddrEnabled = types.ParamStoreKeyWithdrawAddrEnabled ModuleCdc = types.ModuleCdc - NewCodec = types.NewCodec EventTypeSetWithdrawAddress = types.EventTypeSetWithdrawAddress EventTypeRewards = types.EventTypeRewards EventTypeCommission = types.EventTypeCommission @@ -156,5 +155,4 @@ type ( ValidatorSlashEvent = types.ValidatorSlashEvent ValidatorSlashEvents = types.ValidatorSlashEvents ValidatorOutstandingRewards = types.ValidatorOutstandingRewards - Codec = types.Codec ) diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index 0074f84042..e1aeed7cad 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -3,20 +3,20 @@ package keeper import ( "fmt" + "github.com/tendermint/tendermint/libs/log" + "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/distribution/types" - "github.com/cosmos/cosmos-sdk/x/params" - - "github.com/tendermint/tendermint/libs/log" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) // Keeper of the distribution store type Keeper struct { storeKey sdk.StoreKey cdc codec.Marshaler - paramSpace params.Subspace + paramSpace paramtypes.Subspace bankKeeper types.BankKeeper stakingKeeper types.StakingKeeper supplyKeeper types.SupplyKeeper @@ -28,7 +28,7 @@ type Keeper struct { // NewKeeper creates a new distribution Keeper instance func NewKeeper( - cdc codec.Marshaler, key sdk.StoreKey, paramSpace params.Subspace, bk types.BankKeeper, + cdc codec.Marshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace, bk types.BankKeeper, sk types.StakingKeeper, supplyKeeper types.SupplyKeeper, feeCollectorName string, blacklistedAddrs map[string]bool, ) Keeper { diff --git a/x/distribution/keeper/test_common.go b/x/distribution/keeper/test_common.go index dca88dfd16..0c18e92495 100644 --- a/x/distribution/keeper/test_common.go +++ b/x/distribution/keeper/test_common.go @@ -12,15 +12,16 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/codec" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" - "github.com/cosmos/cosmos-sdk/x/params" + "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/supply" - - "github.com/cosmos/cosmos-sdk/x/distribution/types" ) //nolint:deadcode,unused @@ -88,7 +89,7 @@ func CreateTestInputDefault(t *testing.T, isCheckTx bool, initPower int64) ( // hogpodge of all sorts of input required for testing func CreateTestInputAdvanced( t *testing.T, isCheckTx bool, initPower int64, communityTax sdk.Dec, -) (sdk.Context, auth.AccountKeeper, bank.Keeper, Keeper, staking.Keeper, params.Keeper, types.SupplyKeeper, +) (sdk.Context, auth.AccountKeeper, bank.Keeper, Keeper, staking.Keeper, keeper.Keeper, types.SupplyKeeper, ) { initTokens := sdk.TokensFromConsensusPower(initPower) @@ -98,8 +99,8 @@ func CreateTestInputAdvanced( keyStaking := sdk.NewKVStoreKey(staking.StoreKey) keyAcc := sdk.NewKVStoreKey(auth.StoreKey) keySupply := sdk.NewKVStoreKey(supply.StoreKey) - keyParams := sdk.NewKVStoreKey(params.StoreKey) - tkeyParams := sdk.NewTransientStoreKey(params.TStoreKey) + keyParams := sdk.NewKVStoreKey(paramtypes.StoreKey) + tkeyParams := sdk.NewTransientStoreKey(paramtypes.TStoreKey) db := dbm.NewMemDB() ms := store.NewCommitMultiStore(db) @@ -126,18 +127,19 @@ func CreateTestInputAdvanced( blacklistedAddrs[distrAcc.GetAddress().String()] = true cdc := MakeTestCodec() - pk := params.NewKeeper(params.ModuleCdc, keyParams, tkeyParams) + appCodec := simappcodec.NewAppCodec(cdc) + pk := keeper.NewKeeper(appCodec, keyParams, tkeyParams) ctx := sdk.NewContext(ms, abci.Header{ChainID: "foochainid"}, isCheckTx, log.NewNopLogger()) - accountKeeper := auth.NewAccountKeeper(cdc, keyAcc, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) - bankKeeper := bank.NewBaseKeeper(cdc, keyBank, accountKeeper, pk.Subspace(bank.DefaultParamspace), blacklistedAddrs) + accountKeeper := auth.NewAccountKeeper(appCodec, keyAcc, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) + bankKeeper := bank.NewBaseKeeper(appCodec, keyBank, accountKeeper, pk.Subspace(bank.DefaultParamspace), blacklistedAddrs) maccPerms := map[string][]string{ auth.FeeCollectorName: nil, types.ModuleName: nil, staking.NotBondedPoolName: {supply.Burner, supply.Staking}, staking.BondedPoolName: {supply.Burner, supply.Staking}, } - supplyKeeper := supply.NewKeeper(cdc, keySupply, accountKeeper, bankKeeper, maccPerms) + supplyKeeper := supply.NewKeeper(appCodec, keySupply, accountKeeper, bankKeeper, maccPerms) sk := staking.NewKeeper(staking.ModuleCdc, keyStaking, bankKeeper, supplyKeeper, pk.Subspace(staking.DefaultParamspace)) sk.SetParams(ctx, staking.DefaultParams()) diff --git a/x/distribution/module.go b/x/distribution/module.go index 631d9b956f..dfa1b10244 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -43,14 +43,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { // DefaultGenesis returns default genesis state as raw bytes for the distribution // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the distribution module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) } @@ -132,18 +132,18 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { // InitGenesis performs genesis initialization for the distribution module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.bankKeeper, am.supplyKeeper, am.keeper, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the distribution // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, am.keeper) - return ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock returns the begin blocker for the distribution module. diff --git a/x/distribution/types/codec.go b/x/distribution/types/codec.go index 85412d65c7..0bc8316abf 100644 --- a/x/distribution/types/codec.go +++ b/x/distribution/types/codec.go @@ -4,22 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" ) -type Codec struct { - codec.Marshaler - - // Keep reference to the amino codec to allow backwards compatibility along - // with type, and interface registration. - amino *codec.Codec -} - -func NewCodec(amino *codec.Codec) *Codec { - return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino} -} - -// ---------------------------------------------------------------------------- - -// RegisterCodec registers all the necessary crisis module concrete types and -// interfaces with the provided codec reference. +// RegisterCodec registers the necessary x/distribution interfaces and concrete types +// on the provided Amino codec. These types are used for Amino JSON serialization. func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgWithdrawDelegatorReward{}, "cosmos-sdk/MsgWithdrawDelegationReward", nil) cdc.RegisterConcrete(MsgWithdrawValidatorCommission{}, "cosmos-sdk/MsgWithdrawValidatorCommission", nil) @@ -27,12 +13,20 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(CommunityPoolSpendProposal{}, "cosmos-sdk/CommunityPoolSpendProposal", nil) } -// generic sealed codec to be used throughout module -var ModuleCdc *Codec +var ( + amino = codec.New() + + // ModuleCdc references the global x/distribution 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/distribution and + // defined at the application level. + ModuleCdc = codec.NewHybridCodec(amino) +) func init() { - ModuleCdc = NewCodec(codec.New()) - RegisterCodec(ModuleCdc.amino) - codec.RegisterCrypto(ModuleCdc.amino) - ModuleCdc.amino.Seal() + RegisterCodec(amino) + codec.RegisterCrypto(amino) + amino.Seal() } diff --git a/x/distribution/types/errors.go b/x/distribution/types/errors.go index c06b731b6e..147cfd3203 100644 --- a/x/distribution/types/errors.go +++ b/x/distribution/types/errors.go @@ -6,16 +6,16 @@ import ( // x/distribution module sentinel errors var ( - ErrEmptyDelegatorAddr = sdkerrors.Register(ModuleName, 1, "delegator address is empty") - ErrEmptyWithdrawAddr = sdkerrors.Register(ModuleName, 2, "withdraw address is empty") - ErrEmptyValidatorAddr = sdkerrors.Register(ModuleName, 3, "validator address is empty") - ErrEmptyDelegationDistInfo = sdkerrors.Register(ModuleName, 4, "no delegation distribution info") - ErrNoValidatorDistInfo = sdkerrors.Register(ModuleName, 5, "no validator distribution info") - ErrNoValidatorCommission = sdkerrors.Register(ModuleName, 6, "no validator commission to withdraw") - ErrSetWithdrawAddrDisabled = sdkerrors.Register(ModuleName, 7, "set withdraw address disabled") - ErrBadDistribution = sdkerrors.Register(ModuleName, 8, "community pool does not have sufficient coins to distribute") - ErrInvalidProposalAmount = sdkerrors.Register(ModuleName, 9, "invalid community pool spend proposal amount") - ErrEmptyProposalRecipient = sdkerrors.Register(ModuleName, 10, "invalid community pool spend proposal recipient") - ErrNoValidatorExists = sdkerrors.Register(ModuleName, 11, "validator does not exist") - ErrNoDelegationExists = sdkerrors.Register(ModuleName, 12, "delegation does not exist") + ErrEmptyDelegatorAddr = sdkerrors.Register(ModuleName, 2, "delegator address is empty") + ErrEmptyWithdrawAddr = sdkerrors.Register(ModuleName, 3, "withdraw address is empty") + ErrEmptyValidatorAddr = sdkerrors.Register(ModuleName, 4, "validator address is empty") + ErrEmptyDelegationDistInfo = sdkerrors.Register(ModuleName, 5, "no delegation distribution info") + ErrNoValidatorDistInfo = sdkerrors.Register(ModuleName, 6, "no validator distribution info") + ErrNoValidatorCommission = sdkerrors.Register(ModuleName, 7, "no validator commission to withdraw") + ErrSetWithdrawAddrDisabled = sdkerrors.Register(ModuleName, 8, "set withdraw address disabled") + ErrBadDistribution = sdkerrors.Register(ModuleName, 9, "community pool does not have sufficient coins to distribute") + ErrInvalidProposalAmount = sdkerrors.Register(ModuleName, 10, "invalid community pool spend proposal amount") + ErrEmptyProposalRecipient = sdkerrors.Register(ModuleName, 11, "invalid community pool spend proposal recipient") + ErrNoValidatorExists = sdkerrors.Register(ModuleName, 12, "validator does not exist") + ErrNoDelegationExists = sdkerrors.Register(ModuleName, 13, "delegation does not exist") ) diff --git a/x/distribution/types/params.go b/x/distribution/types/params.go index 12daed847d..33b6b2ca20 100644 --- a/x/distribution/types/params.go +++ b/x/distribution/types/params.go @@ -6,7 +6,7 @@ import ( "gopkg.in/yaml.v2" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/params" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) const ( @@ -23,8 +23,8 @@ var ( ) // ParamKeyTable returns the parameter key table. -func ParamKeyTable() params.KeyTable { - return params.NewKeyTable().RegisterParamSet(&Params{}) +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) } // DefaultParams returns default distribution parameters @@ -43,12 +43,12 @@ func (p Params) String() string { } // ParamSetPairs returns the parameter set pairs. -func (p *Params) ParamSetPairs() params.ParamSetPairs { - return params.ParamSetPairs{ - params.NewParamSetPair(ParamStoreKeyCommunityTax, &p.CommunityTax, validateCommunityTax), - params.NewParamSetPair(ParamStoreKeyBaseProposerReward, &p.BaseProposerReward, validateBaseProposerReward), - params.NewParamSetPair(ParamStoreKeyBonusProposerReward, &p.BonusProposerReward, validateBonusProposerReward), - params.NewParamSetPair(ParamStoreKeyWithdrawAddrEnabled, &p.WithdrawAddrEnabled, validateWithdrawAddrEnabled), +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(ParamStoreKeyCommunityTax, &p.CommunityTax, validateCommunityTax), + paramtypes.NewParamSetPair(ParamStoreKeyBaseProposerReward, &p.BaseProposerReward, validateBaseProposerReward), + paramtypes.NewParamSetPair(ParamStoreKeyBonusProposerReward, &p.BonusProposerReward, validateBonusProposerReward), + paramtypes.NewParamSetPair(ParamStoreKeyWithdrawAddrEnabled, &p.WithdrawAddrEnabled, validateWithdrawAddrEnabled), } } diff --git a/x/distribution/types/types.pb.go b/x/distribution/types/types.pb.go index 21a6dfbee3..0571a985cb 100644 --- a/x/distribution/types/types.pb.go +++ b/x/distribution/types/types.pb.go @@ -4,6 +4,7 @@ package types import ( + bytes "bytes" fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" @@ -746,79 +747,497 @@ func init() { func init() { proto.RegisterFile("x/distribution/types/types.proto", fileDescriptor_9fddf2a8e4a90b09) } var fileDescriptor_9fddf2a8e4a90b09 = []byte{ - // 1110 bytes of a gzipped FileDescriptorProto + // 1113 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x57, 0xcf, 0x6f, 0x1b, 0x45, - 0x1b, 0xf6, 0x38, 0x4e, 0x9a, 0x4c, 0xd3, 0xa4, 0xd9, 0xd8, 0x49, 0xe4, 0x7c, 0x9f, 0xd7, 0x1a, - 0x89, 0x2a, 0x12, 0x8a, 0xd3, 0xd0, 0x5b, 0x0e, 0x48, 0x71, 0x7e, 0x08, 0x50, 0x43, 0xa3, 0x4d, - 0x28, 0x12, 0x12, 0x5a, 0x8d, 0x77, 0x27, 0xf6, 0x28, 0xeb, 0x9d, 0xd5, 0xcc, 0xd8, 0x4e, 0x7a, - 0x41, 0xe2, 0x04, 0x82, 0x22, 0x0e, 0x08, 0x7a, 0xe0, 0xd0, 0x0b, 0x07, 0x2a, 0xfe, 0x0e, 0xd4, - 0x63, 0x6f, 0x20, 0x0e, 0x2e, 0x4a, 0x6e, 0x1c, 0x73, 0x83, 0x13, 0xda, 0x9d, 0xd9, 0x5d, 0xc7, - 0xb1, 0xa8, 0x1d, 0xa9, 0x70, 0x49, 0x32, 0xef, 0xbc, 0xf3, 0x3c, 0xcf, 0x3c, 0x33, 0xf3, 0xbe, - 0x1b, 0x58, 0x3e, 0x59, 0x73, 0xa9, 0x90, 0x9c, 0xd6, 0x5a, 0x92, 0x32, 0x7f, 0x4d, 0x9e, 0x06, - 0x44, 0xa8, 0x9f, 0x95, 0x80, 0x33, 0xc9, 0x8c, 0x65, 0x87, 0x89, 0x26, 0x13, 0xb6, 0x70, 0x8f, - 0x2b, 0x27, 0x15, 0x97, 0x26, 0xb9, 0x95, 0xf6, 0x7a, 0xf1, 0x8e, 0x6c, 0x50, 0xee, 0xda, 0x01, - 0xe6, 0xf2, 0x74, 0x2d, 0xca, 0x5f, 0xab, 0xb3, 0x3a, 0x4b, 0xff, 0x52, 0x20, 0xc5, 0xb9, 0x2b, - 0xb8, 0xe8, 0xcb, 0x2c, 0x2c, 0xec, 0x89, 0xfa, 0x01, 0x91, 0x1f, 0x52, 0xd9, 0x70, 0x39, 0xee, - 0x6c, 0xba, 0x2e, 0x27, 0x42, 0x18, 0x8f, 0xe0, 0x9c, 0x4b, 0x3c, 0x52, 0xc7, 0x92, 0x71, 0x1b, - 0xab, 0xe0, 0x12, 0x28, 0x83, 0x95, 0xe9, 0xea, 0xde, 0x45, 0xd7, 0x5c, 0x3a, 0xc5, 0x4d, 0x6f, - 0x03, 0x5d, 0x49, 0x41, 0x7f, 0x75, 0xcd, 0xd5, 0x3a, 0x95, 0x8d, 0x56, 0xad, 0xe2, 0xb0, 0xe6, - 0x9a, 0xd2, 0xad, 0x7f, 0xad, 0x0a, 0xf7, 0x58, 0xd3, 0x6f, 0x3a, 0x8e, 0x66, 0xb2, 0x6e, 0x27, - 0x20, 0x31, 0x77, 0x07, 0xde, 0xee, 0x68, 0x39, 0x09, 0x75, 0x36, 0xa2, 0xbe, 0x7f, 0xd1, 0x35, - 0x17, 0x15, 0x75, 0x7f, 0xc6, 0x35, 0x98, 0x67, 0x3b, 0x97, 0x37, 0x8d, 0xbe, 0xc9, 0xc2, 0xe2, - 0x9e, 0xa8, 0xc7, 0x5e, 0x6c, 0xc7, 0xc2, 0x2c, 0xd2, 0xc1, 0xdc, 0xfd, 0x4f, 0x3d, 0x79, 0x04, - 0xe7, 0xda, 0xd8, 0xa3, 0xee, 0x25, 0xee, 0x6c, 0x3f, 0xf7, 0x95, 0x94, 0x61, 0xb9, 0x1f, 0x62, - 0x2f, 0xe1, 0x4e, 0x40, 0x62, 0x5b, 0xbe, 0x07, 0xb0, 0xd4, 0x63, 0xcb, 0xc3, 0x78, 0x7e, 0x8b, - 0x35, 0x9b, 0x54, 0x08, 0xca, 0xfc, 0xc1, 0xf2, 0xc0, 0xbf, 0x23, 0xef, 0x67, 0x00, 0xf3, 0x7b, - 0xa2, 0xbe, 0xdb, 0xf2, 0xdd, 0x50, 0x51, 0xcb, 0xa7, 0xf2, 0x74, 0x9f, 0x31, 0xcf, 0xf8, 0x18, - 0x4e, 0xe0, 0x26, 0x6b, 0xf9, 0x72, 0x09, 0x94, 0xc7, 0x56, 0x6e, 0xbe, 0x35, 0x5f, 0xe9, 0x79, - 0x46, 0xed, 0xf5, 0xca, 0x16, 0xa3, 0x7e, 0xf5, 0xee, 0xf3, 0xae, 0x99, 0x79, 0xf6, 0xd2, 0x5c, - 0x19, 0x42, 0x46, 0xb8, 0x40, 0x58, 0x1a, 0xd4, 0x78, 0x00, 0xa7, 0x5c, 0x12, 0x30, 0x41, 0x25, - 0xe3, 0xfa, 0x28, 0xd6, 0x47, 0x3f, 0xea, 0x14, 0x03, 0xfd, 0x32, 0x06, 0x27, 0xf6, 0x31, 0xc7, - 0x4d, 0x61, 0x1c, 0xc3, 0x5b, 0x4e, 0xbc, 0x17, 0x5b, 0xe2, 0x93, 0xc8, 0xcb, 0xa9, 0xea, 0x6e, - 0x28, 0xf6, 0xb7, 0xae, 0x79, 0x67, 0x08, 0x8e, 0x6d, 0xe2, 0x5c, 0x74, 0xcd, 0xbc, 0x72, 0xfe, - 0x12, 0x18, 0xb2, 0xa6, 0x93, 0xf1, 0x21, 0x3e, 0x31, 0x3e, 0x81, 0xf9, 0x1a, 0x16, 0xc4, 0x0e, - 0x38, 0x0b, 0x98, 0x20, 0xdc, 0xe6, 0xd1, 0x7d, 0x8f, 0xf6, 0x34, 0x55, 0xdd, 0x1b, 0x99, 0x73, - 0x59, 0x71, 0x0e, 0xc2, 0x44, 0x96, 0x11, 0x86, 0xf7, 0x75, 0x54, 0x3f, 0xac, 0x4f, 0x01, 0x2c, - 0xd4, 0x98, 0xdf, 0x12, 0x57, 0x24, 0x8c, 0x45, 0x12, 0xde, 0x1f, 0x59, 0xc2, 0xff, 0xb4, 0x84, - 0x41, 0xa0, 0xc8, 0x9a, 0x8f, 0xe2, 0x7d, 0x22, 0x0e, 0x61, 0xe1, 0x52, 0x4d, 0xb1, 0x89, 0x8f, - 0x6b, 0x1e, 0x71, 0x97, 0x72, 0x65, 0xb0, 0x32, 0x59, 0x2d, 0xa7, 0xa8, 0x03, 0xd3, 0x90, 0x35, - 0xdf, 0x5b, 0x4e, 0x76, 0x54, 0x74, 0x23, 0xf7, 0xe4, 0xa9, 0x99, 0x41, 0x9f, 0x67, 0x61, 0x31, - 0x79, 0x36, 0xef, 0x50, 0x21, 0x19, 0xa7, 0x0e, 0xf6, 0x14, 0xb3, 0x30, 0x7e, 0x00, 0x70, 0xd1, - 0x69, 0x35, 0x5b, 0x1e, 0x96, 0xb4, 0x4d, 0xb4, 0x4c, 0x9b, 0x63, 0x49, 0x99, 0xbe, 0xba, 0x0b, - 0x7d, 0x57, 0x77, 0x9b, 0x38, 0xd1, 0xed, 0xfd, 0x20, 0x74, 0xe6, 0xa2, 0x6b, 0x96, 0xf4, 0x31, - 0x0f, 0x06, 0x41, 0xcf, 0x5e, 0x9a, 0x6f, 0x0e, 0xe7, 0x9d, 0xba, 0xe2, 0x85, 0x14, 0x48, 0x69, - 0xb4, 0x42, 0x18, 0x63, 0x0b, 0xce, 0x72, 0x72, 0x44, 0x38, 0xf1, 0x1d, 0x62, 0x3b, 0xd1, 0xcb, - 0x0a, 0xef, 0xc8, 0xad, 0x6a, 0xf1, 0xa2, 0x6b, 0x2e, 0x28, 0x09, 0x7d, 0x09, 0xc8, 0x9a, 0x49, - 0x22, 0x5b, 0x51, 0xe0, 0x09, 0x80, 0x8b, 0x69, 0x09, 0x69, 0x71, 0x4e, 0x7c, 0x19, 0x1b, 0x41, - 0xe0, 0x0d, 0xa5, 0x5b, 0xbc, 0x62, 0xdf, 0xf7, 0xf4, 0xab, 0x1d, 0x69, 0x57, 0x31, 0xb6, 0xb1, - 0x00, 0x27, 0x02, 0xc2, 0x29, 0x53, 0x57, 0x3c, 0x67, 0xe9, 0x11, 0x7a, 0x0c, 0x60, 0x29, 0x91, - 0xb6, 0xe9, 0x68, 0x13, 0x88, 0xdb, 0x53, 0xe8, 0x8e, 0x21, 0x74, 0x92, 0xd1, 0xeb, 0x10, 0xd9, - 0x03, 0x8f, 0xbe, 0x05, 0x70, 0x39, 0xd1, 0xf3, 0xa0, 0x25, 0x85, 0xc4, 0xbe, 0x4b, 0xfd, 0x7a, - 0x6c, 0x57, 0x67, 0x58, 0xbb, 0x76, 0xf4, 0x35, 0x99, 0x89, 0xcf, 0x28, 0x5a, 0x84, 0xae, 0x6b, - 0x20, 0xfa, 0x11, 0xc0, 0xf9, 0x44, 0xd8, 0x81, 0x87, 0x45, 0x63, 0xa7, 0x4d, 0x7c, 0x69, 0xec, - 0xc2, 0xb4, 0x3c, 0xdb, 0xda, 0xe2, 0xb0, 0x72, 0xe5, 0xaa, 0xcb, 0x69, 0xe7, 0xee, 0xcf, 0x40, - 0xd6, 0x6c, 0x12, 0xda, 0x8f, 0x22, 0xc6, 0x7b, 0x70, 0xf2, 0x88, 0x63, 0x27, 0xfc, 0xc2, 0xd1, - 0x55, 0xa8, 0x32, 0x5a, 0x09, 0xb0, 0x92, 0xf5, 0xe8, 0x27, 0x00, 0xf3, 0x03, 0xb4, 0x0a, 0xe3, - 0x31, 0x80, 0x0b, 0xa9, 0x16, 0x11, 0xce, 0xd8, 0x24, 0x9a, 0xd2, 0x6e, 0xde, 0xad, 0xfc, 0xc3, - 0x67, 0x57, 0x65, 0x00, 0x66, 0xf5, 0x0d, 0xed, 0xf3, 0xff, 0xfb, 0x77, 0xda, 0x8b, 0x8e, 0xac, - 0x7c, 0x7b, 0x80, 0x1e, 0x5d, 0x2a, 0xbe, 0x03, 0xf0, 0xc6, 0x2e, 0x21, 0x51, 0x03, 0xfb, 0x02, - 0xc0, 0x99, 0xb4, 0x72, 0x07, 0x8c, 0x79, 0xaf, 0x38, 0xe7, 0xfb, 0x9a, 0xbf, 0xd0, 0x5f, 0xf5, - 0xc3, 0xb5, 0x23, 0x1f, 0x77, 0xda, 0x82, 0x42, 0x35, 0xe8, 0xab, 0x2c, 0x2c, 0x5e, 0x6a, 0xb0, - 0x07, 0x01, 0xf1, 0x5d, 0x55, 0x45, 0xb1, 0x67, 0xe4, 0xe1, 0xb8, 0xa4, 0xd2, 0x23, 0xaa, 0x55, - 0x59, 0x6a, 0x60, 0x94, 0xe1, 0x4d, 0x97, 0x08, 0x87, 0xd3, 0x20, 0x3d, 0x4c, 0xab, 0x37, 0x14, - 0xb6, 0x51, 0x4e, 0x1c, 0x1a, 0x50, 0xe2, 0xcb, 0xa8, 0xde, 0x5f, 0xaf, 0x8d, 0x26, 0x18, 0x3d, - 0x6d, 0x3f, 0xf7, 0x1a, 0xda, 0xfe, 0xc6, 0xe4, 0x67, 0x4f, 0xcd, 0x4c, 0x74, 0x54, 0x7f, 0x02, - 0x58, 0x48, 0xbe, 0x11, 0x0f, 0x24, 0xe6, 0x92, 0xfa, 0xf5, 0x77, 0xfd, 0xa3, 0xa8, 0x50, 0x06, - 0x9c, 0xb4, 0x29, 0x0b, 0xbb, 0x4f, 0xef, 0x33, 0xe8, 0x29, 0x94, 0x7d, 0x09, 0xc8, 0x9a, 0x89, - 0x23, 0xfa, 0x11, 0x1c, 0xc2, 0x71, 0x21, 0xf1, 0x31, 0xd1, 0x2f, 0xe0, 0xed, 0x91, 0x9b, 0xe0, - 0xb4, 0x22, 0x8a, 0x40, 0x90, 0xa5, 0xc0, 0x8c, 0x1d, 0x38, 0xd1, 0x20, 0xb4, 0xde, 0x50, 0x5e, - 0xe7, 0xaa, 0xab, 0x7f, 0x74, 0xcd, 0x59, 0x87, 0x93, 0xb0, 0xc0, 0xfb, 0xb6, 0x9a, 0x4a, 0x45, - 0xf6, 0x4d, 0x20, 0x4b, 0x2f, 0xae, 0x9a, 0xcf, 0xcf, 0x4a, 0xe0, 0xc5, 0x59, 0x09, 0xfc, 0x7e, - 0x56, 0x02, 0x5f, 0x9f, 0x97, 0x32, 0x2f, 0xce, 0x4b, 0x99, 0x5f, 0xcf, 0x4b, 0x99, 0x8f, 0xc6, - 0x23, 0x09, 0xb5, 0x89, 0xe8, 0x3f, 0x8c, 0x7b, 0x7f, 0x07, 0x00, 0x00, 0xff, 0xff, 0x2c, 0xac, - 0x10, 0x4b, 0xdd, 0x0c, 0x00, 0x00, + 0x14, 0xf6, 0x38, 0x4e, 0x9a, 0x4c, 0xd3, 0xa4, 0xd9, 0xd8, 0x49, 0xe4, 0x80, 0xd7, 0x1a, 0x44, + 0x15, 0x09, 0xc5, 0x69, 0xe8, 0x2d, 0x07, 0xa4, 0x38, 0x3f, 0x04, 0xa8, 0xa1, 0xd1, 0x26, 0x14, + 0x09, 0x09, 0xad, 0xc6, 0xbb, 0x13, 0x7b, 0x94, 0xf5, 0xce, 0x6a, 0x66, 0x6c, 0x27, 0xbd, 0x20, + 0x71, 0x02, 0x41, 0x11, 0x07, 0x04, 0x3d, 0x70, 0xe8, 0x05, 0x09, 0x2a, 0xfe, 0x0e, 0xd4, 0x63, + 0x6f, 0x20, 0x0e, 0x2e, 0x4a, 0x6e, 0x1c, 0x73, 0x83, 0x13, 0xda, 0x9d, 0xd9, 0x5d, 0xc7, 0xb1, + 0x68, 0x1c, 0xa9, 0xf4, 0x92, 0x64, 0xde, 0xbc, 0xf9, 0xbe, 0x6f, 0xbe, 0x99, 0x79, 0x6f, 0x03, + 0xcb, 0x47, 0x2b, 0x2e, 0x15, 0x92, 0xd3, 0x5a, 0x4b, 0x52, 0xe6, 0xaf, 0xc8, 0xe3, 0x80, 0x08, + 0xf5, 0xb3, 0x12, 0x70, 0x26, 0x99, 0xb1, 0xe8, 0x30, 0xd1, 0x64, 0xc2, 0x16, 0xee, 0x61, 0xe5, + 0xa8, 0xe2, 0xd2, 0x24, 0xb7, 0xd2, 0x5e, 0x2d, 0xde, 0x92, 0x0d, 0xca, 0x5d, 0x3b, 0xc0, 0x5c, + 0x1e, 0xaf, 0x44, 0xf9, 0x2b, 0x75, 0x56, 0x67, 0xe9, 0x5f, 0x0a, 0xa4, 0x38, 0x73, 0x01, 0x17, + 0x7d, 0x95, 0x85, 0x85, 0x1d, 0x51, 0xdf, 0x23, 0xf2, 0x23, 0x2a, 0x1b, 0x2e, 0xc7, 0x9d, 0x75, + 0xd7, 0xe5, 0x44, 0x08, 0xe3, 0x01, 0x9c, 0x71, 0x89, 0x47, 0xea, 0x58, 0x32, 0x6e, 0x63, 0x15, + 0x5c, 0x00, 0x65, 0xb0, 0x34, 0x59, 0xdd, 0x39, 0xeb, 0x9a, 0x0b, 0xc7, 0xb8, 0xe9, 0xad, 0xa1, + 0x0b, 0x29, 0xe8, 0x9f, 0xae, 0xb9, 0x5c, 0xa7, 0xb2, 0xd1, 0xaa, 0x55, 0x1c, 0xd6, 0x5c, 0x51, + 0xba, 0xf5, 0xaf, 0x65, 0xe1, 0x1e, 0x6a, 0xfa, 0x75, 0xc7, 0xd1, 0x4c, 0xd6, 0xcd, 0x04, 0x24, + 0xe6, 0xee, 0xc0, 0x9b, 0x1d, 0x2d, 0x27, 0xa1, 0xce, 0x46, 0xd4, 0x77, 0xcf, 0xba, 0xe6, 0xbc, + 0xa2, 0xee, 0xcf, 0xb8, 0x02, 0xf3, 0x74, 0xe7, 0xfc, 0xa6, 0xd1, 0xb7, 0x59, 0x58, 0xdc, 0x11, + 0xf5, 0xd8, 0x8b, 0xcd, 0x58, 0x98, 0x45, 0x3a, 0x98, 0xbb, 0xaf, 0xd4, 0x93, 0x07, 0x70, 0xa6, + 0x8d, 0x3d, 0xea, 0x9e, 0xe3, 0xce, 0xf6, 0x73, 0x5f, 0x48, 0xb9, 0x2c, 0xf7, 0x7d, 0xec, 0x25, + 0xdc, 0x09, 0x48, 0x6c, 0xcb, 0x0f, 0x00, 0x96, 0x7a, 0x6c, 0xb9, 0x1f, 0xcf, 0x6f, 0xb0, 0x66, + 0x93, 0x0a, 0x41, 0x99, 0x3f, 0x58, 0x1e, 0xf8, 0x7f, 0xe4, 0xfd, 0x0a, 0x60, 0x7e, 0x47, 0xd4, + 0xb7, 0x5b, 0xbe, 0x1b, 0x2a, 0x6a, 0xf9, 0x54, 0x1e, 0xef, 0x32, 0xe6, 0x19, 0x9f, 0xc0, 0x31, + 0xdc, 0x64, 0x2d, 0x5f, 0x2e, 0x80, 0xf2, 0xc8, 0xd2, 0xf5, 0xb7, 0x67, 0x2b, 0x3d, 0xcf, 0xa8, + 0xbd, 0x5a, 0xd9, 0x60, 0xd4, 0xaf, 0xde, 0x7e, 0xda, 0x35, 0x33, 0x4f, 0x9e, 0x9b, 0x4b, 0x97, + 0x90, 0x11, 0x2e, 0x10, 0x96, 0x06, 0x35, 0xee, 0xc1, 0x09, 0x97, 0x04, 0x4c, 0x50, 0xc9, 0xb8, + 0x3e, 0x8a, 0xd5, 0xe1, 0x8f, 0x3a, 0xc5, 0x40, 0xbf, 0x8d, 0xc0, 0xb1, 0x5d, 0xcc, 0x71, 0x53, + 0x18, 0x87, 0xf0, 0x86, 0x13, 0xef, 0xc5, 0x96, 0xf8, 0x28, 0xf2, 0x72, 0xa2, 0xba, 0x1d, 0x8a, + 0xfd, 0xa3, 0x6b, 0xde, 0xba, 0x04, 0xc7, 0x26, 0x71, 0xce, 0xba, 0x66, 0x5e, 0x39, 0x7f, 0x0e, + 0x0c, 0x59, 0x93, 0xc9, 0x78, 0x1f, 0x1f, 0x19, 0x9f, 0xc2, 0x7c, 0x0d, 0x0b, 0x62, 0x07, 0x9c, + 0x05, 0x4c, 0x10, 0x6e, 0xf3, 0xe8, 0xbe, 0x47, 0x7b, 0x9a, 0xa8, 0xee, 0x0c, 0xcd, 0xb9, 0xa8, + 0x38, 0x07, 0x61, 0x22, 0xcb, 0x08, 0xc3, 0xbb, 0x3a, 0xaa, 0x1f, 0xd6, 0x67, 0x00, 0x16, 0x6a, + 0xcc, 0x6f, 0x89, 0x0b, 0x12, 0x46, 0x22, 0x09, 0x1f, 0x0c, 0x2d, 0xe1, 0x35, 0x2d, 0x61, 0x10, + 0x28, 0xb2, 0x66, 0xa3, 0x78, 0x9f, 0x88, 0x7d, 0x58, 0x38, 0x57, 0x53, 0x6c, 0xe2, 0xe3, 0x9a, + 0x47, 0xdc, 0x85, 0x5c, 0x19, 0x2c, 0x8d, 0x57, 0xcb, 0x29, 0xea, 0xc0, 0x34, 0x64, 0xcd, 0xf6, + 0x96, 0x93, 0x2d, 0x15, 0x5d, 0xcb, 0x3d, 0x7a, 0x6c, 0x66, 0xd0, 0x17, 0x59, 0x58, 0x4c, 0x9e, + 0xcd, 0xbb, 0x54, 0x48, 0xc6, 0xa9, 0x83, 0x3d, 0xc5, 0x2c, 0x8c, 0x1f, 0x01, 0x9c, 0x77, 0x5a, + 0xcd, 0x96, 0x87, 0x25, 0x6d, 0x13, 0x2d, 0xd3, 0xe6, 0x58, 0x52, 0xa6, 0xaf, 0xee, 0x5c, 0xdf, + 0xd5, 0xdd, 0x24, 0x4e, 0x74, 0x7b, 0x3f, 0x0c, 0x9d, 0x39, 0xeb, 0x9a, 0x25, 0x7d, 0xcc, 0x83, + 0x41, 0xd0, 0x93, 0xe7, 0xe6, 0x5b, 0x97, 0xf3, 0x4e, 0x5d, 0xf1, 0x42, 0x0a, 0xa4, 0x34, 0x5a, + 0x21, 0x8c, 0xb1, 0x01, 0xa7, 0x39, 0x39, 0x20, 0x9c, 0xf8, 0x0e, 0xb1, 0x9d, 0xe8, 0x65, 0x85, + 0x77, 0xe4, 0x46, 0xb5, 0x78, 0xd6, 0x35, 0xe7, 0x94, 0x84, 0xbe, 0x04, 0x64, 0x4d, 0x25, 0x91, + 0x8d, 0x28, 0xf0, 0x08, 0xc0, 0xf9, 0xb4, 0x84, 0xb4, 0x38, 0x27, 0xbe, 0x8c, 0x8d, 0x20, 0xf0, + 0x9a, 0xd2, 0x2d, 0x5e, 0xb0, 0xef, 0x3b, 0xfa, 0xd5, 0x0e, 0xb5, 0xab, 0x18, 0xdb, 0x98, 0x83, + 0x63, 0x01, 0xe1, 0x94, 0xa9, 0x2b, 0x9e, 0xb3, 0xf4, 0x08, 0x3d, 0x04, 0xb0, 0x94, 0x48, 0x5b, + 0x77, 0xb4, 0x09, 0xc4, 0xed, 0x29, 0x74, 0x87, 0x10, 0x3a, 0xc9, 0xe8, 0x65, 0x88, 0xec, 0x81, + 0x47, 0xdf, 0x01, 0xb8, 0x98, 0xe8, 0xb9, 0xd7, 0x92, 0x42, 0x62, 0xdf, 0xa5, 0x7e, 0x3d, 0xb6, + 0xab, 0x73, 0x59, 0xbb, 0xb6, 0xf4, 0x35, 0x99, 0x8a, 0xcf, 0x28, 0x5a, 0x84, 0xae, 0x6a, 0x20, + 0xfa, 0x19, 0xc0, 0xd9, 0x44, 0xd8, 0x9e, 0x87, 0x45, 0x63, 0xab, 0x4d, 0x7c, 0x69, 0x6c, 0xc3, + 0xb4, 0x3c, 0xdb, 0xda, 0xe2, 0xb0, 0x72, 0xe5, 0xaa, 0x8b, 0x69, 0xe7, 0xee, 0xcf, 0x40, 0xd6, + 0x74, 0x12, 0xda, 0x8d, 0x22, 0xc6, 0xfb, 0x70, 0xfc, 0x80, 0x63, 0x27, 0xfc, 0xc2, 0xd1, 0x55, + 0xa8, 0x32, 0x5c, 0x09, 0xb0, 0x92, 0xf5, 0xe8, 0x17, 0x00, 0xf3, 0x03, 0xb4, 0x0a, 0xe3, 0x21, + 0x80, 0x73, 0xa9, 0x16, 0x11, 0xce, 0xd8, 0x24, 0x9a, 0xd2, 0x6e, 0xde, 0xae, 0xfc, 0xc7, 0x67, + 0x57, 0x65, 0x00, 0x66, 0xf5, 0x4d, 0xed, 0xf3, 0xeb, 0xfd, 0x3b, 0xed, 0x45, 0x47, 0x56, 0xbe, + 0x3d, 0x40, 0x8f, 0x2e, 0x15, 0xdf, 0x03, 0x78, 0x6d, 0x9b, 0x90, 0xa8, 0x81, 0x7d, 0x09, 0xe0, + 0x54, 0x5a, 0xb9, 0x03, 0xc6, 0xbc, 0x17, 0x9c, 0xf3, 0x5d, 0xcd, 0x5f, 0xe8, 0xaf, 0xfa, 0xe1, + 0xda, 0xa1, 0x8f, 0x3b, 0x6d, 0x41, 0xa1, 0x1a, 0xf4, 0x75, 0x16, 0x16, 0xcf, 0x35, 0xd8, 0xbd, + 0x80, 0xf8, 0xae, 0xaa, 0xa2, 0xd8, 0x33, 0xf2, 0x70, 0x54, 0x52, 0xe9, 0x11, 0xd5, 0xaa, 0x2c, + 0x35, 0x30, 0xca, 0xf0, 0xba, 0x4b, 0x84, 0xc3, 0x69, 0x90, 0x1e, 0xa6, 0xd5, 0x1b, 0x0a, 0xdb, + 0x28, 0x27, 0x0e, 0x0d, 0x28, 0xf1, 0x65, 0x54, 0xef, 0xaf, 0xd6, 0x46, 0x13, 0x8c, 0x9e, 0xb6, + 0x9f, 0x7b, 0x09, 0x6d, 0x7f, 0x6d, 0xfc, 0xf3, 0xc7, 0x66, 0x26, 0x3a, 0xaa, 0xbf, 0x01, 0x2c, + 0x24, 0xdf, 0x88, 0x7b, 0x12, 0x73, 0x49, 0xfd, 0xfa, 0x7b, 0xfe, 0x41, 0x54, 0x28, 0x03, 0x4e, + 0xda, 0x94, 0x85, 0xdd, 0xa7, 0xf7, 0x19, 0xf4, 0x14, 0xca, 0xbe, 0x04, 0x64, 0x4d, 0xc5, 0x11, + 0xfd, 0x08, 0xf6, 0xe1, 0xa8, 0x90, 0xf8, 0x90, 0xe8, 0x17, 0xf0, 0xce, 0xd0, 0x4d, 0x70, 0x52, + 0x11, 0x45, 0x20, 0xc8, 0x52, 0x60, 0xc6, 0x16, 0x1c, 0x6b, 0x10, 0x5a, 0x6f, 0x28, 0xaf, 0x73, + 0xd5, 0xe5, 0xbf, 0xba, 0xe6, 0xb4, 0xc3, 0x49, 0x58, 0xe0, 0x7d, 0x5b, 0x4d, 0xa5, 0x22, 0xfb, + 0x26, 0x90, 0xa5, 0x17, 0x57, 0xdf, 0xf8, 0xe9, 0xa4, 0x04, 0x9e, 0x9e, 0x94, 0xc0, 0xb3, 0x93, + 0x12, 0xf8, 0xf3, 0xa4, 0x04, 0xbe, 0x39, 0x2d, 0x65, 0x9e, 0x9d, 0x96, 0x32, 0xbf, 0x9f, 0x96, + 0x32, 0x1f, 0x8f, 0x46, 0x32, 0x6a, 0x63, 0xd1, 0x7f, 0x19, 0x77, 0xfe, 0x0d, 0x00, 0x00, 0xff, + 0xff, 0x7b, 0x35, 0xec, 0x82, 0xe1, 0x0c, 0x00, 0x00, } +func (this *MsgSetWithdrawAddress) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgSetWithdrawAddress) + if !ok { + that2, ok := that.(MsgSetWithdrawAddress) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.DelegatorAddress, that1.DelegatorAddress) { + return false + } + if !bytes.Equal(this.WithdrawAddress, that1.WithdrawAddress) { + return false + } + return true +} +func (this *MsgWithdrawDelegatorReward) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgWithdrawDelegatorReward) + if !ok { + that2, ok := that.(MsgWithdrawDelegatorReward) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.DelegatorAddress, that1.DelegatorAddress) { + return false + } + if !bytes.Equal(this.ValidatorAddress, that1.ValidatorAddress) { + return false + } + return true +} +func (this *MsgWithdrawValidatorCommission) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgWithdrawValidatorCommission) + if !ok { + that2, ok := that.(MsgWithdrawValidatorCommission) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.ValidatorAddress, that1.ValidatorAddress) { + return false + } + return true +} +func (this *MsgFundCommunityPool) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgFundCommunityPool) + if !ok { + that2, ok := that.(MsgFundCommunityPool) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Amount) != len(that1.Amount) { + return false + } + for i := range this.Amount { + if !this.Amount[i].Equal(&that1.Amount[i]) { + return false + } + } + if !bytes.Equal(this.Depositor, that1.Depositor) { + return false + } + return true +} +func (this *Params) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Params) + if !ok { + that2, ok := that.(Params) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.CommunityTax.Equal(that1.CommunityTax) { + return false + } + if !this.BaseProposerReward.Equal(that1.BaseProposerReward) { + return false + } + if !this.BonusProposerReward.Equal(that1.BonusProposerReward) { + return false + } + if this.WithdrawAddrEnabled != that1.WithdrawAddrEnabled { + return false + } + return true +} +func (this *ValidatorHistoricalRewards) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ValidatorHistoricalRewards) + if !ok { + that2, ok := that.(ValidatorHistoricalRewards) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.CumulativeRewardRatio) != len(that1.CumulativeRewardRatio) { + return false + } + for i := range this.CumulativeRewardRatio { + if !this.CumulativeRewardRatio[i].Equal(&that1.CumulativeRewardRatio[i]) { + return false + } + } + if this.ReferenceCount != that1.ReferenceCount { + return false + } + return true +} +func (this *ValidatorCurrentRewards) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ValidatorCurrentRewards) + if !ok { + that2, ok := that.(ValidatorCurrentRewards) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Rewards) != len(that1.Rewards) { + return false + } + for i := range this.Rewards { + if !this.Rewards[i].Equal(&that1.Rewards[i]) { + return false + } + } + if this.Period != that1.Period { + return false + } + return true +} +func (this *ValidatorAccumulatedCommission) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ValidatorAccumulatedCommission) + if !ok { + that2, ok := that.(ValidatorAccumulatedCommission) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Commission) != len(that1.Commission) { + return false + } + for i := range this.Commission { + if !this.Commission[i].Equal(&that1.Commission[i]) { + return false + } + } + return true +} +func (this *ValidatorOutstandingRewards) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ValidatorOutstandingRewards) + if !ok { + that2, ok := that.(ValidatorOutstandingRewards) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Rewards) != len(that1.Rewards) { + return false + } + for i := range this.Rewards { + if !this.Rewards[i].Equal(&that1.Rewards[i]) { + return false + } + } + return true +} +func (this *ValidatorSlashEvent) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ValidatorSlashEvent) + if !ok { + that2, ok := that.(ValidatorSlashEvent) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.ValidatorPeriod != that1.ValidatorPeriod { + return false + } + if !this.Fraction.Equal(that1.Fraction) { + return false + } + return true +} +func (this *ValidatorSlashEvents) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ValidatorSlashEvents) + if !ok { + that2, ok := that.(ValidatorSlashEvents) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.ValidatorSlashEvents) != len(that1.ValidatorSlashEvents) { + return false + } + for i := range this.ValidatorSlashEvents { + if !this.ValidatorSlashEvents[i].Equal(&that1.ValidatorSlashEvents[i]) { + return false + } + } + return true +} +func (this *FeePool) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*FeePool) + if !ok { + that2, ok := that.(FeePool) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.CommunityPool) != len(that1.CommunityPool) { + return false + } + for i := range this.CommunityPool { + if !this.CommunityPool[i].Equal(&that1.CommunityPool[i]) { + return false + } + } + return true +} +func (this *CommunityPoolSpendProposal) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*CommunityPoolSpendProposal) + if !ok { + that2, ok := that.(CommunityPoolSpendProposal) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Title != that1.Title { + return false + } + if this.Description != that1.Description { + return false + } + if !bytes.Equal(this.Recipient, that1.Recipient) { + return false + } + if len(this.Amount) != len(that1.Amount) { + return false + } + for i := range this.Amount { + if !this.Amount[i].Equal(&that1.Amount[i]) { + return false + } + } + return true +} +func (this *DelegatorStartingInfo) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*DelegatorStartingInfo) + if !ok { + that2, ok := that.(DelegatorStartingInfo) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.PreviousPeriod != that1.PreviousPeriod { + return false + } + if !this.Stake.Equal(that1.Stake) { + return false + } + if this.Height != that1.Height { + return false + } + return true +} func (m *MsgSetWithdrawAddress) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) diff --git a/x/distribution/types/types.proto b/x/distribution/types/types.proto index be398e0912..a783be13f5 100644 --- a/x/distribution/types/types.proto +++ b/x/distribution/types/types.proto @@ -1,7 +1,8 @@ syntax = "proto3"; package cosmos_sdk.x.ditribution.v1; -option go_package = "types"; +option go_package = "types"; +option (gogoproto.equal_all) = true; import "third_party/proto/gogoproto/gogo.proto"; import "types/types.proto"; @@ -175,8 +176,6 @@ message DelegatorStartingInfo { (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false ]; - uint64 height = 3 [ - (gogoproto.moretags) = "yaml:\"creation_height\"", - (gogoproto.jsontag) = "creation_height" - ]; + uint64 height = 3 + [(gogoproto.moretags) = "yaml:\"creation_height\"", (gogoproto.jsontag) = "creation_height"]; } diff --git a/x/evidence/alias.go b/x/evidence/alias.go index 29b8447a36..395d8a3661 100644 --- a/x/evidence/alias.go +++ b/x/evidence/alias.go @@ -1,8 +1,8 @@ package evidence import ( - "github.com/cosmos/cosmos-sdk/x/evidence/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" + "github.com/cosmos/cosmos-sdk/x/evidence/keeper" + "github.com/cosmos/cosmos-sdk/x/evidence/types" ) // nolint @@ -27,12 +27,11 @@ var ( NewKeeper = keeper.NewKeeper NewQuerier = keeper.NewQuerier - NewMsgSubmitEvidence = types.NewMsgSubmitEvidence + NewMsgSubmitEvidenceBase = types.NewMsgSubmitEvidenceBase NewRouter = types.NewRouter NewQueryEvidenceParams = types.NewQueryEvidenceParams NewQueryAllEvidenceParams = types.NewQueryAllEvidenceParams RegisterCodec = types.RegisterCodec - RegisterEvidenceTypeCodec = types.RegisterEvidenceTypeCodec ModuleCdc = types.ModuleCdc NewGenesisState = types.NewGenesisState DefaultGenesisState = types.DefaultGenesisState @@ -40,14 +39,19 @@ var ( KeyMaxEvidenceAge = types.KeyMaxEvidenceAge DoubleSignJailEndTime = types.DoubleSignJailEndTime ParamKeyTable = types.ParamKeyTable + ErrNoEvidenceHandlerExists = types.ErrNoEvidenceHandlerExists + ErrInvalidEvidence = types.ErrInvalidEvidence + ErrNoEvidenceExists = types.ErrNoEvidenceExists + ErrEvidenceExists = types.ErrEvidenceExists ) type ( Keeper = keeper.Keeper - GenesisState = types.GenesisState - MsgSubmitEvidence = types.MsgSubmitEvidence - Handler = types.Handler - Router = types.Router - Equivocation = types.Equivocation + GenesisState = types.GenesisState + MsgSubmitEvidenceBase = types.MsgSubmitEvidenceBase + Handler = types.Handler + Router = types.Router + Equivocation = types.Equivocation + Codec = types.Codec ) diff --git a/x/evidence/client/cli/query.go b/x/evidence/client/cli/query.go index da09ae7b4b..141711ab7a 100644 --- a/x/evidence/client/cli/query.go +++ b/x/evidence/client/cli/query.go @@ -14,7 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/evidence/exported" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" + "github.com/cosmos/cosmos-sdk/x/evidence/types" ) // GetQueryCmd returns the CLI command with all evidence module query commands diff --git a/x/evidence/client/cli/tx.go b/x/evidence/client/cli/tx.go index b97b56c0a2..c14c3d5d05 100644 --- a/x/evidence/client/cli/tx.go +++ b/x/evidence/client/cli/tx.go @@ -4,7 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" + "github.com/cosmos/cosmos-sdk/x/evidence/types" "github.com/spf13/cobra" ) diff --git a/x/evidence/client/rest/query.go b/x/evidence/client/rest/query.go index 45b66660ac..24fc811eb5 100644 --- a/x/evidence/client/rest/query.go +++ b/x/evidence/client/rest/query.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" + "github.com/cosmos/cosmos-sdk/x/evidence/types" "github.com/gorilla/mux" ) diff --git a/x/evidence/exported/evidence.go b/x/evidence/exported/evidence.go index 55b9ef1671..b8b6d9ef39 100644 --- a/x/evidence/exported/evidence.go +++ b/x/evidence/exported/evidence.go @@ -27,3 +27,13 @@ type Evidence interface { // The total validator set power at time of infraction GetTotalPower() int64 } + +// MsgSubmitEvidence defines the specific interface a concrete message must +// implement in order to process submitted evidence. The concrete MsgSubmitEvidence +// must be defined at the application-level. +type MsgSubmitEvidence interface { + sdk.Msg + + GetEvidence() Evidence + GetSubmitter() sdk.AccAddress +} diff --git a/x/evidence/genesis_test.go b/x/evidence/genesis_test.go index 10a8a2c757..83e9e26bf2 100644 --- a/x/evidence/genesis_test.go +++ b/x/evidence/genesis_test.go @@ -3,16 +3,16 @@ package evidence_test import ( "testing" + "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/ed25519" + "github.com/tendermint/tendermint/types/time" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/evidence" "github.com/cosmos/cosmos-sdk/x/evidence/exported" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" - - "github.com/stretchr/testify/suite" + "github.com/cosmos/cosmos-sdk/x/evidence/types" ) type GenesisTestSuite struct { @@ -26,20 +26,8 @@ func (suite *GenesisTestSuite) SetupTest() { checkTx := false app := simapp.Setup(checkTx) - // get the app's codec and register custom testing types - cdc := app.Codec() - cdc.RegisterConcrete(types.TestEquivocationEvidence{}, "test/TestEquivocationEvidence", nil) - - // recreate keeper in order to use custom testing types - evidenceKeeper := evidence.NewKeeper( - cdc, app.GetKey(evidence.StoreKey), app.GetSubspace(evidence.ModuleName), app.StakingKeeper, app.SlashingKeeper, - ) - router := evidence.NewRouter() - router = router.AddRoute(types.TestEvidenceRouteEquivocation, types.TestEquivocationHandler(*evidenceKeeper)) - evidenceKeeper.SetRouter(router) - suite.ctx = app.BaseApp.NewContext(checkTx, abci.Header{Height: 1}) - suite.keeper = *evidenceKeeper + suite.keeper = app.EvidenceKeeper } func (suite *GenesisTestSuite) TestInitGenesis_Valid() { @@ -47,21 +35,11 @@ func (suite *GenesisTestSuite) TestInitGenesis_Valid() { testEvidence := make([]exported.Evidence, 100) for i := 0; i < 100; i++ { - sv := types.TestVote{ - ValidatorAddress: pk.PubKey().Address(), - Height: int64(i), - Round: 0, - } - sig, err := pk.Sign(sv.SignBytes("test-chain")) - suite.NoError(err) - sv.Signature = sig - - testEvidence[i] = types.TestEquivocationEvidence{ - Power: 100, - TotalPower: 100000, - PubKey: pk.PubKey(), - VoteA: sv, - VoteB: sv, + testEvidence[i] = types.Equivocation{ + Height: int64(i + 1), + Power: 100, + Time: time.Now().UTC(), + ConsensusAddress: pk.PubKey().Address().Bytes(), } } @@ -80,21 +58,10 @@ func (suite *GenesisTestSuite) TestInitGenesis_Invalid() { testEvidence := make([]exported.Evidence, 100) for i := 0; i < 100; i++ { - sv := types.TestVote{ - ValidatorAddress: pk.PubKey().Address(), - Height: int64(i), - Round: 0, - } - sig, err := pk.Sign(sv.SignBytes("test-chain")) - suite.NoError(err) - sv.Signature = sig - - testEvidence[i] = types.TestEquivocationEvidence{ - Power: 100, - TotalPower: 100000, - PubKey: pk.PubKey(), - VoteA: sv, - VoteB: types.TestVote{Height: 10, Round: 1}, + testEvidence[i] = types.Equivocation{ + Power: 100, + Time: time.Now().UTC(), + ConsensusAddress: pk.PubKey().Address().Bytes(), } } diff --git a/x/evidence/handler.go b/x/evidence/handler.go index d5af1206bc..e7b83eb190 100644 --- a/x/evidence/handler.go +++ b/x/evidence/handler.go @@ -3,6 +3,7 @@ package evidence import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/evidence/exported" ) func NewHandler(k Keeper) sdk.Handler { @@ -10,17 +11,23 @@ func NewHandler(k Keeper) sdk.Handler { ctx = ctx.WithEventManager(sdk.NewEventManager()) switch msg := msg.(type) { - case MsgSubmitEvidence: - return handleMsgSubmitEvidence(ctx, k, msg) + case MsgSubmitEvidenceBase: + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "%T must be extended to support evidence", msg) default: + msgSubEv, ok := msg.(exported.MsgSubmitEvidence) + if ok { + return handleMsgSubmitEvidence(ctx, k, msgSubEv) + } + return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg) } } } -func handleMsgSubmitEvidence(ctx sdk.Context, k Keeper, msg MsgSubmitEvidence) (*sdk.Result, error) { - if err := k.SubmitEvidence(ctx, msg.Evidence); err != nil { +func handleMsgSubmitEvidence(ctx sdk.Context, k Keeper, msg exported.MsgSubmitEvidence) (*sdk.Result, error) { + evidence := msg.GetEvidence() + if err := k.SubmitEvidence(ctx, evidence); err != nil { return nil, err } @@ -28,12 +35,12 @@ func handleMsgSubmitEvidence(ctx sdk.Context, k Keeper, msg MsgSubmitEvidence) ( sdk.NewEvent( sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyModule, AttributeValueCategory), - sdk.NewAttribute(sdk.AttributeKeySender, msg.Submitter.String()), + sdk.NewAttribute(sdk.AttributeKeySender, msg.GetSubmitter().String()), ), ) return &sdk.Result{ - Data: msg.Evidence.Hash(), + Data: evidence.Hash(), Events: ctx.EventManager().Events(), }, nil } diff --git a/x/evidence/handler_test.go b/x/evidence/handler_test.go index e5798bd014..2d766e9d8f 100644 --- a/x/evidence/handler_test.go +++ b/x/evidence/handler_test.go @@ -1,102 +1,118 @@ package evidence_test import ( + "fmt" "testing" - - "github.com/cosmos/cosmos-sdk/simapp" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/evidence" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" + "time" "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/ed25519" + + "github.com/cosmos/cosmos-sdk/simapp" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/evidence" + "github.com/cosmos/cosmos-sdk/x/evidence/exported" + "github.com/cosmos/cosmos-sdk/x/evidence/types" ) type HandlerTestSuite struct { suite.Suite - ctx sdk.Context handler sdk.Handler - keeper evidence.Keeper + app *simapp.SimApp +} + +func testEquivocationHandler(k interface{}) types.Handler { + return func(ctx sdk.Context, e exported.Evidence) error { + if err := e.ValidateBasic(); err != nil { + return err + } + + ee, ok := e.(*types.Equivocation) + if !ok { + return fmt.Errorf("unexpected evidence type: %T", e) + } + if ee.Height%2 == 0 { + return fmt.Errorf("unexpected even evidence height: %d", ee.Height) + } + + return nil + } } func (suite *HandlerTestSuite) SetupTest() { checkTx := false app := simapp.Setup(checkTx) - // get the app's codec and register custom testing types - cdc := app.Codec() - cdc.RegisterConcrete(types.TestEquivocationEvidence{}, "test/TestEquivocationEvidence", nil) - // recreate keeper in order to use custom testing types evidenceKeeper := evidence.NewKeeper( - cdc, app.GetKey(evidence.StoreKey), app.GetSubspace(evidence.ModuleName), app.StakingKeeper, app.SlashingKeeper, + simappcodec.NewAppCodec(app.Codec()), app.GetKey(evidence.StoreKey), + app.GetSubspace(evidence.ModuleName), app.StakingKeeper, app.SlashingKeeper, ) router := evidence.NewRouter() - router = router.AddRoute(types.TestEvidenceRouteEquivocation, types.TestEquivocationHandler(*evidenceKeeper)) + router = router.AddRoute(types.RouteEquivocation, testEquivocationHandler(*evidenceKeeper)) evidenceKeeper.SetRouter(router) - suite.ctx = app.BaseApp.NewContext(checkTx, abci.Header{Height: 1}) + app.EvidenceKeeper = *evidenceKeeper + suite.handler = evidence.NewHandler(*evidenceKeeper) - suite.keeper = *evidenceKeeper + suite.app = app } -func (suite *HandlerTestSuite) TestMsgSubmitEvidence_Valid() { +func (suite *HandlerTestSuite) TestMsgSubmitEvidence() { pk := ed25519.GenPrivKey() - sv := types.TestVote{ - ValidatorAddress: pk.PubKey().Address(), - Height: 11, - Round: 0, - } - - sig, err := pk.Sign(sv.SignBytes(suite.ctx.ChainID())) - suite.NoError(err) - sv.Signature = sig - s := sdk.AccAddress("test") - e := types.TestEquivocationEvidence{ - Power: 100, - TotalPower: 100000, - PubKey: pk.PubKey(), - VoteA: sv, - VoteB: sv, + + testCases := []struct { + msg sdk.Msg + expectErr bool + }{ + { + simappcodec.NewMsgSubmitEvidence( + &types.Equivocation{ + Height: 11, + Time: time.Now().UTC(), + Power: 100, + ConsensusAddress: pk.PubKey().Address().Bytes(), + }, + s, + ), + false, + }, + { + simappcodec.NewMsgSubmitEvidence( + &types.Equivocation{ + Height: 10, + Time: time.Now().UTC(), + Power: 100, + ConsensusAddress: pk.PubKey().Address().Bytes(), + }, + s, + ), + true, + }, + { + types.NewMsgSubmitEvidenceBase(s), + true, + }, } - ctx := suite.ctx.WithIsCheckTx(false) - msg := evidence.NewMsgSubmitEvidence(e, s) - res, err := suite.handler(ctx, msg) - suite.NoError(err) - suite.NotNil(res) - suite.Equal(e.Hash().Bytes(), res.Data) -} + for i, tc := range testCases { + ctx := suite.app.BaseApp.NewContext(false, abci.Header{Height: suite.app.LastBlockHeight() + 1}) -func (suite *HandlerTestSuite) TestMsgSubmitEvidence_Invalid() { - pk := ed25519.GenPrivKey() - sv := types.TestVote{ - ValidatorAddress: pk.PubKey().Address(), - Height: 11, - Round: 0, + res, err := suite.handler(ctx, tc.msg) + if tc.expectErr { + suite.Require().Error(err, "expected error; tc #%d", i) + } else { + suite.Require().NoError(err, "unexpected error; tc #%d", i) + suite.Require().NotNil(res, "expected non-nil result; tc #%d", i) + + msg := tc.msg.(simappcodec.MsgSubmitEvidence) + suite.Require().Equal(msg.GetEvidence().Hash().Bytes(), res.Data, "invalid hash; tc #%d", i) + } } - - sig, err := pk.Sign(sv.SignBytes(suite.ctx.ChainID())) - suite.NoError(err) - sv.Signature = sig - - s := sdk.AccAddress("test") - e := types.TestEquivocationEvidence{ - Power: 100, - TotalPower: 100000, - PubKey: pk.PubKey(), - VoteA: sv, - VoteB: types.TestVote{Height: 10, Round: 1}, - } - - ctx := suite.ctx.WithIsCheckTx(false) - msg := evidence.NewMsgSubmitEvidence(e, s) - res, err := suite.handler(ctx, msg) - suite.Error(err) - suite.Nil(res) } func TestHandlerTestSuite(t *testing.T) { diff --git a/x/evidence/internal/keeper/params_test.go b/x/evidence/internal/keeper/params_test.go deleted file mode 100644 index 58d25230ee..0000000000 --- a/x/evidence/internal/keeper/params_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package keeper_test - -import ( - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" -) - -func (suite *KeeperTestSuite) TestParams() { - ctx := suite.ctx.WithIsCheckTx(false) - suite.Equal(types.DefaultParams(), suite.keeper.GetParams(ctx)) - suite.Equal(types.DefaultMaxEvidenceAge, suite.keeper.MaxEvidenceAge(ctx)) -} diff --git a/x/evidence/internal/types/codec.go b/x/evidence/internal/types/codec.go deleted file mode 100644 index 7c57bc4a71..0000000000 --- a/x/evidence/internal/types/codec.go +++ /dev/null @@ -1,29 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/evidence/exported" -) - -// ModuleCdc defines the evidence module's codec. The codec is not sealed as to -// allow other modules to register their concrete Evidence types. -var ModuleCdc = codec.New() - -// RegisterCodec registers all the necessary types and interfaces for the -// evidence module. -func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterInterface((*exported.Evidence)(nil), nil) - cdc.RegisterConcrete(MsgSubmitEvidence{}, "cosmos-sdk/MsgSubmitEvidence", nil) - cdc.RegisterConcrete(Equivocation{}, "cosmos-sdk/Equivocation", nil) -} - -// RegisterEvidenceTypeCodec registers an external concrete Evidence type defined -// in another module for the internal ModuleCdc. This allows the MsgSubmitEvidence -// to be correctly Amino encoded and decoded. -func RegisterEvidenceTypeCodec(o interface{}, name string) { - ModuleCdc.RegisterConcrete(o, name, nil) -} - -func init() { - RegisterCodec(ModuleCdc) -} diff --git a/x/evidence/internal/types/codec_test.go b/x/evidence/internal/types/codec_test.go deleted file mode 100644 index e175a7292e..0000000000 --- a/x/evidence/internal/types/codec_test.go +++ /dev/null @@ -1,42 +0,0 @@ -package types_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/evidence/exported" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" -) - -var _ exported.Evidence = (*testEvidence)(nil) - -type testEvidence struct{} - -func (te testEvidence) Route() string { return "" } -func (te testEvidence) Type() string { return "" } -func (te testEvidence) String() string { return "" } -func (te testEvidence) ValidateBasic() error { return nil } -func (te testEvidence) GetConsensusAddress() sdk.ConsAddress { return nil } -func (te testEvidence) Hash() tmbytes.HexBytes { return nil } -func (te testEvidence) GetHeight() int64 { return 0 } -func (te testEvidence) GetValidatorPower() int64 { return 0 } -func (te testEvidence) GetTotalPower() int64 { return 0 } - -func TestCodec(t *testing.T) { - cdc := codec.New() - types.RegisterCodec(cdc) - types.RegisterEvidenceTypeCodec(testEvidence{}, "cosmos-sdk/testEvidence") - - var e exported.Evidence = testEvidence{} - bz, err := cdc.MarshalBinaryBare(e) - require.NoError(t, err) - - var te testEvidence - require.NoError(t, cdc.UnmarshalBinaryBare(bz, &te)) - - require.Panics(t, func() { types.RegisterEvidenceTypeCodec(testEvidence{}, "cosmos-sdk/testEvidence") }) -} diff --git a/x/evidence/internal/types/msgs.go b/x/evidence/internal/types/msgs.go deleted file mode 100644 index 3fbb50844f..0000000000 --- a/x/evidence/internal/types/msgs.go +++ /dev/null @@ -1,59 +0,0 @@ -package types - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/evidence/exported" -) - -// Message types for the evidence module -const ( - TypeMsgSubmitEvidence = "submit_evidence" -) - -var ( - _ sdk.Msg = MsgSubmitEvidence{} -) - -// MsgSubmitEvidence defines an sdk.Msg type that supports submitting arbitrary -// Evidence. -type MsgSubmitEvidence struct { - Evidence exported.Evidence `json:"evidence" yaml:"evidence"` - Submitter sdk.AccAddress `json:"submitter" yaml:"submitter"` -} - -func NewMsgSubmitEvidence(e exported.Evidence, s sdk.AccAddress) MsgSubmitEvidence { - return MsgSubmitEvidence{Evidence: e, Submitter: s} -} - -// Route returns the MsgSubmitEvidence's route. -func (m MsgSubmitEvidence) Route() string { return RouterKey } - -// Type returns the MsgSubmitEvidence's type. -func (m MsgSubmitEvidence) Type() string { return TypeMsgSubmitEvidence } - -// ValidateBasic performs basic (non-state-dependant) validation on a MsgSubmitEvidence. -func (m MsgSubmitEvidence) ValidateBasic() error { - if m.Evidence == nil { - return sdkerrors.Wrap(ErrInvalidEvidence, "missing evidence") - } - if err := m.Evidence.ValidateBasic(); err != nil { - return err - } - if m.Submitter.Empty() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, m.Submitter.String()) - } - - return nil -} - -// GetSignBytes returns the raw bytes a signer is expected to sign when submitting -// a MsgSubmitEvidence message. -func (m MsgSubmitEvidence) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m)) -} - -// GetSigners returns the single expected signer for a MsgSubmitEvidence. -func (m MsgSubmitEvidence) GetSigners() []sdk.AccAddress { - return []sdk.AccAddress{m.Submitter} -} diff --git a/x/evidence/internal/types/msgs_test.go b/x/evidence/internal/types/msgs_test.go deleted file mode 100644 index 5a50ba6e7b..0000000000 --- a/x/evidence/internal/types/msgs_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package types_test - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/evidence/exported" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" - - "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/crypto/ed25519" -) - -func TestMsgSubmitEvidence(t *testing.T) { - pk := ed25519.GenPrivKey() - sv := types.TestVote{ - ValidatorAddress: pk.PubKey().Address(), - Height: 11, - Round: 0, - } - sig, err := pk.Sign(sv.SignBytes("test-chain")) - require.NoError(t, err) - sv.Signature = sig - - submitter := sdk.AccAddress("test") - testCases := []struct { - evidence exported.Evidence - submitter sdk.AccAddress - expectErr bool - }{ - {nil, submitter, true}, - { - types.TestEquivocationEvidence{ - Power: 100, - TotalPower: 100000, - PubKey: pk.PubKey(), - VoteA: sv, - VoteB: sv, - }, - submitter, - false, - }, - { - types.TestEquivocationEvidence{ - Power: 100, - TotalPower: 100000, - PubKey: pk.PubKey(), - VoteA: sv, - VoteB: types.TestVote{Height: 10, Round: 1}, - }, - submitter, - true, - }, - } - - for i, tc := range testCases { - msg := types.NewMsgSubmitEvidence(tc.evidence, tc.submitter) - require.Equal(t, msg.Route(), types.RouterKey, "unexpected result for tc #%d", i) - require.Equal(t, msg.Type(), types.TypeMsgSubmitEvidence, "unexpected result for tc #%d", i) - require.Equal(t, tc.expectErr, msg.ValidateBasic() != nil, "unexpected result for tc #%d", i) - - if !tc.expectErr { - require.Equal(t, msg.GetSigners(), []sdk.AccAddress{tc.submitter}, "unexpected result for tc #%d", i) - } - } -} diff --git a/x/evidence/internal/types/test_util.go b/x/evidence/internal/types/test_util.go deleted file mode 100644 index 24500cba99..0000000000 --- a/x/evidence/internal/types/test_util.go +++ /dev/null @@ -1,135 +0,0 @@ -/* -Common testing types and utility functions and methods to be used in unit and -integration testing of the evidence module. -*/ -// DONTCOVER -package types - -import ( - "bytes" - "errors" - "fmt" - "time" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/evidence/exported" - - "gopkg.in/yaml.v2" - - "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/tmhash" - tmbytes "github.com/tendermint/tendermint/libs/bytes" -) - -var ( - _ exported.Evidence = (*TestEquivocationEvidence)(nil) - - TestingCdc = codec.New() -) - -const ( - TestEvidenceRouteEquivocation = "TestEquivocationEvidence" - TestEvidenceTypeEquivocation = "equivocation" -) - -type ( - TestVote struct { - Height int64 - Round int64 - Timestamp time.Time - ValidatorAddress tmbytes.HexBytes - Signature []byte - } - - TestCanonicalVote struct { - Height int64 - Round int64 - Timestamp time.Time - ChainID string - } - - TestEquivocationEvidence struct { - Power int64 - TotalPower int64 - PubKey crypto.PubKey - VoteA TestVote - VoteB TestVote - } -) - -func init() { - RegisterCodec(TestingCdc) - codec.RegisterCrypto(TestingCdc) - TestingCdc.RegisterConcrete(TestEquivocationEvidence{}, "test/TestEquivocationEvidence", nil) -} - -func (e TestEquivocationEvidence) Route() string { return TestEvidenceRouteEquivocation } -func (e TestEquivocationEvidence) Type() string { return TestEvidenceTypeEquivocation } -func (e TestEquivocationEvidence) GetHeight() int64 { return e.VoteA.Height } -func (e TestEquivocationEvidence) GetValidatorPower() int64 { return e.Power } -func (e TestEquivocationEvidence) GetTotalPower() int64 { return e.TotalPower } - -func (e TestEquivocationEvidence) String() string { - bz, _ := yaml.Marshal(e) - return string(bz) -} - -func (e TestEquivocationEvidence) GetConsensusAddress() sdk.ConsAddress { - return sdk.ConsAddress(e.PubKey.Address()) -} - -func (e TestEquivocationEvidence) ValidateBasic() error { - if e.VoteA.Height != e.VoteB.Height || - e.VoteA.Round != e.VoteB.Round { - return fmt.Errorf("H/R/S does not match (got %v and %v)", e.VoteA, e.VoteB) - } - - if !bytes.Equal(e.VoteA.ValidatorAddress, e.VoteB.ValidatorAddress) { - return fmt.Errorf( - "validator addresses do not match (got %X and %X)", - e.VoteA.ValidatorAddress, - e.VoteB.ValidatorAddress, - ) - } - - return nil -} - -func (e TestEquivocationEvidence) Hash() tmbytes.HexBytes { - return tmhash.Sum(TestingCdc.MustMarshalBinaryBare(e)) -} - -func (v TestVote) SignBytes(chainID string) []byte { - scv := TestCanonicalVote{ - Height: v.Height, - Round: v.Round, - Timestamp: v.Timestamp, - ChainID: chainID, - } - bz, _ := TestingCdc.MarshalBinaryLengthPrefixed(scv) - return bz -} - -func TestEquivocationHandler(k interface{}) Handler { - return func(ctx sdk.Context, e exported.Evidence) error { - if err := e.ValidateBasic(); err != nil { - return err - } - - ee, ok := e.(TestEquivocationEvidence) - if !ok { - return fmt.Errorf("unexpected evidence type: %T", e) - } - if !ee.PubKey.VerifyBytes(ee.VoteA.SignBytes(ctx.ChainID()), ee.VoteA.Signature) { - return errors.New("failed to verify vote A signature") - } - if !ee.PubKey.VerifyBytes(ee.VoteB.SignBytes(ctx.ChainID()), ee.VoteB.Signature) { - return errors.New("failed to verify vote B signature") - } - - // TODO: Slashing! - - return nil - } -} diff --git a/x/evidence/internal/keeper/infraction.go b/x/evidence/keeper/infraction.go similarity index 98% rename from x/evidence/internal/keeper/infraction.go rename to x/evidence/keeper/infraction.go index fab16c833e..17970863ba 100644 --- a/x/evidence/internal/keeper/infraction.go +++ b/x/evidence/keeper/infraction.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" + "github.com/cosmos/cosmos-sdk/x/evidence/types" ) // HandleDoubleSign implements an equivocation evidence handler. Assuming the diff --git a/x/evidence/internal/keeper/infraction_test.go b/x/evidence/keeper/infraction_test.go similarity index 95% rename from x/evidence/internal/keeper/infraction_test.go rename to x/evidence/keeper/infraction_test.go index d0ae5d7423..71177df01b 100644 --- a/x/evidence/internal/keeper/infraction_test.go +++ b/x/evidence/keeper/infraction_test.go @@ -4,7 +4,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" + "github.com/cosmos/cosmos-sdk/x/evidence/types" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/tendermint/tendermint/crypto" @@ -51,7 +51,7 @@ func (suite *KeeperTestSuite) TestHandleDoubleSign() { Power: power, ConsensusAddress: sdk.ConsAddress(val.Address()), } - suite.keeper.HandleDoubleSign(ctx, evidence) + suite.app.EvidenceKeeper.HandleDoubleSign(ctx, evidence) // should be jailed and tombstoned suite.True(suite.app.StakingKeeper.Validator(ctx, operatorAddr).IsJailed()) @@ -62,7 +62,7 @@ func (suite *KeeperTestSuite) TestHandleDoubleSign() { suite.True(newTokens.LT(oldTokens)) // submit duplicate evidence - suite.keeper.HandleDoubleSign(ctx, evidence) + suite.app.EvidenceKeeper.HandleDoubleSign(ctx, evidence) // tokens should be the same (capped slash) suite.True(suite.app.StakingKeeper.Validator(ctx, operatorAddr).GetTokens().Equal(newTokens)) @@ -113,7 +113,7 @@ func (suite *KeeperTestSuite) TestHandleDoubleSign_TooOld() { ConsensusAddress: sdk.ConsAddress(val.Address()), } ctx = ctx.WithBlockTime(ctx.BlockTime().Add(suite.app.EvidenceKeeper.MaxEvidenceAge(ctx) + 1)) - suite.keeper.HandleDoubleSign(ctx, evidence) + suite.app.EvidenceKeeper.HandleDoubleSign(ctx, evidence) suite.False(suite.app.StakingKeeper.Validator(ctx, operatorAddr).IsJailed()) suite.False(suite.app.SlashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(val.Address()))) diff --git a/x/evidence/internal/keeper/keeper.go b/x/evidence/keeper/keeper.go similarity index 80% rename from x/evidence/internal/keeper/keeper.go rename to x/evidence/keeper/keeper.go index 29a3df0bf3..93672ab0c7 100644 --- a/x/evidence/internal/keeper/keeper.go +++ b/x/evidence/keeper/keeper.go @@ -6,29 +6,28 @@ import ( tmbytes "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/evidence/exported" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" - "github.com/cosmos/cosmos-sdk/x/params" + "github.com/cosmos/cosmos-sdk/x/evidence/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) // Keeper defines the evidence module's keeper. The keeper is responsible for // managing persistence, state transitions and query handling for the evidence // module. type Keeper struct { - cdc *codec.Codec + cdc types.Codec storeKey sdk.StoreKey - paramSpace params.Subspace + paramSpace paramtypes.Subspace router types.Router stakingKeeper types.StakingKeeper slashingKeeper types.SlashingKeeper } func NewKeeper( - cdc *codec.Codec, storeKey sdk.StoreKey, paramSpace params.Subspace, + cdc types.Codec, storeKey sdk.StoreKey, paramSpace paramtypes.Subspace, stakingKeeper types.StakingKeeper, slashingKeeper types.SlashingKeeper, ) *Keeper { @@ -110,13 +109,12 @@ func (k Keeper) SubmitEvidence(ctx sdk.Context, evidence exported.Evidence) erro // SetEvidence sets Evidence by hash in the module's KVStore. func (k Keeper) SetEvidence(ctx sdk.Context, evidence exported.Evidence) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixEvidence) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(evidence) - store.Set(evidence.Hash(), bz) + store.Set(evidence.Hash(), k.MustMarshalEvidence(evidence)) } // GetEvidence retrieves Evidence by hash if it exists. If no Evidence exists for // the given hash, (nil, false) is returned. -func (k Keeper) GetEvidence(ctx sdk.Context, hash tmbytes.HexBytes) (evidence exported.Evidence, found bool) { +func (k Keeper) GetEvidence(ctx sdk.Context, hash tmbytes.HexBytes) (exported.Evidence, bool) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixEvidence) bz := store.Get(hash) @@ -124,8 +122,7 @@ func (k Keeper) GetEvidence(ctx sdk.Context, hash tmbytes.HexBytes) (evidence ex return nil, false } - k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &evidence) - return evidence, true + return k.MustUnmarshalEvidence(bz), true } // IterateEvidence provides an interator over all stored Evidence objects. For @@ -137,8 +134,7 @@ func (k Keeper) IterateEvidence(ctx sdk.Context, cb func(exported.Evidence) bool defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - var evidence exported.Evidence - k.cdc.MustUnmarshalBinaryLengthPrefixed(iterator.Value(), &evidence) + evidence := k.MustUnmarshalEvidence(iterator.Value()) if cb(evidence) { break @@ -152,5 +148,28 @@ func (k Keeper) GetAllEvidence(ctx sdk.Context) (evidence []exported.Evidence) { evidence = append(evidence, e) return false }) + return evidence } + +// MustUnmarshalEvidence attempts to decode and return an Evidence object from +// raw encoded bytes. It panics on error. +func (k Keeper) MustUnmarshalEvidence(bz []byte) exported.Evidence { + evidence, err := k.cdc.UnmarshalEvidence(bz) + if err != nil { + panic(fmt.Errorf("failed to decode evidence: %w", err)) + } + + return evidence +} + +// MustMarshalEvidence attempts to encode an Evidence object and returns the +// raw encoded bytes. It panics on error. +func (k Keeper) MustMarshalEvidence(evidence exported.Evidence) []byte { + bz, err := k.cdc.MarshalEvidence(evidence) + if err != nil { + panic(fmt.Errorf("failed to encode evidence: %w", err)) + } + + return bz +} diff --git a/x/evidence/internal/keeper/keeper_test.go b/x/evidence/keeper/keeper_test.go similarity index 57% rename from x/evidence/internal/keeper/keeper_test.go rename to x/evidence/keeper/keeper_test.go index d6e35a4956..a28f66efea 100644 --- a/x/evidence/internal/keeper/keeper_test.go +++ b/x/evidence/keeper/keeper_test.go @@ -2,15 +2,18 @@ package keeper_test import ( "encoding/hex" + "fmt" "testing" + "time" "github.com/cosmos/cosmos-sdk/simapp" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/evidence" "github.com/cosmos/cosmos-sdk/x/evidence/exported" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" + "github.com/cosmos/cosmos-sdk/x/evidence/keeper" + "github.com/cosmos/cosmos-sdk/x/evidence/types" "github.com/cosmos/cosmos-sdk/x/supply" "github.com/stretchr/testify/suite" @@ -48,12 +51,29 @@ func newPubKey(pk string) (res crypto.PubKey) { return pubkey } +func testEquivocationHandler(k interface{}) types.Handler { + return func(ctx sdk.Context, e exported.Evidence) error { + if err := e.ValidateBasic(); err != nil { + return err + } + + ee, ok := e.(types.Equivocation) + if !ok { + return fmt.Errorf("unexpected evidence type: %T", e) + } + if ee.Height%2 == 0 { + return fmt.Errorf("unexpected even evidence height: %d", ee.Height) + } + + return nil + } +} + type KeeperTestSuite struct { suite.Suite ctx sdk.Context querier sdk.Querier - keeper keeper.Keeper app *simapp.SimApp } @@ -61,21 +81,19 @@ func (suite *KeeperTestSuite) SetupTest() { checkTx := false app := simapp.Setup(checkTx) - // get the app's codec and register custom testing types - cdc := app.Codec() - cdc.RegisterConcrete(types.TestEquivocationEvidence{}, "test/TestEquivocationEvidence", nil) - // recreate keeper in order to use custom testing types evidenceKeeper := evidence.NewKeeper( - cdc, app.GetKey(evidence.StoreKey), app.GetSubspace(evidence.ModuleName), app.StakingKeeper, app.SlashingKeeper, + simappcodec.NewAppCodec(app.Codec()), app.GetKey(evidence.StoreKey), + app.GetSubspace(evidence.ModuleName), app.StakingKeeper, app.SlashingKeeper, ) router := evidence.NewRouter() - router = router.AddRoute(types.TestEvidenceRouteEquivocation, types.TestEquivocationHandler(*evidenceKeeper)) + router = router.AddRoute(types.RouteEquivocation, testEquivocationHandler(*evidenceKeeper)) evidenceKeeper.SetRouter(router) + app.EvidenceKeeper = *evidenceKeeper + suite.ctx = app.BaseApp.NewContext(checkTx, abci.Header{Height: 1}) suite.querier = keeper.NewQuerier(*evidenceKeeper) - suite.keeper = *evidenceKeeper suite.app = app for i, addr := range valAddresses { @@ -89,25 +107,15 @@ func (suite *KeeperTestSuite) populateEvidence(ctx sdk.Context, numEvidence int) for i := 0; i < numEvidence; i++ { pk := ed25519.GenPrivKey() - sv := types.TestVote{ - ValidatorAddress: pk.PubKey().Address(), - Height: int64(i), - Round: 0, + + evidence[i] = types.Equivocation{ + Height: 11, + Power: 100, + Time: time.Now().UTC(), + ConsensusAddress: sdk.ConsAddress(pk.PubKey().Address().Bytes()), } - sig, err := pk.Sign(sv.SignBytes(ctx.ChainID())) - suite.NoError(err) - sv.Signature = sig - - evidence[i] = types.TestEquivocationEvidence{ - Power: 100, - TotalPower: 100000, - PubKey: pk.PubKey(), - VoteA: sv, - VoteB: sv, - } - - suite.Nil(suite.keeper.SubmitEvidence(ctx, evidence[i])) + suite.Nil(suite.app.EvidenceKeeper.SubmitEvidence(ctx, evidence[i])) } return evidence @@ -128,82 +136,53 @@ func (suite *KeeperTestSuite) populateValidators(ctx sdk.Context) { func (suite *KeeperTestSuite) TestSubmitValidEvidence() { ctx := suite.ctx.WithIsCheckTx(false) pk := ed25519.GenPrivKey() - sv := types.TestVote{ - ValidatorAddress: pk.PubKey().Address(), - Height: 11, - Round: 0, + + e := types.Equivocation{ + Height: 1, + Power: 100, + Time: time.Now().UTC(), + ConsensusAddress: sdk.ConsAddress(pk.PubKey().Address().Bytes()), } - sig, err := pk.Sign(sv.SignBytes(ctx.ChainID())) - suite.NoError(err) - sv.Signature = sig + suite.Nil(suite.app.EvidenceKeeper.SubmitEvidence(ctx, e)) - e := types.TestEquivocationEvidence{ - Power: 100, - TotalPower: 100000, - PubKey: pk.PubKey(), - VoteA: sv, - VoteB: sv, - } - - suite.Nil(suite.keeper.SubmitEvidence(ctx, e)) - - res, ok := suite.keeper.GetEvidence(ctx, e.Hash()) + res, ok := suite.app.EvidenceKeeper.GetEvidence(ctx, e.Hash()) suite.True(ok) - suite.Equal(e, res) + suite.Equal(&e, res) } func (suite *KeeperTestSuite) TestSubmitValidEvidence_Duplicate() { ctx := suite.ctx.WithIsCheckTx(false) pk := ed25519.GenPrivKey() - sv := types.TestVote{ - ValidatorAddress: pk.PubKey().Address(), - Height: 11, - Round: 0, + + e := types.Equivocation{ + Height: 1, + Power: 100, + Time: time.Now().UTC(), + ConsensusAddress: sdk.ConsAddress(pk.PubKey().Address().Bytes()), } - sig, err := pk.Sign(sv.SignBytes(ctx.ChainID())) - suite.NoError(err) - sv.Signature = sig + suite.Nil(suite.app.EvidenceKeeper.SubmitEvidence(ctx, e)) + suite.Error(suite.app.EvidenceKeeper.SubmitEvidence(ctx, e)) - e := types.TestEquivocationEvidence{ - Power: 100, - TotalPower: 100000, - PubKey: pk.PubKey(), - VoteA: sv, - VoteB: sv, - } - - suite.Nil(suite.keeper.SubmitEvidence(ctx, e)) - suite.Error(suite.keeper.SubmitEvidence(ctx, e)) - - res, ok := suite.keeper.GetEvidence(ctx, e.Hash()) + res, ok := suite.app.EvidenceKeeper.GetEvidence(ctx, e.Hash()) suite.True(ok) - suite.Equal(e, res) + suite.Equal(&e, res) } func (suite *KeeperTestSuite) TestSubmitInvalidEvidence() { ctx := suite.ctx.WithIsCheckTx(false) pk := ed25519.GenPrivKey() - e := types.TestEquivocationEvidence{ - Power: 100, - TotalPower: 100000, - PubKey: pk.PubKey(), - VoteA: types.TestVote{ - ValidatorAddress: pk.PubKey().Address(), - Height: 10, - Round: 0, - }, - VoteB: types.TestVote{ - ValidatorAddress: pk.PubKey().Address(), - Height: 11, - Round: 0, - }, + e := types.Equivocation{ + Height: 0, + Power: 100, + Time: time.Now().UTC(), + ConsensusAddress: sdk.ConsAddress(pk.PubKey().Address().Bytes()), } - suite.Error(suite.keeper.SubmitEvidence(ctx, e)) + suite.Error(suite.app.EvidenceKeeper.SubmitEvidence(ctx, e)) - res, ok := suite.keeper.GetEvidence(ctx, e.Hash()) + res, ok := suite.app.EvidenceKeeper.GetEvidence(ctx, e.Hash()) suite.False(ok) suite.Nil(res) } @@ -213,16 +192,16 @@ func (suite *KeeperTestSuite) TestIterateEvidence() { numEvidence := 100 suite.populateEvidence(ctx, numEvidence) - evidence := suite.keeper.GetAllEvidence(ctx) + evidence := suite.app.EvidenceKeeper.GetAllEvidence(ctx) suite.Len(evidence, numEvidence) } func (suite *KeeperTestSuite) TestGetEvidenceHandler() { - handler, err := suite.keeper.GetEvidenceHandler(types.TestEquivocationEvidence{}.Route()) + handler, err := suite.app.EvidenceKeeper.GetEvidenceHandler(types.Equivocation{}.Route()) suite.NoError(err) suite.NotNil(handler) - handler, err = suite.keeper.GetEvidenceHandler("invalidHandler") + handler, err = suite.app.EvidenceKeeper.GetEvidenceHandler("invalidHandler") suite.Error(err) suite.Nil(handler) } diff --git a/x/evidence/internal/keeper/params.go b/x/evidence/keeper/params.go similarity index 91% rename from x/evidence/internal/keeper/params.go rename to x/evidence/keeper/params.go index 8db4867781..b49512e2e5 100644 --- a/x/evidence/internal/keeper/params.go +++ b/x/evidence/keeper/params.go @@ -4,7 +4,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" + "github.com/cosmos/cosmos-sdk/x/evidence/types" ) // MaxEvidenceAge returns the maximum age for submitted evidence. diff --git a/x/evidence/keeper/params_test.go b/x/evidence/keeper/params_test.go new file mode 100644 index 0000000000..08db55e9b8 --- /dev/null +++ b/x/evidence/keeper/params_test.go @@ -0,0 +1,11 @@ +package keeper_test + +import ( + "github.com/cosmos/cosmos-sdk/x/evidence/types" +) + +func (suite *KeeperTestSuite) TestParams() { + ctx := suite.ctx.WithIsCheckTx(false) + suite.Equal(types.DefaultParams(), suite.app.EvidenceKeeper.GetParams(ctx)) + suite.Equal(types.DefaultMaxEvidenceAge, suite.app.EvidenceKeeper.MaxEvidenceAge(ctx)) +} diff --git a/x/evidence/internal/keeper/querier.go b/x/evidence/keeper/querier.go similarity index 97% rename from x/evidence/internal/keeper/querier.go rename to x/evidence/keeper/querier.go index cbb616677e..064ad2cb4a 100644 --- a/x/evidence/internal/keeper/querier.go +++ b/x/evidence/keeper/querier.go @@ -8,7 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/evidence/exported" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" + "github.com/cosmos/cosmos-sdk/x/evidence/types" abci "github.com/tendermint/tendermint/abci/types" ) diff --git a/x/evidence/internal/keeper/querier_test.go b/x/evidence/keeper/querier_test.go similarity index 73% rename from x/evidence/internal/keeper/querier_test.go rename to x/evidence/keeper/querier_test.go index 68af96640a..069f41c6ce 100644 --- a/x/evidence/internal/keeper/querier_test.go +++ b/x/evidence/keeper/querier_test.go @@ -3,8 +3,9 @@ package keeper_test import ( "strings" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" "github.com/cosmos/cosmos-sdk/x/evidence/exported" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" + "github.com/cosmos/cosmos-sdk/x/evidence/types" abci "github.com/tendermint/tendermint/abci/types" ) @@ -16,11 +17,12 @@ const ( func (suite *KeeperTestSuite) TestQueryEvidence_Existing() { ctx := suite.ctx.WithIsCheckTx(false) numEvidence := 100 + cdc := simappcodec.NewAppCodec(suite.app.Codec()) evidence := suite.populateEvidence(ctx, numEvidence) query := abci.RequestQuery{ Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryEvidence}, "/"), - Data: types.TestingCdc.MustMarshalJSON(types.NewQueryEvidenceParams(evidence[0].Hash().String())), + Data: cdc.MustMarshalJSON(types.NewQueryEvidenceParams(evidence[0].Hash().String())), } bz, err := suite.querier(ctx, []string{types.QueryEvidence}, query) @@ -28,18 +30,19 @@ func (suite *KeeperTestSuite) TestQueryEvidence_Existing() { suite.NotNil(bz) var e exported.Evidence - suite.Nil(types.TestingCdc.UnmarshalJSON(bz, &e)) + suite.Nil(cdc.UnmarshalJSON(bz, &e)) suite.Equal(evidence[0], e) } func (suite *KeeperTestSuite) TestQueryEvidence_NonExisting() { ctx := suite.ctx.WithIsCheckTx(false) + cdc := simappcodec.NewAppCodec(suite.app.Codec()) numEvidence := 100 suite.populateEvidence(ctx, numEvidence) query := abci.RequestQuery{ Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryEvidence}, "/"), - Data: types.TestingCdc.MustMarshalJSON(types.NewQueryEvidenceParams("0000000000000000000000000000000000000000000000000000000000000000")), + Data: cdc.MustMarshalJSON(types.NewQueryEvidenceParams("0000000000000000000000000000000000000000000000000000000000000000")), } bz, err := suite.querier(ctx, []string{types.QueryEvidence}, query) @@ -49,12 +52,13 @@ func (suite *KeeperTestSuite) TestQueryEvidence_NonExisting() { func (suite *KeeperTestSuite) TestQueryAllEvidence() { ctx := suite.ctx.WithIsCheckTx(false) + cdc := simappcodec.NewAppCodec(suite.app.Codec()) numEvidence := 100 suite.populateEvidence(ctx, numEvidence) query := abci.RequestQuery{ Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryAllEvidence}, "/"), - Data: types.TestingCdc.MustMarshalJSON(types.NewQueryAllEvidenceParams(1, numEvidence)), + Data: cdc.MustMarshalJSON(types.NewQueryAllEvidenceParams(1, numEvidence)), } bz, err := suite.querier(ctx, []string{types.QueryAllEvidence}, query) @@ -62,18 +66,19 @@ func (suite *KeeperTestSuite) TestQueryAllEvidence() { suite.NotNil(bz) var e []exported.Evidence - suite.Nil(types.TestingCdc.UnmarshalJSON(bz, &e)) + suite.Nil(cdc.UnmarshalJSON(bz, &e)) suite.Len(e, numEvidence) } func (suite *KeeperTestSuite) TestQueryAllEvidence_InvalidPagination() { ctx := suite.ctx.WithIsCheckTx(false) + cdc := simappcodec.NewAppCodec(suite.app.Codec()) numEvidence := 100 suite.populateEvidence(ctx, numEvidence) query := abci.RequestQuery{ Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryAllEvidence}, "/"), - Data: types.TestingCdc.MustMarshalJSON(types.NewQueryAllEvidenceParams(0, numEvidence)), + Data: cdc.MustMarshalJSON(types.NewQueryAllEvidenceParams(0, numEvidence)), } bz, err := suite.querier(ctx, []string{types.QueryAllEvidence}, query) @@ -81,7 +86,7 @@ func (suite *KeeperTestSuite) TestQueryAllEvidence_InvalidPagination() { suite.NotNil(bz) var e []exported.Evidence - suite.Nil(types.TestingCdc.UnmarshalJSON(bz, &e)) + suite.Nil(cdc.UnmarshalJSON(bz, &e)) suite.Len(e, 0) } diff --git a/x/evidence/module.go b/x/evidence/module.go index 30b427a95c..87900aba30 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -51,14 +51,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { } // DefaultGenesis returns the evidence module's default genesis state. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the evidence module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var gs GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &gs); err != nil { + if err := cdc.UnmarshalJSON(bz, &gs); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) } @@ -140,9 +140,9 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {} // InitGenesis performs the evidence module's genesis initialization It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, bz json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, bz json.RawMessage) []abci.ValidatorUpdate { var gs GenesisState - err := ModuleCdc.UnmarshalJSON(bz, &gs) + err := cdc.UnmarshalJSON(bz, &gs) if err != nil { panic(fmt.Sprintf("failed to unmarshal %s genesis state: %s", ModuleName, err)) } @@ -152,8 +152,8 @@ func (am AppModule) InitGenesis(ctx sdk.Context, bz json.RawMessage) []abci.Vali } // ExportGenesis returns the evidence module's exported genesis state as raw JSON bytes. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { - return ModuleCdc.MustMarshalJSON(ExportGenesis(ctx, am.keeper)) +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(ExportGenesis(ctx, am.keeper)) } // BeginBlock executes all ABCI BeginBlock logic respective to the evidence module. diff --git a/x/evidence/types/codec.go b/x/evidence/types/codec.go new file mode 100644 index 0000000000..6cfd762c38 --- /dev/null +++ b/x/evidence/types/codec.go @@ -0,0 +1,42 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/x/evidence/exported" +) + +// EvidenceCodec defines the interface required to serialize evidence +type Codec interface { + codec.Marshaler + + MarshalEvidence(exported.Evidence) ([]byte, error) + UnmarshalEvidence([]byte) (exported.Evidence, error) + MarshalEvidenceJSON(exported.Evidence) ([]byte, error) + UnmarshalEvidenceJSON([]byte) (exported.Evidence, error) +} + +// RegisterCodec registers all the necessary types and interfaces for the +// evidence module. +func RegisterCodec(cdc *codec.Codec) { + cdc.RegisterInterface((*exported.Evidence)(nil), nil) + cdc.RegisterConcrete(MsgSubmitEvidenceBase{}, "cosmos-sdk/MsgSubmitEvidenceBase", nil) + cdc.RegisterConcrete(Equivocation{}, "cosmos-sdk/Equivocation", nil) +} + +var ( + amino = codec.New() + + // ModuleCdc references the global x/evidence 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/evidence and + // defined at the application level. + ModuleCdc = codec.NewHybridCodec(amino) +) + +func init() { + RegisterCodec(amino) + codec.RegisterCrypto(amino) + amino.Seal() +} diff --git a/x/evidence/types/codec_test.go b/x/evidence/types/codec_test.go new file mode 100644 index 0000000000..af2656d38c --- /dev/null +++ b/x/evidence/types/codec_test.go @@ -0,0 +1,33 @@ +package types_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto/ed25519" + + "github.com/cosmos/cosmos-sdk/simapp" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" + "github.com/cosmos/cosmos-sdk/x/evidence/exported" + "github.com/cosmos/cosmos-sdk/x/evidence/types" +) + +func TestCodec(t *testing.T) { + app := simapp.Setup(false) + appCodec := simappcodec.NewAppCodec(app.Codec()) + pk := ed25519.GenPrivKey() + + var e exported.Evidence = &types.Equivocation{ + Height: 10, + Time: time.Now().UTC(), + Power: 100000, + ConsensusAddress: pk.PubKey().Address().Bytes(), + } + bz, err := appCodec.MarshalEvidence(e) + require.NoError(t, err) + + other, err := appCodec.UnmarshalEvidence(bz) + require.NoError(t, err) + require.Equal(t, e, other) +} diff --git a/x/evidence/internal/types/errors.go b/x/evidence/types/errors.go similarity index 50% rename from x/evidence/internal/types/errors.go rename to x/evidence/types/errors.go index 83ffe06002..f448027091 100644 --- a/x/evidence/internal/types/errors.go +++ b/x/evidence/types/errors.go @@ -7,8 +7,8 @@ import ( // x/evidence module sentinel errors var ( - ErrNoEvidenceHandlerExists = sdkerrors.Register(ModuleName, 1, "unregistered handler for evidence type") - ErrInvalidEvidence = sdkerrors.Register(ModuleName, 2, "invalid evidence") - ErrNoEvidenceExists = sdkerrors.Register(ModuleName, 3, "evidence does not exist") - ErrEvidenceExists = sdkerrors.Register(ModuleName, 4, "evidence already exists") + ErrNoEvidenceHandlerExists = sdkerrors.Register(ModuleName, 2, "unregistered handler for evidence type") + ErrInvalidEvidence = sdkerrors.Register(ModuleName, 3, "invalid evidence") + ErrNoEvidenceExists = sdkerrors.Register(ModuleName, 4, "evidence does not exist") + ErrEvidenceExists = sdkerrors.Register(ModuleName, 5, "evidence already exists") ) diff --git a/x/evidence/internal/types/events.go b/x/evidence/types/events.go similarity index 100% rename from x/evidence/internal/types/events.go rename to x/evidence/types/events.go diff --git a/x/evidence/internal/types/evidence.go b/x/evidence/types/evidence.go similarity index 85% rename from x/evidence/internal/types/evidence.go rename to x/evidence/types/evidence.go index 4306acbe0d..d62023530a 100644 --- a/x/evidence/internal/types/evidence.go +++ b/x/evidence/types/evidence.go @@ -21,15 +21,6 @@ const ( var _ exported.Evidence = (*Equivocation)(nil) -// Equivocation implements the Evidence interface and defines evidence of double -// signing misbehavior. -type Equivocation struct { - Height int64 `json:"height" yaml:"height"` - Time time.Time `json:"time" yaml:"time"` - Power int64 `json:"power" yaml:"power"` - ConsensusAddress sdk.ConsAddress `json:"consensus_address" yaml:"consensus_address"` -} - // Route returns the Evidence Handler route for an Equivocation type. func (e Equivocation) Route() string { return RouteEquivocation } @@ -43,7 +34,7 @@ func (e Equivocation) String() string { // Hash returns the hash of an Equivocation object. func (e Equivocation) Hash() tmbytes.HexBytes { - return tmhash.Sum(ModuleCdc.MustMarshalBinaryBare(e)) + return tmhash.Sum(ModuleCdc.MustMarshalBinaryBare(&e)) } // ValidateBasic performs basic stateless validation checks on an Equivocation object. diff --git a/x/evidence/internal/types/evidence_test.go b/x/evidence/types/evidence_test.go similarity index 91% rename from x/evidence/internal/types/evidence_test.go rename to x/evidence/types/evidence_test.go index 8871f553eb..623af3a7cb 100644 --- a/x/evidence/internal/types/evidence_test.go +++ b/x/evidence/types/evidence_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/evidence/internal/types" + "github.com/cosmos/cosmos-sdk/x/evidence/types" ) func TestEquivocation_Valid(t *testing.T) { @@ -26,7 +26,7 @@ func TestEquivocation_Valid(t *testing.T) { require.Equal(t, e.GetHeight(), e.Height) require.Equal(t, e.Type(), types.TypeEquivocation) require.Equal(t, e.Route(), types.RouteEquivocation) - require.Equal(t, e.Hash().String(), "808DA679674C9C0599965D02EBC5D4DCFD5E700D03035BBCD2DECCBBF44386F7") + require.Equal(t, e.Hash().String(), "16337536D55FB6DB93360AED8FDB9B615BFACAF0440C28C46B89F167D042154A") require.Equal(t, e.String(), "height: 100\ntime: 2006-01-02T15:04:05Z\npower: 1000000\nconsensus_address: cosmosvalcons1vehk7pqt5u4\n") require.NoError(t, e.ValidateBasic()) } diff --git a/x/evidence/internal/types/expected_keepers.go b/x/evidence/types/expected_keepers.go similarity index 100% rename from x/evidence/internal/types/expected_keepers.go rename to x/evidence/types/expected_keepers.go diff --git a/x/evidence/internal/types/genesis.go b/x/evidence/types/genesis.go similarity index 100% rename from x/evidence/internal/types/genesis.go rename to x/evidence/types/genesis.go diff --git a/x/evidence/internal/types/genesis_test.go b/x/evidence/types/genesis_test.go similarity index 51% rename from x/evidence/internal/types/genesis_test.go rename to x/evidence/types/genesis_test.go index f7ef8027b2..110838f86c 100644 --- a/x/evidence/internal/types/genesis_test.go +++ b/x/evidence/types/genesis_test.go @@ -2,12 +2,13 @@ package types_test import ( "testing" + "time" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/ed25519" "github.com/cosmos/cosmos-sdk/x/evidence/exported" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" + "github.com/cosmos/cosmos-sdk/x/evidence/types" ) func TestDefaultGenesisState(t *testing.T) { @@ -21,21 +22,11 @@ func TestGenesisStateValidate_Valid(t *testing.T) { evidence := make([]exported.Evidence, 100) for i := 0; i < 100; i++ { - sv := types.TestVote{ - ValidatorAddress: pk.PubKey().Address(), - Height: int64(i), - Round: 0, - } - sig, err := pk.Sign(sv.SignBytes("test-chain")) - require.NoError(t, err) - sv.Signature = sig - - evidence[i] = types.TestEquivocationEvidence{ - Power: 100, - TotalPower: 100000, - PubKey: pk.PubKey(), - VoteA: sv, - VoteB: sv, + evidence[i] = types.Equivocation{ + Height: int64(i) + 1, + Power: 100, + Time: time.Now().UTC(), + ConsensusAddress: pk.PubKey().Address().Bytes(), } } @@ -48,21 +39,11 @@ func TestGenesisStateValidate_Invalid(t *testing.T) { evidence := make([]exported.Evidence, 100) for i := 0; i < 100; i++ { - sv := types.TestVote{ - ValidatorAddress: pk.PubKey().Address(), + evidence[i] = types.Equivocation{ Height: int64(i), - Round: 0, - } - sig, err := pk.Sign(sv.SignBytes("test-chain")) - require.NoError(t, err) - sv.Signature = sig - - evidence[i] = types.TestEquivocationEvidence{ - Power: 100, - TotalPower: 100000, - PubKey: pk.PubKey(), - VoteA: sv, - VoteB: types.TestVote{Height: 10, Round: 1}, + Power: 100, + Time: time.Now().UTC(), + ConsensusAddress: pk.PubKey().Address().Bytes(), } } diff --git a/x/evidence/internal/types/keys.go b/x/evidence/types/keys.go similarity index 100% rename from x/evidence/internal/types/keys.go rename to x/evidence/types/keys.go diff --git a/x/evidence/types/msgs.go b/x/evidence/types/msgs.go new file mode 100644 index 0000000000..eb0367b28b --- /dev/null +++ b/x/evidence/types/msgs.go @@ -0,0 +1,48 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +// Message types for the evidence module +const ( + TypeMsgSubmitEvidence = "submit_evidence" +) + +var ( + _ sdk.Msg = MsgSubmitEvidenceBase{} +) + +// NewMsgSubmitEvidenceBase returns a new MsgSubmitEvidenceBase with a signer/submitter. +// Note, the MsgSubmitEvidenceBase is not to be used as an actual message, but +// rather to be extended with Evidence. +func NewMsgSubmitEvidenceBase(s sdk.AccAddress) MsgSubmitEvidenceBase { + return MsgSubmitEvidenceBase{Submitter: s} +} + +// Route returns the MsgSubmitEvidenceBase's route. +func (m MsgSubmitEvidenceBase) Route() string { return RouterKey } + +// Type returns the MsgSubmitEvidenceBase's type. +func (m MsgSubmitEvidenceBase) Type() string { return TypeMsgSubmitEvidence } + +// ValidateBasic performs basic (non-state-dependant) validation on a MsgSubmitEvidenceBase. +func (m MsgSubmitEvidenceBase) ValidateBasic() error { + if m.Submitter.Empty() { + return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, m.Submitter.String()) + } + + return nil +} + +// GetSignBytes returns the raw bytes a signer is expected to sign when submitting +// a MsgSubmitEvidenceBase message. +func (m MsgSubmitEvidenceBase) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m)) +} + +// GetSigners returns the single expected signer for a MsgSubmitEvidenceBase. +func (m MsgSubmitEvidenceBase) GetSigners() []sdk.AccAddress { + return []sdk.AccAddress{m.Submitter} +} diff --git a/x/evidence/types/msgs_test.go b/x/evidence/types/msgs_test.go new file mode 100644 index 0000000000..304f49efbf --- /dev/null +++ b/x/evidence/types/msgs_test.go @@ -0,0 +1,60 @@ +package types_test + +import ( + "testing" + "time" + + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/evidence/types" + + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto/ed25519" +) + +func TestMsgSubmitEvidence(t *testing.T) { + pk := ed25519.GenPrivKey() + submitter := sdk.AccAddress("test") + + testCases := []struct { + msg sdk.Msg + submitter sdk.AccAddress + expectErr bool + }{ + { + types.NewMsgSubmitEvidenceBase(submitter), + submitter, + false, + }, + { + simappcodec.NewMsgSubmitEvidence(&types.Equivocation{ + Height: 0, + Power: 100, + Time: time.Now().UTC(), + ConsensusAddress: pk.PubKey().Address().Bytes(), + }, submitter), + submitter, + true, + }, + { + simappcodec.NewMsgSubmitEvidence(&types.Equivocation{ + Height: 10, + Power: 100, + Time: time.Now().UTC(), + ConsensusAddress: pk.PubKey().Address().Bytes(), + }, submitter), + submitter, + false, + }, + } + + for i, tc := range testCases { + require.Equal(t, tc.msg.Route(), types.RouterKey, "unexpected result for tc #%d", i) + require.Equal(t, tc.msg.Type(), types.TypeMsgSubmitEvidence, "unexpected result for tc #%d", i) + require.Equal(t, tc.expectErr, tc.msg.ValidateBasic() != nil, "unexpected result for tc #%d", i) + + if !tc.expectErr { + require.Equal(t, tc.msg.GetSigners(), []sdk.AccAddress{tc.submitter}, "unexpected result for tc #%d", i) + } + } +} diff --git a/x/evidence/internal/types/params.go b/x/evidence/types/params.go similarity index 68% rename from x/evidence/internal/types/params.go rename to x/evidence/types/params.go index 5c0dbe638f..1f4bab1f41 100644 --- a/x/evidence/internal/types/params.go +++ b/x/evidence/types/params.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - "github.com/cosmos/cosmos-sdk/x/params" - "gopkg.in/yaml.v2" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) // DONTCOVER @@ -26,14 +26,9 @@ var ( DoubleSignJailEndTime = time.Unix(253402300799, 0) ) -// Params defines the total set of parameters for the evidence module -type Params struct { - MaxEvidenceAge time.Duration `json:"max_evidence_age" yaml:"max_evidence_age"` -} - // ParamKeyTable returns the parameter key table. -func ParamKeyTable() params.KeyTable { - return params.NewKeyTable().RegisterParamSet(&Params{}) +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) } func (p Params) String() string { @@ -42,9 +37,9 @@ func (p Params) String() string { } // ParamSetPairs returns the parameter set pairs. -func (p *Params) ParamSetPairs() params.ParamSetPairs { - return params.ParamSetPairs{ - params.NewParamSetPair(KeyMaxEvidenceAge, &p.MaxEvidenceAge, validateMaxEvidenceAge), +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyMaxEvidenceAge, &p.MaxEvidenceAge, validateMaxEvidenceAge), } } diff --git a/x/evidence/internal/types/querier.go b/x/evidence/types/querier.go similarity index 100% rename from x/evidence/internal/types/querier.go rename to x/evidence/types/querier.go diff --git a/x/evidence/internal/types/router.go b/x/evidence/types/router.go similarity index 100% rename from x/evidence/internal/types/router.go rename to x/evidence/types/router.go diff --git a/x/evidence/internal/types/router_test.go b/x/evidence/types/router_test.go similarity index 92% rename from x/evidence/internal/types/router_test.go rename to x/evidence/types/router_test.go index b8cb42d2d4..01e942e9ea 100644 --- a/x/evidence/internal/types/router_test.go +++ b/x/evidence/types/router_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/evidence/exported" - "github.com/cosmos/cosmos-sdk/x/evidence/internal/types" + "github.com/cosmos/cosmos-sdk/x/evidence/types" ) func testHandler(sdk.Context, exported.Evidence) error { return nil } diff --git a/x/evidence/types/types.pb.go b/x/evidence/types/types.pb.go new file mode 100644 index 0000000000..cf70cfe6ab --- /dev/null +++ b/x/evidence/types/types.pb.go @@ -0,0 +1,876 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: x/evidence/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/duration" + _ "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 + +// MsgSubmitEvidenceBase defines an sdk.Msg type that supports submitting arbitrary +// Evidence. +// +// Note, this message type provides the basis for which a true MsgSubmitEvidence +// can be constructed. Since the evidence submitted in the message can be arbitrary, +// assuming it fulfills the Evidence interface, it must be defined at the +// application-level and extend MsgSubmitEvidenceBase. +type MsgSubmitEvidenceBase struct { + Submitter github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=submitter,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"submitter,omitempty"` +} + +func (m *MsgSubmitEvidenceBase) Reset() { *m = MsgSubmitEvidenceBase{} } +func (m *MsgSubmitEvidenceBase) String() string { return proto.CompactTextString(m) } +func (*MsgSubmitEvidenceBase) ProtoMessage() {} +func (*MsgSubmitEvidenceBase) Descriptor() ([]byte, []int) { + return fileDescriptor_72113e6a7b2536ae, []int{0} +} +func (m *MsgSubmitEvidenceBase) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSubmitEvidenceBase) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSubmitEvidenceBase.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 *MsgSubmitEvidenceBase) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSubmitEvidenceBase.Merge(m, src) +} +func (m *MsgSubmitEvidenceBase) XXX_Size() int { + return m.Size() +} +func (m *MsgSubmitEvidenceBase) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSubmitEvidenceBase.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSubmitEvidenceBase proto.InternalMessageInfo + +func (m *MsgSubmitEvidenceBase) GetSubmitter() github_com_cosmos_cosmos_sdk_types.AccAddress { + if m != nil { + return m.Submitter + } + return nil +} + +// Equivocation implements the Evidence interface and defines evidence of double +// signing misbehavior. +type Equivocation struct { + Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` + Time time.Time `protobuf:"bytes,2,opt,name=time,proto3,stdtime" json:"time"` + Power int64 `protobuf:"varint,3,opt,name=power,proto3" json:"power,omitempty"` + ConsensusAddress github_com_cosmos_cosmos_sdk_types.ConsAddress `protobuf:"bytes,4,opt,name=consensus_address,json=consensusAddress,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ConsAddress" json:"consensus_address,omitempty" yaml:"consensus_address"` +} + +func (m *Equivocation) Reset() { *m = Equivocation{} } +func (*Equivocation) ProtoMessage() {} +func (*Equivocation) Descriptor() ([]byte, []int) { + return fileDescriptor_72113e6a7b2536ae, []int{1} +} +func (m *Equivocation) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Equivocation) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Equivocation.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 *Equivocation) XXX_Merge(src proto.Message) { + xxx_messageInfo_Equivocation.Merge(m, src) +} +func (m *Equivocation) XXX_Size() int { + return m.Size() +} +func (m *Equivocation) XXX_DiscardUnknown() { + xxx_messageInfo_Equivocation.DiscardUnknown(m) +} + +var xxx_messageInfo_Equivocation proto.InternalMessageInfo + +// Params defines the total set of parameters for the evidence module +type Params struct { + MaxEvidenceAge time.Duration `protobuf:"bytes,1,opt,name=max_evidence_age,json=maxEvidenceAge,proto3,stdduration" json:"max_evidence_age" yaml:"max_evidence_age"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_72113e6a7b2536ae, []int{2} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetMaxEvidenceAge() time.Duration { + if m != nil { + return m.MaxEvidenceAge + } + return 0 +} + +func init() { + proto.RegisterType((*MsgSubmitEvidenceBase)(nil), "cosmos_sdk.x.evidence.v1.MsgSubmitEvidenceBase") + proto.RegisterType((*Equivocation)(nil), "cosmos_sdk.x.evidence.v1.Equivocation") + proto.RegisterType((*Params)(nil), "cosmos_sdk.x.evidence.v1.Params") +} + +func init() { proto.RegisterFile("x/evidence/types/types.proto", fileDescriptor_72113e6a7b2536ae) } + +var fileDescriptor_72113e6a7b2536ae = []byte{ + // 455 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x3d, 0x6f, 0xd4, 0x30, + 0x1c, 0xc6, 0x63, 0x7a, 0x9c, 0x8a, 0x5b, 0xa1, 0x12, 0xf1, 0x12, 0x4e, 0x28, 0xae, 0x82, 0x84, + 0xba, 0xd4, 0x51, 0xcb, 0x82, 0x6e, 0xbb, 0x40, 0x27, 0xc4, 0x8b, 0x0e, 0x26, 0x96, 0xc8, 0x97, + 0x18, 0x27, 0x6a, 0x1d, 0x07, 0xdb, 0x39, 0x72, 0xe2, 0x0b, 0x30, 0x76, 0xec, 0xd8, 0x91, 0x8f, + 0xd2, 0xb1, 0x23, 0x53, 0x40, 0x77, 0xdf, 0xa0, 0x63, 0x25, 0x24, 0x74, 0x76, 0x42, 0xa5, 0xab, + 0x84, 0xba, 0x24, 0xb1, 0xf3, 0xe4, 0xc9, 0xf3, 0xfb, 0x3f, 0x86, 0x4f, 0xea, 0x90, 0x4e, 0xf3, + 0x94, 0x16, 0x09, 0x0d, 0xf5, 0xac, 0xa4, 0xca, 0x5e, 0x71, 0x29, 0x85, 0x16, 0xae, 0x97, 0x08, + 0xc5, 0x85, 0x8a, 0x55, 0x7a, 0x88, 0x6b, 0xdc, 0x09, 0xf1, 0x74, 0x6f, 0xf0, 0x4c, 0x67, 0xb9, + 0x4c, 0xe3, 0x92, 0x48, 0x3d, 0x0b, 0x8d, 0x38, 0x64, 0x82, 0x89, 0xab, 0x27, 0xeb, 0x30, 0x40, + 0x4c, 0x08, 0x76, 0x44, 0xad, 0x64, 0x52, 0x7d, 0x0e, 0x75, 0xce, 0xa9, 0xd2, 0x84, 0x97, 0xad, + 0xc0, 0x5f, 0x15, 0xa4, 0x95, 0x24, 0x3a, 0x17, 0x85, 0x7d, 0x1f, 0x64, 0xf0, 0xc1, 0x1b, 0xc5, + 0x3e, 0x54, 0x13, 0x9e, 0xeb, 0x83, 0x36, 0x40, 0x44, 0x14, 0x75, 0xdf, 0xc1, 0x3b, 0xca, 0xec, + 0x6a, 0x2a, 0x3d, 0xb0, 0x0d, 0x76, 0x36, 0xa3, 0xbd, 0xcb, 0x06, 0xed, 0xb2, 0x5c, 0x67, 0xd5, + 0x04, 0x27, 0x82, 0x87, 0x36, 0x7d, 0x7b, 0xdb, 0x55, 0xe9, 0x61, 0x0b, 0x37, 0x4a, 0x92, 0x51, + 0x9a, 0x4a, 0xaa, 0xd4, 0xf8, 0xca, 0x23, 0xf8, 0x03, 0xe0, 0xe6, 0xc1, 0x97, 0x2a, 0x9f, 0x8a, + 0xc4, 0x04, 0x70, 0x1f, 0xc2, 0x7e, 0x46, 0x73, 0x96, 0x69, 0x63, 0xbf, 0x36, 0x6e, 0x57, 0xee, + 0x0b, 0xd8, 0x5b, 0x52, 0x78, 0xb7, 0xb6, 0xc1, 0xce, 0xc6, 0xfe, 0x00, 0x5b, 0x02, 0xdc, 0x11, + 0xe0, 0x8f, 0x1d, 0x62, 0xb4, 0x7e, 0xd6, 0x20, 0xe7, 0xf8, 0x17, 0x02, 0x63, 0xf3, 0x85, 0x7b, + 0x1f, 0xde, 0x2e, 0xc5, 0x57, 0x2a, 0xbd, 0x35, 0x63, 0x68, 0x17, 0xee, 0x37, 0x78, 0x2f, 0x11, + 0x85, 0xa2, 0x85, 0xaa, 0x54, 0x4c, 0x6c, 0x30, 0xaf, 0x67, 0x88, 0xde, 0x5e, 0x34, 0xc8, 0x9b, + 0x11, 0x7e, 0x34, 0x0c, 0xae, 0x49, 0x82, 0xcb, 0x06, 0xe1, 0x1b, 0xd0, 0xbe, 0x14, 0x85, 0xea, + 0x70, 0xb7, 0xfe, 0xb9, 0xb4, 0x3b, 0xc3, 0xf5, 0xef, 0xa7, 0xc8, 0x39, 0x39, 0x45, 0x4e, 0x50, + 0xc3, 0xfe, 0x7b, 0x22, 0x09, 0x57, 0x6e, 0x06, 0xb7, 0x38, 0xa9, 0xe3, 0xae, 0xef, 0x98, 0x30, + 0x6a, 0x46, 0xb0, 0xb1, 0xff, 0xf8, 0x1a, 0xec, 0xab, 0xb6, 0xae, 0xe8, 0xe9, 0x92, 0xf5, 0xa2, + 0x41, 0x8f, 0x6c, 0xdc, 0x55, 0x83, 0xe0, 0x64, 0x39, 0x86, 0xbb, 0x9c, 0xd4, 0x5d, 0x8b, 0x23, + 0x46, 0x87, 0xbd, 0xe5, 0x9f, 0xa3, 0xd7, 0x3f, 0xe6, 0x3e, 0x38, 0x9b, 0xfb, 0xe0, 0x7c, 0xee, + 0x83, 0xdf, 0x73, 0x1f, 0x1c, 0x2f, 0x7c, 0xe7, 0x7c, 0xe1, 0x3b, 0x3f, 0x17, 0xbe, 0xf3, 0xe9, + 0xff, 0x8d, 0xae, 0x9e, 0xdf, 0x49, 0xdf, 0x44, 0x7b, 0xfe, 0x37, 0x00, 0x00, 0xff, 0xff, 0x35, + 0xfb, 0xe6, 0x44, 0xda, 0x02, 0x00, 0x00, +} + +func (this *MsgSubmitEvidenceBase) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgSubmitEvidenceBase) + if !ok { + that2, ok := that.(MsgSubmitEvidenceBase) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.Submitter, that1.Submitter) { + return false + } + return true +} +func (this *Equivocation) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Equivocation) + if !ok { + that2, ok := that.(Equivocation) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Height != that1.Height { + return false + } + if !this.Time.Equal(that1.Time) { + return false + } + if this.Power != that1.Power { + return false + } + if !bytes.Equal(this.ConsensusAddress, that1.ConsensusAddress) { + return false + } + return true +} +func (this *Params) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Params) + if !ok { + that2, ok := that.(Params) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.MaxEvidenceAge != that1.MaxEvidenceAge { + return false + } + return true +} +func (m *MsgSubmitEvidenceBase) 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 *MsgSubmitEvidenceBase) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSubmitEvidenceBase) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Submitter) > 0 { + i -= len(m.Submitter) + copy(dAtA[i:], m.Submitter) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Submitter))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Equivocation) 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 *Equivocation) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Equivocation) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ConsensusAddress) > 0 { + i -= len(m.ConsensusAddress) + copy(dAtA[i:], m.ConsensusAddress) + i = encodeVarintTypes(dAtA, i, uint64(len(m.ConsensusAddress))) + i-- + dAtA[i] = 0x22 + } + if m.Power != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Power)) + i-- + dAtA[i] = 0x18 + } + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Time, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.Time):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintTypes(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x12 + if m.Height != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n2, err2 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.MaxEvidenceAge, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.MaxEvidenceAge):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintTypes(dAtA, i, uint64(n2)) + 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 *MsgSubmitEvidenceBase) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Submitter) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *Equivocation) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Height != 0 { + n += 1 + sovTypes(uint64(m.Height)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.Time) + n += 1 + l + sovTypes(uint64(l)) + if m.Power != 0 { + n += 1 + sovTypes(uint64(m.Power)) + } + l = len(m.ConsensusAddress) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.MaxEvidenceAge) + 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 *MsgSubmitEvidenceBase) 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: MsgSubmitEvidenceBase: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSubmitEvidenceBase: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Submitter", 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.Submitter = append(m.Submitter[:0], dAtA[iNdEx:postIndex]...) + if m.Submitter == nil { + m.Submitter = []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 *Equivocation) 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: Equivocation: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Equivocation: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Time", 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.Time, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Power", wireType) + } + m.Power = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Power |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConsensusAddress", 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.ConsensusAddress = append(m.ConsensusAddress[:0], dAtA[iNdEx:postIndex]...) + if m.ConsensusAddress == nil { + m.ConsensusAddress = []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 *Params) 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: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxEvidenceAge", 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.StdDurationUnmarshal(&m.MaxEvidenceAge, 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/evidence/types/types.proto b/x/evidence/types/types.proto new file mode 100644 index 0000000000..5000686ae6 --- /dev/null +++ b/x/evidence/types/types.proto @@ -0,0 +1,46 @@ +syntax = "proto3"; +package cosmos_sdk.x.evidence.v1; + +option go_package = "github.com/cosmos/cosmos-sdk/x/evidence/types"; +option (gogoproto.equal_all) = true; + +import "third_party/proto/gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/duration.proto"; + +// MsgSubmitEvidenceBase defines an sdk.Msg type that supports submitting arbitrary +// Evidence. +// +// Note, this message type provides the basis for which a true MsgSubmitEvidence +// can be constructed. Since the evidence submitted in the message can be arbitrary, +// assuming it fulfills the Evidence interface, it must be defined at the +// application-level and extend MsgSubmitEvidenceBase. +message MsgSubmitEvidenceBase { + bytes submitter = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; +} + +// Equivocation implements the Evidence interface and defines evidence of double +// signing misbehavior. +message Equivocation { + option (gogoproto.goproto_stringer) = false; + option (gogoproto.goproto_getters) = false; + + int64 height = 1; + google.protobuf.Timestamp time = 2 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; + int64 power = 3; + bytes consensus_address = 4 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress", + (gogoproto.moretags) = "yaml:\"consensus_address\"" + ]; +} + +// Params defines the total set of parameters for the evidence module +message Params { + option (gogoproto.goproto_stringer) = false; + + google.protobuf.Duration max_evidence_age = 1 [ + (gogoproto.nullable) = false, + (gogoproto.stdduration) = true, + (gogoproto.moretags) = "yaml:\"max_evidence_age\"" + ]; +} diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index b992f446fe..641a609990 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -88,7 +88,7 @@ func GenTxCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicManager, sm return errors.Wrap(err, "failed to unmarshal genesis state") } - if err = mbm.ValidateGenesis(genesisState); err != nil { + if err = mbm.ValidateGenesis(cdc, genesisState); err != nil { return errors.Wrap(err, "failed to validate genesis state") } diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index 618f389da5..0f81c51f77 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -87,7 +87,7 @@ func InitCmd(ctx *server.Context, cdc codec.JSONMarshaler, mbm module.BasicManag if !viper.GetBool(flagOverwrite) && tmos.FileExists(genFile) { return fmt.Errorf("genesis.json file already exists: %v", genFile) } - appState, err := codec.MarshalJSONIndent(cdc, mbm.DefaultGenesis()) + appState, err := codec.MarshalJSONIndent(cdc, mbm.DefaultGenesis(cdc)) if err != nil { return errors.Wrap(err, "Failed to marshall default genesis state") } diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index 6be33bdabf..70e26f01eb 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -41,7 +41,7 @@ func ValidateGenesisCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicM return fmt.Errorf("error unmarshalling genesis doc %s: %s", genesis, err.Error()) } - if err = mbm.ValidateGenesis(genState); err != nil { + if err = mbm.ValidateGenesis(cdc, genState); err != nil { return fmt.Errorf("error validating genesis file %s: %s", genesis, err.Error()) } diff --git a/x/genutil/module.go b/x/genutil/module.go index 31ca1b4635..cedf7171f5 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -34,14 +34,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {} // DefaultGenesis returns default genesis state as raw bytes for the genutil // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(types.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the genutil module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) } @@ -82,14 +82,14 @@ func NewAppModule(accountKeeper types.AccountKeeper, // InitGenesis performs genesis initialization for the genutil module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) return InitGenesis(ctx, ModuleCdc, am.stakingKeeper, am.deliverTx, genesisState) } // ExportGenesis returns the exported genesis state as raw bytes for the genutil // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(_ sdk.Context, _ codec.JSONMarshaler) json.RawMessage { return nil } diff --git a/x/gov/genesis_test.go b/x/gov/genesis_test.go index 5e86d71cf7..133c7c4f3a 100644 --- a/x/gov/genesis_test.go +++ b/x/gov/genesis_test.go @@ -52,19 +52,19 @@ func TestImportExportQueues(t *testing.T) { // export the state and import it into a new app govGenState := gov.ExportGenesis(ctx, app.GovKeeper) - - db := dbm.NewMemDB() - app2 := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, 0) genesisState := simapp.NewDefaultGenesisState() genesisState[auth.ModuleName] = app.Codec().MustMarshalJSON(authGenState) genesisState[gov.ModuleName] = app.Codec().MustMarshalJSON(govGenState) - stateBytes, err := codec.MarshalJSONIndent(app2.Codec(), genesisState) + stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState) if err != nil { panic(err) } + db := dbm.NewMemDB() + app2 := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, 0) + app2.InitChain( abci.RequestInitChain{ Validators: []abci.ValidatorUpdate{}, diff --git a/x/gov/keeper/test_common.go b/x/gov/keeper/test_common.go index 42fe87626b..84df63afb5 100644 --- a/x/gov/keeper/test_common.go +++ b/x/gov/keeper/test_common.go @@ -1,6 +1,7 @@ -// nolint -package keeper // noalias +package keeper +// noalias +// nolint // DONTCOVER import ( @@ -9,22 +10,22 @@ import ( "testing" "github.com/stretchr/testify/require" - + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" - - abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" tmtypes "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/codec" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/params" + "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/supply" ) @@ -102,8 +103,8 @@ func createTestInput( keyGov := sdk.NewKVStoreKey(types.StoreKey) keyStaking := sdk.NewKVStoreKey(staking.StoreKey) keySupply := sdk.NewKVStoreKey(supply.StoreKey) - keyParams := sdk.NewKVStoreKey(params.StoreKey) - tkeyParams := sdk.NewTransientStoreKey(params.TStoreKey) + keyParams := sdk.NewKVStoreKey(paramtypes.StoreKey) + tkeyParams := sdk.NewTransientStoreKey(paramtypes.TStoreKey) db := dbm.NewMemDB() ms := store.NewCommitMultiStore(db) @@ -125,7 +126,9 @@ func createTestInput( }, }, ) + cdc := makeTestCodec() + appCodec := simappcodec.NewAppCodec(cdc) maccPerms := map[string][]string{ auth.FeeCollectorName: nil, @@ -146,10 +149,10 @@ func createTestInput( blacklistedAddrs[notBondedPool.GetAddress().String()] = true blacklistedAddrs[bondPool.GetAddress().String()] = true - pk := params.NewKeeper(params.ModuleCdc, keyParams, tkeyParams) - accountKeeper := auth.NewAccountKeeper(cdc, keyAcc, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) - bankKeeper := bank.NewBaseKeeper(cdc, keyBank, accountKeeper, pk.Subspace(bank.DefaultParamspace), blacklistedAddrs) - supplyKeeper := supply.NewKeeper(cdc, keySupply, accountKeeper, bankKeeper, maccPerms) + pk := keeper.NewKeeper(appCodec, keyParams, tkeyParams) + accountKeeper := auth.NewAccountKeeper(appCodec, keyAcc, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) + 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)) sk.SetParams(ctx, staking.DefaultParams()) diff --git a/x/gov/module.go b/x/gov/module.go index bd2cabb97e..5d07091fd1 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -54,14 +54,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { // DefaultGenesis returns default genesis state as raw bytes for the gov // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the gov module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) } @@ -149,18 +149,18 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { // InitGenesis performs genesis initialization for the gov module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.bankKeeper, am.supplyKeeper, am.keeper, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the gov // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, am.keeper) - return ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock performs a no-op. diff --git a/x/gov/types/errors.go b/x/gov/types/errors.go index 2327a6f05b..96973f1751 100644 --- a/x/gov/types/errors.go +++ b/x/gov/types/errors.go @@ -6,12 +6,12 @@ import ( // x/gov module sentinel errors var ( - ErrUnknownProposal = sdkerrors.Register(ModuleName, 1, "unknown proposal") - ErrInactiveProposal = sdkerrors.Register(ModuleName, 2, "inactive proposal") - ErrAlreadyActiveProposal = sdkerrors.Register(ModuleName, 3, "proposal already active") - ErrInvalidProposalContent = sdkerrors.Register(ModuleName, 4, "invalid proposal content") - ErrInvalidProposalType = sdkerrors.Register(ModuleName, 5, "invalid proposal type") - ErrInvalidVote = sdkerrors.Register(ModuleName, 6, "invalid vote option") - ErrInvalidGenesis = sdkerrors.Register(ModuleName, 7, "invalid genesis state") - ErrNoProposalHandlerExists = sdkerrors.Register(ModuleName, 8, "no handler exists for proposal type") + ErrUnknownProposal = sdkerrors.Register(ModuleName, 2, "unknown proposal") + ErrInactiveProposal = sdkerrors.Register(ModuleName, 3, "inactive proposal") + ErrAlreadyActiveProposal = sdkerrors.Register(ModuleName, 4, "proposal already active") + ErrInvalidProposalContent = sdkerrors.Register(ModuleName, 5, "invalid proposal content") + ErrInvalidProposalType = sdkerrors.Register(ModuleName, 6, "invalid proposal type") + ErrInvalidVote = sdkerrors.Register(ModuleName, 7, "invalid vote option") + ErrInvalidGenesis = sdkerrors.Register(ModuleName, 8, "invalid genesis state") + ErrNoProposalHandlerExists = sdkerrors.Register(ModuleName, 9, "no handler exists for proposal type") ) diff --git a/x/gov/types/params.go b/x/gov/types/params.go index ff671d4931..d15ae88b85 100644 --- a/x/gov/types/params.go +++ b/x/gov/types/params.go @@ -5,7 +5,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" - params "github.com/cosmos/cosmos-sdk/x/params/subspace" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) // Default period for deposits & voting @@ -29,11 +29,11 @@ var ( ) // ParamKeyTable - Key declaration for parameters -func ParamKeyTable() params.KeyTable { - return params.NewKeyTable( - params.NewParamSetPair(ParamStoreKeyDepositParams, DepositParams{}, validateDepositParams), - params.NewParamSetPair(ParamStoreKeyVotingParams, VotingParams{}, validateVotingParams), - params.NewParamSetPair(ParamStoreKeyTallyParams, TallyParams{}, validateTallyParams), +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable( + paramtypes.NewParamSetPair(ParamStoreKeyDepositParams, DepositParams{}, validateDepositParams), + paramtypes.NewParamSetPair(ParamStoreKeyVotingParams, VotingParams{}, validateVotingParams), + paramtypes.NewParamSetPair(ParamStoreKeyTallyParams, TallyParams{}, validateTallyParams), ) } diff --git a/x/ibc/24-host/errors.go b/x/ibc/24-host/errors.go new file mode 100644 index 0000000000..26b7919e6c --- /dev/null +++ b/x/ibc/24-host/errors.go @@ -0,0 +1,15 @@ +package host + +import ( + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +// SubModuleName defines the ICS 24 host +const SubModuleName = "host" + +// IBC client sentinel errors +var ( + ErrInvalidID = sdkerrors.Register(SubModuleName, 1, "invalid identifier") + ErrInvalidPath = sdkerrors.Register(SubModuleName, 2, "invalid path") + ErrInvalidPacket = sdkerrors.Register(SubModuleName, 3, "invalid packet") +) diff --git a/x/ibc/24-host/utils.go b/x/ibc/24-host/utils.go new file mode 100644 index 0000000000..c75f356561 --- /dev/null +++ b/x/ibc/24-host/utils.go @@ -0,0 +1,11 @@ +package host + +// RemovePath is an util function to remove a path from a set. +func RemovePath(paths []string, path string) ([]string, bool) { + for i, p := range paths { + if p == path { + return append(paths[:i], paths[i+1:]...), true + } + } + return paths, false +} diff --git a/x/ibc/24-host/validate.go b/x/ibc/24-host/validate.go new file mode 100644 index 0000000000..e75e63e6c2 --- /dev/null +++ b/x/ibc/24-host/validate.go @@ -0,0 +1,96 @@ +package host + +import ( + "strings" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +// ICS 024 Identifier and Path Validation Implementation +// +// This file defines ValidateFn to validate identifier and path strings +// The spec for ICS 024 can be located here: +// https://github.com/cosmos/ics/tree/master/spec/ics-024-host-requirements + +// ValidateFn function type to validate path and identifier bytestrings +type ValidateFn func(string) error + +func defaultIdentifierValidator(id string, min, max int) error { + // valid id MUST NOT contain "/" separator + if strings.Contains(id, "/") { + return sdkerrors.Wrapf(ErrInvalidID, "identifier %s cannot contain separator '/'", id) + } + // valid id must be between 10 and 20 characters + if len(id) < min || len(id) > max { + return sdkerrors.Wrapf(ErrInvalidID, "identifier %s has invalid length: %d, must be between %d-%d characters", id, len(id), min, max) + } + // valid id must contain only lower alphabetic characters + if !sdk.IsAlphaLower(id) { + return sdkerrors.Wrapf(ErrInvalidID, "identifier %s must contain only lowercase alphabetic characters", id) + } + return nil +} + +// DefaultClientIdentifierValidator is the default validator function for Client identifiers +// A valid Identifier must be between 10-20 characters and only contain lowercase +// alphabetic characters, +func DefaultClientIdentifierValidator(id string) error { + return defaultIdentifierValidator(id, 10, 20) +} + +// DefaultConnectionIdentifierValidator is the default validator function for Connection identifiers +// A valid Identifier must be between 10-20 characters and only contain lowercase +// alphabetic characters, +func DefaultConnectionIdentifierValidator(id string) error { + return defaultIdentifierValidator(id, 10, 20) +} + +// DefaultChannelIdentifierValidator is the default validator function for Channel identifiers +// A valid Identifier must be between 10-20 characters and only contain lowercase +// alphabetic characters, +func DefaultChannelIdentifierValidator(id string) error { + return defaultIdentifierValidator(id, 10, 20) +} + +// DefaultPortIdentifierValidator is the default validator function for Port identifiers +// A valid Identifier must be between 2-20 characters and only contain lowercase +// alphabetic characters, +func DefaultPortIdentifierValidator(id string) error { + return defaultIdentifierValidator(id, 2, 20) +} + +// NewPathValidator takes in a Identifier Validator function and returns +// a Path Validator function which requires path only has valid identifiers +// alphanumeric character strings, and "/" separators +func NewPathValidator(idValidator ValidateFn) ValidateFn { + return func(path string) error { + pathArr := strings.Split(path, "/") + for _, p := range pathArr { + // Each path element must either be valid identifier or alphanumeric + err := idValidator(p) + if err != nil && !sdk.IsAlphaNumeric(p) { + return sdkerrors.Wrapf(ErrInvalidPath, "path %s contains invalid identifier or non-alphanumeric path element: %s", path, p) + } + } + return nil + } +} + +// DefaultPathValidator takes in path string and validates +// with default identifier rules. This is optimized by simply +// checking that all path elements are alphanumeric +func DefaultPathValidator(path string) error { + pathArr := strings.Split(path, "/") + if pathArr[0] == path { + return sdkerrors.Wrapf(ErrInvalidPath, "path %s doesn't contain any separator '/'", path) + } + + for _, p := range pathArr { + // Each path element must be alphanumeric and non-blank + if strings.TrimSpace(p) == "" || !sdk.IsAlphaNumeric(p) { + return sdkerrors.Wrapf(ErrInvalidPath, "path %s contains an invalid non-alphanumeric character: '%s'", path, p) + } + } + return nil +} diff --git a/x/mint/abci.go b/x/mint/abci.go index 07d8d84624..21595b466f 100644 --- a/x/mint/abci.go +++ b/x/mint/abci.go @@ -2,7 +2,7 @@ package mint import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/mint/internal/types" + "github.com/cosmos/cosmos-sdk/x/mint/types" ) // BeginBlocker mints new tokens for the previous block. diff --git a/x/mint/alias.go b/x/mint/alias.go index c6d2330f9a..62c75396a8 100644 --- a/x/mint/alias.go +++ b/x/mint/alias.go @@ -3,8 +3,8 @@ package mint // nolint import ( - "github.com/cosmos/cosmos-sdk/x/mint/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/mint/internal/types" + "github.com/cosmos/cosmos-sdk/x/mint/keeper" + "github.com/cosmos/cosmos-sdk/x/mint/types" ) const ( diff --git a/x/mint/client/cli/query.go b/x/mint/client/cli/query.go index ec37cde40c..c11f7394ab 100644 --- a/x/mint/client/cli/query.go +++ b/x/mint/client/cli/query.go @@ -10,7 +10,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/mint/internal/types" + "github.com/cosmos/cosmos-sdk/x/mint/types" ) // GetQueryCmd returns the cli query commands for the minting module. diff --git a/x/mint/client/rest/query.go b/x/mint/client/rest/query.go index f6e79cc31d..f9fc7d43b1 100644 --- a/x/mint/client/rest/query.go +++ b/x/mint/client/rest/query.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/cosmos/cosmos-sdk/x/mint/internal/types" + "github.com/cosmos/cosmos-sdk/x/mint/types" ) func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) { diff --git a/x/mint/internal/types/codec.go b/x/mint/internal/types/codec.go deleted file mode 100644 index 5787f242ad..0000000000 --- a/x/mint/internal/types/codec.go +++ /dev/null @@ -1,14 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/codec" -) - -// generic sealed codec to be used throughout this module -var ModuleCdc *codec.Codec - -func init() { - ModuleCdc = codec.New() - codec.RegisterCrypto(ModuleCdc) - ModuleCdc.Seal() -} diff --git a/x/mint/internal/keeper/integration_test.go b/x/mint/keeper/integration_test.go similarity index 90% rename from x/mint/internal/keeper/integration_test.go rename to x/mint/keeper/integration_test.go index ba02e04447..db1efaca3f 100644 --- a/x/mint/internal/keeper/integration_test.go +++ b/x/mint/keeper/integration_test.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/mint/internal/types" + "github.com/cosmos/cosmos-sdk/x/mint/types" ) // returns context and an app with updated mint keeper diff --git a/x/mint/internal/keeper/keeper.go b/x/mint/keeper/keeper.go similarity index 91% rename from x/mint/internal/keeper/keeper.go rename to x/mint/keeper/keeper.go index 3be3146fdf..9c708f6b5b 100644 --- a/x/mint/internal/keeper/keeper.go +++ b/x/mint/keeper/keeper.go @@ -7,15 +7,15 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/mint/internal/types" - "github.com/cosmos/cosmos-sdk/x/params" + "github.com/cosmos/cosmos-sdk/x/mint/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) // Keeper of the mint store type Keeper struct { - cdc *codec.Codec + cdc codec.Marshaler storeKey sdk.StoreKey - paramSpace params.Subspace + paramSpace paramtypes.Subspace sk types.StakingKeeper supplyKeeper types.SupplyKeeper feeCollectorName string @@ -23,7 +23,7 @@ type Keeper struct { // NewKeeper creates a new mint Keeper instance func NewKeeper( - cdc *codec.Codec, key sdk.StoreKey, paramSpace params.Subspace, + cdc codec.Marshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace, sk types.StakingKeeper, supplyKeeper types.SupplyKeeper, feeCollectorName string, ) Keeper { @@ -64,7 +64,7 @@ func (k Keeper) GetMinter(ctx sdk.Context) (minter types.Minter) { // set the minter func (k Keeper) SetMinter(ctx sdk.Context, minter types.Minter) { store := ctx.KVStore(k.storeKey) - b := k.cdc.MustMarshalBinaryLengthPrefixed(minter) + b := k.cdc.MustMarshalBinaryLengthPrefixed(&minter) store.Set(types.MinterKey, b) } diff --git a/x/mint/internal/keeper/querier.go b/x/mint/keeper/querier.go similarity index 96% rename from x/mint/internal/keeper/querier.go rename to x/mint/keeper/querier.go index 258d1b111e..7c52ef1001 100644 --- a/x/mint/internal/keeper/querier.go +++ b/x/mint/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/mint/internal/types" + "github.com/cosmos/cosmos-sdk/x/mint/types" ) // NewQuerier returns a minting Querier handler. diff --git a/x/mint/internal/keeper/querier_test.go b/x/mint/keeper/querier_test.go similarity index 94% rename from x/mint/internal/keeper/querier_test.go rename to x/mint/keeper/querier_test.go index 287afea9fa..07c191f1b7 100644 --- a/x/mint/internal/keeper/querier_test.go +++ b/x/mint/keeper/querier_test.go @@ -6,8 +6,8 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" - keep "github.com/cosmos/cosmos-sdk/x/mint/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/mint/internal/types" + keep "github.com/cosmos/cosmos-sdk/x/mint/keeper" + "github.com/cosmos/cosmos-sdk/x/mint/types" abci "github.com/tendermint/tendermint/abci/types" ) diff --git a/x/mint/module.go b/x/mint/module.go index 95b171251e..53bd8fff13 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -41,14 +41,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {} // DefaultGenesis returns default genesis state as raw bytes for the mint // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the mint module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) } @@ -111,18 +111,18 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { // InitGenesis performs genesis initialization for the mint module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.keeper, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the mint // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, am.keeper) - return ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock returns the begin blocker for the mint module. diff --git a/x/mint/simulation/decoder.go b/x/mint/simulation/decoder.go index f1c9f6bda6..5cdac40e88 100644 --- a/x/mint/simulation/decoder.go +++ b/x/mint/simulation/decoder.go @@ -7,7 +7,7 @@ import ( tmkv "github.com/tendermint/tendermint/libs/kv" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/mint/internal/types" + "github.com/cosmos/cosmos-sdk/x/mint/types" ) // DecodeStore unmarshals the KVPair's Value to the corresponding mint type diff --git a/x/mint/simulation/decoder_test.go b/x/mint/simulation/decoder_test.go index f92a84f5df..47ed9bebbe 100644 --- a/x/mint/simulation/decoder_test.go +++ b/x/mint/simulation/decoder_test.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/mint/internal/types" + "github.com/cosmos/cosmos-sdk/x/mint/types" ) func makeTestCodec() (cdc *codec.Codec) { diff --git a/x/mint/simulation/genesis.go b/x/mint/simulation/genesis.go index 07a750d30e..b4b3e1534c 100644 --- a/x/mint/simulation/genesis.go +++ b/x/mint/simulation/genesis.go @@ -10,7 +10,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/x/mint/internal/types" + "github.com/cosmos/cosmos-sdk/x/mint/types" ) // Simulation parameter constants diff --git a/x/mint/simulation/params.go b/x/mint/simulation/params.go index 4f73183f05..a467ac0fbf 100644 --- a/x/mint/simulation/params.go +++ b/x/mint/simulation/params.go @@ -6,7 +6,7 @@ import ( "fmt" "math/rand" - "github.com/cosmos/cosmos-sdk/x/mint/internal/types" + "github.com/cosmos/cosmos-sdk/x/mint/types" "github.com/cosmos/cosmos-sdk/x/simulation" ) diff --git a/x/mint/types/codec.go b/x/mint/types/codec.go new file mode 100644 index 0000000000..04b22f57f2 --- /dev/null +++ b/x/mint/types/codec.go @@ -0,0 +1,22 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" +) + +var ( + amino = codec.New() + + // ModuleCdc references the global x/mint 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/mint and + // defined at the application level. + ModuleCdc = codec.NewHybridCodec(amino) +) + +func init() { + codec.RegisterCrypto(amino) + amino.Seal() +} diff --git a/x/mint/internal/types/events.go b/x/mint/types/events.go similarity index 100% rename from x/mint/internal/types/events.go rename to x/mint/types/events.go diff --git a/x/mint/internal/types/expected_keepers.go b/x/mint/types/expected_keepers.go similarity index 100% rename from x/mint/internal/types/expected_keepers.go rename to x/mint/types/expected_keepers.go diff --git a/x/mint/internal/types/genesis.go b/x/mint/types/genesis.go similarity index 100% rename from x/mint/internal/types/genesis.go rename to x/mint/types/genesis.go diff --git a/x/mint/internal/types/keys.go b/x/mint/types/keys.go similarity index 100% rename from x/mint/internal/types/keys.go rename to x/mint/types/keys.go diff --git a/x/mint/internal/types/minter.go b/x/mint/types/minter.go similarity index 89% rename from x/mint/internal/types/minter.go rename to x/mint/types/minter.go index 3654ef7287..3285d6ddf0 100644 --- a/x/mint/internal/types/minter.go +++ b/x/mint/types/minter.go @@ -6,12 +6,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// Minter represents the minting state. -type Minter struct { - Inflation sdk.Dec `json:"inflation" yaml:"inflation"` // current annual inflation rate - AnnualProvisions sdk.Dec `json:"annual_provisions" yaml:"annual_provisions"` // current annual expected provisions -} - // NewMinter returns a new Minter object with the given inflation and annual // provisions values. func NewMinter(inflation, annualProvisions sdk.Dec) Minter { diff --git a/x/mint/internal/types/minter_test.go b/x/mint/types/minter_test.go similarity index 100% rename from x/mint/internal/types/minter_test.go rename to x/mint/types/minter_test.go diff --git a/x/mint/internal/types/params.go b/x/mint/types/params.go similarity index 68% rename from x/mint/internal/types/params.go rename to x/mint/types/params.go index 082c9ff225..674c04d489 100644 --- a/x/mint/internal/types/params.go +++ b/x/mint/types/params.go @@ -5,8 +5,10 @@ import ( "fmt" "strings" + "gopkg.in/yaml.v2" + sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/params" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) // Parameter store keys @@ -19,19 +21,9 @@ var ( KeyBlocksPerYear = []byte("BlocksPerYear") ) -// mint parameters -type Params struct { - MintDenom string `json:"mint_denom" yaml:"mint_denom"` // type of coin to mint - InflationRateChange sdk.Dec `json:"inflation_rate_change" yaml:"inflation_rate_change"` // maximum annual change in inflation rate - InflationMax sdk.Dec `json:"inflation_max" yaml:"inflation_max"` // maximum inflation rate - InflationMin sdk.Dec `json:"inflation_min" yaml:"inflation_min"` // minimum inflation rate - GoalBonded sdk.Dec `json:"goal_bonded" yaml:"goal_bonded"` // goal of percent bonded atoms - BlocksPerYear uint64 `json:"blocks_per_year" yaml:"blocks_per_year"` // expected blocks per year -} - // ParamTable for minting module. -func ParamKeyTable() params.KeyTable { - return params.NewKeyTable().RegisterParamSet(&Params{}) +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) } func NewParams( @@ -91,29 +83,21 @@ func (p Params) Validate() error { } +// String implements the Stringer interface. func (p Params) String() string { - return fmt.Sprintf(`Minting Params: - Mint Denom: %s - Inflation Rate Change: %s - Inflation Max: %s - Inflation Min: %s - Goal Bonded: %s - Blocks Per Year: %d -`, - p.MintDenom, p.InflationRateChange, p.InflationMax, - p.InflationMin, p.GoalBonded, p.BlocksPerYear, - ) + out, _ := yaml.Marshal(p) + return string(out) } // Implements params.ParamSet -func (p *Params) ParamSetPairs() params.ParamSetPairs { - return params.ParamSetPairs{ - params.NewParamSetPair(KeyMintDenom, &p.MintDenom, validateMintDenom), - params.NewParamSetPair(KeyInflationRateChange, &p.InflationRateChange, validateInflationRateChange), - params.NewParamSetPair(KeyInflationMax, &p.InflationMax, validateInflationMax), - params.NewParamSetPair(KeyInflationMin, &p.InflationMin, validateInflationMin), - params.NewParamSetPair(KeyGoalBonded, &p.GoalBonded, validateGoalBonded), - params.NewParamSetPair(KeyBlocksPerYear, &p.BlocksPerYear, validateBlocksPerYear), +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyMintDenom, &p.MintDenom, validateMintDenom), + paramtypes.NewParamSetPair(KeyInflationRateChange, &p.InflationRateChange, validateInflationRateChange), + paramtypes.NewParamSetPair(KeyInflationMax, &p.InflationMax, validateInflationMax), + paramtypes.NewParamSetPair(KeyInflationMin, &p.InflationMin, validateInflationMin), + paramtypes.NewParamSetPair(KeyGoalBonded, &p.GoalBonded, validateGoalBonded), + paramtypes.NewParamSetPair(KeyBlocksPerYear, &p.BlocksPerYear, validateBlocksPerYear), } } diff --git a/x/mint/types/types.pb.go b/x/mint/types/types.pb.go new file mode 100644 index 0000000000..039fcbe081 --- /dev/null +++ b/x/mint/types/types.pb.go @@ -0,0 +1,785 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: x/mint/types/types.proto + +package types + +import ( + 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" + 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 + +// Minter represents the minting state. +type Minter struct { + // current annual inflation rate + Inflation github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=inflation,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"inflation"` + // current annual expected provisions + AnnualProvisions github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=annual_provisions,json=annualProvisions,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"annual_provisions" yaml:"annual_provisions"` +} + +func (m *Minter) Reset() { *m = Minter{} } +func (m *Minter) String() string { return proto.CompactTextString(m) } +func (*Minter) ProtoMessage() {} +func (*Minter) Descriptor() ([]byte, []int) { + return fileDescriptor_fcb8be2eaea25b48, []int{0} +} +func (m *Minter) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Minter) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Minter.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 *Minter) XXX_Merge(src proto.Message) { + xxx_messageInfo_Minter.Merge(m, src) +} +func (m *Minter) XXX_Size() int { + return m.Size() +} +func (m *Minter) XXX_DiscardUnknown() { + xxx_messageInfo_Minter.DiscardUnknown(m) +} + +var xxx_messageInfo_Minter proto.InternalMessageInfo + +// mint parameters +type Params struct { + // type of coin to mint + MintDenom string `protobuf:"bytes,1,opt,name=mint_denom,json=mintDenom,proto3" json:"mint_denom,omitempty"` + // maximum annual change in inflation rate + InflationRateChange github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=inflation_rate_change,json=inflationRateChange,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"inflation_rate_change" yaml:"inflation_rate_change"` + // maximum inflation rate + InflationMax github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=inflation_max,json=inflationMax,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"inflation_max" yaml:"inflation_max"` + // minimum inflation rate + InflationMin github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=inflation_min,json=inflationMin,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"inflation_min" yaml:"inflation_min"` + // goal of percent bonded atoms + GoalBonded github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=goal_bonded,json=goalBonded,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"goal_bonded" yaml:"goal_bonded"` + // expected blocks per year + BlocksPerYear uint64 `protobuf:"varint,6,opt,name=blocks_per_year,json=blocksPerYear,proto3" json:"blocks_per_year,omitempty" yaml:"blocks_per_year"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_fcb8be2eaea25b48, []int{1} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetMintDenom() string { + if m != nil { + return m.MintDenom + } + return "" +} + +func (m *Params) GetBlocksPerYear() uint64 { + if m != nil { + return m.BlocksPerYear + } + return 0 +} + +func init() { + proto.RegisterType((*Minter)(nil), "cosmos_sdk.x.mint.v1.Minter") + proto.RegisterType((*Params)(nil), "cosmos_sdk.x.mint.v1.Params") +} + +func init() { proto.RegisterFile("x/mint/types/types.proto", fileDescriptor_fcb8be2eaea25b48) } + +var fileDescriptor_fcb8be2eaea25b48 = []byte{ + // 439 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x93, 0xb1, 0x6e, 0xd3, 0x40, + 0x1c, 0xc6, 0x6d, 0x48, 0x23, 0xe5, 0xa0, 0x02, 0x8e, 0x82, 0xac, 0x0a, 0xec, 0xca, 0x43, 0xd5, + 0x05, 0x5b, 0x88, 0xad, 0xa3, 0x89, 0x18, 0x10, 0x45, 0x91, 0x37, 0x58, 0x4e, 0xff, 0xd8, 0x87, + 0x73, 0x8a, 0xef, 0xce, 0xba, 0xbb, 0x16, 0x67, 0xe5, 0x09, 0x18, 0x19, 0x79, 0x0b, 0x5e, 0xa1, + 0x1b, 0x1d, 0x11, 0x43, 0x84, 0x92, 0x37, 0xe8, 0x13, 0x20, 0xdf, 0x45, 0x09, 0x04, 0x96, 0x48, + 0x5d, 0x6c, 0xff, 0x3f, 0x7d, 0xff, 0xef, 0xf7, 0xf9, 0xa4, 0x43, 0x41, 0x9b, 0x72, 0x26, 0x4c, + 0x6a, 0x66, 0x0d, 0xd5, 0xee, 0x99, 0x34, 0x4a, 0x1a, 0x89, 0x0f, 0x0a, 0xa9, 0xb9, 0xd4, 0x44, + 0x97, 0xd3, 0xa4, 0x4d, 0x3a, 0x53, 0x72, 0xf1, 0xfc, 0xf0, 0xd8, 0x4c, 0x98, 0x2a, 0x49, 0x03, + 0xca, 0xcc, 0x52, 0x6b, 0x4c, 0x2b, 0x59, 0xc9, 0xcd, 0x97, 0xdb, 0x8e, 0xbf, 0xfb, 0xa8, 0x7f, + 0xc6, 0x84, 0xa1, 0x0a, 0xbf, 0x41, 0x03, 0x26, 0x3e, 0xd4, 0x60, 0x98, 0x14, 0x81, 0x7f, 0xe4, + 0x9f, 0x0c, 0xb2, 0xe4, 0x72, 0x1e, 0x79, 0x3f, 0xe7, 0xd1, 0x71, 0xc5, 0xcc, 0xe4, 0x7c, 0x9c, + 0x14, 0x92, 0xa7, 0x0e, 0xb7, 0x7a, 0x3d, 0xd3, 0xe5, 0x74, 0xd5, 0x66, 0x48, 0x8b, 0x7c, 0x13, + 0x80, 0x3f, 0xa2, 0x07, 0x20, 0xc4, 0x39, 0xd4, 0xa4, 0x51, 0xf2, 0x82, 0x69, 0x26, 0x85, 0x0e, + 0x6e, 0xd9, 0xd4, 0xd7, 0xbb, 0xa5, 0x5e, 0xcf, 0xa3, 0x60, 0x06, 0xbc, 0x3e, 0x8d, 0xff, 0x09, + 0x8c, 0xf3, 0xfb, 0x4e, 0x1b, 0x6d, 0xa4, 0x6f, 0x3d, 0xd4, 0x1f, 0x81, 0x02, 0xae, 0xf1, 0x53, + 0x84, 0xba, 0xf3, 0x20, 0x25, 0x15, 0x92, 0xbb, 0x5f, 0xca, 0x07, 0x9d, 0x32, 0xec, 0x04, 0xfc, + 0xc9, 0x47, 0x8f, 0xd6, 0x85, 0x89, 0x02, 0x43, 0x49, 0x31, 0x01, 0x51, 0xd1, 0x55, 0xcf, 0xb7, + 0x3b, 0xf7, 0x7c, 0xe2, 0x7a, 0xfe, 0x37, 0x34, 0xce, 0x1f, 0xae, 0xf5, 0x1c, 0x0c, 0x7d, 0x69, + 0x55, 0x3c, 0x45, 0xfb, 0x1b, 0x3b, 0x87, 0x36, 0xb8, 0x6d, 0xd9, 0xaf, 0x76, 0x66, 0x1f, 0x6c, + 0xb3, 0x39, 0xb4, 0x71, 0x7e, 0x77, 0x3d, 0x9f, 0x41, 0xbb, 0x05, 0x63, 0x22, 0xe8, 0xdd, 0x18, + 0x8c, 0x89, 0xbf, 0x60, 0x4c, 0x60, 0x8a, 0xee, 0x54, 0x12, 0x6a, 0x32, 0x96, 0xa2, 0xa4, 0x65, + 0xb0, 0x67, 0x51, 0xc3, 0x9d, 0x51, 0xd8, 0xa1, 0xfe, 0x88, 0x8a, 0x73, 0xd4, 0x4d, 0x99, 0x1d, + 0x70, 0x86, 0xee, 0x8d, 0x6b, 0x59, 0x4c, 0x35, 0x69, 0xa8, 0x22, 0x33, 0x0a, 0x2a, 0xe8, 0x1f, + 0xf9, 0x27, 0xbd, 0xec, 0xf0, 0x7a, 0x1e, 0x3d, 0x76, 0xcb, 0x5b, 0x86, 0x38, 0xdf, 0x77, 0xca, + 0x88, 0xaa, 0x77, 0x14, 0xd4, 0x69, 0xef, 0xcb, 0xd7, 0xc8, 0xcb, 0xa2, 0xcb, 0x45, 0xe8, 0x5f, + 0x2d, 0x42, 0xff, 0xd7, 0x22, 0xf4, 0x3f, 0x2f, 0x43, 0xef, 0x6a, 0x19, 0x7a, 0x3f, 0x96, 0xa1, + 0xf7, 0x7e, 0xcf, 0x16, 0x1a, 0xf7, 0xed, 0x9d, 0x79, 0xf1, 0x3b, 0x00, 0x00, 0xff, 0xff, 0x9e, + 0xe3, 0xbd, 0x88, 0x8d, 0x03, 0x00, 0x00, +} + +func (m *Minter) 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 *Minter) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Minter) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.AnnualProvisions.Size() + i -= size + if _, err := m.AnnualProvisions.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size := m.Inflation.Size() + i -= size + if _, err := m.Inflation.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BlocksPerYear != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.BlocksPerYear)) + i-- + dAtA[i] = 0x30 + } + { + size := m.GoalBonded.Size() + i -= size + if _, err := m.GoalBonded.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + { + size := m.InflationMin.Size() + i -= size + if _, err := m.InflationMin.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + { + size := m.InflationMax.Size() + i -= size + if _, err := m.InflationMax.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size := m.InflationRateChange.Size() + i -= size + if _, err := m.InflationRateChange.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.MintDenom) > 0 { + i -= len(m.MintDenom) + copy(dAtA[i:], m.MintDenom) + i = encodeVarintTypes(dAtA, i, uint64(len(m.MintDenom))) + 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 *Minter) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Inflation.Size() + n += 1 + l + sovTypes(uint64(l)) + l = m.AnnualProvisions.Size() + n += 1 + l + sovTypes(uint64(l)) + return n +} + +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.MintDenom) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = m.InflationRateChange.Size() + n += 1 + l + sovTypes(uint64(l)) + l = m.InflationMax.Size() + n += 1 + l + sovTypes(uint64(l)) + l = m.InflationMin.Size() + n += 1 + l + sovTypes(uint64(l)) + l = m.GoalBonded.Size() + n += 1 + l + sovTypes(uint64(l)) + if m.BlocksPerYear != 0 { + n += 1 + sovTypes(uint64(m.BlocksPerYear)) + } + 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 *Minter) 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: Minter: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Minter: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Inflation", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Inflation.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AnnualProvisions", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.AnnualProvisions.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 *Params) 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: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MintDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MintDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InflationRateChange", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.InflationRateChange.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InflationMax", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.InflationMax.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InflationMin", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.InflationMin.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GoalBonded", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.GoalBonded.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BlocksPerYear", wireType) + } + m.BlocksPerYear = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BlocksPerYear |= uint64(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/mint/types/types.proto b/x/mint/types/types.proto new file mode 100644 index 0000000000..700e05cb1a --- /dev/null +++ b/x/mint/types/types.proto @@ -0,0 +1,53 @@ +syntax = "proto3"; +package cosmos_sdk.x.mint.v1; + +option go_package = "types"; + +import "third_party/proto/gogoproto/gogo.proto"; + +// Minter represents the minting state. +message Minter { + // current annual inflation rate + string inflation = 1 + [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + // current annual expected provisions + string annual_provisions = 2 [ + (gogoproto.moretags) = "yaml:\"annual_provisions\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; +} + +// mint parameters +message Params { + option (gogoproto.goproto_stringer) = false; + + // type of coin to mint + string mint_denom = 1; + // maximum annual change in inflation rate + string inflation_rate_change = 2 [ + (gogoproto.moretags) = "yaml:\"inflation_rate_change\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + // maximum inflation rate + string inflation_max = 3 [ + (gogoproto.moretags) = "yaml:\"inflation_max\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + // minimum inflation rate + string inflation_min = 4 [ + (gogoproto.moretags) = "yaml:\"inflation_min\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + // goal of percent bonded atoms + string goal_bonded = 5 [ + (gogoproto.moretags) = "yaml:\"goal_bonded\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + // expected blocks per year + uint64 blocks_per_year = 6 [(gogoproto.moretags) = "yaml:\"blocks_per_year\""]; +} diff --git a/x/params/alias.go b/x/params/alias.go index 668056267e..3824236d23 100644 --- a/x/params/alias.go +++ b/x/params/alias.go @@ -3,47 +3,26 @@ package params // nolint import ( - "github.com/cosmos/cosmos-sdk/x/params/subspace" + "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/cosmos/cosmos-sdk/x/params/types" ) const ( - StoreKey = subspace.StoreKey - TStoreKey = subspace.TStoreKey - ModuleName = types.ModuleName - RouterKey = types.RouterKey - ProposalTypeChange = types.ProposalTypeChange + StoreKey = types.StoreKey + TStoreKey = types.TStoreKey ) var ( // functions aliases - NewParamSetPair = subspace.NewParamSetPair - NewSubspace = subspace.NewSubspace - NewKeyTable = subspace.NewKeyTable - RegisterCodec = types.RegisterCodec - ErrUnknownSubspace = types.ErrUnknownSubspace - ErrSettingParameter = types.ErrSettingParameter - ErrEmptyChanges = types.ErrEmptyChanges - ErrEmptySubspace = types.ErrEmptySubspace - ErrEmptyKey = types.ErrEmptyKey - ErrEmptyValue = types.ErrEmptyValue - NewParameterChangeProposal = types.NewParameterChangeProposal - NewParamChange = types.NewParamChange - ValidateChanges = types.ValidateChanges - NewCodec = types.NewCodec - - // variable aliases - ModuleCdc = types.ModuleCdc + NewKeeper = keeper.NewKeeper ) type ( - Codec = types.Codec - ParamSetPair = subspace.ParamSetPair - ParamSetPairs = subspace.ParamSetPairs - ParamSet = subspace.ParamSet - Subspace = subspace.Subspace - ReadOnlySubspace = subspace.ReadOnlySubspace - KeyTable = subspace.KeyTable - ParameterChangeProposal = types.ParameterChangeProposal - ParamChange = types.ParamChange + Keeper = keeper.Keeper + ParamSetPair = types.ParamSetPair + ParamSetPairs = types.ParamSetPairs + ParamSet = types.ParamSet + Subspace = types.Subspace + ReadOnlySubspace = types.ReadOnlySubspace + KeyTable = types.KeyTable ) diff --git a/x/params/client/cli/tx.go b/x/params/client/cli/tx.go index 5b4fe2a9fa..67a890a51e 100644 --- a/x/params/client/cli/tx.go +++ b/x/params/client/cli/tx.go @@ -15,7 +15,7 @@ import ( authclient "github.com/cosmos/cosmos-sdk/x/auth/client" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" paramscutils "github.com/cosmos/cosmos-sdk/x/params/client/utils" - "github.com/cosmos/cosmos-sdk/x/params/types" + paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" ) // GetCmdSubmitProposal implements a command handler for submitting a parameter @@ -75,7 +75,7 @@ Where proposal.json contains: } from := cliCtx.GetFromAddress() - content := types.NewParameterChangeProposal(proposal.Title, proposal.Description, proposal.Changes.ToParamChanges()) + content := paramproposal.NewParameterChangeProposal(proposal.Title, proposal.Description, proposal.Changes.ToParamChanges()) msg := govtypes.NewMsgSubmitProposal(content, proposal.Deposit, from) if err := msg.ValidateBasic(); err != nil { diff --git a/x/params/client/rest/rest.go b/x/params/client/rest/rest.go index e7461d3914..665dea834f 100644 --- a/x/params/client/rest/rest.go +++ b/x/params/client/rest/rest.go @@ -9,8 +9,8 @@ import ( authclient "github.com/cosmos/cosmos-sdk/x/auth/client" govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/params" paramscutils "github.com/cosmos/cosmos-sdk/x/params/client/utils" + "github.com/cosmos/cosmos-sdk/x/params/types/proposal" ) // ProposalRESTHandler returns a ProposalRESTHandler that exposes the param @@ -34,7 +34,7 @@ func postProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - content := params.NewParameterChangeProposal(req.Title, req.Description, req.Changes.ToParamChanges()) + content := proposal.NewParameterChangeProposal(req.Title, req.Description, req.Changes.ToParamChanges()) msg := govtypes.NewMsgSubmitProposal(content, req.Deposit, req.Proposer) if err := msg.ValidateBasic(); err != nil { diff --git a/x/params/client/utils/utils.go b/x/params/client/utils/utils.go index 748d98502d..231c5e2b06 100644 --- a/x/params/client/utils/utils.go +++ b/x/params/client/utils/utils.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/cosmos/cosmos-sdk/x/params" + "github.com/cosmos/cosmos-sdk/x/params/types/proposal" ) type ( @@ -49,14 +49,14 @@ func NewParamChangeJSON(subspace, key string, value json.RawMessage) ParamChange } // ToParamChange converts a ParamChangeJSON object to ParamChange. -func (pcj ParamChangeJSON) ToParamChange() params.ParamChange { - return params.NewParamChange(pcj.Subspace, pcj.Key, string(pcj.Value)) +func (pcj ParamChangeJSON) ToParamChange() proposal.ParamChange { + return proposal.NewParamChange(pcj.Subspace, pcj.Key, string(pcj.Value)) } // ToParamChanges converts a slice of ParamChangeJSON objects to a slice of // ParamChange. -func (pcj ParamChangesJSON) ToParamChanges() []params.ParamChange { - res := make([]params.ParamChange, len(pcj)) +func (pcj ParamChangesJSON) ToParamChanges() []proposal.ParamChange { + res := make([]proposal.ParamChange, len(pcj)) for i, pc := range pcj { res[i] = pc.ToParamChange() } diff --git a/x/params/commmon_test.go b/x/params/keeper/common_test.go similarity index 81% rename from x/params/commmon_test.go rename to x/params/keeper/common_test.go index c1d4bd0242..92d9f1ee56 100644 --- a/x/params/commmon_test.go +++ b/x/params/keeper/common_test.go @@ -1,16 +1,26 @@ -// nolint:deadcode,unused -package params +package keeper_test import ( - abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/libs/log" - dbm "github.com/tendermint/tm-db" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + "github.com/cosmos/cosmos-sdk/x/params/types/proposal" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/log" + dbm "github.com/tendermint/tm-db" ) +func testComponents() (codec.Marshaler, sdk.Context, sdk.StoreKey, sdk.StoreKey, paramskeeper.Keeper) { + cdc := createTestCodec() + mkey := sdk.NewKVStoreKey("test") + tkey := sdk.NewTransientStoreKey("transient_test") + ctx := defaultContext(mkey, tkey) + keeper := paramskeeper.NewKeeper(cdc, mkey, tkey) + + return cdc, ctx, mkey, tkey, keeper +} + type invalid struct{} type s struct { @@ -22,7 +32,7 @@ func createTestCodec() codec.Marshaler { sdk.RegisterCodec(cdc) cdc.RegisterConcrete(s{}, "test/s", nil) cdc.RegisterConcrete(invalid{}, "test/invalid", nil) - return NewCodec(cdc) + return proposal.NewCodec(cdc) } func defaultContext(key sdk.StoreKey, tkey sdk.StoreKey) sdk.Context { @@ -37,13 +47,3 @@ func defaultContext(key sdk.StoreKey, tkey sdk.StoreKey) sdk.Context { ctx := sdk.NewContext(cms, abci.Header{}, false, log.NewNopLogger()) return ctx } - -func testComponents() (codec.Marshaler, sdk.Context, sdk.StoreKey, sdk.StoreKey, Keeper) { - cdc := createTestCodec() - mkey := sdk.NewKVStoreKey("test") - tkey := sdk.NewTransientStoreKey("transient_test") - ctx := defaultContext(mkey, tkey) - keeper := NewKeeper(cdc, mkey, tkey) - - return cdc, ctx, mkey, tkey, keeper -} diff --git a/x/params/keeper.go b/x/params/keeper/keeper.go similarity index 67% rename from x/params/keeper.go rename to x/params/keeper/keeper.go index a290e65612..628548acb1 100644 --- a/x/params/keeper.go +++ b/x/params/keeper/keeper.go @@ -1,14 +1,14 @@ -package params +package keeper import ( "fmt" + "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/params/subspace" "github.com/cosmos/cosmos-sdk/x/params/types" - - "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/x/params/types/proposal" ) // Keeper of the global paramstore @@ -16,7 +16,7 @@ type Keeper struct { cdc codec.Marshaler key sdk.StoreKey tkey sdk.StoreKey - spaces map[string]*Subspace + spaces map[string]*types.Subspace } // NewKeeper constructs a params keeper @@ -25,17 +25,17 @@ func NewKeeper(cdc codec.Marshaler, key, tkey sdk.StoreKey) Keeper { cdc: cdc, key: key, tkey: tkey, - spaces: make(map[string]*Subspace), + spaces: make(map[string]*types.Subspace), } } // Logger returns a module-specific logger. func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) + return ctx.Logger().With("module", fmt.Sprintf("x/%s", proposal.ModuleName)) } // Allocate subspace used for keepers -func (k Keeper) Subspace(s string) Subspace { +func (k Keeper) Subspace(s string) types.Subspace { _, ok := k.spaces[s] if ok { panic("subspace already occupied") @@ -45,17 +45,17 @@ func (k Keeper) Subspace(s string) Subspace { panic("cannot use empty string for subspace") } - space := subspace.NewSubspace(k.cdc, k.key, k.tkey, s) + space := types.NewSubspace(k.cdc, k.key, k.tkey, s) k.spaces[s] = &space return space } // Get existing substore from keeper -func (k Keeper) GetSubspace(s string) (Subspace, bool) { +func (k Keeper) GetSubspace(s string) (types.Subspace, bool) { space, ok := k.spaces[s] if !ok { - return Subspace{}, false + return types.Subspace{}, false } return *space, ok } diff --git a/x/params/keeper_test.go b/x/params/keeper/keeper_test.go similarity index 81% rename from x/params/keeper_test.go rename to x/params/keeper/keeper_test.go index 3f2f1a4b2b..0c34558e9f 100644 --- a/x/params/keeper_test.go +++ b/x/params/keeper/keeper_test.go @@ -1,13 +1,13 @@ -package params +package keeper_test import ( "reflect" "testing" - "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/stretchr/testify/require" ) func validateNoOp(_ interface{}) error { return nil } @@ -26,16 +26,16 @@ func TestKeeper(t *testing.T) { {"key7", 9058701}, } - table := NewKeyTable( - NewParamSetPair([]byte("key1"), int64(0), validateNoOp), - NewParamSetPair([]byte("key2"), int64(0), validateNoOp), - NewParamSetPair([]byte("key3"), int64(0), validateNoOp), - NewParamSetPair([]byte("key4"), int64(0), validateNoOp), - NewParamSetPair([]byte("key5"), int64(0), validateNoOp), - NewParamSetPair([]byte("key6"), int64(0), validateNoOp), - NewParamSetPair([]byte("key7"), int64(0), validateNoOp), - NewParamSetPair([]byte("extra1"), bool(false), validateNoOp), - NewParamSetPair([]byte("extra2"), string(""), validateNoOp), + table := types.NewKeyTable( + types.NewParamSetPair([]byte("key1"), int64(0), validateNoOp), + types.NewParamSetPair([]byte("key2"), int64(0), validateNoOp), + types.NewParamSetPair([]byte("key3"), int64(0), validateNoOp), + types.NewParamSetPair([]byte("key4"), int64(0), validateNoOp), + types.NewParamSetPair([]byte("key5"), int64(0), validateNoOp), + types.NewParamSetPair([]byte("key6"), int64(0), validateNoOp), + types.NewParamSetPair([]byte("key7"), int64(0), validateNoOp), + types.NewParamSetPair([]byte("extra1"), bool(false), validateNoOp), + types.NewParamSetPair([]byte("extra2"), string(""), validateNoOp), ) cdc, ctx, skey, _, keeper := testComponents() @@ -136,19 +136,19 @@ func TestSubspace(t *testing.T) { {"struct", s{1}, s{0}, new(s)}, } - table := NewKeyTable( - NewParamSetPair([]byte("string"), string(""), validateNoOp), - NewParamSetPair([]byte("bool"), bool(false), validateNoOp), - NewParamSetPair([]byte("int16"), int16(0), validateNoOp), - NewParamSetPair([]byte("int32"), int32(0), validateNoOp), - NewParamSetPair([]byte("int64"), int64(0), validateNoOp), - NewParamSetPair([]byte("uint16"), uint16(0), validateNoOp), - NewParamSetPair([]byte("uint32"), uint32(0), validateNoOp), - NewParamSetPair([]byte("uint64"), uint64(0), validateNoOp), - NewParamSetPair([]byte("int"), sdk.Int{}, validateNoOp), - NewParamSetPair([]byte("uint"), sdk.Uint{}, validateNoOp), - NewParamSetPair([]byte("dec"), sdk.Dec{}, validateNoOp), - NewParamSetPair([]byte("struct"), s{}, validateNoOp), + table := types.NewKeyTable( + types.NewParamSetPair([]byte("string"), "", validateNoOp), + types.NewParamSetPair([]byte("bool"), false, validateNoOp), + types.NewParamSetPair([]byte("int16"), int16(0), validateNoOp), + types.NewParamSetPair([]byte("int32"), int32(0), validateNoOp), + types.NewParamSetPair([]byte("int64"), int64(0), validateNoOp), + types.NewParamSetPair([]byte("uint16"), uint16(0), validateNoOp), + types.NewParamSetPair([]byte("uint32"), uint32(0), validateNoOp), + types.NewParamSetPair([]byte("uint64"), uint64(0), validateNoOp), + types.NewParamSetPair([]byte("int"), sdk.Int{}, validateNoOp), + types.NewParamSetPair([]byte("uint"), sdk.Uint{}, validateNoOp), + types.NewParamSetPair([]byte("dec"), sdk.Dec{}, validateNoOp), + types.NewParamSetPair([]byte("struct"), s{}, validateNoOp), ) store := prefix.NewStore(ctx.KVStore(key), []byte("test/")) @@ -202,7 +202,7 @@ func TestJSONUpdate(t *testing.T) { key := []byte("key") - space := keeper.Subspace("test").WithKeyTable(NewKeyTable(NewParamSetPair(key, paramJSON{}, validateNoOp))) + space := keeper.Subspace("test").WithKeyTable(types.NewKeyTable(types.NewParamSetPair(key, paramJSON{}, validateNoOp))) var param paramJSON diff --git a/x/params/module.go b/x/params/module.go index 5817b482b3..0510ed5f92 100644 --- a/x/params/module.go +++ b/x/params/module.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/params/simulation" - "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/cosmos/cosmos-sdk/x/params/types/proposal" sim "github.com/cosmos/cosmos-sdk/x/simulation" ) @@ -26,20 +26,20 @@ type AppModuleBasic struct{} // Name returns the params module's name. func (AppModuleBasic) Name() string { - return ModuleName + return proposal.ModuleName } // RegisterCodec registers the params module's types for the given codec. func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { - types.RegisterCodec(cdc) + proposal.RegisterCodec(cdc) } // DefaultGenesis returns default genesis state as raw bytes for the params // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { return nil } +func (AppModuleBasic) DefaultGenesis(_ codec.JSONMarshaler) json.RawMessage { return nil } // ValidateGenesis performs genesis state validation for the params module. -func (AppModuleBasic) ValidateGenesis(_ json.RawMessage) error { return nil } +func (AppModuleBasic) ValidateGenesis(_ codec.JSONMarshaler, _ json.RawMessage) error { return nil } // RegisterRESTRoutes registers the REST routes for the params module. func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router) {} diff --git a/x/params/proposal_handler.go b/x/params/proposal_handler.go index 339cfd7410..6af7668aa3 100644 --- a/x/params/proposal_handler.go +++ b/x/params/proposal_handler.go @@ -6,13 +6,15 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/cosmos-sdk/x/params/keeper" + "github.com/cosmos/cosmos-sdk/x/params/types/proposal" ) // NewParamChangeProposalHandler creates a new governance Handler for a ParamChangeProposal -func NewParamChangeProposalHandler(k Keeper) govtypes.Handler { +func NewParamChangeProposalHandler(k keeper.Keeper) govtypes.Handler { return func(ctx sdk.Context, content govtypes.Content) error { switch c := content.(type) { - case ParameterChangeProposal: + case proposal.ParameterChangeProposal: return handleParameterChangeProposal(ctx, k, c) default: @@ -21,11 +23,11 @@ func NewParamChangeProposalHandler(k Keeper) govtypes.Handler { } } -func handleParameterChangeProposal(ctx sdk.Context, k Keeper, p ParameterChangeProposal) error { +func handleParameterChangeProposal(ctx sdk.Context, k keeper.Keeper, p proposal.ParameterChangeProposal) error { for _, c := range p.Changes { ss, ok := k.GetSubspace(c.Subspace) if !ok { - return sdkerrors.Wrap(ErrUnknownSubspace, c.Subspace) + return sdkerrors.Wrap(proposal.ErrUnknownSubspace, c.Subspace) } k.Logger(ctx).Info( @@ -33,7 +35,7 @@ func handleParameterChangeProposal(ctx sdk.Context, k Keeper, p ParameterChangeP ) if err := ss.Update(ctx, []byte(c.Key), []byte(c.Value)); err != nil { - return sdkerrors.Wrapf(ErrSettingParameter, "key: %s, value: %s, err: %s", c.Key, c.Value, err.Error()) + return sdkerrors.Wrapf(proposal.ErrSettingParameter, "key: %s, value: %s, err: %s", c.Key, c.Value, err.Error()) } } diff --git a/x/params/proposal_handler_test.go b/x/params/proposal_handler_test.go index b0444f32ab..e15fea3596 100644 --- a/x/params/proposal_handler_test.go +++ b/x/params/proposal_handler_test.go @@ -4,17 +4,18 @@ import ( "testing" "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" - dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/params" - "github.com/cosmos/cosmos-sdk/x/params/subspace" + "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/cosmos/cosmos-sdk/x/params/types/proposal" ) func validateNoOp(_ interface{}) error { return nil } @@ -22,11 +23,11 @@ func validateNoOp(_ interface{}) error { return nil } type testInput struct { ctx sdk.Context cdc *codec.Codec - keeper params.Keeper + keeper keeper.Keeper } var ( - _ subspace.ParamSet = (*testParams)(nil) + _ types.ParamSet = (*testParams)(nil) keyMaxValidators = "MaxValidators" keySlashingRate = "SlashingRate" @@ -43,15 +44,15 @@ type testParams struct { SlashingRate testParamsSlashingRate `json:"slashing_rate" yaml:"slashing_rate"` } -func (tp *testParams) ParamSetPairs() subspace.ParamSetPairs { - return subspace.ParamSetPairs{ - params.NewParamSetPair([]byte(keyMaxValidators), &tp.MaxValidators, validateNoOp), - params.NewParamSetPair([]byte(keySlashingRate), &tp.SlashingRate, validateNoOp), +func (tp *testParams) ParamSetPairs() types.ParamSetPairs { + return types.ParamSetPairs{ + types.NewParamSetPair([]byte(keyMaxValidators), &tp.MaxValidators, validateNoOp), + types.NewParamSetPair([]byte(keySlashingRate), &tp.SlashingRate, validateNoOp), } } -func testProposal(changes ...params.ParamChange) params.ParameterChangeProposal { - return params.NewParameterChangeProposal( +func testProposal(changes ...proposal.ParamChange) proposal.ParameterChangeProposal { + return proposal.NewParameterChangeProposal( "Test", "description", changes, @@ -60,7 +61,7 @@ func testProposal(changes ...params.ParamChange) params.ParameterChangeProposal func newTestInput(t *testing.T) testInput { cdc := codec.New() - types.RegisterCodec(cdc) + proposal.RegisterCodec(cdc) db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db) @@ -74,7 +75,7 @@ func newTestInput(t *testing.T) testInput { err := cms.LoadLatestVersion() require.Nil(t, err) - keeper := params.NewKeeper(types.ModuleCdc, keyParams, tKeyParams) + keeper := keeper.NewKeeper(proposal.ModuleCdc, keyParams, tKeyParams) ctx := sdk.NewContext(cms, abci.Header{}, false, log.NewNopLogger()) return testInput{ctx, cdc, keeper} @@ -83,10 +84,10 @@ func newTestInput(t *testing.T) testInput { func TestProposalHandlerPassed(t *testing.T) { input := newTestInput(t) ss := input.keeper.Subspace(testSubspace).WithKeyTable( - params.NewKeyTable().RegisterParamSet(&testParams{}), + types.NewKeyTable().RegisterParamSet(&testParams{}), ) - tp := testProposal(params.NewParamChange(testSubspace, keyMaxValidators, "1")) + tp := testProposal(proposal.NewParamChange(testSubspace, keyMaxValidators, "1")) hdlr := params.NewParamChangeProposalHandler(input.keeper) require.NoError(t, hdlr(input.ctx, tp)) @@ -98,10 +99,10 @@ func TestProposalHandlerPassed(t *testing.T) { func TestProposalHandlerFailed(t *testing.T) { input := newTestInput(t) ss := input.keeper.Subspace(testSubspace).WithKeyTable( - params.NewKeyTable().RegisterParamSet(&testParams{}), + types.NewKeyTable().RegisterParamSet(&testParams{}), ) - tp := testProposal(params.NewParamChange(testSubspace, keyMaxValidators, "invalidType")) + tp := testProposal(proposal.NewParamChange(testSubspace, keyMaxValidators, "invalidType")) hdlr := params.NewParamChangeProposalHandler(input.keeper) require.Error(t, hdlr(input.ctx, tp)) @@ -111,19 +112,19 @@ func TestProposalHandlerFailed(t *testing.T) { func TestProposalHandlerUpdateOmitempty(t *testing.T) { input := newTestInput(t) ss := input.keeper.Subspace(testSubspace).WithKeyTable( - params.NewKeyTable().RegisterParamSet(&testParams{}), + types.NewKeyTable().RegisterParamSet(&testParams{}), ) hdlr := params.NewParamChangeProposalHandler(input.keeper) var param testParamsSlashingRate - tp := testProposal(params.NewParamChange(testSubspace, keySlashingRate, `{"downtime": 7}`)) + tp := testProposal(proposal.NewParamChange(testSubspace, keySlashingRate, `{"downtime": 7}`)) require.NoError(t, hdlr(input.ctx, tp)) ss.Get(input.ctx, []byte(keySlashingRate), ¶m) require.Equal(t, testParamsSlashingRate{0, 7}, param) - tp = testProposal(params.NewParamChange(testSubspace, keySlashingRate, `{"double_sign": 10}`)) + tp = testProposal(proposal.NewParamChange(testSubspace, keySlashingRate, `{"double_sign": 10}`)) require.NoError(t, hdlr(input.ctx, tp)) ss.Get(input.ctx, []byte(keySlashingRate), ¶m) diff --git a/x/params/simulation/operations.go b/x/params/simulation/operations.go index c9415a68e1..82018b158b 100644 --- a/x/params/simulation/operations.go +++ b/x/params/simulation/operations.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/cosmos/cosmos-sdk/x/params/types/proposal" "github.com/cosmos/cosmos-sdk/x/simulation" ) @@ -21,7 +21,7 @@ func SimulateParamChangeProposalContent(paramChangePool []simulation.ParamChange } numChanges := simulation.RandIntBetween(r, 1, lenParamChange) - paramChanges := make([]types.ParamChange, numChanges) + paramChanges := make([]proposal.ParamChange, numChanges) // map from key to empty struct; used only for look-up of the keys of the // parameters that are already in the random set of changes. @@ -40,10 +40,10 @@ func SimulateParamChangeProposalContent(paramChangePool []simulation.ParamChange // add a new distinct parameter to the set of changes and register the key // to avoid further duplicates paramChangesKeys[spc.ComposedKey()] = struct{}{} - paramChanges[i] = types.NewParamChange(spc.Subspace, spc.Key, spc.SimValue(r)) + paramChanges[i] = proposal.NewParamChange(spc.Subspace, spc.Key, spc.SimValue(r)) } - return types.NewParameterChangeProposal( + return proposal.NewParameterChangeProposal( simulation.RandStringOfLength(r, 140), // title simulation.RandStringOfLength(r, 5000), // description paramChanges, // set of changes diff --git a/x/params/subspace/table_test.go b/x/params/subspace/table_test.go deleted file mode 100644 index 6bc1a8af2a..0000000000 --- a/x/params/subspace/table_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package subspace_test - -import ( - "testing" - "time" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/x/params/subspace" -) - -func TestKeyTable(t *testing.T) { - table := subspace.NewKeyTable() - - require.Panics(t, func() { table.RegisterType(subspace.ParamSetPair{[]byte(""), nil, nil}) }) - require.Panics(t, func() { table.RegisterType(subspace.ParamSetPair{[]byte("!@#$%"), nil, nil}) }) - require.Panics(t, func() { table.RegisterType(subspace.ParamSetPair{[]byte("hello,"), nil, nil}) }) - require.Panics(t, func() { table.RegisterType(subspace.ParamSetPair{[]byte("hello"), nil, nil}) }) - - require.NotPanics(t, func() { - table.RegisterType(subspace.ParamSetPair{keyBondDenom, string("stake"), validateBondDenom}) - }) - require.NotPanics(t, func() { - table.RegisterType(subspace.ParamSetPair{keyMaxValidators, uint16(100), validateMaxValidators}) - }) - require.Panics(t, func() { - table.RegisterType(subspace.ParamSetPair{keyUnbondingTime, time.Duration(1), nil}) - }) - require.NotPanics(t, func() { - table.RegisterType(subspace.ParamSetPair{keyUnbondingTime, time.Duration(1), validateMaxValidators}) - }) - require.NotPanics(t, func() { - newTable := subspace.NewKeyTable() - newTable.RegisterParamSet(¶ms{}) - }) - - require.Panics(t, func() { table.RegisterParamSet(¶ms{}) }) - require.Panics(t, func() { subspace.NewKeyTable(subspace.ParamSetPair{[]byte(""), nil, nil}) }) - - require.NotPanics(t, func() { - subspace.NewKeyTable( - subspace.ParamSetPair{[]byte("test"), string("stake"), validateBondDenom}, - subspace.ParamSetPair{[]byte("test2"), uint16(100), validateMaxValidators}, - ) - }) -} diff --git a/x/params/subspace/common_test.go b/x/params/types/common_test.go similarity index 83% rename from x/params/subspace/common_test.go rename to x/params/types/common_test.go index 69c41478db..c7cb067c62 100644 --- a/x/params/subspace/common_test.go +++ b/x/params/types/common_test.go @@ -1,4 +1,4 @@ -package subspace_test +package types_test import ( "errors" @@ -6,7 +6,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/params/subspace" + "github.com/cosmos/cosmos-sdk/x/params/types" ) var ( @@ -59,14 +59,14 @@ func validateBondDenom(i interface{}) error { return nil } -func (p *params) ParamSetPairs() subspace.ParamSetPairs { - return subspace.ParamSetPairs{ +func (p *params) ParamSetPairs() types.ParamSetPairs { + return types.ParamSetPairs{ {keyUnbondingTime, &p.UnbondingTime, validateUnbondingTime}, {keyMaxValidators, &p.MaxValidators, validateMaxValidators}, {keyBondDenom, &p.BondDenom, validateBondDenom}, } } -func paramKeyTable() subspace.KeyTable { - return subspace.NewKeyTable().RegisterParamSet(¶ms{}) +func paramKeyTable() types.KeyTable { + return types.NewKeyTable().RegisterParamSet(¶ms{}) } diff --git a/x/params/subspace/doc.go b/x/params/types/doc.go similarity index 97% rename from x/params/subspace/doc.go rename to x/params/types/doc.go index 0bde2ebe62..861a4a2f58 100644 --- a/x/params/subspace/doc.go +++ b/x/params/types/doc.go @@ -10,4 +10,4 @@ respective parameters safely. Keeper can be treated as master permission for all Subspaces (via Keeper.GetSubspace), so should be passed to proper modules (ex. x/governance). */ -package subspace +package types diff --git a/x/params/types/errors.go b/x/params/types/errors.go deleted file mode 100644 index 4b218d9444..0000000000 --- a/x/params/types/errors.go +++ /dev/null @@ -1,15 +0,0 @@ -package types - -import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -// x/params module sentinel errors -var ( - ErrUnknownSubspace = sdkerrors.Register(ModuleName, 1, "unknown subspace") - ErrSettingParameter = sdkerrors.Register(ModuleName, 2, "failed to set parameter") - ErrEmptyChanges = sdkerrors.Register(ModuleName, 3, "submitted parameter changes are empty") - ErrEmptySubspace = sdkerrors.Register(ModuleName, 4, "parameter subspace is empty") - ErrEmptyKey = sdkerrors.Register(ModuleName, 5, "parameter key is empty") - ErrEmptyValue = sdkerrors.Register(ModuleName, 6, "parameter value is empty") -) diff --git a/x/params/subspace/paramset.go b/x/params/types/paramset.go similarity index 97% rename from x/params/subspace/paramset.go rename to x/params/types/paramset.go index 195944d8c9..80d0852be4 100644 --- a/x/params/subspace/paramset.go +++ b/x/params/types/paramset.go @@ -1,4 +1,4 @@ -package subspace +package types type ( ValueValidatorFn func(value interface{}) error diff --git a/x/params/types/codec.go b/x/params/types/proposal/codec.go similarity index 97% rename from x/params/types/codec.go rename to x/params/types/proposal/codec.go index a9436062cb..8160d51c1a 100644 --- a/x/params/types/codec.go +++ b/x/params/types/proposal/codec.go @@ -1,4 +1,4 @@ -package types +package proposal import ( "github.com/cosmos/cosmos-sdk/codec" diff --git a/x/params/types/proposal/errors.go b/x/params/types/proposal/errors.go new file mode 100644 index 0000000000..a8c891af2c --- /dev/null +++ b/x/params/types/proposal/errors.go @@ -0,0 +1,15 @@ +package proposal + +import ( + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +// x/params module sentinel errors +var ( + ErrUnknownSubspace = sdkerrors.Register(ModuleName, 2, "unknown subspace") + ErrSettingParameter = sdkerrors.Register(ModuleName, 3, "failed to set parameter") + ErrEmptyChanges = sdkerrors.Register(ModuleName, 4, "submitted parameter changes are empty") + ErrEmptySubspace = sdkerrors.Register(ModuleName, 5, "parameter subspace is empty") + ErrEmptyKey = sdkerrors.Register(ModuleName, 6, "parameter key is empty") + ErrEmptyValue = sdkerrors.Register(ModuleName, 7, "parameter value is empty") +) diff --git a/x/params/types/keys.go b/x/params/types/proposal/keys.go similarity index 90% rename from x/params/types/keys.go rename to x/params/types/proposal/keys.go index 1355a7427b..0649f41743 100644 --- a/x/params/types/keys.go +++ b/x/params/types/proposal/keys.go @@ -1,4 +1,4 @@ -package types +package proposal const ( // ModuleName defines the name of the module diff --git a/x/params/types/proposal.go b/x/params/types/proposal/proposal.go similarity index 99% rename from x/params/types/proposal.go rename to x/params/types/proposal/proposal.go index b61b59d25c..60fd6ce800 100644 --- a/x/params/types/proposal.go +++ b/x/params/types/proposal/proposal.go @@ -1,4 +1,4 @@ -package types +package proposal import ( "fmt" diff --git a/x/params/types/proposal_test.go b/x/params/types/proposal/proposal_test.go similarity index 98% rename from x/params/types/proposal_test.go rename to x/params/types/proposal/proposal_test.go index aa891c8203..a18f9c4076 100644 --- a/x/params/types/proposal_test.go +++ b/x/params/types/proposal/proposal_test.go @@ -1,4 +1,4 @@ -package types +package proposal import ( "testing" diff --git a/x/params/types/types.pb.go b/x/params/types/proposal/types.pb.go similarity index 81% rename from x/params/types/types.pb.go rename to x/params/types/proposal/types.pb.go index 5f27a306bd..29f95f728a 100644 --- a/x/params/types/types.pb.go +++ b/x/params/types/proposal/types.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: x/params/types/types.proto +// source: x/params/types/proposal/types.proto -package types +package proposal import ( fmt "fmt" @@ -34,7 +34,7 @@ type ParameterChangeProposal struct { func (m *ParameterChangeProposal) Reset() { *m = ParameterChangeProposal{} } func (*ParameterChangeProposal) ProtoMessage() {} func (*ParameterChangeProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_ed04c33aa1766c78, []int{0} + return fileDescriptor_0ab50f1d22a2cb61, []int{0} } func (m *ParameterChangeProposal) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -73,7 +73,7 @@ type ParamChange struct { func (m *ParamChange) Reset() { *m = ParamChange{} } func (*ParamChange) ProtoMessage() {} func (*ParamChange) Descriptor() ([]byte, []int) { - return fileDescriptor_ed04c33aa1766c78, []int{1} + return fileDescriptor_0ab50f1d22a2cb61, []int{1} } func (m *ParamChange) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -128,30 +128,99 @@ func init() { proto.RegisterType((*ParamChange)(nil), "cosmos_sdk.x.params.v1.ParamChange") } -func init() { proto.RegisterFile("x/params/types/types.proto", fileDescriptor_ed04c33aa1766c78) } - -var fileDescriptor_ed04c33aa1766c78 = []byte{ - // 287 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xaa, 0xd0, 0x2f, 0x48, - 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2f, 0xa9, 0x2c, 0x48, 0x85, 0x92, 0x7a, 0x05, 0x45, 0xf9, 0x25, - 0xf9, 0x42, 0x62, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, 0x7a, - 0x10, 0x65, 0x7a, 0x65, 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, - 0x25, 0x95, 0xfa, 0x60, 0xa5, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0x44, 0xbf, 0xd2, 0x02, - 0x46, 0x2e, 0xf1, 0x00, 0x90, 0xae, 0xd4, 0x92, 0xd4, 0x22, 0xe7, 0x8c, 0xc4, 0xbc, 0xf4, 0xd4, - 0x80, 0xa2, 0xfc, 0x82, 0xfc, 0xe2, 0xc4, 0x1c, 0x21, 0x11, 0x2e, 0xd6, 0x92, 0xcc, 0x92, 0x9c, - 0x54, 0x09, 0x46, 0x05, 0x46, 0x0d, 0xce, 0x20, 0x08, 0x47, 0x48, 0x81, 0x8b, 0x3b, 0x25, 0xb5, - 0x38, 0xb9, 0x28, 0xb3, 0xa0, 0x24, 0x33, 0x3f, 0x4f, 0x82, 0x09, 0x2c, 0x87, 0x2c, 0x24, 0xe4, - 0xcc, 0xc5, 0x9e, 0x0c, 0x36, 0xa9, 0x58, 0x82, 0x59, 0x81, 0x59, 0x83, 0xdb, 0x48, 0x59, 0x0f, - 0xbb, 0x2b, 0xf5, 0xc0, 0x36, 0x43, 0x6c, 0x75, 0x62, 0x39, 0x71, 0x4f, 0x9e, 0x21, 0x08, 0xa6, - 0xd3, 0x8a, 0xa3, 0x63, 0x81, 0x3c, 0xc3, 0x8c, 0x05, 0xf2, 0x0c, 0x4a, 0xe1, 0x5c, 0xdc, 0x48, - 0xea, 0x84, 0xa4, 0xb8, 0x38, 0x8a, 0x4b, 0x93, 0x8a, 0x0b, 0x12, 0x93, 0x61, 0x0e, 0x83, 0xf3, - 0x85, 0x04, 0xb8, 0x98, 0xb3, 0x53, 0x2b, 0xa1, 0x6e, 0x02, 0x31, 0x41, 0x7e, 0x28, 0x4b, 0xcc, - 0x29, 0x4d, 0x95, 0x60, 0x86, 0xf8, 0x01, 0xcc, 0xb1, 0x62, 0x01, 0x19, 0xec, 0x24, 0x7f, 0xe2, - 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, - 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xac, 0xe0, 0x20, 0x4e, 0x62, 0x03, 0x87, - 0x91, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x83, 0x64, 0xb6, 0xa5, 0x81, 0x01, 0x00, 0x00, +func init() { + proto.RegisterFile("x/params/types/proposal/types.proto", fileDescriptor_0ab50f1d22a2cb61) } +var fileDescriptor_0ab50f1d22a2cb61 = []byte{ + // 317 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xae, 0xd0, 0x2f, 0x48, + 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x2f, 0x28, 0xca, 0x2f, 0xc8, + 0x2f, 0x4e, 0xcc, 0x81, 0x70, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0xc4, 0x92, 0xf3, 0x8b, + 0x73, 0xf3, 0x8b, 0xe3, 0x8b, 0x53, 0xb2, 0xf5, 0x2a, 0xf4, 0x20, 0xea, 0xf5, 0xca, 0x0c, 0xa5, + 0xd4, 0x4a, 0x32, 0x32, 0x8b, 0x52, 0xe2, 0x0b, 0x12, 0x8b, 0x4a, 0x2a, 0xf5, 0xc1, 0x4a, 0xf5, + 0xd3, 0xf3, 0xd3, 0xf3, 0x11, 0x2c, 0x88, 0x7e, 0xa5, 0x05, 0x8c, 0x5c, 0xe2, 0x01, 0x20, 0x5d, + 0xa9, 0x25, 0xa9, 0x45, 0xce, 0x19, 0x89, 0x79, 0xe9, 0xa9, 0x01, 0x50, 0x7b, 0x84, 0x44, 0xb8, + 0x58, 0x4b, 0x32, 0x4b, 0x72, 0x52, 0x25, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0x20, 0x1c, 0x21, + 0x05, 0x2e, 0xee, 0x94, 0xd4, 0xe2, 0xe4, 0xa2, 0xcc, 0x82, 0x92, 0xcc, 0xfc, 0x3c, 0x09, 0x26, + 0xb0, 0x1c, 0xb2, 0x90, 0x90, 0x33, 0x17, 0x7b, 0x32, 0xd8, 0xa4, 0x62, 0x09, 0x66, 0x05, 0x66, + 0x0d, 0x6e, 0x23, 0x65, 0x3d, 0xec, 0xae, 0xd4, 0x03, 0xdb, 0x0c, 0xb1, 0xd5, 0x89, 0xe5, 0xc4, + 0x3d, 0x79, 0x86, 0x20, 0x98, 0x4e, 0x2b, 0x8e, 0x8e, 0x05, 0xf2, 0x0c, 0x33, 0x16, 0xc8, 0x33, + 0x28, 0x85, 0x73, 0x71, 0x23, 0xa9, 0x13, 0x92, 0xe2, 0xe2, 0x28, 0x2e, 0x4d, 0x2a, 0x2e, 0x48, + 0x4c, 0x86, 0x39, 0x0c, 0xce, 0x17, 0x12, 0xe0, 0x62, 0xce, 0x4e, 0xad, 0x84, 0xba, 0x09, 0xc4, + 0x04, 0xf9, 0xa1, 0x2c, 0x31, 0xa7, 0x34, 0x55, 0x82, 0x19, 0xe2, 0x07, 0x30, 0xc7, 0x8a, 0x05, + 0x64, 0xb0, 0x53, 0xd0, 0x8a, 0x47, 0x72, 0x8c, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, + 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, + 0xc7, 0x10, 0x65, 0x92, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x0f, 0x71, + 0x3e, 0x94, 0xd2, 0x2d, 0x4e, 0xc9, 0xd6, 0xc7, 0x11, 0x37, 0x49, 0x6c, 0xe0, 0x60, 0x35, 0x06, + 0x04, 0x00, 0x00, 0xff, 0xff, 0x17, 0xa9, 0xe7, 0x51, 0xbd, 0x01, 0x00, 0x00, +} + +func (this *ParameterChangeProposal) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ParameterChangeProposal) + if !ok { + that2, ok := that.(ParameterChangeProposal) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Title != that1.Title { + return false + } + if this.Description != that1.Description { + return false + } + if len(this.Changes) != len(that1.Changes) { + return false + } + for i := range this.Changes { + if !this.Changes[i].Equal(&that1.Changes[i]) { + return false + } + } + return true +} +func (this *ParamChange) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ParamChange) + if !ok { + that2, ok := that.(ParamChange) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Subspace != that1.Subspace { + return false + } + if this.Key != that1.Key { + return false + } + if this.Value != that1.Value { + return false + } + return true +} func (m *ParameterChangeProposal) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) diff --git a/x/params/types/types.proto b/x/params/types/proposal/types.proto similarity index 84% rename from x/params/types/types.proto rename to x/params/types/proposal/types.proto index 74f25fe097..8563b8c82d 100644 --- a/x/params/types/types.proto +++ b/x/params/types/proposal/types.proto @@ -1,7 +1,8 @@ syntax = "proto3"; package cosmos_sdk.x.params.v1; -option go_package = "types"; +option go_package = "github.com/cosmos/cosmos-sdk/x/params/types/proposal"; +option (gogoproto.equal_all) = true; import "third_party/proto/gogoproto/gogo.proto"; diff --git a/x/params/subspace/subspace.go b/x/params/types/subspace.go similarity index 99% rename from x/params/subspace/subspace.go rename to x/params/types/subspace.go index 90dc143ebb..e7fd47d3c2 100644 --- a/x/params/subspace/subspace.go +++ b/x/params/types/subspace.go @@ -1,13 +1,12 @@ -package subspace +package types import ( "fmt" "reflect" "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" ) const ( diff --git a/x/params/subspace/subspace_test.go b/x/params/types/subspace_test.go similarity index 94% rename from x/params/subspace/subspace_test.go rename to x/params/types/subspace_test.go index 3a1e56ae6b..a4c4f74d4c 100644 --- a/x/params/subspace/subspace_test.go +++ b/x/params/types/subspace_test.go @@ -1,4 +1,4 @@ -package subspace_test +package types_test import ( "fmt" @@ -13,8 +13,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/params/subspace" "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/cosmos/cosmos-sdk/x/params/types/proposal" ) type SubspaceTestSuite struct { @@ -22,11 +22,11 @@ type SubspaceTestSuite struct { cdc codec.Marshaler ctx sdk.Context - ss subspace.Subspace + ss types.Subspace } func (suite *SubspaceTestSuite) SetupTest() { - cdc := types.ModuleCdc + cdc := proposal.ModuleCdc db := dbm.NewMemDB() ms := store.NewCommitMultiStore(db) @@ -34,7 +34,7 @@ func (suite *SubspaceTestSuite) SetupTest() { ms.MountStoreWithDB(tkey, sdk.StoreTypeTransient, db) suite.NoError(ms.LoadLatestVersion()) - ss := subspace.NewSubspace(cdc, key, tkey, "testsubspace") + ss := types.NewSubspace(cdc, key, tkey, "testsubspace") suite.cdc = cdc suite.ctx = sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger()) @@ -47,7 +47,7 @@ func (suite *SubspaceTestSuite) TestKeyTable() { suite.ss.WithKeyTable(paramKeyTable()) }) suite.Require().NotPanics(func() { - ss := subspace.NewSubspace(types.ModuleCdc, key, tkey, "testsubspace2") + ss := types.NewSubspace(proposal.ModuleCdc, key, tkey, "testsubspace2") ss = ss.WithKeyTable(paramKeyTable()) }) } @@ -163,7 +163,7 @@ func (suite *SubspaceTestSuite) TestGetParamSet() { func (suite *SubspaceTestSuite) TestSetParamSet() { testCases := []struct { name string - ps subspace.ParamSet + ps types.ParamSet }{ {"invalid unbonding time", ¶ms{time.Hour * 1, 100, "stake"}}, {"invalid bond denom", ¶ms{time.Hour * 48, 100, ""}}, diff --git a/x/params/subspace/table.go b/x/params/types/table.go similarity index 98% rename from x/params/subspace/table.go rename to x/params/types/table.go index 92e72242b9..72c24dedc8 100644 --- a/x/params/subspace/table.go +++ b/x/params/types/table.go @@ -1,4 +1,4 @@ -package subspace +package types import ( "reflect" diff --git a/x/params/types/table_test.go b/x/params/types/table_test.go new file mode 100644 index 0000000000..db2c9d3215 --- /dev/null +++ b/x/params/types/table_test.go @@ -0,0 +1,45 @@ +package types_test + +import ( + "testing" + "time" + + "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/stretchr/testify/require" +) + +func TestKeyTable(t *testing.T) { + table := types.NewKeyTable() + + require.Panics(t, func() { table.RegisterType(types.ParamSetPair{[]byte(""), nil, nil}) }) + require.Panics(t, func() { table.RegisterType(types.ParamSetPair{[]byte("!@#$%"), nil, nil}) }) + require.Panics(t, func() { table.RegisterType(types.ParamSetPair{[]byte("hello,"), nil, nil}) }) + require.Panics(t, func() { table.RegisterType(types.ParamSetPair{[]byte("hello"), nil, nil}) }) + + require.NotPanics(t, func() { + table.RegisterType(types.ParamSetPair{keyBondDenom, string("stake"), validateBondDenom}) + }) + require.NotPanics(t, func() { + table.RegisterType(types.ParamSetPair{keyMaxValidators, uint16(100), validateMaxValidators}) + }) + require.Panics(t, func() { + table.RegisterType(types.ParamSetPair{keyUnbondingTime, time.Duration(1), nil}) + }) + require.NotPanics(t, func() { + table.RegisterType(types.ParamSetPair{keyUnbondingTime, time.Duration(1), validateMaxValidators}) + }) + require.NotPanics(t, func() { + newTable := types.NewKeyTable() + newTable.RegisterParamSet(¶ms{}) + }) + + require.Panics(t, func() { table.RegisterParamSet(¶ms{}) }) + require.Panics(t, func() { types.NewKeyTable(types.ParamSetPair{[]byte(""), nil, nil}) }) + + require.NotPanics(t, func() { + types.NewKeyTable( + types.ParamSetPair{[]byte("test"), string("stake"), validateBondDenom}, + types.ParamSetPair{[]byte("test2"), uint16(100), validateMaxValidators}, + ) + }) +} diff --git a/x/slashing/abci_test.go b/x/slashing/abci_test.go index a6a14c885b..c1b0f62fff 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 38d556a6e4..9ebdd29edf 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 71f4042307..c661b589f1 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 117e216a95..4233d5c7a0 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 751fe648dc..2d3d9bfab7 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 1257b8e105..9498ea8ba5 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 8b959c8a0b..a5d2eb0f13 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 fe4ef7cb7c..629a92dde2 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 c168f8052f..abd5e52559 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 34790d54d6..0000000000 --- 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 a8ef6e093e..e6374a87f9 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 a10b6f945b..a8e349b75b 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 e725519314..43f21a516e 100644 --- a/x/slashing/internal/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -3,24 +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 { +func NewKeeper(cdc codec.Marshaler, key sdk.StoreKey, sk types.StakingKeeper, paramspace types.ParamSubspace) Keeper { return Keeper{ storeKey: key, cdc: cdc, @@ -37,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 @@ -79,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 fdf50a261e..4f4f555bbf 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 82fe991ccc..8ece97a687 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 11b365e1ee..1eab719a63 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 ea4095dc61..fd924bc8e8 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 1162c258f3..0e1a82c62f 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 7d9e7c56e5..ac8c507527 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 84% rename from x/slashing/internal/keeper/test_common.go rename to x/slashing/keeper/test_common.go index 60dc394604..d80c68b7ed 100644 --- a/x/slashing/internal/keeper/test_common.go +++ b/x/slashing/keeper/test_common.go @@ -1,7 +1,8 @@ +package keeper + // nolint:deadcode,unused // DONTCOVER // noalias -package keeper import ( "encoding/hex" @@ -9,7 +10,6 @@ import ( "time" "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" @@ -17,12 +17,14 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/codec" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" - "github.com/cosmos/cosmos-sdk/x/params" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/supply" ) @@ -55,14 +57,14 @@ func createTestCodec() *codec.Codec { return cdc } -func CreateTestInput(t *testing.T, defaults types.Params) (sdk.Context, bank.Keeper, staking.Keeper, params.Subspace, Keeper) { +func CreateTestInput(t *testing.T, defaults types.Params) (sdk.Context, bank.Keeper, staking.Keeper, paramtypes.Subspace, Keeper) { keyAcc := sdk.NewKVStoreKey(auth.StoreKey) keyBank := sdk.NewKVStoreKey(bank.StoreKey) keyStaking := sdk.NewKVStoreKey(staking.StoreKey) keySlashing := sdk.NewKVStoreKey(types.StoreKey) keySupply := sdk.NewKVStoreKey(supply.StoreKey) - keyParams := sdk.NewKVStoreKey(params.StoreKey) - tkeyParams := sdk.NewTransientStoreKey(params.TStoreKey) + keyParams := sdk.NewKVStoreKey(paramtypes.StoreKey) + tkeyParams := sdk.NewTransientStoreKey(paramtypes.TStoreKey) db := dbm.NewMemDB() @@ -80,6 +82,7 @@ func CreateTestInput(t *testing.T, defaults types.Params) (sdk.Context, bank.Kee ctx := sdk.NewContext(ms, abci.Header{Time: time.Unix(0, 0)}, false, log.NewNopLogger()) cdc := createTestCodec() + appCodec := simappcodec.NewAppCodec(cdc) feeCollectorAcc := supply.NewEmptyModuleAccount(auth.FeeCollectorName) notBondedPool := supply.NewEmptyModuleAccount(staking.NotBondedPoolName, supply.Burner, supply.Staking) @@ -90,16 +93,16 @@ func CreateTestInput(t *testing.T, defaults types.Params) (sdk.Context, bank.Kee blacklistedAddrs[notBondedPool.GetAddress().String()] = true blacklistedAddrs[bondPool.GetAddress().String()] = true - paramsKeeper := params.NewKeeper(params.ModuleCdc, keyParams, tkeyParams) - accountKeeper := auth.NewAccountKeeper(cdc, keyAcc, paramsKeeper.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount) + 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}, staking.BondedPoolName: {supply.Burner, supply.Staking}, } - supplyKeeper := supply.NewKeeper(cdc, keySupply, accountKeeper, bk, maccPerms) + supplyKeeper := supply.NewKeeper(appCodec, keySupply, accountKeeper, bk, maccPerms) totalSupply := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, InitTokens.MulRaw(int64(len(Addrs))))) supplyKeeper.SetSupply(ctx, supply.NewSupply(totalSupply)) @@ -121,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 51fda48553..cf57c1e71c 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 4b739ef217..b404b8c4ec 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" ) @@ -45,14 +45,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { // DefaultGenesis returns default genesis state as raw bytes for the slashing // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the slashing module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) } @@ -127,7 +127,7 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { // InitGenesis performs genesis initialization for the slashing module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState ModuleCdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.keeper, am.stakingKeeper, genesisState) @@ -136,9 +136,9 @@ func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.Va // ExportGenesis returns the exported genesis state as raw bytes for the slashing // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, am.keeper) - return ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock returns the begin blocker for the slashing module. diff --git a/x/slashing/simulation/decoder.go b/x/slashing/simulation/decoder.go index 9aea5f701b..48a12705a7 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 acd3be67c6..522bff7475 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 a26a626642..d9dae7cd3d 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 8b7124609c..c0f0b94554 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 6679928d8f..72048f2264 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 0000000000..04114f1465 --- /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 61% rename from x/slashing/internal/types/errors.go rename to x/slashing/types/errors.go index 290ed36cad..daff6ecc04 100644 --- a/x/slashing/internal/types/errors.go +++ b/x/slashing/types/errors.go @@ -6,11 +6,11 @@ import ( // x/slashing module sentinel errors var ( - ErrNoValidatorForAddress = sdkerrors.Register(ModuleName, 1, "address is not associated with any known validator") - ErrBadValidatorAddr = sdkerrors.Register(ModuleName, 2, "validator does not exist for that address") - ErrValidatorJailed = sdkerrors.Register(ModuleName, 3, "validator still jailed; cannot be unjailed") - ErrValidatorNotJailed = sdkerrors.Register(ModuleName, 4, "validator not jailed; cannot be unjailed") - ErrMissingSelfDelegation = sdkerrors.Register(ModuleName, 5, "validator has no self-delegation; cannot be unjailed") - ErrSelfDelegationTooLowToUnjail = sdkerrors.Register(ModuleName, 6, "validator's self delegation less than minimum; cannot be unjailed") - ErrNoSigningInfoFound = sdkerrors.Register(ModuleName, 7, "no validator signing info found") + ErrNoValidatorForAddress = sdkerrors.Register(ModuleName, 2, "address is not associated with any known validator") + ErrBadValidatorAddr = sdkerrors.Register(ModuleName, 3, "validator does not exist for that address") + ErrValidatorJailed = sdkerrors.Register(ModuleName, 4, "validator still jailed; cannot be unjailed") + ErrValidatorNotJailed = sdkerrors.Register(ModuleName, 5, "validator not jailed; cannot be unjailed") + ErrMissingSelfDelegation = sdkerrors.Register(ModuleName, 6, "validator has no self-delegation; cannot be unjailed") + ErrSelfDelegationTooLowToUnjail = sdkerrors.Register(ModuleName, 7, "validator's self delegation less than minimum; cannot be unjailed") + ErrNoSigningInfoFound = sdkerrors.Register(ModuleName, 8, "no validator signing info found") ) 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 92% rename from x/slashing/internal/types/expected_keepers.go rename to x/slashing/types/expected_keepers.go index fe5695eebb..4a9dd4f7f2 100644 --- a/x/slashing/internal/types/expected_keepers.go +++ b/x/slashing/types/expected_keepers.go @@ -5,7 +5,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" - "github.com/cosmos/cosmos-sdk/x/params" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported" ) @@ -26,10 +26,10 @@ type BankKeeper interface { // ParamSubspace defines the expected Subspace interfacace type ParamSubspace interface { - WithKeyTable(table params.KeyTable) params.Subspace + WithKeyTable(table paramtypes.KeyTable) paramtypes.Subspace Get(ctx sdk.Context, key []byte, ptr interface{}) - GetParamSet(ctx sdk.Context, ps params.ParamSet) - SetParamSet(ctx sdk.Context, ps params.ParamSet) + GetParamSet(ctx sdk.Context, ps paramtypes.ParamSet) + SetParamSet(ctx sdk.Context, ps paramtypes.ParamSet) } // StakingKeeper expected staking keeper 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 b2ccdce173..a9798615f6 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 83% rename from x/slashing/internal/types/params.go rename to x/slashing/types/params.go index 15dd6cca62..8499efdbac 100644 --- a/x/slashing/internal/types/params.go +++ b/x/slashing/types/params.go @@ -5,7 +5,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/params" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) // Default parameter namespace @@ -31,8 +31,8 @@ var ( ) // ParamKeyTable for slashing module -func ParamKeyTable() params.KeyTable { - return params.NewKeyTable().RegisterParamSet(&Params{}) +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) } // Params - used for initializing default parameter for slashing at genesis @@ -73,13 +73,13 @@ func (p Params) String() string { } // ParamSetPairs - Implements params.ParamSet -func (p *Params) ParamSetPairs() params.ParamSetPairs { - return params.ParamSetPairs{ - params.NewParamSetPair(KeySignedBlocksWindow, &p.SignedBlocksWindow, validateSignedBlocksWindow), - params.NewParamSetPair(KeyMinSignedPerWindow, &p.MinSignedPerWindow, validateMinSignedPerWindow), - params.NewParamSetPair(KeyDowntimeJailDuration, &p.DowntimeJailDuration, validateDowntimeJailDuration), - params.NewParamSetPair(KeySlashFractionDoubleSign, &p.SlashFractionDoubleSign, validateSlashFractionDoubleSign), - params.NewParamSetPair(KeySlashFractionDowntime, &p.SlashFractionDowntime, validateSlashFractionDowntime), +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeySignedBlocksWindow, &p.SignedBlocksWindow, validateSignedBlocksWindow), + paramtypes.NewParamSetPair(KeyMinSignedPerWindow, &p.MinSignedPerWindow, validateMinSignedPerWindow), + paramtypes.NewParamSetPair(KeyDowntimeJailDuration, &p.DowntimeJailDuration, validateDowntimeJailDuration), + paramtypes.NewParamSetPair(KeySlashFractionDoubleSign, &p.SlashFractionDoubleSign, validateSlashFractionDoubleSign), + paramtypes.NewParamSetPair(KeySlashFractionDowntime, &p.SlashFractionDowntime, validateSlashFractionDowntime), } } 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 431658c224..315cac792c 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 0000000000..7358555a10 --- /dev/null +++ b/x/slashing/types/types.pb.go @@ -0,0 +1,788 @@ +// 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{ + // 492 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, 0x05, 0xc4, 0x2f, 0xc9, 0xb4, 0x1d, 0x18, 0xb0, 0xce, 0xb9, + 0xcb, 0xf9, 0x88, 0x7d, 0x17, 0xf9, 0xce, 0x55, 0xb2, 0xf2, 0x17, 0x74, 0x64, 0xec, 0xc8, 0x1f, + 0xc1, 0x1f, 0xd0, 0xb1, 0x23, 0x93, 0x41, 0xc9, 0x82, 0x18, 0x33, 0x76, 0x42, 0xf6, 0xc5, 0x34, + 0xaa, 0x10, 0x62, 0xb1, 0xef, 0x7d, 0xee, 0xfb, 0xde, 0xf7, 0xde, 0xbd, 0x83, 0x7b, 0x33, 0x5f, + 0xa5, 0x58, 0x25, 0x5c, 0x30, 0x5f, 0xcf, 0xa7, 0x54, 0x99, 0xaf, 0x37, 0xcd, 0xa5, 0x96, 0x96, + 0x3d, 0x92, 0x2a, 0x93, 0x2a, 0x52, 0x64, 0xe2, 0xcd, 0xbc, 0x46, 0xe8, 0x9d, 0x3e, 0xe9, 0x3d, + 0xd6, 0x09, 0xcf, 0x49, 0x34, 0xc5, 0xb9, 0x9e, 0xfb, 0xb5, 0xd8, 0x67, 0x92, 0xc9, 0xeb, 0x95, + 0xa9, 0xd0, 0x43, 0x4c, 0x4a, 0x96, 0x52, 0x23, 0x89, 0x8b, 0xb1, 0xaf, 0x79, 0x46, 0x95, 0xc6, + 0xd9, 0xd4, 0x08, 0xdc, 0x4f, 0x00, 0xde, 0x7b, 0xad, 0xd8, 0xb1, 0xf8, 0x88, 0x79, 0x6a, 0x15, + 0x70, 0xe7, 0x14, 0xa7, 0x9c, 0x60, 0x2d, 0xf3, 0x08, 0x13, 0x92, 0xdb, 0xa0, 0x0f, 0x06, 0xdd, + 0xe0, 0xcd, 0xaf, 0x12, 0xdd, 0xad, 0x62, 0xaa, 0xd4, 0xaa, 0x44, 0x3b, 0x73, 0x9c, 0xa5, 0x43, + 0x77, 0x0d, 0xdc, 0xab, 0x12, 0xed, 0x33, 0xae, 0x93, 0x22, 0xf6, 0x46, 0x32, 0xf3, 0xcd, 0xa1, + 0xd7, 0xbf, 0x7d, 0x45, 0x26, 0xeb, 0x9e, 0x4e, 0x70, 0xfa, 0xcc, 0x64, 0x84, 0xf7, 0xff, 0xb8, + 0x54, 0xc4, 0xfd, 0xda, 0x86, 0x0f, 0x4e, 0x1a, 0xf2, 0x8e, 0x33, 0xc1, 0x05, 0x7b, 0x21, 0xc6, + 0xd2, 0x7a, 0x05, 0x1b, 0xd7, 0xf5, 0x41, 0x0e, 0xae, 0x4a, 0xe4, 0xfd, 0x87, 0xd7, 0xa1, 0x14, + 0xaa, 0x31, 0x6b, 0x4a, 0x58, 0x43, 0xd8, 0x55, 0x1a, 0xe7, 0x3a, 0x4a, 0x28, 0x67, 0x89, 0xb6, + 0x6f, 0xf5, 0xc1, 0xa0, 0x1d, 0x3c, 0x5a, 0x95, 0x68, 0xd7, 0x34, 0xb4, 0xb9, 0xeb, 0x86, 0x9d, + 0x3a, 0x7c, 0x5e, 0x47, 0x55, 0x2e, 0x17, 0x84, 0xce, 0x22, 0x39, 0x1e, 0x2b, 0xaa, 0xed, 0xf6, + 0xcd, 0xdc, 0xcd, 0x5d, 0x37, 0xec, 0xd4, 0xe1, 0xdb, 0x3a, 0xb2, 0x3e, 0xc0, 0x6e, 0x75, 0xbb, + 0x94, 0x44, 0x85, 0xd0, 0x3c, 0xb5, 0x6f, 0xf7, 0xc1, 0xa0, 0x73, 0xd0, 0xf3, 0xcc, 0x6c, 0xbc, + 0x66, 0x36, 0xde, 0x51, 0x33, 0x9b, 0x00, 0x5d, 0x94, 0xa8, 0x75, 0x5d, 0x7b, 0x33, 0xdb, 0x3d, + 0xfb, 0x8e, 0x40, 0xd8, 0x31, 0xe8, 0xb8, 0x22, 0x96, 0x03, 0xa1, 0x96, 0x59, 0xac, 0xb4, 0x14, + 0x94, 0xd8, 0x77, 0xfa, 0x60, 0xb0, 0x1d, 0x6e, 0x10, 0xeb, 0x08, 0x3e, 0xcc, 0xb8, 0x52, 0x94, + 0x44, 0x71, 0x2a, 0x47, 0x13, 0x15, 0x8d, 0x64, 0x21, 0x34, 0xcd, 0xed, 0xad, 0xba, 0x89, 0xfe, + 0xaa, 0x44, 0x7b, 0xc6, 0xe8, 0xaf, 0x32, 0x37, 0xdc, 0x35, 0x3c, 0xa8, 0xf1, 0xa1, 0xa1, 0xc3, + 0xed, 0xcf, 0xe7, 0xa8, 0xf5, 0xf3, 0x1c, 0x81, 0xe0, 0xe5, 0x97, 0x85, 0x03, 0x2e, 0x16, 0x0e, + 0xb8, 0x5c, 0x38, 0xe0, 0xc7, 0xc2, 0x01, 0x67, 0x4b, 0xa7, 0x75, 0xb9, 0x74, 0x5a, 0xdf, 0x96, + 0x4e, 0xeb, 0xfd, 0xbf, 0x9f, 0xc6, 0xcd, 0xf7, 0x1f, 0x6f, 0xd5, 0xd7, 0xf1, 0xf4, 0x77, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x72, 0x9e, 0xc6, 0x73, 0x1a, 0x03, 0x00, 0x00, +} + +func (this *MsgUnjail) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgUnjail) + if !ok { + that2, ok := that.(MsgUnjail) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.ValidatorAddr, that1.ValidatorAddr) { + return false + } + return true +} +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 0000000000..d89affb62f --- /dev/null +++ b/x/slashing/types/types.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; +package cosmos_sdk.x.slashing.v1; + +option go_package = "github.com/cosmos/cosmos-sdk/x/slashing/types"; +option (gogoproto.equal_all) = true; + +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/alias.go b/x/staking/alias.go index 445ead018e..1b7c78772f 100644 --- a/x/staking/alias.go +++ b/x/staking/alias.go @@ -176,7 +176,6 @@ var ( NewDescription = types.NewDescription // variable aliases - NewCodec = types.NewCodec ModuleCdc = types.ModuleCdc LastValidatorPowerKey = types.LastValidatorPowerKey LastTotalPowerKey = types.LastTotalPowerKey @@ -201,7 +200,6 @@ var ( type ( Keeper = keeper.Keeper - Codec = types.Codec Commission = types.Commission CommissionRates = types.CommissionRates DVPair = types.DVPair diff --git a/x/staking/keeper/common_test.go b/x/staking/keeper/common_test.go index 9293ed884a..69a168e5a4 100644 --- a/x/staking/keeper/common_test.go +++ b/x/staking/keeper/common_test.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simapp" + cdc "github.com/cosmos/cosmos-sdk/simapp/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/staking/keeper" @@ -53,19 +54,20 @@ func NewPubKey(pk string) (res crypto.PubKey) { // getBaseSimappWithCustomKeeper Returns a simapp with custom StakingKeeper // to avoid messing with the hooks. func getBaseSimappWithCustomKeeper() (*codec.Codec, *simapp.SimApp, sdk.Context) { - cdc := codec.New() app := simapp.Setup(false) ctx := app.BaseApp.NewContext(false, abci.Header{}) + appCodec := cdc.NewAppCodec(codec.New()) + app.StakingKeeper = keeper.NewKeeper( - simapp.NewAppCodec().Staking, + appCodec, app.GetKey(staking.StoreKey), app.BankKeeper, app.SupplyKeeper, app.GetSubspace(staking.ModuleName), ) - return cdc, app, ctx + return codec.New(), app, ctx } // intended to be used with require/assert: require.True(ValEq(...)) diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 80fbf61919..451065b3c2 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/params" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -27,14 +27,14 @@ type Keeper struct { bankKeeper types.BankKeeper supplyKeeper types.SupplyKeeper hooks types.StakingHooks - paramstore params.Subspace + paramstore paramtypes.Subspace validatorCache map[string]cachedValidator validatorCacheList *list.List } // NewKeeper creates a new staking Keeper instance func NewKeeper( - cdc codec.Marshaler, key sdk.StoreKey, bk types.BankKeeper, sk types.SupplyKeeper, ps params.Subspace, + cdc codec.Marshaler, key sdk.StoreKey, bk types.BankKeeper, sk types.SupplyKeeper, ps paramtypes.Subspace, ) Keeper { if !ps.HasKeyTable() { ps = ps.WithKeyTable(ParamKeyTable()) diff --git a/x/staking/keeper/params.go b/x/staking/keeper/params.go index e50e6ccd64..25ef7cf4bb 100644 --- a/x/staking/keeper/params.go +++ b/x/staking/keeper/params.go @@ -4,7 +4,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/params" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -14,8 +14,8 @@ const ( ) // ParamTable for staking module -func ParamKeyTable() params.KeyTable { - return params.NewKeyTable().RegisterParamSet(&types.Params{}) +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&types.Params{}) } // UnbondingTime diff --git a/x/staking/module.go b/x/staking/module.go index 0c7023a019..33034842f7 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -48,14 +48,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { // DefaultGenesis returns default genesis state as raw bytes for the staking // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the staking module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) } @@ -154,17 +154,17 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { // InitGenesis performs genesis initialization for the staking module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) return InitGenesis(ctx, am.keeper, am.accountKeeper, am.bankKeeper, am.supplyKeeper, genesisState) } // ExportGenesis returns the exported genesis state as raw bytes for the staking // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, am.keeper) - return ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock returns the begin blocker for the staking module. diff --git a/x/staking/test_common.go b/x/staking/test_common.go index 0760ebcc57..1b9708e78e 100644 --- a/x/staking/test_common.go +++ b/x/staking/test_common.go @@ -6,6 +6,8 @@ import ( "strconv" "testing" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -102,6 +104,7 @@ func CreateTestInput(t *testing.T, isCheckTx bool, initPower int64) (sdk.Context }, ) cdc := MakeTestCodec() + appCodec := simappcodec.NewAppCodec(cdc) feeCollectorAcc := supply.NewEmptyModuleAccount(auth.FeeCollectorName) notBondedPool := supply.NewEmptyModuleAccount(types.NotBondedPoolName, supply.Burner, supply.Staking) @@ -112,17 +115,17 @@ func CreateTestInput(t *testing.T, isCheckTx bool, initPower int64) (sdk.Context blacklistedAddrs[notBondedPool.GetAddress().String()] = true blacklistedAddrs[bondPool.GetAddress().String()] = true - pk := params.NewKeeper(params.ModuleCdc, keyParams, tkeyParams) + pk := params.NewKeeper(appCodec, keyParams, tkeyParams) accountKeeper := auth.NewAccountKeeper( - cdc, // amino codec + appCodec, keyAcc, // target store pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount, // prototype ) bk := bank.NewBaseKeeper( - cdc, + appCodec, bankKey, accountKeeper, pk.Subspace(bank.DefaultParamspace), @@ -134,7 +137,7 @@ func CreateTestInput(t *testing.T, isCheckTx bool, initPower int64) (sdk.Context types.NotBondedPoolName: {supply.Burner, supply.Staking}, types.BondedPoolName: {supply.Burner, supply.Staking}, } - supplyKeeper := supply.NewKeeper(cdc, keySupply, accountKeeper, bk, maccPerms) + supplyKeeper := supply.NewKeeper(appCodec, keySupply, accountKeeper, bk, maccPerms) initTokens := sdk.TokensFromConsensusPower(initPower) initCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens)) diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index 9832789b69..940e5ac8a4 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -4,22 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" ) -type Codec struct { - codec.Marshaler - - // Keep reference to the amino codec to allow backwards compatibility along - // with type, and interface registration. - amino *codec.Codec -} - -func NewCodec(amino *codec.Codec) *Codec { - return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino} -} - -// ---------------------------------------------------------------------------- - -// RegisterCodec registers all the necessary staking module concrete types and -// interfaces with the provided codec reference. +// RegisterCodec registers the necessary x/staking interfaces and concrete types +// on the provided Amino codec. These types are used for Amino JSON serialization. func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator", nil) cdc.RegisterConcrete(MsgEditValidator{}, "cosmos-sdk/MsgEditValidator", nil) @@ -28,13 +14,20 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgBeginRedelegate{}, "cosmos-sdk/MsgBeginRedelegate", nil) } -// ModuleCdc defines a staking module global Amino codec. -var ModuleCdc *Codec +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() { - ModuleCdc = NewCodec(codec.New()) - - RegisterCodec(ModuleCdc.amino) - codec.RegisterCrypto(ModuleCdc.amino) - ModuleCdc.amino.Seal() + RegisterCodec(amino) + codec.RegisterCrypto(amino) + amino.Seal() } diff --git a/x/staking/types/errors.go b/x/staking/types/errors.go index 62fdd0725b..d6c31a15dc 100644 --- a/x/staking/types/errors.go +++ b/x/staking/types/errors.go @@ -11,50 +11,50 @@ import ( // // REF: https://github.com/cosmos/cosmos-sdk/issues/5450 var ( - ErrEmptyValidatorAddr = sdkerrors.Register(ModuleName, 1, "empty validator address") - ErrBadValidatorAddr = sdkerrors.Register(ModuleName, 2, "validator address is invalid") - ErrNoValidatorFound = sdkerrors.Register(ModuleName, 3, "validator does not exist") - ErrValidatorOwnerExists = sdkerrors.Register(ModuleName, 4, "validator already exist for this operator address; must use new validator operator address") - ErrValidatorPubKeyExists = sdkerrors.Register(ModuleName, 5, "validator already exist for this pubkey; must use new validator pubkey") - ErrValidatorPubKeyTypeNotSupported = sdkerrors.Register(ModuleName, 6, "validator pubkey type is not supported") - ErrValidatorJailed = sdkerrors.Register(ModuleName, 7, "validator for this address is currently jailed") - ErrBadRemoveValidator = sdkerrors.Register(ModuleName, 8, "failed to remove validator") - ErrCommissionNegative = sdkerrors.Register(ModuleName, 9, "commission must be positive") - ErrCommissionHuge = sdkerrors.Register(ModuleName, 10, "commission cannot be more than 100%") - ErrCommissionGTMaxRate = sdkerrors.Register(ModuleName, 11, "commission cannot be more than the max rate") - ErrCommissionUpdateTime = sdkerrors.Register(ModuleName, 12, "commission cannot be changed more than once in 24h") - ErrCommissionChangeRateNegative = sdkerrors.Register(ModuleName, 13, "commission change rate must be positive") - ErrCommissionChangeRateGTMaxRate = sdkerrors.Register(ModuleName, 14, "commission change rate cannot be more than the max rate") - ErrCommissionGTMaxChangeRate = sdkerrors.Register(ModuleName, 15, "commission cannot be changed more than max change rate") - ErrSelfDelegationBelowMinimum = sdkerrors.Register(ModuleName, 16, "validator's self delegation must be greater than their minimum self delegation") - ErrMinSelfDelegationInvalid = sdkerrors.Register(ModuleName, 17, "minimum self delegation must be a positive integer") - ErrMinSelfDelegationDecreased = sdkerrors.Register(ModuleName, 18, "minimum self delegation cannot be decrease") - ErrEmptyDelegatorAddr = sdkerrors.Register(ModuleName, 19, "empty delegator address") - ErrBadDenom = sdkerrors.Register(ModuleName, 20, "invalid coin denomination") - ErrBadDelegationAddr = sdkerrors.Register(ModuleName, 21, "invalid address for (address, validator) tuple") - ErrBadDelegationAmount = sdkerrors.Register(ModuleName, 22, "invalid delegation amount") - ErrNoDelegation = sdkerrors.Register(ModuleName, 23, "no delegation for (address, validator) tuple") - ErrBadDelegatorAddr = sdkerrors.Register(ModuleName, 24, "delegator does not exist with address") - ErrNoDelegatorForAddress = sdkerrors.Register(ModuleName, 25, "delegator does not contain delegation") - ErrInsufficientShares = sdkerrors.Register(ModuleName, 26, "insufficient delegation shares") - ErrDelegationValidatorEmpty = sdkerrors.Register(ModuleName, 27, "cannot delegate to an empty validator") - ErrNotEnoughDelegationShares = sdkerrors.Register(ModuleName, 28, "not enough delegation shares") - ErrBadSharesAmount = sdkerrors.Register(ModuleName, 29, "invalid shares amount") - ErrBadSharesPercent = sdkerrors.Register(ModuleName, 30, "Invalid shares percent") - ErrNotMature = sdkerrors.Register(ModuleName, 31, "entry not mature") - ErrNoUnbondingDelegation = sdkerrors.Register(ModuleName, 32, "no unbonding delegation found") - ErrMaxUnbondingDelegationEntries = sdkerrors.Register(ModuleName, 33, "too many unbonding delegation entries for (delegator, validator) tuple") - ErrBadRedelegationAddr = sdkerrors.Register(ModuleName, 34, "invalid address for (address, src-validator, dst-validator) tuple") - ErrNoRedelegation = sdkerrors.Register(ModuleName, 35, "no redelegation found") - ErrSelfRedelegation = sdkerrors.Register(ModuleName, 36, "cannot redelegate to the same validator") - ErrTinyRedelegationAmount = sdkerrors.Register(ModuleName, 37, "too few tokens to redelegate (truncates to zero tokens)") - ErrBadRedelegationDst = sdkerrors.Register(ModuleName, 38, "redelegation destination validator not found") - ErrTransitiveRedelegation = sdkerrors.Register(ModuleName, 39, "redelegation to this validator already in progress; first redelegation to this validator must complete before next redelegation") - ErrMaxRedelegationEntries = sdkerrors.Register(ModuleName, 40, "too many redelegation entries for (delegator, src-validator, dst-validator) tuple") - ErrDelegatorShareExRateInvalid = sdkerrors.Register(ModuleName, 41, "cannot delegate to validators with invalid (zero) ex-rate") - ErrBothShareMsgsGiven = sdkerrors.Register(ModuleName, 42, "both shares amount and shares percent provided") - ErrNeitherShareMsgsGiven = sdkerrors.Register(ModuleName, 43, "neither shares amount nor shares percent provided") - ErrInvalidHistoricalInfo = sdkerrors.Register(ModuleName, 44, "invalid historical info") - ErrNoHistoricalInfo = sdkerrors.Register(ModuleName, 45, "no historical info found") - ErrEmptyValidatorPubKey = sdkerrors.Register(ModuleName, 46, "empty validator public key") + ErrEmptyValidatorAddr = sdkerrors.Register(ModuleName, 2, "empty validator address") + ErrBadValidatorAddr = sdkerrors.Register(ModuleName, 3, "validator address is invalid") + ErrNoValidatorFound = sdkerrors.Register(ModuleName, 4, "validator does not exist") + ErrValidatorOwnerExists = sdkerrors.Register(ModuleName, 5, "validator already exist for this operator address; must use new validator operator address") + ErrValidatorPubKeyExists = sdkerrors.Register(ModuleName, 6, "validator already exist for this pubkey; must use new validator pubkey") + ErrValidatorPubKeyTypeNotSupported = sdkerrors.Register(ModuleName, 7, "validator pubkey type is not supported") + ErrValidatorJailed = sdkerrors.Register(ModuleName, 8, "validator for this address is currently jailed") + ErrBadRemoveValidator = sdkerrors.Register(ModuleName, 9, "failed to remove validator") + ErrCommissionNegative = sdkerrors.Register(ModuleName, 10, "commission must be positive") + ErrCommissionHuge = sdkerrors.Register(ModuleName, 11, "commission cannot be more than 100%") + ErrCommissionGTMaxRate = sdkerrors.Register(ModuleName, 12, "commission cannot be more than the max rate") + ErrCommissionUpdateTime = sdkerrors.Register(ModuleName, 13, "commission cannot be changed more than once in 24h") + ErrCommissionChangeRateNegative = sdkerrors.Register(ModuleName, 14, "commission change rate must be positive") + ErrCommissionChangeRateGTMaxRate = sdkerrors.Register(ModuleName, 15, "commission change rate cannot be more than the max rate") + ErrCommissionGTMaxChangeRate = sdkerrors.Register(ModuleName, 16, "commission cannot be changed more than max change rate") + ErrSelfDelegationBelowMinimum = sdkerrors.Register(ModuleName, 17, "validator's self delegation must be greater than their minimum self delegation") + ErrMinSelfDelegationInvalid = sdkerrors.Register(ModuleName, 18, "minimum self delegation must be a positive integer") + ErrMinSelfDelegationDecreased = sdkerrors.Register(ModuleName, 19, "minimum self delegation cannot be decrease") + ErrEmptyDelegatorAddr = sdkerrors.Register(ModuleName, 20, "empty delegator address") + ErrBadDenom = sdkerrors.Register(ModuleName, 21, "invalid coin denomination") + ErrBadDelegationAddr = sdkerrors.Register(ModuleName, 22, "invalid address for (address, validator) tuple") + ErrBadDelegationAmount = sdkerrors.Register(ModuleName, 23, "invalid delegation amount") + ErrNoDelegation = sdkerrors.Register(ModuleName, 24, "no delegation for (address, validator) tuple") + ErrBadDelegatorAddr = sdkerrors.Register(ModuleName, 25, "delegator does not exist with address") + ErrNoDelegatorForAddress = sdkerrors.Register(ModuleName, 26, "delegator does not contain delegation") + ErrInsufficientShares = sdkerrors.Register(ModuleName, 27, "insufficient delegation shares") + ErrDelegationValidatorEmpty = sdkerrors.Register(ModuleName, 28, "cannot delegate to an empty validator") + ErrNotEnoughDelegationShares = sdkerrors.Register(ModuleName, 29, "not enough delegation shares") + ErrBadSharesAmount = sdkerrors.Register(ModuleName, 30, "invalid shares amount") + ErrBadSharesPercent = sdkerrors.Register(ModuleName, 31, "Invalid shares percent") + ErrNotMature = sdkerrors.Register(ModuleName, 32, "entry not mature") + ErrNoUnbondingDelegation = sdkerrors.Register(ModuleName, 33, "no unbonding delegation found") + ErrMaxUnbondingDelegationEntries = sdkerrors.Register(ModuleName, 34, "too many unbonding delegation entries for (delegator, validator) tuple") + ErrBadRedelegationAddr = sdkerrors.Register(ModuleName, 35, "invalid address for (address, src-validator, dst-validator) tuple") + ErrNoRedelegation = sdkerrors.Register(ModuleName, 36, "no redelegation found") + ErrSelfRedelegation = sdkerrors.Register(ModuleName, 37, "cannot redelegate to the same validator") + ErrTinyRedelegationAmount = sdkerrors.Register(ModuleName, 38, "too few tokens to redelegate (truncates to zero tokens)") + ErrBadRedelegationDst = sdkerrors.Register(ModuleName, 39, "redelegation destination validator not found") + ErrTransitiveRedelegation = sdkerrors.Register(ModuleName, 40, "redelegation to this validator already in progress; first redelegation to this validator must complete before next redelegation") + ErrMaxRedelegationEntries = sdkerrors.Register(ModuleName, 41, "too many redelegation entries for (delegator, src-validator, dst-validator) tuple") + ErrDelegatorShareExRateInvalid = sdkerrors.Register(ModuleName, 42, "cannot delegate to validators with invalid (zero) ex-rate") + ErrBothShareMsgsGiven = sdkerrors.Register(ModuleName, 43, "both shares amount and shares percent provided") + ErrNeitherShareMsgsGiven = sdkerrors.Register(ModuleName, 44, "neither shares amount nor shares percent provided") + ErrInvalidHistoricalInfo = sdkerrors.Register(ModuleName, 45, "invalid historical info") + ErrNoHistoricalInfo = sdkerrors.Register(ModuleName, 46, "no historical info found") + ErrEmptyValidatorPubKey = sdkerrors.Register(ModuleName, 47, "empty validator public key") ) diff --git a/x/staking/types/params.go b/x/staking/types/params.go index ae3dd7cf8a..b738f1b06e 100644 --- a/x/staking/types/params.go +++ b/x/staking/types/params.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/params" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" yaml "gopkg.in/yaml.v2" ) @@ -39,7 +39,7 @@ var ( KeyHistoricalEntries = []byte("HistoricalEntries") ) -var _ params.ParamSet = (*Params)(nil) +var _ paramtypes.ParamSet = (*Params)(nil) // NewParams creates a new Params instance func NewParams( @@ -56,13 +56,13 @@ func NewParams( } // Implements params.ParamSet -func (p *Params) ParamSetPairs() params.ParamSetPairs { - return params.ParamSetPairs{ - params.NewParamSetPair(KeyUnbondingTime, &p.UnbondingTime, validateUnbondingTime), - params.NewParamSetPair(KeyMaxValidators, &p.MaxValidators, validateMaxValidators), - params.NewParamSetPair(KeyMaxEntries, &p.MaxEntries, validateMaxEntries), - params.NewParamSetPair(KeyHistoricalEntries, &p.HistoricalEntries, validateHistoricalEntries), - params.NewParamSetPair(KeyBondDenom, &p.BondDenom, validateBondDenom), +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyUnbondingTime, &p.UnbondingTime, validateUnbondingTime), + paramtypes.NewParamSetPair(KeyMaxValidators, &p.MaxValidators, validateMaxValidators), + paramtypes.NewParamSetPair(KeyMaxEntries, &p.MaxEntries, validateMaxEntries), + paramtypes.NewParamSetPair(KeyHistoricalEntries, &p.HistoricalEntries, validateHistoricalEntries), + paramtypes.NewParamSetPair(KeyBondDenom, &p.BondDenom, validateBondDenom), } } diff --git a/x/staking/types/types.pb.go b/x/staking/types/types.pb.go index 78da36fae4..ca93948547 100644 --- a/x/staking/types/types.pb.go +++ b/x/staking/types/types.pb.go @@ -1242,13 +1242,13 @@ func init() { func init() { proto.RegisterFile("x/staking/types/types.proto", fileDescriptor_c669c0a3ee1b124c) } var fileDescriptor_c669c0a3ee1b124c = []byte{ - // 1678 bytes of a gzipped FileDescriptorProto + // 1682 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x59, 0xcd, 0x6f, 0x23, 0x49, 0x15, 0x4f, 0xdb, 0x8e, 0x9d, 0x3c, 0x4f, 0xec, 0xa4, 0xa3, 0xc9, 0x78, 0xb2, 0xac, 0x3b, 0xf4, 0xa2, 0x55, 0x84, 0x58, 0x5b, 0xd9, 0x45, 0x42, 0xca, 0x5e, 0x76, 0x1c, 0x27, 0x4a, 0x50, 0x82, 0x66, 0x3b, 0xb3, 0x39, 0xf0, 0x21, 0xab, 0xdc, 0x5d, 0x69, 0x17, 0x71, 0x77, 0x9b, 0xae, 0x72, - 0xd6, 0x41, 0x5c, 0x91, 0x10, 0x12, 0x62, 0x2f, 0x48, 0x73, 0x1c, 0xf1, 0x0f, 0x70, 0x45, 0x70, - 0xe1, 0x38, 0xdc, 0x46, 0x20, 0x21, 0xc4, 0xc1, 0xa0, 0x99, 0x0b, 0xe2, 0x04, 0x3e, 0x70, 0xe0, + 0xd6, 0x41, 0x5c, 0x91, 0x10, 0x12, 0x62, 0x2f, 0x48, 0x7b, 0x1c, 0xf1, 0x0f, 0xf0, 0x1f, 0xa0, + 0xe1, 0x36, 0xdc, 0x46, 0x1c, 0x10, 0x70, 0x30, 0x68, 0xe6, 0x82, 0x38, 0x21, 0x1f, 0x40, 0xe2, 0x84, 0xba, 0xaa, 0xfa, 0x23, 0x6d, 0x7b, 0xc6, 0xc9, 0x30, 0xc3, 0x48, 0x93, 0xcb, 0x8c, 0xeb, 0xf5, 0x7b, 0xbf, 0x57, 0xf5, 0xbe, 0xab, 0x02, 0xef, 0x0c, 0xea, 0x94, 0xa1, 0x33, 0xe2, 0xda, 0x75, 0x76, 0xd1, 0xc3, 0x54, 0xfc, 0x5b, 0xeb, 0xf9, 0x1e, 0xf3, 0xd4, 0x3b, 0xa6, 0x47, 0x1d, @@ -1257,99 +1257,276 @@ var fileDescriptor_c669c0a3ee1b124c = []byte{ 0xd6, 0x3f, 0x1a, 0xe7, 0x63, 0xd8, 0xb5, 0xb0, 0xef, 0x10, 0x97, 0xd5, 0x51, 0xdb, 0x24, 0xe3, 0x5a, 0xd7, 0x35, 0xdb, 0xf3, 0xec, 0x2e, 0x16, 0xfc, 0xed, 0xfe, 0x69, 0x9d, 0x11, 0x07, 0x53, 0x86, 0x9c, 0x9e, 0x64, 0xa8, 0xa6, 0x19, 0xac, 0xbe, 0x8f, 0x18, 0xf1, 0x5c, 0xf9, 0x7d, 0x65, - 0x0c, 0x53, 0xff, 0x57, 0x0e, 0xd4, 0x23, 0x6a, 0xef, 0xf8, 0x18, 0x31, 0x7c, 0x82, 0xba, 0xc4, + 0x0c, 0x53, 0xff, 0x77, 0x0e, 0xd4, 0x23, 0x6a, 0xef, 0xf8, 0x18, 0x31, 0x7c, 0x82, 0xba, 0xc4, 0x42, 0xcc, 0xf3, 0xd5, 0x43, 0x28, 0x5a, 0x98, 0x9a, 0x3e, 0xe9, 0x05, 0xe2, 0x15, 0x65, 0x43, - 0xd9, 0x2c, 0x7e, 0xf8, 0x95, 0xda, 0x94, 0x63, 0xd7, 0x9a, 0x31, 0x6f, 0x23, 0xf7, 0x78, 0xa8, - 0xcd, 0x19, 0x49, 0x71, 0xf5, 0x5b, 0x00, 0xa6, 0xe7, 0x38, 0x84, 0xd2, 0x00, 0x2c, 0xc3, 0xc1, - 0x36, 0xa7, 0x82, 0xed, 0x44, 0xac, 0x06, 0x62, 0x98, 0x4a, 0xc0, 0x04, 0x82, 0xfa, 0x23, 0x58, + 0xd9, 0x2c, 0x7e, 0xf8, 0xb5, 0xda, 0x94, 0x63, 0xd7, 0x9a, 0x31, 0x6f, 0x23, 0xf7, 0x78, 0xa8, + 0xcd, 0x19, 0x49, 0x71, 0xf5, 0x3b, 0x00, 0xa6, 0xe7, 0x38, 0x84, 0xd2, 0x00, 0x2c, 0xc3, 0xc1, + 0x36, 0xa7, 0x82, 0xed, 0x44, 0xac, 0x06, 0x62, 0x98, 0x4a, 0xc0, 0x04, 0x82, 0xfa, 0x13, 0x58, 0x75, 0x88, 0xdb, 0xa2, 0xb8, 0x7b, 0xda, 0xb2, 0x70, 0x17, 0xdb, 0xfc, 0x90, 0x95, 0xec, 0x86, 0xb2, 0xb9, 0xd8, 0x38, 0x0c, 0xd8, 0xff, 0x32, 0xd4, 0xde, 0xb7, 0x09, 0xeb, 0xf4, 0xdb, 0x35, 0xd3, 0x73, 0xea, 0x42, 0x95, 0xfc, 0xef, 0x03, 0x6a, 0x9d, 0x49, 0x1b, 0x1c, 0xb8, 0x6c, 0x34, 0xd4, 0xd6, 0x2f, 0x90, 0xd3, 0xdd, 0xd6, 0x27, 0x40, 0xea, 0xc6, 0x8a, 0x43, 0xdc, 0x63, 0xdc, - 0x3d, 0x6d, 0x46, 0x34, 0xf5, 0x87, 0xb0, 0x22, 0x39, 0x3c, 0xbf, 0x85, 0x2c, 0xcb, 0xc7, 0x94, + 0x3d, 0x6d, 0x46, 0x34, 0xf5, 0xc7, 0xb0, 0x22, 0x39, 0x3c, 0xbf, 0x85, 0x2c, 0xcb, 0xc7, 0x94, 0x56, 0x72, 0x1b, 0xca, 0xe6, 0xad, 0xc6, 0xd1, 0x68, 0xa8, 0x55, 0x04, 0xda, 0x18, 0x8b, 0xfe, 0x9f, 0xa1, 0xf6, 0xc1, 0x0c, 0x7b, 0xba, 0x67, 0x9a, 0xf7, 0x84, 0x84, 0xb1, 0x1c, 0x81, 0x48, 0x4a, 0xa0, 0xfb, 0x3c, 0x74, 0x52, 0xa4, 0x7b, 0x3e, 0xad, 0x7b, 0x8c, 0x65, 0x56, 0xdd, 0x27, 0xa8, 0x1b, 0xe9, 0x8e, 0x40, 0x42, 0xdd, 0x6b, 0x90, 0xef, 0xf5, 0xdb, 0x67, 0xf8, 0xa2, 0x92, 0x0f, 0x0c, 0x6d, 0xc8, 0x95, 0x5a, 0x87, 0xf9, 0x73, 0xd4, 0xed, 0xe3, 0x4a, 0x81, 0x3b, 0x76, - 0x35, 0xe9, 0x58, 0xee, 0x4e, 0x12, 0x06, 0x85, 0xe0, 0xd3, 0x7f, 0x9b, 0x85, 0xe5, 0x23, 0x6a, - 0xef, 0x5a, 0x84, 0xbd, 0xaa, 0x88, 0xeb, 0x4d, 0xb2, 0x53, 0x86, 0xdb, 0x69, 0x67, 0x34, 0xd4, - 0x4a, 0xc2, 0x4e, 0xff, 0x4b, 0xeb, 0x38, 0x50, 0x8e, 0x23, 0xb4, 0xe5, 0x23, 0x86, 0x65, 0x3c, - 0x36, 0x67, 0x8c, 0xc5, 0x26, 0x36, 0x47, 0x43, 0x6d, 0x4d, 0xec, 0x2c, 0x05, 0xa5, 0x1b, 0x25, - 0xf3, 0x52, 0x56, 0xa8, 0x83, 0xc9, 0x29, 0x90, 0xe3, 0x2a, 0xf7, 0x5f, 0x61, 0xf8, 0xeb, 0xbf, - 0xce, 0x40, 0xf1, 0x88, 0xda, 0x92, 0x82, 0x27, 0xa7, 0x83, 0xf2, 0x7f, 0x4c, 0x87, 0xcc, 0xeb, - 0x49, 0x87, 0x2d, 0xc8, 0x23, 0xc7, 0xeb, 0xbb, 0x8c, 0xfb, 0xf9, 0xb9, 0x71, 0x2f, 0x19, 0xf5, - 0x3f, 0x66, 0x79, 0xb1, 0x6d, 0x60, 0x9b, 0xb8, 0x06, 0xb6, 0xde, 0x04, 0x0b, 0xfe, 0x58, 0x81, - 0xdb, 0xb1, 0x7d, 0xa8, 0x6f, 0xa6, 0xcc, 0xf8, 0xe9, 0x68, 0xa8, 0x7d, 0x29, 0x6d, 0xc6, 0x04, - 0xdb, 0x35, 0x4c, 0xb9, 0x1a, 0x01, 0x1d, 0xfb, 0xe6, 0xe4, 0x7d, 0x58, 0x94, 0x45, 0xfb, 0xc8, - 0x4e, 0xdf, 0x47, 0x82, 0xed, 0xa5, 0xf6, 0xd1, 0xa4, 0x6c, 0xdc, 0xab, 0xb9, 0x59, 0xbd, 0xfa, - 0x9b, 0x0c, 0x2c, 0x1d, 0x51, 0xfb, 0x33, 0xd7, 0xba, 0x49, 0x89, 0x2b, 0xa7, 0xc4, 0x2f, 0x14, - 0x28, 0xed, 0x13, 0xca, 0x3c, 0x9f, 0x98, 0xa8, 0x7b, 0xe0, 0x9e, 0x7a, 0xea, 0xc7, 0x90, 0xef, - 0x60, 0x64, 0x61, 0x5f, 0x36, 0x81, 0x77, 0x6b, 0xf1, 0x68, 0x54, 0x0b, 0x46, 0xa3, 0x9a, 0xd8, - 0xca, 0x3e, 0x67, 0x0a, 0xf1, 0x84, 0x88, 0xfa, 0x09, 0xe4, 0xcf, 0x51, 0x97, 0x62, 0x56, 0xc9, - 0x6c, 0x64, 0x37, 0x8b, 0x1f, 0xea, 0x53, 0x3b, 0x48, 0xd4, 0x7a, 0x42, 0x04, 0x21, 0xb7, 0x9d, - 0xfb, 0xfb, 0x23, 0x4d, 0xd1, 0x7f, 0x95, 0x81, 0x72, 0x6a, 0x10, 0x51, 0x1b, 0x90, 0xe3, 0x75, - 0x5d, 0xe1, 0x45, 0xb6, 0x76, 0x85, 0x39, 0xa3, 0x89, 0x4d, 0x83, 0xcb, 0xaa, 0xdf, 0x85, 0x05, - 0x07, 0x0d, 0x44, 0x7f, 0xc8, 0x70, 0x9c, 0x7b, 0x57, 0xc3, 0x19, 0x0d, 0xb5, 0xb2, 0x2c, 0xd8, - 0x12, 0x47, 0x37, 0x0a, 0x0e, 0x1a, 0xf0, 0xae, 0xd0, 0x83, 0x72, 0x40, 0x35, 0x3b, 0xc8, 0xb5, - 0x71, 0xb2, 0x09, 0xed, 0x5f, 0x59, 0xc9, 0x5a, 0xac, 0x24, 0x01, 0xa7, 0x1b, 0x4b, 0x0e, 0x1a, - 0xec, 0x70, 0x42, 0xa0, 0x71, 0x7b, 0xe1, 0xe1, 0x23, 0x6d, 0x8e, 0x5b, 0xec, 0x0f, 0x0a, 0x40, - 0x6c, 0x31, 0xf5, 0x7b, 0xb0, 0x9c, 0x6a, 0x62, 0x54, 0xfa, 0x73, 0xf6, 0xc9, 0x6f, 0x21, 0xd8, - 0xf5, 0x93, 0xa1, 0xa6, 0x18, 0x65, 0x33, 0xe5, 0x8b, 0xef, 0x40, 0xb1, 0xdf, 0xb3, 0x10, 0xc3, - 0xad, 0x60, 0x08, 0x96, 0x33, 0xe5, 0x7a, 0x4d, 0x0c, 0xc0, 0xb5, 0x70, 0x00, 0xae, 0x3d, 0x08, - 0x27, 0xe4, 0x46, 0x35, 0xc0, 0x1a, 0x0d, 0x35, 0x55, 0x9c, 0x2b, 0x21, 0xac, 0x7f, 0xf1, 0x57, - 0x4d, 0x31, 0x40, 0x50, 0x02, 0x81, 0xc4, 0xa1, 0x7e, 0xaf, 0x40, 0x31, 0x31, 0x6a, 0xa8, 0x15, - 0x28, 0x38, 0x9e, 0x4b, 0xce, 0x64, 0x70, 0x2e, 0x1a, 0xe1, 0x52, 0x5d, 0x87, 0x05, 0x62, 0x61, - 0x97, 0x11, 0x76, 0x21, 0x1c, 0x6b, 0x44, 0xeb, 0x40, 0xea, 0x73, 0xdc, 0xa6, 0x24, 0x74, 0x87, - 0x11, 0x2e, 0xd5, 0x3d, 0x58, 0xa6, 0xd8, 0xec, 0xfb, 0x84, 0x5d, 0xb4, 0x4c, 0xcf, 0x65, 0xc8, - 0x64, 0xb2, 0x87, 0xbf, 0x33, 0x1a, 0x6a, 0x77, 0xc4, 0x5e, 0xd3, 0x1c, 0xba, 0x51, 0x0e, 0x49, - 0x3b, 0x82, 0x12, 0x68, 0xb0, 0x30, 0x43, 0xa4, 0x2b, 0xa6, 0xc1, 0x45, 0x23, 0x5c, 0x26, 0xce, - 0xf2, 0xbb, 0x02, 0x2c, 0xc6, 0xf3, 0xd6, 0xe7, 0xb0, 0xec, 0xf5, 0xb0, 0x3f, 0xa1, 0x44, 0x1d, - 0xc6, 0x9a, 0xd3, 0x1c, 0xd7, 0xa8, 0x12, 0xe5, 0x10, 0x23, 0x2c, 0x12, 0x7b, 0x41, 0x60, 0xb8, - 0x14, 0xbb, 0xb4, 0x4f, 0x5b, 0x72, 0xa0, 0xcc, 0xa4, 0x8f, 0x9c, 0xe6, 0xd0, 0x83, 0x08, 0x90, - 0xa4, 0xfb, 0x62, 0xec, 0x5c, 0x83, 0xfc, 0xf7, 0x11, 0xe9, 0x62, 0x8b, 0xdb, 0x74, 0xc1, 0x90, - 0x2b, 0xf5, 0x00, 0xf2, 0x94, 0x21, 0xd6, 0x17, 0x33, 0xf9, 0x7c, 0x63, 0x6b, 0xc6, 0x3d, 0x37, - 0x3c, 0xd7, 0x3a, 0xe6, 0x82, 0x86, 0x04, 0x50, 0xf7, 0x20, 0xcf, 0xbc, 0x33, 0xec, 0x4a, 0xa3, - 0x5e, 0x29, 0xe5, 0x0f, 0x5c, 0x66, 0x48, 0x69, 0x95, 0x41, 0x5c, 0xa7, 0x5b, 0xb4, 0x83, 0x7c, - 0x4c, 0xc5, 0x0c, 0xdd, 0x38, 0xb8, 0x72, 0x5e, 0xde, 0x49, 0x37, 0x0f, 0x81, 0xa7, 0x1b, 0xe5, - 0x88, 0x74, 0xcc, 0x29, 0xe9, 0x89, 0xba, 0xf0, 0x72, 0x13, 0xf5, 0x1e, 0x2c, 0xf7, 0xdd, 0xb6, - 0xe7, 0x5a, 0xc4, 0xb5, 0x5b, 0x1d, 0x4c, 0xec, 0x0e, 0xab, 0x2c, 0x6c, 0x28, 0x9b, 0xd9, 0xa4, - 0xdb, 0xd2, 0x1c, 0xba, 0x51, 0x8e, 0x48, 0xfb, 0x9c, 0xa2, 0x5a, 0x50, 0x8a, 0xb9, 0x78, 0xee, - 0x2e, 0xbe, 0x30, 0x77, 0xbf, 0x2c, 0x73, 0xf7, 0x76, 0x5a, 0x4b, 0x9c, 0xbe, 0x4b, 0x11, 0x31, - 0x10, 0x53, 0x0f, 0x2e, 0xdd, 0x38, 0x81, 0x6b, 0x78, 0x6f, 0x86, 0xba, 0x33, 0xfb, 0x65, 0xb3, - 0xf8, 0x5a, 0x2e, 0x9b, 0xdb, 0xb7, 0x7e, 0xf2, 0x48, 0x9b, 0x8b, 0x52, 0xf8, 0xa7, 0x19, 0xc8, - 0x37, 0x4f, 0xee, 0x23, 0xe2, 0xbf, 0xad, 0x33, 0x46, 0xa2, 0x9e, 0xed, 0x41, 0x41, 0xd8, 0x82, - 0xaa, 0x1f, 0xc3, 0x7c, 0x2f, 0xf8, 0x51, 0x51, 0x78, 0xd3, 0xd7, 0xa6, 0x07, 0x39, 0x17, 0x08, - 0xaf, 0xa3, 0x5c, 0x46, 0xff, 0x65, 0x16, 0xa0, 0x79, 0x72, 0xf2, 0xc0, 0x27, 0xbd, 0x2e, 0x66, - 0x37, 0xd3, 0xf8, 0x9b, 0x33, 0x8d, 0x27, 0x9c, 0xfd, 0x00, 0x8a, 0xb1, 0x8f, 0xa8, 0xba, 0x0b, - 0x0b, 0x4c, 0xfe, 0x96, 0x3e, 0x7f, 0xef, 0x39, 0x3e, 0x0f, 0xe5, 0xa4, 0xdf, 0x23, 0x51, 0xfd, - 0x4f, 0x19, 0x80, 0x17, 0xbd, 0xec, 0xbc, 0x05, 0x73, 0xfb, 0x1e, 0xe4, 0x65, 0x57, 0xca, 0x5e, - 0x6b, 0xb4, 0x95, 0xd2, 0x09, 0x77, 0xfd, 0x23, 0x03, 0xab, 0x9f, 0x85, 0x15, 0xf9, 0xc6, 0xc2, - 0xea, 0xa7, 0x50, 0xc0, 0x2e, 0xf3, 0x09, 0x37, 0x71, 0x10, 0xae, 0x5b, 0x53, 0xc3, 0x75, 0x82, - 0xd9, 0x76, 0x5d, 0xe6, 0x5f, 0xc8, 0xe0, 0x0d, 0x71, 0x12, 0xc6, 0xfe, 0x79, 0x16, 0x2a, 0xd3, - 0xa4, 0xd4, 0x1d, 0x28, 0x9b, 0x3e, 0xe6, 0x84, 0xb0, 0x6d, 0x2b, 0xbc, 0x6d, 0xaf, 0x27, 0x5e, - 0x9b, 0x2e, 0x33, 0xe8, 0x46, 0x29, 0xa4, 0xc8, 0xa6, 0x6d, 0xf3, 0xc7, 0xad, 0x20, 0x67, 0x02, - 0xae, 0x19, 0x27, 0x6e, 0x5d, 0x76, 0xed, 0xf8, 0x49, 0x2b, 0x09, 0x20, 0xda, 0x76, 0x29, 0xa6, - 0xf2, 0xbe, 0xfd, 0x03, 0x28, 0x13, 0x97, 0x30, 0x82, 0xba, 0xad, 0x36, 0xea, 0x22, 0xd7, 0xbc, - 0xce, 0x05, 0x46, 0x34, 0x5a, 0xa9, 0x36, 0x05, 0xa7, 0x1b, 0x25, 0x49, 0x69, 0x08, 0x82, 0xba, - 0x0f, 0x85, 0x50, 0x55, 0xee, 0x5a, 0x53, 0x5e, 0x28, 0x9e, 0xf0, 0xc8, 0xcf, 0xb2, 0xb0, 0x12, - 0x3d, 0xf0, 0xdc, 0xb8, 0x62, 0x56, 0x57, 0x1c, 0x01, 0x88, 0x4a, 0x12, 0xf4, 0x92, 0x6b, 0x78, - 0x23, 0xa8, 0x45, 0x8b, 0x02, 0xa1, 0x49, 0x59, 0xc2, 0x1f, 0xff, 0xcc, 0xc2, 0xad, 0xa4, 0x3f, - 0x6e, 0x9a, 0xfc, 0x1b, 0xf4, 0xe4, 0xf6, 0xcd, 0xb8, 0x36, 0xe6, 0x78, 0x6d, 0xfc, 0xea, 0xd4, - 0xda, 0x38, 0x96, 0x53, 0xd3, 0x8b, 0xe2, 0xbf, 0x33, 0x90, 0xbf, 0x8f, 0x7c, 0xe4, 0x50, 0xd5, - 0x1c, 0xbb, 0x72, 0x88, 0x87, 0x88, 0xbb, 0x63, 0x19, 0xd3, 0x94, 0x7f, 0x2f, 0x7b, 0xc1, 0x8d, - 0xe3, 0xe1, 0x84, 0x1b, 0xc7, 0x27, 0x50, 0x72, 0xd0, 0xa0, 0x15, 0x1d, 0x50, 0x78, 0x73, 0xa9, - 0x71, 0x37, 0x46, 0xb9, 0xfc, 0x5d, 0x3c, 0xa5, 0x44, 0x17, 0x72, 0xaa, 0x7e, 0x03, 0x8a, 0x01, - 0x47, 0xdc, 0x27, 0x02, 0xf1, 0xb5, 0xf8, 0xc9, 0x22, 0xf1, 0x51, 0x37, 0xc0, 0x41, 0x83, 0x5d, - 0xb1, 0x50, 0x0f, 0x41, 0xed, 0x44, 0x4f, 0x68, 0xad, 0xd8, 0x96, 0x81, 0xfc, 0xbb, 0xa3, 0xa1, - 0x76, 0x57, 0xc8, 0x8f, 0xf3, 0xe8, 0xc6, 0x4a, 0x4c, 0x0c, 0xd1, 0xbe, 0x0e, 0x10, 0x9c, 0xab, - 0x65, 0x61, 0xd7, 0x73, 0xe4, 0xc5, 0xf7, 0xf6, 0x68, 0xa8, 0xad, 0x08, 0x94, 0xf8, 0x9b, 0x6e, - 0x2c, 0x06, 0x8b, 0x66, 0xf0, 0x3b, 0x36, 0x7c, 0x63, 0xef, 0xf1, 0xd3, 0xaa, 0xf2, 0xe4, 0x69, - 0x55, 0xf9, 0xdb, 0xd3, 0xaa, 0xf2, 0xc5, 0xb3, 0xea, 0xdc, 0x93, 0x67, 0xd5, 0xb9, 0x3f, 0x3f, - 0xab, 0xce, 0x7d, 0xfb, 0x6b, 0xcf, 0x0d, 0x96, 0xd4, 0xdf, 0x5b, 0xdb, 0x79, 0xee, 0x95, 0x8f, - 0xfe, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x62, 0xe9, 0xa4, 0xfa, 0x89, 0x1d, 0x00, 0x00, + 0x35, 0xe9, 0x58, 0xee, 0x4e, 0x12, 0x06, 0x85, 0xe0, 0xdb, 0xce, 0xfd, 0xfd, 0xa1, 0xa6, 0xe8, + 0xbf, 0xcb, 0xc2, 0xf2, 0x11, 0xb5, 0x77, 0x2d, 0xc2, 0x5e, 0x55, 0xdc, 0xf5, 0x26, 0x59, 0x2b, + 0xc3, 0xad, 0xb5, 0x33, 0x1a, 0x6a, 0x25, 0x61, 0xad, 0xff, 0xa5, 0x8d, 0x1c, 0x28, 0xc7, 0x71, + 0xda, 0xf2, 0x11, 0xc3, 0x32, 0x2a, 0x9b, 0x33, 0x46, 0x64, 0x13, 0x9b, 0xa3, 0xa1, 0xb6, 0x26, + 0x76, 0x96, 0x82, 0xd2, 0x8d, 0x92, 0x79, 0x29, 0x37, 0xd4, 0xc1, 0xe4, 0x44, 0xc8, 0x71, 0x95, + 0xfb, 0xaf, 0x30, 0x09, 0xa4, 0x0f, 0x7f, 0x9b, 0x81, 0xe2, 0x11, 0xb5, 0x25, 0x1d, 0x4f, 0x4e, + 0x0d, 0xe5, 0xff, 0x98, 0x1a, 0x99, 0xd7, 0x93, 0x1a, 0x5b, 0x90, 0x47, 0x8e, 0xd7, 0x77, 0x19, + 0xf7, 0xf6, 0x73, 0x73, 0x40, 0x32, 0x4a, 0x03, 0xfe, 0x39, 0xcb, 0xcb, 0x6f, 0x03, 0xdb, 0xc4, + 0x35, 0xb0, 0xf5, 0x26, 0xd8, 0xf1, 0xa7, 0x0a, 0xdc, 0x8e, 0xad, 0x44, 0x7d, 0x33, 0x65, 0xcc, + 0x4f, 0x47, 0x43, 0xed, 0x2b, 0x69, 0x63, 0x26, 0xd8, 0xae, 0x61, 0xd0, 0xd5, 0x08, 0xe8, 0xd8, + 0x37, 0x27, 0xef, 0xc3, 0xa2, 0x2c, 0xda, 0x47, 0x76, 0xfa, 0x3e, 0x12, 0x6c, 0x2f, 0xb5, 0x8f, + 0x26, 0x65, 0xe3, 0xbe, 0xcd, 0x5d, 0xcd, 0xb7, 0x8f, 0x32, 0xb0, 0x74, 0x44, 0xed, 0xcf, 0x5c, + 0xeb, 0x26, 0x3d, 0xae, 0x99, 0x1e, 0xbf, 0x52, 0xa0, 0xb4, 0x4f, 0x28, 0xf3, 0x7c, 0x62, 0xa2, + 0xee, 0x81, 0x7b, 0xea, 0xa9, 0x1f, 0x43, 0xbe, 0x83, 0x91, 0x85, 0x7d, 0xd9, 0x1c, 0xde, 0xad, + 0xc5, 0x83, 0x53, 0x2d, 0x18, 0x9c, 0x6a, 0x62, 0x43, 0xfb, 0x9c, 0x29, 0x44, 0x15, 0x22, 0xea, + 0x27, 0x90, 0x3f, 0x47, 0x5d, 0x8a, 0x59, 0x25, 0xb3, 0x91, 0xdd, 0x2c, 0x7e, 0xa8, 0x4f, 0xed, + 0x2c, 0x51, 0x4b, 0x0a, 0x11, 0x84, 0x9c, 0xdc, 0xd7, 0x6f, 0x32, 0x50, 0x4e, 0x8d, 0x29, 0x6a, + 0x03, 0x72, 0xbc, 0xde, 0x2b, 0xbc, 0xf8, 0xd6, 0xae, 0x30, 0x85, 0x34, 0xb1, 0x69, 0x70, 0x59, + 0xf5, 0xfb, 0xb0, 0xe0, 0xa0, 0x81, 0xe8, 0x1b, 0x19, 0x8e, 0x73, 0xef, 0x6a, 0x38, 0xa3, 0xa1, + 0x56, 0x96, 0x85, 0x5c, 0xe2, 0xe8, 0x46, 0xc1, 0x41, 0x03, 0xde, 0x2d, 0x7a, 0x50, 0x0e, 0xa8, + 0x66, 0x07, 0xb9, 0x36, 0x4e, 0x36, 0xa7, 0xfd, 0x2b, 0x2b, 0x59, 0x8b, 0x95, 0x24, 0xe0, 0x74, + 0x63, 0xc9, 0x41, 0x83, 0x1d, 0x4e, 0x08, 0x34, 0x6e, 0x2f, 0x7c, 0xf9, 0x50, 0x9b, 0xe3, 0x16, + 0xfb, 0x83, 0x02, 0x10, 0x5b, 0x4c, 0xfd, 0x01, 0x2c, 0xa7, 0x9a, 0x1b, 0x95, 0xfe, 0x9c, 0x7d, + 0x2e, 0x5c, 0x08, 0x76, 0xfd, 0x64, 0xa8, 0x29, 0x46, 0xd9, 0x4c, 0xf9, 0xe2, 0x7b, 0x50, 0xec, + 0xf7, 0x2c, 0xc4, 0x70, 0x2b, 0x18, 0x91, 0xe5, 0xc4, 0xb9, 0x5e, 0x13, 0xe3, 0x71, 0x2d, 0x1c, + 0x8f, 0x6b, 0x0f, 0xc2, 0xf9, 0xb9, 0x51, 0x0d, 0xb0, 0x46, 0x43, 0x4d, 0x15, 0xe7, 0x4a, 0x08, + 0xeb, 0x5f, 0xfc, 0x55, 0x53, 0x0c, 0x10, 0x94, 0x40, 0x20, 0x71, 0xa8, 0xdf, 0x2b, 0x50, 0x4c, + 0x8c, 0x20, 0x6a, 0x05, 0x0a, 0x8e, 0xe7, 0x92, 0x33, 0x19, 0x9c, 0x8b, 0x46, 0xb8, 0x54, 0xd7, + 0x61, 0x81, 0x58, 0xd8, 0x65, 0x84, 0x5d, 0x08, 0xc7, 0x1a, 0xd1, 0x3a, 0x90, 0xfa, 0x1c, 0xb7, + 0x29, 0x09, 0xdd, 0x61, 0x84, 0x4b, 0x75, 0x0f, 0x96, 0x29, 0x36, 0xfb, 0x3e, 0x61, 0x17, 0x2d, + 0xd3, 0x73, 0x19, 0x32, 0x99, 0xec, 0xed, 0xef, 0x8c, 0x86, 0xda, 0x1d, 0xb1, 0xd7, 0x34, 0x87, + 0x6e, 0x94, 0x43, 0xd2, 0x8e, 0xa0, 0x04, 0x1a, 0x2c, 0xcc, 0x10, 0xe9, 0x8a, 0x59, 0x71, 0xd1, + 0x08, 0x97, 0x89, 0xb3, 0x3c, 0x2a, 0xc0, 0x62, 0x3c, 0x87, 0x7d, 0x0e, 0xcb, 0x5e, 0x0f, 0xfb, + 0x13, 0x0a, 0xd5, 0x61, 0xac, 0x39, 0xcd, 0x71, 0x8d, 0x5a, 0x51, 0x0e, 0x31, 0xc2, 0x52, 0xb1, + 0x17, 0x04, 0x86, 0x4b, 0xb1, 0x4b, 0xfb, 0xb4, 0x25, 0xc7, 0xcd, 0x4c, 0xfa, 0xc8, 0x69, 0x0e, + 0x3d, 0x88, 0x00, 0x49, 0xba, 0x2f, 0x86, 0xd2, 0x35, 0xc8, 0xff, 0x10, 0x91, 0x2e, 0xb6, 0xb8, + 0x4d, 0x17, 0x0c, 0xb9, 0x52, 0x0f, 0x20, 0x4f, 0x19, 0x62, 0x7d, 0x31, 0xb1, 0xcf, 0x37, 0xb6, + 0x66, 0xdc, 0x73, 0xc3, 0x73, 0xad, 0x63, 0x2e, 0x68, 0x48, 0x00, 0x75, 0x0f, 0xf2, 0xcc, 0x3b, + 0xc3, 0xae, 0x34, 0xea, 0x95, 0x52, 0xfe, 0xc0, 0x65, 0x86, 0x94, 0x56, 0x19, 0xc4, 0xd5, 0xba, + 0x45, 0x3b, 0xc8, 0xc7, 0x54, 0x4c, 0xd8, 0x8d, 0x83, 0x2b, 0xe7, 0xe5, 0x9d, 0x74, 0x0b, 0x11, + 0x78, 0xba, 0x51, 0x8e, 0x48, 0xc7, 0x9c, 0x92, 0x9e, 0xb4, 0x0b, 0x2f, 0x37, 0x69, 0xef, 0xc1, + 0x72, 0xdf, 0x6d, 0x7b, 0xae, 0x45, 0x5c, 0xbb, 0xd5, 0xc1, 0xc4, 0xee, 0xb0, 0xca, 0xc2, 0x86, + 0xb2, 0x99, 0x4d, 0xba, 0x2d, 0xcd, 0xa1, 0x1b, 0xe5, 0x88, 0xb4, 0xcf, 0x29, 0xaa, 0x05, 0xa5, + 0x98, 0x8b, 0xe7, 0xee, 0xe2, 0x0b, 0x73, 0xf7, 0xab, 0x32, 0x77, 0x6f, 0xa7, 0xb5, 0xc4, 0xe9, + 0xbb, 0x14, 0x11, 0x03, 0x31, 0xf5, 0xe0, 0xd2, 0x7d, 0x14, 0xb8, 0x86, 0xf7, 0x66, 0xa8, 0x3b, + 0xb3, 0x5f, 0x45, 0x8b, 0xaf, 0xe5, 0x2a, 0xba, 0x7d, 0xeb, 0x67, 0x0f, 0xb5, 0xb9, 0x28, 0x85, + 0x7f, 0x9e, 0x81, 0x7c, 0xf3, 0xe4, 0x3e, 0x22, 0xfe, 0xdb, 0x3a, 0x69, 0x24, 0xea, 0xd9, 0x1e, + 0x14, 0x84, 0x2d, 0xa8, 0xfa, 0x31, 0xcc, 0xf7, 0x82, 0x1f, 0x15, 0x85, 0x37, 0x7d, 0x6d, 0x7a, + 0x90, 0x73, 0x81, 0xf0, 0xb2, 0xca, 0x65, 0xf4, 0x5f, 0x67, 0x01, 0x9a, 0x27, 0x27, 0x0f, 0x7c, + 0xd2, 0xeb, 0x62, 0x76, 0x33, 0x99, 0xbf, 0x39, 0x93, 0x79, 0xc2, 0xd9, 0x0f, 0xa0, 0x18, 0xfb, + 0x88, 0xaa, 0xbb, 0xb0, 0xc0, 0xe4, 0x6f, 0xe9, 0xf3, 0xf7, 0x9e, 0xe3, 0xf3, 0x50, 0x4e, 0xfa, + 0x3d, 0x12, 0xd5, 0xff, 0x98, 0x01, 0x78, 0xd1, 0xbb, 0xcf, 0x5b, 0x30, 0xbd, 0xef, 0x41, 0x5e, + 0x76, 0xa5, 0xec, 0xb5, 0x46, 0x5b, 0x29, 0x9d, 0x70, 0xd7, 0x3f, 0x32, 0xb0, 0xfa, 0x59, 0x58, + 0x91, 0x6f, 0x2c, 0xac, 0x7e, 0x0a, 0x05, 0xec, 0x32, 0x9f, 0x70, 0x13, 0x07, 0xe1, 0xba, 0x35, + 0x35, 0x5c, 0x27, 0x98, 0x6d, 0xd7, 0x65, 0xfe, 0x85, 0x0c, 0xde, 0x10, 0x27, 0x61, 0xec, 0x5f, + 0x66, 0xa1, 0x32, 0x4d, 0x4a, 0xdd, 0x81, 0xb2, 0xe9, 0x63, 0x4e, 0x08, 0xdb, 0xb6, 0xc2, 0xdb, + 0xf6, 0x7a, 0xe2, 0x15, 0xea, 0x32, 0x83, 0x6e, 0x94, 0x42, 0x8a, 0x6c, 0xda, 0x36, 0x7f, 0xf4, + 0x0a, 0x72, 0x26, 0xe0, 0x9a, 0x71, 0xe2, 0xd6, 0x65, 0xd7, 0x8e, 0x9f, 0xba, 0x92, 0x00, 0xa2, + 0x6d, 0x97, 0x62, 0x2a, 0xef, 0xdb, 0x3f, 0x82, 0x32, 0x71, 0x09, 0x23, 0xa8, 0xdb, 0x6a, 0xa3, + 0x2e, 0x72, 0xcd, 0xeb, 0x5c, 0x60, 0x44, 0xa3, 0x95, 0x6a, 0x53, 0x70, 0xba, 0x51, 0x92, 0x94, + 0x86, 0x20, 0xa8, 0xfb, 0x50, 0x08, 0x55, 0xe5, 0xae, 0x35, 0xe5, 0x85, 0xe2, 0x09, 0x8f, 0xfc, + 0x22, 0x0b, 0x2b, 0xd1, 0x63, 0xcf, 0x8d, 0x2b, 0x66, 0x75, 0xc5, 0x11, 0x80, 0xa8, 0x24, 0x41, + 0x2f, 0xb9, 0x86, 0x37, 0x82, 0x5a, 0xb4, 0x28, 0x10, 0x9a, 0x94, 0x25, 0xfc, 0xf1, 0xcf, 0x2c, + 0xdc, 0x4a, 0xfa, 0xe3, 0xa6, 0xc9, 0xbf, 0x41, 0xcf, 0x6f, 0xdf, 0x8e, 0x6b, 0x63, 0x8e, 0xd7, + 0xc6, 0xaf, 0x4f, 0xad, 0x8d, 0x63, 0x39, 0x35, 0xbd, 0x28, 0xfe, 0x2b, 0x03, 0xf9, 0xfb, 0xc8, + 0x47, 0x0e, 0x55, 0xcd, 0xb1, 0x2b, 0x87, 0x78, 0x88, 0xb8, 0x3b, 0x96, 0x31, 0x4d, 0xf9, 0xd7, + 0xb4, 0x17, 0xdc, 0x38, 0xbe, 0x9c, 0x70, 0xe3, 0xf8, 0x04, 0x4a, 0x0e, 0x1a, 0xb4, 0xa2, 0x03, + 0x0a, 0x6f, 0x2e, 0x35, 0xee, 0xc6, 0x28, 0x97, 0xbf, 0x8b, 0xa7, 0x94, 0xe8, 0x42, 0x4e, 0xd5, + 0x6f, 0x41, 0x31, 0xe0, 0x88, 0xfb, 0x44, 0x20, 0xbe, 0x16, 0x3f, 0x59, 0x24, 0x3e, 0xea, 0x06, + 0x38, 0x68, 0xb0, 0x2b, 0x16, 0xea, 0x21, 0xa8, 0x9d, 0xe8, 0x09, 0xad, 0x15, 0xdb, 0x32, 0x90, + 0x7f, 0x77, 0x34, 0xd4, 0xee, 0x0a, 0xf9, 0x71, 0x1e, 0xdd, 0x58, 0x89, 0x89, 0x21, 0xda, 0x37, + 0x01, 0x82, 0x73, 0xb5, 0x2c, 0xec, 0x7a, 0x8e, 0xbc, 0xf8, 0xde, 0x1e, 0x0d, 0xb5, 0x15, 0x81, + 0x12, 0x7f, 0xd3, 0x8d, 0xc5, 0x60, 0xd1, 0x0c, 0x7e, 0xc7, 0x86, 0x6f, 0xec, 0x3d, 0x7e, 0x5a, + 0x55, 0x9e, 0x3c, 0xad, 0x2a, 0x7f, 0x7b, 0x5a, 0x55, 0xbe, 0x78, 0x56, 0x9d, 0x7b, 0xf2, 0xac, + 0x3a, 0xf7, 0xa7, 0x67, 0xd5, 0xb9, 0xef, 0x7e, 0xe3, 0xb9, 0xc1, 0x92, 0xfa, 0x6b, 0x6c, 0x3b, + 0xcf, 0xbd, 0xf2, 0xd1, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xa9, 0x93, 0x44, 0xcc, 0xa7, 0x1d, + 0x00, 0x00, } +func (this *MsgCreateValidator) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgCreateValidator) + if !ok { + that2, ok := that.(MsgCreateValidator) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.Description.Equal(&that1.Description) { + return false + } + if !this.Commission.Equal(&that1.Commission) { + return false + } + if !this.MinSelfDelegation.Equal(that1.MinSelfDelegation) { + return false + } + if !bytes.Equal(this.DelegatorAddress, that1.DelegatorAddress) { + return false + } + if !bytes.Equal(this.ValidatorAddress, that1.ValidatorAddress) { + return false + } + if this.Pubkey != that1.Pubkey { + return false + } + if !this.Value.Equal(&that1.Value) { + return false + } + return true +} +func (this *MsgEditValidator) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgEditValidator) + if !ok { + that2, ok := that.(MsgEditValidator) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.Description.Equal(&that1.Description) { + return false + } + if !bytes.Equal(this.ValidatorAddress, that1.ValidatorAddress) { + return false + } + if that1.CommissionRate == nil { + if this.CommissionRate != nil { + return false + } + } else if !this.CommissionRate.Equal(*that1.CommissionRate) { + return false + } + if that1.MinSelfDelegation == nil { + if this.MinSelfDelegation != nil { + return false + } + } else if !this.MinSelfDelegation.Equal(*that1.MinSelfDelegation) { + return false + } + return true +} +func (this *MsgDelegate) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgDelegate) + if !ok { + that2, ok := that.(MsgDelegate) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.DelegatorAddress, that1.DelegatorAddress) { + return false + } + if !bytes.Equal(this.ValidatorAddress, that1.ValidatorAddress) { + return false + } + if !this.Amount.Equal(&that1.Amount) { + return false + } + return true +} +func (this *MsgBeginRedelegate) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgBeginRedelegate) + if !ok { + that2, ok := that.(MsgBeginRedelegate) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.DelegatorAddress, that1.DelegatorAddress) { + return false + } + if !bytes.Equal(this.ValidatorSrcAddress, that1.ValidatorSrcAddress) { + return false + } + if !bytes.Equal(this.ValidatorDstAddress, that1.ValidatorDstAddress) { + return false + } + if !this.Amount.Equal(&that1.Amount) { + return false + } + return true +} +func (this *MsgUndelegate) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MsgUndelegate) + if !ok { + that2, ok := that.(MsgUndelegate) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.DelegatorAddress, that1.DelegatorAddress) { + return false + } + if !bytes.Equal(this.ValidatorAddress, that1.ValidatorAddress) { + return false + } + if !this.Amount.Equal(&that1.Amount) { + return false + } + return true +} func (this *HistoricalInfo) Equal(that interface{}) bool { if that == nil { return this == nil diff --git a/x/staking/types/types.proto b/x/staking/types/types.proto index 281d1db892..15e8733c98 100644 --- a/x/staking/types/types.proto +++ b/x/staking/types/types.proto @@ -11,6 +11,8 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/staking/types"; // MsgCreateValidator defines an SDK message for creating a new validator. message MsgCreateValidator { + option (gogoproto.equal) = true; + Description description = 1 [(gogoproto.nullable) = false]; CommissionRates commission = 2 [(gogoproto.nullable) = false]; string min_self_delegation = 3 [ @@ -32,6 +34,8 @@ message MsgCreateValidator { // MsgEditValidator defines an SDK message for editing an existing validator. message MsgEditValidator { + option (gogoproto.equal) = true; + Description description = 1 [(gogoproto.nullable) = false]; bytes validator_address = 2 [ (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress", @@ -56,6 +60,8 @@ message MsgEditValidator { // MsgDelegate defines an SDK message for performing a delegation from a // delegate to a validator. message MsgDelegate { + option (gogoproto.equal) = true; + bytes delegator_address = 1 [ (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", (gogoproto.moretags) = "yaml:\"delegator_address\"" @@ -70,6 +76,8 @@ message MsgDelegate { // MsgBeginRedelegate defines an SDK message for performing a redelegation from // a delegate and source validator to a destination validator. message MsgBeginRedelegate { + option (gogoproto.equal) = true; + bytes delegator_address = 1 [ (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", (gogoproto.moretags) = "yaml:\"delegator_address\"" @@ -88,6 +96,8 @@ message MsgBeginRedelegate { // MsgUndelegate defines an SDK message for performing an undelegation from a // delegate and a validator. message MsgUndelegate { + option (gogoproto.equal) = true; + bytes delegator_address = 1 [ (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", (gogoproto.moretags) = "yaml:\"delegator_address\"" diff --git a/x/supply/alias.go b/x/supply/alias.go index 1138f7c5ee..40d9c2fbe1 100644 --- a/x/supply/alias.go +++ b/x/supply/alias.go @@ -1,13 +1,11 @@ -// nolint -// autogenerated code using github.com/rigelrozanski/multitool -// aliases generated for the following subdirectories: -// ALIASGEN: github.com/cosmos/cosmos-sdk/x/supply/internal/keeper -// ALIASGEN: github.com/cosmos/cosmos-sdk/x/supply/internal/types package supply +// DONTCOVER +// nolint + import ( - "github.com/cosmos/cosmos-sdk/x/supply/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/keeper" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) const ( @@ -46,4 +44,5 @@ type ( ModuleAccount = types.ModuleAccount GenesisState = types.GenesisState Supply = types.Supply + Codec = types.Codec ) diff --git a/x/supply/client/cli/query.go b/x/supply/client/cli/query.go index 26c4a77cd5..95dd5b7bc5 100644 --- a/x/supply/client/cli/query.go +++ b/x/supply/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/version" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // GetQueryCmd returns the cli query commands for this module diff --git a/x/supply/client/rest/query.go b/x/supply/client/rest/query.go index cea93b50b0..021159dfaf 100644 --- a/x/supply/client/rest/query.go +++ b/x/supply/client/rest/query.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // RegisterRoutes registers staking-related REST handlers to a router diff --git a/x/supply/exported/exported.go b/x/supply/exported/exported.go index e872e1deab..cecfc8e204 100644 --- a/x/supply/exported/exported.go +++ b/x/supply/exported/exported.go @@ -6,7 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/exported" ) -// ModuleAccountI defines an account interface for modules that hold tokens in an escrow +// ModuleAccountI defines an account interface for modules that hold tokens in +// an escrow. type ModuleAccountI interface { exported.Account @@ -19,10 +20,10 @@ type ModuleAccountI interface { // token supply. type SupplyI interface { GetTotal() sdk.Coins - SetTotal(total sdk.Coins) SupplyI + SetTotal(total sdk.Coins) - Inflate(amount sdk.Coins) SupplyI - Deflate(amount sdk.Coins) SupplyI + Inflate(amount sdk.Coins) + Deflate(amount sdk.Coins) String() string ValidateBasic() error diff --git a/x/supply/genesis.go b/x/supply/genesis.go index 17546515cf..98f0e1f4f7 100644 --- a/x/supply/genesis.go +++ b/x/supply/genesis.go @@ -2,7 +2,7 @@ package supply import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // InitGenesis sets supply information for genesis. diff --git a/x/supply/internal/keeper/integration_test.go b/x/supply/internal/keeper/integration_test.go deleted file mode 100644 index be065ea16a..0000000000 --- a/x/supply/internal/keeper/integration_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package keeper_test - -import ( - abci "github.com/tendermint/tendermint/abci/types" - - "github.com/cosmos/cosmos-sdk/simapp" - sdk "github.com/cosmos/cosmos-sdk/types" - keep "github.com/cosmos/cosmos-sdk/x/supply/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" -) - -var ( - multiPerm = "multiple permissions account" - randomPerm = "random permission" - holder = "holder" -) - -// nolint:deadcode,unused -func createTestApp(isCheckTx bool) (*simapp.SimApp, sdk.Context) { - app := simapp.Setup(isCheckTx) - - // add module accounts to supply keeper - maccPerms := simapp.GetMaccPerms() - maccPerms[holder] = nil - maccPerms[types.Burner] = []string{types.Burner} - maccPerms[types.Minter] = []string{types.Minter} - maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} - maccPerms[randomPerm] = []string{"random"} - - ctx := app.BaseApp.NewContext(isCheckTx, abci.Header{}) - app.SupplyKeeper = keep.NewKeeper(app.Codec(), app.GetKey(types.StoreKey), app.AccountKeeper, app.BankKeeper, maccPerms) - app.SupplyKeeper.SetSupply(ctx, types.NewSupply(sdk.NewCoins())) - - return app, ctx -} diff --git a/x/supply/internal/keeper/keeper_test.go b/x/supply/internal/keeper/keeper_test.go deleted file mode 100644 index d4ff2849e4..0000000000 --- a/x/supply/internal/keeper/keeper_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package keeper_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" -) - -func TestSupply(t *testing.T) { - initialPower := int64(100) - initTokens := sdk.TokensFromConsensusPower(initialPower) - - app, ctx := createTestApp(false) - totalSupply := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens)) - app.SupplyKeeper.SetSupply(ctx, types.NewSupply(totalSupply)) - - total := app.SupplyKeeper.GetSupply(ctx).GetTotal() - - require.Equal(t, totalSupply, total) -} - -func TestValidatePermissions(t *testing.T) { - app, _ := createTestApp(false) - - err := app.SupplyKeeper.ValidatePermissions(multiPermAcc) - require.NoError(t, err) - - err = app.SupplyKeeper.ValidatePermissions(randomPermAcc) - require.NoError(t, err) - - // unregistered permissions - otherAcc := types.NewEmptyModuleAccount("other", "other") - err = app.SupplyKeeper.ValidatePermissions(otherAcc) - require.Error(t, err) -} diff --git a/x/supply/internal/types/codec.go b/x/supply/internal/types/codec.go deleted file mode 100644 index 89bc9a2ffc..0000000000 --- a/x/supply/internal/types/codec.go +++ /dev/null @@ -1,24 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/supply/exported" -) - -// RegisterCodec registers the account types and interface -func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterInterface((*exported.ModuleAccountI)(nil), nil) - cdc.RegisterInterface((*exported.SupplyI)(nil), nil) - cdc.RegisterConcrete(&ModuleAccount{}, "cosmos-sdk/ModuleAccount", nil) - cdc.RegisterConcrete(&Supply{}, "cosmos-sdk/Supply", nil) -} - -// ModuleCdc generic sealed codec to be used throughout module -var ModuleCdc *codec.Codec - -func init() { - cdc := codec.New() - RegisterCodec(cdc) - codec.RegisterCrypto(cdc) - ModuleCdc = cdc.Seal() -} diff --git a/x/supply/internal/keeper/account.go b/x/supply/keeper/account.go similarity index 97% rename from x/supply/internal/keeper/account.go rename to x/supply/keeper/account.go index 312b039be2..685308cf61 100644 --- a/x/supply/internal/keeper/account.go +++ b/x/supply/keeper/account.go @@ -3,7 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/supply/exported" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // GetModuleAddress returns an address based on the module name diff --git a/x/supply/internal/keeper/bank.go b/x/supply/keeper/bank.go similarity index 97% rename from x/supply/internal/keeper/bank.go rename to x/supply/keeper/bank.go index 9117286aae..4213c8b0d8 100644 --- a/x/supply/internal/keeper/bank.go +++ b/x/supply/keeper/bank.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // SendCoinsFromModuleToAccount transfers coins from a ModuleAccount to an AccAddress. @@ -112,7 +112,7 @@ func (k Keeper) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) err // update total supply supply := k.GetSupply(ctx) - supply = supply.Inflate(amt) + supply.Inflate(amt) k.SetSupply(ctx, supply) @@ -141,7 +141,7 @@ func (k Keeper) BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) err // update total supply supply := k.GetSupply(ctx) - supply = supply.Deflate(amt) + supply.Deflate(amt) k.SetSupply(ctx, supply) logger := k.Logger(ctx) diff --git a/x/supply/internal/keeper/bank_test.go b/x/supply/keeper/bank_test.go similarity index 72% rename from x/supply/internal/keeper/bank_test.go rename to x/supply/keeper/bank_test.go index 5388dc804d..cb62371478 100644 --- a/x/supply/internal/keeper/bank_test.go +++ b/x/supply/keeper/bank_test.go @@ -4,13 +4,21 @@ import ( "testing" "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/cosmos/cosmos-sdk/simapp" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" sdk "github.com/cosmos/cosmos-sdk/types" - keep "github.com/cosmos/cosmos-sdk/x/supply/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + keep "github.com/cosmos/cosmos-sdk/x/supply/keeper" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) -const initialPower = int64(100) +const ( + initialPower = int64(100) + holder = "holder" + multiPerm = "multiple permissions account" + randomPerm = "random permission" +) // create module accounts for testing var ( @@ -36,8 +44,20 @@ func getCoinsByName(ctx sdk.Context, sk keep.Keeper, ak types.AccountKeeper, bk } func TestSendCoins(t *testing.T) { - app, ctx := createTestApp(false) - keeper := app.SupplyKeeper + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, abci.Header{Height: 1}) + + // add module accounts to supply keeper + maccPerms := simapp.GetMaccPerms() + maccPerms[holder] = nil + maccPerms[types.Burner] = []string{types.Burner} + maccPerms[types.Minter] = []string{types.Minter} + maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} + maccPerms[randomPerm] = []string{"random"} + + appCodec := simappcodec.NewAppCodec(app.Codec()) + + keeper := keep.NewKeeper(appCodec, app.GetKey(types.StoreKey), app.AccountKeeper, app.BankKeeper, maccPerms) ak := app.AccountKeeper bk := app.BankKeeper @@ -85,8 +105,20 @@ func TestSendCoins(t *testing.T) { } func TestMintCoins(t *testing.T) { - app, ctx := createTestApp(false) - keeper := app.SupplyKeeper + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, abci.Header{Height: 1}) + + // add module accounts to supply keeper + maccPerms := simapp.GetMaccPerms() + maccPerms[holder] = nil + maccPerms[types.Burner] = []string{types.Burner} + maccPerms[types.Minter] = []string{types.Minter} + maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} + maccPerms[randomPerm] = []string{"random"} + + appCodec := simappcodec.NewAppCodec(app.Codec()) + + keeper := keep.NewKeeper(appCodec, app.GetKey(types.StoreKey), app.AccountKeeper, app.BankKeeper, maccPerms) ak := app.AccountKeeper bk := app.BankKeeper @@ -121,8 +153,20 @@ func TestMintCoins(t *testing.T) { } func TestBurnCoins(t *testing.T) { - app, ctx := createTestApp(false) - keeper := app.SupplyKeeper + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, abci.Header{Height: 1}) + + // add module accounts to supply keeper + maccPerms := simapp.GetMaccPerms() + maccPerms[holder] = nil + maccPerms[types.Burner] = []string{types.Burner} + maccPerms[types.Minter] = []string{types.Minter} + maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} + maccPerms[randomPerm] = []string{"random"} + + appCodec := simappcodec.NewAppCodec(app.Codec()) + + keeper := keep.NewKeeper(appCodec, app.GetKey(types.StoreKey), app.AccountKeeper, app.BankKeeper, maccPerms) ak := app.AccountKeeper bk := app.BankKeeper @@ -131,7 +175,7 @@ func TestBurnCoins(t *testing.T) { keeper.SetModuleAccount(ctx, burnerAcc) initialSupply := keeper.GetSupply(ctx) - initialSupply = initialSupply.Inflate(initCoins) + initialSupply.Inflate(initCoins) keeper.SetSupply(ctx, initialSupply) require.Panics(t, func() { keeper.BurnCoins(ctx, "", initCoins) }, "no module account") @@ -147,7 +191,7 @@ func TestBurnCoins(t *testing.T) { // test same functionality on module account with multiple permissions initialSupply = keeper.GetSupply(ctx) - initialSupply = initialSupply.Inflate(initCoins) + initialSupply.Inflate(initCoins) keeper.SetSupply(ctx, initialSupply) require.NoError(t, bk.SetBalances(ctx, multiPermAcc.GetAddress(), initCoins)) diff --git a/x/supply/internal/keeper/invariants.go b/x/supply/keeper/invariants.go similarity index 95% rename from x/supply/internal/keeper/invariants.go rename to x/supply/keeper/invariants.go index 0b5ca06694..d53b7637f1 100644 --- a/x/supply/internal/keeper/invariants.go +++ b/x/supply/keeper/invariants.go @@ -4,7 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // RegisterInvariants register all supply invariants diff --git a/x/supply/internal/keeper/keeper.go b/x/supply/keeper/keeper.go similarity index 74% rename from x/supply/internal/keeper/keeper.go rename to x/supply/keeper/keeper.go index b071f878db..012a5cf284 100644 --- a/x/supply/internal/keeper/keeper.go +++ b/x/supply/keeper/keeper.go @@ -5,15 +5,14 @@ import ( "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/supply/exported" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // Keeper of the supply store type Keeper struct { - cdc *codec.Codec + cdc types.Codec storeKey sdk.StoreKey ak types.AccountKeeper bk types.BankKeeper @@ -21,8 +20,11 @@ type Keeper struct { } // NewKeeper creates a new Keeper instance -func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, maccPerms map[string][]string) Keeper { - // set the addresses +func NewKeeper( + cdc types.Codec, key sdk.StoreKey, ak types.AccountKeeper, + bk types.BankKeeper, maccPerms map[string][]string, +) Keeper { + permAddrs := make(map[string]types.PermissionsForAddress) for name, perms := range maccPerms { permAddrs[name] = types.NewPermissionsForAddress(name, perms) @@ -43,21 +45,30 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { } // GetSupply retrieves the Supply from store -func (k Keeper) GetSupply(ctx sdk.Context) (supply exported.SupplyI) { +func (k Keeper) GetSupply(ctx sdk.Context) exported.SupplyI { store := ctx.KVStore(k.storeKey) - b := store.Get(SupplyKey) - if b == nil { + bz := store.Get(SupplyKey) + if bz == nil { panic("stored supply should not have been nil") } - k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &supply) - return + + supply, err := k.cdc.UnmarshalSupply(bz) + if err != nil { + panic(err) + } + + return supply } // SetSupply sets the Supply to store func (k Keeper) SetSupply(ctx sdk.Context, supply exported.SupplyI) { store := ctx.KVStore(k.storeKey) - b := k.cdc.MustMarshalBinaryLengthPrefixed(supply) - store.Set(SupplyKey, b) + bz, err := k.cdc.MarshalSupply(supply) + if err != nil { + panic(err) + } + + store.Set(SupplyKey, bz) } // ValidatePermissions validates that the module account has been granted @@ -69,5 +80,6 @@ func (k Keeper) ValidatePermissions(macc exported.ModuleAccountI) error { return fmt.Errorf("invalid module permission %s", perm) } } + return nil } diff --git a/x/supply/keeper/keeper_test.go b/x/supply/keeper/keeper_test.go new file mode 100644 index 0000000000..a81575914a --- /dev/null +++ b/x/supply/keeper/keeper_test.go @@ -0,0 +1,55 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/simapp" + simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + keep "github.com/cosmos/cosmos-sdk/x/supply/keeper" + "github.com/cosmos/cosmos-sdk/x/supply/types" +) + +func TestSupply(t *testing.T) { + initialPower := int64(100) + initTokens := sdk.TokensFromConsensusPower(initialPower) + + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, abci.Header{Height: 1}) + + totalSupply := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens)) + app.SupplyKeeper.SetSupply(ctx, types.NewSupply(totalSupply)) + + total := app.SupplyKeeper.GetSupply(ctx).GetTotal() + + require.Equal(t, totalSupply, total) +} + +func TestValidatePermissions(t *testing.T) { + app := simapp.Setup(false) + + // add module accounts to supply keeper + maccPerms := simapp.GetMaccPerms() + maccPerms[holder] = nil + maccPerms[types.Burner] = []string{types.Burner} + maccPerms[types.Minter] = []string{types.Minter} + maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} + maccPerms[randomPerm] = []string{"random"} + + appCodec := simappcodec.NewAppCodec(app.Codec()) + keeper := keep.NewKeeper(appCodec, app.GetKey(types.StoreKey), app.AccountKeeper, app.BankKeeper, maccPerms) + + err := keeper.ValidatePermissions(multiPermAcc) + require.NoError(t, err) + + err = keeper.ValidatePermissions(randomPermAcc) + require.NoError(t, err) + + // unregistered permissions + otherAcc := types.NewEmptyModuleAccount("other", "other") + err = app.SupplyKeeper.ValidatePermissions(otherAcc) + require.Error(t, err) +} diff --git a/x/supply/internal/keeper/key.go b/x/supply/keeper/key.go similarity index 100% rename from x/supply/internal/keeper/key.go rename to x/supply/keeper/key.go diff --git a/x/supply/internal/keeper/querier.go b/x/supply/keeper/querier.go similarity index 97% rename from x/supply/internal/keeper/querier.go rename to x/supply/keeper/querier.go index 093edd2c6b..1150fe3ad4 100644 --- a/x/supply/internal/keeper/querier.go +++ b/x/supply/keeper/querier.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // NewQuerier creates a querier for supply REST endpoints diff --git a/x/supply/internal/keeper/querier_test.go b/x/supply/keeper/querier_test.go similarity index 89% rename from x/supply/internal/keeper/querier_test.go rename to x/supply/keeper/querier_test.go index 92b0dcf32b..e71fa664bb 100644 --- a/x/supply/internal/keeper/querier_test.go +++ b/x/supply/keeper/querier_test.go @@ -7,13 +7,16 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" + "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - keep "github.com/cosmos/cosmos-sdk/x/supply/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + keep "github.com/cosmos/cosmos-sdk/x/supply/keeper" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) func TestNewQuerier(t *testing.T) { - app, ctx := createTestApp(false) + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, abci.Header{Height: 1}) + keeper := app.SupplyKeeper cdc := app.Codec() @@ -59,7 +62,9 @@ func TestNewQuerier(t *testing.T) { } func TestQuerySupply(t *testing.T) { - app, ctx := createTestApp(false) + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, abci.Header{Height: 1}) + keeper := app.SupplyKeeper cdc := app.Codec() diff --git a/x/supply/module.go b/x/supply/module.go index 73d05a7722..1a2531d992 100644 --- a/x/supply/module.go +++ b/x/supply/module.go @@ -17,8 +17,8 @@ import ( sim "github.com/cosmos/cosmos-sdk/x/simulation" "github.com/cosmos/cosmos-sdk/x/supply/client/cli" "github.com/cosmos/cosmos-sdk/x/supply/client/rest" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" "github.com/cosmos/cosmos-sdk/x/supply/simulation" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) var ( @@ -42,14 +42,14 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { // DefaultGenesis returns default genesis state as raw bytes for the supply // module. -func (AppModuleBasic) DefaultGenesis() json.RawMessage { - return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { + return cdc.MustMarshalJSON(DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the supply module. -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { var data GenesisState - if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { + if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) } @@ -120,18 +120,18 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { // InitGenesis performs genesis initialization for the supply module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState - ModuleCdc.MustUnmarshalJSON(data, &genesisState) + cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.keeper, am.bk, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the supply // module. -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { gs := ExportGenesis(ctx, am.keeper) - return ModuleCdc.MustMarshalJSON(gs) + return cdc.MustMarshalJSON(gs) } // BeginBlock returns the begin blocker for the supply module. diff --git a/x/supply/simulation/decoder.go b/x/supply/simulation/decoder.go index 3337e4b068..b67e07651b 100644 --- a/x/supply/simulation/decoder.go +++ b/x/supply/simulation/decoder.go @@ -7,8 +7,8 @@ import ( tmkv "github.com/tendermint/tendermint/libs/kv" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/supply/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/keeper" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // DecodeStore unmarshals the KVPair's Value to the corresponding supply type @@ -19,6 +19,7 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string { cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &supplyA) cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &supplyB) return fmt.Sprintf("%v\n%v", supplyB, supplyB) + default: panic(fmt.Sprintf("invalid supply key %X", kvA.Key)) } diff --git a/x/supply/simulation/decoder_test.go b/x/supply/simulation/decoder_test.go index f653632f16..413e0a930e 100644 --- a/x/supply/simulation/decoder_test.go +++ b/x/supply/simulation/decoder_test.go @@ -10,8 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/supply/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/keeper" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) func makeTestCodec() (cdc *codec.Codec) { diff --git a/x/supply/simulation/genesis.go b/x/supply/simulation/genesis.go index 53775fbc07..b261fa8aa8 100644 --- a/x/supply/simulation/genesis.go +++ b/x/supply/simulation/genesis.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/x/supply/internal/types" + "github.com/cosmos/cosmos-sdk/x/supply/types" ) // RandomizedGenState generates a random GenesisState for supply diff --git a/x/supply/internal/types/account.go b/x/supply/types/account.go similarity index 85% rename from x/supply/internal/types/account.go rename to x/supply/types/account.go index 533084d2b0..14b91bb234 100644 --- a/x/supply/internal/types/account.go +++ b/x/supply/types/account.go @@ -21,21 +21,6 @@ var ( _ exported.ModuleAccountI = (*ModuleAccount)(nil) ) -func init() { - // Register the ModuleAccount type as a GenesisAccount so that when no - // concrete GenesisAccount types exist and **default** genesis state is used, - // the genesis state will serialize correctly. - authtypes.RegisterAccountTypeCodec(&ModuleAccount{}, "cosmos-sdk/ModuleAccount") -} - -// ModuleAccount defines an account for modules that holds coins on a pool -type ModuleAccount struct { - *authtypes.BaseAccount - - Name string `json:"name" yaml:"name"` // name of the module - Permissions []string `json:"permissions" yaml:"permissions"` // permissions of module account -} - // NewModuleAddress creates an AccAddress from the hash of the module's name func NewModuleAddress(name string) sdk.AccAddress { return sdk.AccAddress(crypto.AddressHash([]byte(name))) @@ -51,16 +36,14 @@ func NewEmptyModuleAccount(name string, permissions ...string) *ModuleAccount { } return &ModuleAccount{ - BaseAccount: &baseAcc, + BaseAccount: baseAcc, Name: name, Permissions: permissions, } } // NewModuleAccount creates a new ModuleAccount instance -func NewModuleAccount(ba *authtypes.BaseAccount, - name string, permissions ...string) *ModuleAccount { - +func NewModuleAccount(ba *authtypes.BaseAccount, name string, permissions ...string) *ModuleAccount { if err := validatePermissions(permissions...); err != nil { panic(err) } diff --git a/x/supply/internal/types/account_test.go b/x/supply/types/account_test.go similarity index 99% rename from x/supply/internal/types/account_test.go rename to x/supply/types/account_test.go index a3ee01bf1a..a93fa5c949 100644 --- a/x/supply/internal/types/account_test.go +++ b/x/supply/types/account_test.go @@ -6,15 +6,13 @@ import ( "fmt" "testing" - yaml "gopkg.in/yaml.v2" - + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/secp256k1" + yaml "gopkg.in/yaml.v2" 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" - - "github.com/stretchr/testify/require" ) func TestModuleAccountMarshalYAML(t *testing.T) { diff --git a/x/supply/types/codec.go b/x/supply/types/codec.go new file mode 100644 index 0000000000..f452d4b5a9 --- /dev/null +++ b/x/supply/types/codec.go @@ -0,0 +1,45 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/x/supply/exported" +) + +// Codec defines the interface needed to serialize x/supply state. It must +// be aware of all concrete supply types. +type Codec interface { + codec.Marshaler + + MarshalSupply(supply exported.SupplyI) ([]byte, error) + UnmarshalSupply(bz []byte) (exported.SupplyI, error) + + MarshalSupplyJSON(supply exported.SupplyI) ([]byte, error) + UnmarshalSupplyJSON(bz []byte) (exported.SupplyI, error) +} + +// RegisterCodec registers the necessary x/supply interfaces and concrete types +// on the provided Amino codec. These types are used for Amino JSON serialization. +func RegisterCodec(cdc *codec.Codec) { + cdc.RegisterInterface((*exported.ModuleAccountI)(nil), nil) + cdc.RegisterInterface((*exported.SupplyI)(nil), nil) + cdc.RegisterConcrete(&ModuleAccount{}, "cosmos-sdk/ModuleAccount", nil) + cdc.RegisterConcrete(&Supply{}, "cosmos-sdk/Supply", nil) +} + +var ( + amino = codec.New() + + // ModuleCdc references the global x/supply 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/supply and + // defined at the application level. + ModuleCdc = codec.NewHybridCodec(amino) +) + +func init() { + RegisterCodec(amino) + codec.RegisterCrypto(amino) + amino.Seal() +} diff --git a/x/supply/internal/types/expected_keepers.go b/x/supply/types/expected_keepers.go similarity index 100% rename from x/supply/internal/types/expected_keepers.go rename to x/supply/types/expected_keepers.go diff --git a/x/supply/internal/types/genesis.go b/x/supply/types/genesis.go similarity index 100% rename from x/supply/internal/types/genesis.go rename to x/supply/types/genesis.go diff --git a/x/supply/internal/types/key.go b/x/supply/types/key.go similarity index 100% rename from x/supply/internal/types/key.go rename to x/supply/types/key.go diff --git a/x/supply/internal/types/permissions.go b/x/supply/types/permissions.go similarity index 100% rename from x/supply/internal/types/permissions.go rename to x/supply/types/permissions.go diff --git a/x/supply/internal/types/permissions_test.go b/x/supply/types/permissions_test.go similarity index 100% rename from x/supply/internal/types/permissions_test.go rename to x/supply/types/permissions_test.go diff --git a/x/supply/internal/types/querier.go b/x/supply/types/querier.go similarity index 100% rename from x/supply/internal/types/querier.go rename to x/supply/types/querier.go diff --git a/x/supply/internal/types/supply.go b/x/supply/types/supply.go similarity index 56% rename from x/supply/internal/types/supply.go rename to x/supply/types/supply.go index 92e4a3e5d2..de5a4d751f 100644 --- a/x/supply/internal/types/supply.go +++ b/x/supply/types/supply.go @@ -10,17 +10,21 @@ import ( ) // Implements Delegation interface -var _ exported.SupplyI = Supply{} +var _ exported.SupplyI = (*Supply)(nil) -// Supply represents a struct that passively keeps track of the total supply amounts in the network -type Supply struct { - Total sdk.Coins `json:"total" yaml:"total"` // total supply of tokens registered on the chain +// NewSupply creates a new Supply instance +func NewSupply(total sdk.Coins) *Supply { + return &Supply{total} +} + +// DefaultSupply creates an empty Supply +func DefaultSupply() *Supply { + return NewSupply(sdk.NewCoins()) } // SetTotal sets the total supply. -func (supply Supply) SetTotal(total sdk.Coins) exported.SupplyI { +func (supply *Supply) SetTotal(total sdk.Coins) { supply.Total = total - return supply } // GetTotal returns the supply total. @@ -28,35 +32,20 @@ func (supply Supply) GetTotal() sdk.Coins { return supply.Total } -// NewSupply creates a new Supply instance -func NewSupply(total sdk.Coins) exported.SupplyI { - return Supply{total} -} - -// DefaultSupply creates an empty Supply -func DefaultSupply() exported.SupplyI { - return NewSupply(sdk.NewCoins()) -} - // Inflate adds coins to the total supply -func (supply Supply) Inflate(amount sdk.Coins) exported.SupplyI { +func (supply *Supply) Inflate(amount sdk.Coins) { supply.Total = supply.Total.Add(amount...) - return supply } -// Deflate subtracts coins from the total supply -func (supply Supply) Deflate(amount sdk.Coins) exported.SupplyI { +// Deflate subtracts coins from the total supply. +func (supply *Supply) Deflate(amount sdk.Coins) { supply.Total = supply.Total.Sub(amount) - return supply } // String returns a human readable string representation of a supplier. func (supply Supply) String() string { - b, err := yaml.Marshal(supply) - if err != nil { - panic(err) - } - return string(b) + bz, _ := yaml.Marshal(supply) + return string(bz) } // ValidateBasic validates the Supply coins and returns error if invalid diff --git a/x/supply/internal/types/supply_test.go b/x/supply/types/supply_test.go similarity index 94% rename from x/supply/internal/types/supply_test.go rename to x/supply/types/supply_test.go index e99e1e5aea..4af49d362f 100644 --- a/x/supply/internal/types/supply_test.go +++ b/x/supply/types/supply_test.go @@ -14,7 +14,7 @@ import ( func TestSupplyMarshalYAML(t *testing.T) { supply := DefaultSupply() coins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.OneInt())) - supply = supply.Inflate(coins) + supply.Inflate(coins) bz, err := yaml.Marshal(supply) require.NoError(t, err) diff --git a/x/supply/types/types.pb.go b/x/supply/types/types.pb.go new file mode 100644 index 0000000000..d94ee7669f --- /dev/null +++ b/x/supply/types/types.pb.go @@ -0,0 +1,635 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: x/supply/types/types.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types1 "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/x/auth/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 + +// ModuleAccount defines an account for modules that holds coins on a pool +type ModuleAccount struct { + *types.BaseAccount `protobuf:"bytes,1,opt,name=base_account,json=baseAccount,proto3,embedded=base_account" json:"base_account,omitempty" yaml:"base_account"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Permissions []string `protobuf:"bytes,3,rep,name=permissions,proto3" json:"permissions,omitempty"` +} + +func (m *ModuleAccount) Reset() { *m = ModuleAccount{} } +func (*ModuleAccount) ProtoMessage() {} +func (*ModuleAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_e14b855c341cf347, []int{0} +} +func (m *ModuleAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ModuleAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ModuleAccount.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 *ModuleAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_ModuleAccount.Merge(m, src) +} +func (m *ModuleAccount) XXX_Size() int { + return m.Size() +} +func (m *ModuleAccount) XXX_DiscardUnknown() { + xxx_messageInfo_ModuleAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_ModuleAccount proto.InternalMessageInfo + +// Supply represents a struct that passively keeps track of the total supply +// amounts in the network. +type Supply struct { + Total github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=total,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"total"` +} + +func (m *Supply) Reset() { *m = Supply{} } +func (*Supply) ProtoMessage() {} +func (*Supply) Descriptor() ([]byte, []int) { + return fileDescriptor_e14b855c341cf347, []int{1} +} +func (m *Supply) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Supply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Supply.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 *Supply) XXX_Merge(src proto.Message) { + xxx_messageInfo_Supply.Merge(m, src) +} +func (m *Supply) XXX_Size() int { + return m.Size() +} +func (m *Supply) XXX_DiscardUnknown() { + xxx_messageInfo_Supply.DiscardUnknown(m) +} + +var xxx_messageInfo_Supply proto.InternalMessageInfo + +func init() { + proto.RegisterType((*ModuleAccount)(nil), "cosmos_sdk.x.supply.v1.ModuleAccount") + proto.RegisterType((*Supply)(nil), "cosmos_sdk.x.supply.v1.Supply") +} + +func init() { proto.RegisterFile("x/supply/types/types.proto", fileDescriptor_e14b855c341cf347) } + +var fileDescriptor_e14b855c341cf347 = []byte{ + // 355 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xaa, 0xd0, 0x2f, 0x2e, + 0x2d, 0x28, 0xc8, 0xa9, 0xd4, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, + 0x25, 0xf9, 0x42, 0x62, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, + 0x7a, 0x10, 0x65, 0x7a, 0x65, 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, + 0x45, 0x25, 0x95, 0xfa, 0x60, 0xa5, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0x44, 0xbf, 0x94, + 0x20, 0x86, 0x91, 0x52, 0x12, 0x15, 0xfa, 0x89, 0xa5, 0x25, 0x19, 0x98, 0x96, 0x29, 0x6d, 0x62, + 0xe4, 0xe2, 0xf5, 0xcd, 0x4f, 0x29, 0xcd, 0x49, 0x75, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0x11, + 0x4a, 0xe4, 0xe2, 0x49, 0x4a, 0x2c, 0x4e, 0x8d, 0x4f, 0x84, 0xf0, 0x25, 0x18, 0x15, 0x18, 0x35, + 0xb8, 0x8d, 0x14, 0xf5, 0x50, 0x5c, 0x05, 0x32, 0x4d, 0xaf, 0xcc, 0x50, 0xcf, 0x29, 0xb1, 0x18, + 0xa6, 0xd1, 0x49, 0xfa, 0xc2, 0x3d, 0x79, 0xc6, 0x4f, 0xf7, 0xe4, 0x85, 0x2b, 0x13, 0x73, 0x73, + 0xac, 0x94, 0x90, 0x0d, 0x51, 0x0a, 0xe2, 0x4e, 0x42, 0xa8, 0x14, 0x12, 0xe2, 0x62, 0xc9, 0x4b, + 0xcc, 0x4d, 0x95, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x0c, 0x02, 0xb3, 0x85, 0x14, 0xb8, 0xb8, 0x0b, + 0x52, 0x8b, 0x72, 0x33, 0x8b, 0x8b, 0x33, 0xf3, 0xf3, 0x8a, 0x25, 0x98, 0x15, 0x98, 0x35, 0x38, + 0x83, 0x90, 0x85, 0xac, 0x38, 0x3a, 0x16, 0xc8, 0x33, 0xcc, 0x58, 0x20, 0xcf, 0xa0, 0x54, 0xcc, + 0xc5, 0x16, 0x0c, 0x0e, 0x16, 0xa1, 0x68, 0x2e, 0xd6, 0x92, 0xfc, 0x92, 0xc4, 0x1c, 0x09, 0x46, + 0x05, 0x66, 0x0d, 0x6e, 0x23, 0x61, 0x64, 0x57, 0x96, 0x19, 0xea, 0x39, 0xe7, 0x67, 0xe6, 0x39, + 0x19, 0x9c, 0xb8, 0x27, 0xcf, 0xb0, 0xea, 0xbe, 0xbc, 0x46, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, + 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0x44, 0x19, 0x94, 0xd2, 0x2d, 0x4e, 0xc9, 0x86, 0x06, 0x0a, 0x48, + 0x43, 0x71, 0x10, 0xc4, 0x4c, 0x2b, 0x1e, 0x98, 0x85, 0x2f, 0x16, 0xc8, 0x33, 0x3a, 0xb9, 0x9e, + 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, + 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x36, 0x5e, 0x83, 0x51, 0x63, 0x3a, + 0x89, 0x0d, 0x1c, 0xee, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x83, 0x25, 0xe2, 0x0f, 0x02, + 0x02, 0x00, 0x00, +} + +func (this *Supply) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Supply) + if !ok { + that2, ok := that.(Supply) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Total) != len(that1.Total) { + return false + } + for i := range this.Total { + if !this.Total[i].Equal(&that1.Total[i]) { + return false + } + } + return true +} +func (m *ModuleAccount) 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 *ModuleAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ModuleAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Permissions) > 0 { + for iNdEx := len(m.Permissions) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Permissions[iNdEx]) + copy(dAtA[i:], m.Permissions[iNdEx]) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Permissions[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x12 + } + if m.BaseAccount != nil { + { + size, err := m.BaseAccount.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 (m *Supply) 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 *Supply) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Supply) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Total) > 0 { + for iNdEx := len(m.Total) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Total[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 *ModuleAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BaseAccount != nil { + l = m.BaseAccount.Size() + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.Permissions) > 0 { + for _, s := range m.Permissions { + l = len(s) + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *Supply) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Total) > 0 { + for _, e := range m.Total { + 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 *ModuleAccount) 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: ModuleAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ModuleAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseAccount", 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 m.BaseAccount == nil { + m.BaseAccount = &types.BaseAccount{} + } + if err := m.BaseAccount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Permissions", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Permissions = append(m.Permissions, string(dAtA[iNdEx:postIndex])) + 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 *Supply) 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: Supply: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Supply: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Total", 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.Total = append(m.Total, types1.Coin{}) + if err := m.Total[len(m.Total)-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/supply/types/types.proto b/x/supply/types/types.proto new file mode 100644 index 0000000000..979e1459df --- /dev/null +++ b/x/supply/types/types.proto @@ -0,0 +1,32 @@ +syntax = "proto3"; +package cosmos_sdk.x.supply.v1; + +import "third_party/proto/gogoproto/gogo.proto"; +import "types/types.proto"; +import "x/auth/types/types.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/supply/types"; + +// ModuleAccount defines an account for modules that holds coins on a pool +message ModuleAccount { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + cosmos_sdk.x.auth.v1.BaseAccount base_account = 1 + [(gogoproto.embed) = true, (gogoproto.moretags) = "yaml:\"base_account\""]; + string name = 2; + repeated string permissions = 3; +} + +// Supply represents a struct that passively keeps track of the total supply +// amounts in the network. +message Supply { + option (gogoproto.equal) = true; + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + repeated cosmos_sdk.v1.Coin total = 1 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} diff --git a/x/upgrade/alias.go b/x/upgrade/alias.go index d8089d35d5..c8ae7bf631 100644 --- a/x/upgrade/alias.go +++ b/x/upgrade/alias.go @@ -3,8 +3,8 @@ package upgrade // nolint import ( - "github.com/cosmos/cosmos-sdk/x/upgrade/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/upgrade/internal/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) const ( diff --git a/x/upgrade/client/cli/query.go b/x/upgrade/client/cli/query.go index 0b33a01207..c9022a4824 100644 --- a/x/upgrade/client/cli/query.go +++ b/x/upgrade/client/cli/query.go @@ -3,12 +3,12 @@ package cli import ( "encoding/binary" "fmt" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" - upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/internal/types" ) // GetPlanCmd returns the query upgrade plan command @@ -22,7 +22,7 @@ func GetPlanCmd(storeName string, cdc *codec.Codec) *cobra.Command { cliCtx := context.NewCLIContext().WithCodec(cdc) // ignore height for now - res, _, err := cliCtx.Query(fmt.Sprintf("custom/%s/%s", upgrade.QuerierKey, upgrade.QueryCurrent)) + res, _, err := cliCtx.Query(fmt.Sprintf("custom/%s/%s", types.QuerierKey, types.QueryCurrent)) if err != nil { return err } @@ -31,7 +31,7 @@ func GetPlanCmd(storeName string, cdc *codec.Codec) *cobra.Command { return fmt.Errorf("no upgrade scheduled") } - var plan upgrade.Plan + var plan types.Plan err = cdc.UnmarshalJSON(res, &plan) if err != nil { return err @@ -53,13 +53,13 @@ func GetAppliedHeightCmd(storeName string, cdc *codec.Codec) *cobra.Command { cliCtx := context.NewCLIContext().WithCodec(cdc) name := args[0] - params := upgrade.NewQueryAppliedParams(name) + params := types.NewQueryAppliedParams(name) bz, err := cliCtx.Codec.MarshalJSON(params) if err != nil { return err } - res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", upgrade.QuerierKey, upgrade.QueryApplied), bz) + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierKey, types.QueryApplied), bz) if err != nil { return err } diff --git a/x/upgrade/client/cli/tx.go b/x/upgrade/client/cli/tx.go index a06347bc1d..6e325aa9c0 100644 --- a/x/upgrade/client/cli/tx.go +++ b/x/upgrade/client/cli/tx.go @@ -15,7 +15,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/gov" - upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/internal/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) const ( @@ -65,8 +65,8 @@ func parseArgsToContent(cmd *cobra.Command, name string) (gov.Content, error) { return nil, err } - plan := upgrade.Plan{Name: name, Time: upgradeTime, Height: height, Info: info} - content := upgrade.NewSoftwareUpgradeProposal(title, description, plan) + plan := types.Plan{Name: name, Time: upgradeTime, Height: height, Info: info} + content := types.NewSoftwareUpgradeProposal(title, description, plan) return content, nil } @@ -151,7 +151,7 @@ func GetCmdSubmitCancelUpgradeProposal(cdc *codec.Codec) *cobra.Command { return err } - content := upgrade.NewCancelSoftwareUpgradeProposal(title, description) + content := types.NewCancelSoftwareUpgradeProposal(title, description) msg := gov.NewMsgSubmitProposal(content, deposit, from) if err := msg.ValidateBasic(); err != nil { diff --git a/x/upgrade/client/rest/query.go b/x/upgrade/client/rest/query.go index bf9bdd3410..8c3372b2a7 100644 --- a/x/upgrade/client/rest/query.go +++ b/x/upgrade/client/rest/query.go @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/types/rest" - upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/internal/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) // RegisterRoutes registers REST routes for the upgrade module under the path specified by routeName. @@ -22,7 +22,7 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) { func getCurrentPlanHandler(cliCtx context.CLIContext) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, request *http.Request) { // ignore height for now - res, _, err := cliCtx.Query(fmt.Sprintf("custom/%s/%s", upgrade.QuerierKey, upgrade.QueryCurrent)) + res, _, err := cliCtx.Query(fmt.Sprintf("custom/%s/%s", types.QuerierKey, types.QueryCurrent)) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -32,7 +32,7 @@ func getCurrentPlanHandler(cliCtx context.CLIContext) func(http.ResponseWriter, return } - var plan upgrade.Plan + var plan types.Plan err = cliCtx.Codec.UnmarshalBinaryBare(res, &plan) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) @@ -47,14 +47,14 @@ func getDonePlanHandler(cliCtx context.CLIContext) func(http.ResponseWriter, *ht return func(w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] - params := upgrade.NewQueryAppliedParams(name) + params := types.NewQueryAppliedParams(name) bz, err := cliCtx.Codec.MarshalJSON(params) if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return } - res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", upgrade.QuerierKey, upgrade.QueryApplied), bz) + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierKey, types.QueryApplied), bz) if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return diff --git a/x/upgrade/client/rest/tx.go b/x/upgrade/client/rest/tx.go index 9354d9dd05..e67aa79bfc 100644 --- a/x/upgrade/client/rest/tx.go +++ b/x/upgrade/client/rest/tx.go @@ -13,7 +13,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" "github.com/cosmos/cosmos-sdk/x/gov" - "github.com/cosmos/cosmos-sdk/x/upgrade/internal/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) { diff --git a/x/upgrade/internal/keeper/keeper.go b/x/upgrade/keeper/keeper.go similarity index 96% rename from x/upgrade/internal/keeper/keeper.go rename to x/upgrade/keeper/keeper.go index 7a33d7e4b6..03802b335c 100644 --- a/x/upgrade/internal/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -3,6 +3,7 @@ package keeper import ( "encoding/binary" "fmt" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/tendermint/tendermint/libs/log" @@ -10,18 +11,17 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/upgrade/internal/types" ) type Keeper struct { skipUpgradeHeights map[int64]bool storeKey sdk.StoreKey - cdc *codec.Codec + cdc codec.Marshaler upgradeHandlers map[string]types.UpgradeHandler } // NewKeeper constructs an upgrade Keeper -func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc *codec.Codec) Keeper { +func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.Marshaler) Keeper { return Keeper{ skipUpgradeHeights: skipUpgradeHeights, storeKey: storeKey, @@ -57,7 +57,7 @@ func (k Keeper) ScheduleUpgrade(ctx sdk.Context, plan types.Plan) error { return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "upgrade with name %s has already been completed", plan.Name) } - bz := k.cdc.MustMarshalBinaryBare(plan) + bz := k.cdc.MustMarshalBinaryBare(&plan) store := ctx.KVStore(k.storeKey) store.Set(types.PlanKey(), bz) diff --git a/x/upgrade/internal/keeper/querier.go b/x/upgrade/keeper/querier.go similarity index 96% rename from x/upgrade/internal/keeper/querier.go rename to x/upgrade/keeper/querier.go index 7bddfad345..2a3ff8bf6d 100644 --- a/x/upgrade/internal/keeper/querier.go +++ b/x/upgrade/keeper/querier.go @@ -2,12 +2,12 @@ package keeper import ( "encoding/binary" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" abci "github.com/tendermint/tendermint/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/upgrade/internal/types" ) // NewQuerier creates a querier for upgrade cli and REST endpoints diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 5605ca0b67..f5a9b461ef 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -103,23 +103,23 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { } // InitGenesis is ignored, no sense in serializing future upgrades -func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONMarshaler, _ json.RawMessage) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} } // DefaultGenesis is an empty object -func (AppModuleBasic) DefaultGenesis() json.RawMessage { +func (AppModuleBasic) DefaultGenesis(_ codec.JSONMarshaler) json.RawMessage { return []byte("{}") } // ValidateGenesis is always successful, as we ignore the value -func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(_ codec.JSONMarshaler, _ json.RawMessage) error { return nil } // ExportGenesis is always empty, as InitGenesis does nothing either -func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { - return am.DefaultGenesis() +func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { + return am.DefaultGenesis(cdc) } // BeginBlock calls the upgrade module hooks diff --git a/x/upgrade/internal/types/codec.go b/x/upgrade/types/codec.go similarity index 100% rename from x/upgrade/internal/types/codec.go rename to x/upgrade/types/codec.go diff --git a/x/upgrade/internal/types/handler.go b/x/upgrade/types/handler.go similarity index 100% rename from x/upgrade/internal/types/handler.go rename to x/upgrade/types/handler.go diff --git a/x/upgrade/internal/types/keys.go b/x/upgrade/types/keys.go similarity index 100% rename from x/upgrade/internal/types/keys.go rename to x/upgrade/types/keys.go diff --git a/x/upgrade/internal/types/plan.go b/x/upgrade/types/plan.go similarity index 56% rename from x/upgrade/internal/types/plan.go rename to x/upgrade/types/plan.go index c2b88171e2..4f31063bc7 100644 --- a/x/upgrade/internal/types/plan.go +++ b/x/upgrade/types/plan.go @@ -9,28 +9,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// Plan specifies information about a planned upgrade and when it should occur -type Plan struct { - // Sets the name for the upgrade. This name will be used by the upgraded version of the software to apply any - // special "on-upgrade" commands during the first BeginBlock method after the upgrade is applied. It is also used - // to detect whether a software version can handle a given upgrade. If no upgrade handler with this name has been - // set in the software, it will be assumed that the software is out-of-date when the upgrade Time or Height - // is reached and the software will exit. - Name string `json:"name,omitempty"` - - // The time after which the upgrade must be performed. - // Leave set to its zero value to use a pre-defined Height instead. - Time time.Time `json:"time,omitempty"` - - // The height at which the upgrade must be performed. - // Only used if Time is not set. - Height int64 `json:"height,omitempty"` - - // Any application specific upgrade info to be included on-chain - // such as a git commit that validators could automatically upgrade to - Info string `json:"info,omitempty"` -} - func (p Plan) String() string { due := p.DueAt() dueUp := strings.ToUpper(due[0:1]) + due[1:] diff --git a/x/upgrade/internal/types/plan_test.go b/x/upgrade/types/plan_test.go similarity index 100% rename from x/upgrade/internal/types/plan_test.go rename to x/upgrade/types/plan_test.go diff --git a/x/upgrade/internal/types/proposal.go b/x/upgrade/types/proposal.go similarity index 84% rename from x/upgrade/internal/types/proposal.go rename to x/upgrade/types/proposal.go index 958c106746..2067110e74 100644 --- a/x/upgrade/internal/types/proposal.go +++ b/x/upgrade/types/proposal.go @@ -11,13 +11,6 @@ const ( ProposalTypeCancelSoftwareUpgrade string = "CancelSoftwareUpgrade" ) -// Software Upgrade Proposals -type SoftwareUpgradeProposal struct { - Title string `json:"title" yaml:"title"` - Description string `json:"description" yaml:"description"` - Plan Plan `json:"plan" yaml:"plan"` -} - func NewSoftwareUpgradeProposal(title, description string, plan Plan) gov.Content { return SoftwareUpgradeProposal{title, description, plan} } @@ -51,12 +44,6 @@ func (sup SoftwareUpgradeProposal) String() string { `, sup.Title, sup.Description) } -// Cancel Software Upgrade Proposals -type CancelSoftwareUpgradeProposal struct { - Title string `json:"title" yaml:"title"` - Description string `json:"description" yaml:"description"` -} - func NewCancelSoftwareUpgradeProposal(title, description string) gov.Content { return CancelSoftwareUpgradeProposal{title, description} } diff --git a/x/upgrade/internal/types/proposal_test.go b/x/upgrade/types/proposal_test.go similarity index 100% rename from x/upgrade/internal/types/proposal_test.go rename to x/upgrade/types/proposal_test.go diff --git a/x/upgrade/internal/types/querier.go b/x/upgrade/types/querier.go similarity index 100% rename from x/upgrade/internal/types/querier.go rename to x/upgrade/types/querier.go diff --git a/x/upgrade/types/types.pb.go b/x/upgrade/types/types.pb.go new file mode 100644 index 0000000000..4e8f7cbb98 --- /dev/null +++ b/x/upgrade/types/types.pb.go @@ -0,0 +1,922 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: x/upgrade/internal/types/types.proto + +package types + +import ( + fmt "fmt" + _ "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 + +// Plan specifies information about a planned upgrade and when it should occur +type Plan struct { + // Sets the name for the upgrade. This name will be used by the upgraded version of the software to apply any + // special "on-upgrade" commands during the first BeginBlock method after the upgrade is applied. It is also used + // to detect whether a software version can handle a given upgrade. If no upgrade handler with this name has been + // set in the software, it will be assumed that the software is out-of-date when the upgrade Time or Height + // is reached and the software will exit. + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // The time after which the upgrade must be performed. + // Leave set to its zero value to use a pre-defined Height instead. + Time time.Time `protobuf:"bytes,2,opt,name=time,proto3,stdtime" json:"time"` + // The height at which the upgrade must be performed. + // Only used if Time is not set. + Height int64 `protobuf:"varint,3,opt,name=height,proto3" json:"height,omitempty"` + // Any application specific upgrade info to be included on-chain + // such as a git commit that validators could automatically upgrade to + Info string `protobuf:"bytes,4,opt,name=info,proto3" json:"info,omitempty"` +} + +func (m *Plan) Reset() { *m = Plan{} } +func (*Plan) ProtoMessage() {} +func (*Plan) Descriptor() ([]byte, []int) { + return fileDescriptor_6199ecc2c05edfcb, []int{0} +} +func (m *Plan) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Plan) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Plan.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 *Plan) XXX_Merge(src proto.Message) { + xxx_messageInfo_Plan.Merge(m, src) +} +func (m *Plan) XXX_Size() int { + return m.Size() +} +func (m *Plan) XXX_DiscardUnknown() { + xxx_messageInfo_Plan.DiscardUnknown(m) +} + +var xxx_messageInfo_Plan proto.InternalMessageInfo + +type SoftwareUpgradeProposal struct { + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + Plan Plan `protobuf:"bytes,3,opt,name=plan,proto3" json:"plan"` +} + +func (m *SoftwareUpgradeProposal) Reset() { *m = SoftwareUpgradeProposal{} } +func (*SoftwareUpgradeProposal) ProtoMessage() {} +func (*SoftwareUpgradeProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_6199ecc2c05edfcb, []int{1} +} +func (m *SoftwareUpgradeProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SoftwareUpgradeProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SoftwareUpgradeProposal.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 *SoftwareUpgradeProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_SoftwareUpgradeProposal.Merge(m, src) +} +func (m *SoftwareUpgradeProposal) XXX_Size() int { + return m.Size() +} +func (m *SoftwareUpgradeProposal) XXX_DiscardUnknown() { + xxx_messageInfo_SoftwareUpgradeProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_SoftwareUpgradeProposal proto.InternalMessageInfo + +type CancelSoftwareUpgradeProposal struct { + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` +} + +func (m *CancelSoftwareUpgradeProposal) Reset() { *m = CancelSoftwareUpgradeProposal{} } +func (*CancelSoftwareUpgradeProposal) ProtoMessage() {} +func (*CancelSoftwareUpgradeProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_6199ecc2c05edfcb, []int{2} +} +func (m *CancelSoftwareUpgradeProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CancelSoftwareUpgradeProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CancelSoftwareUpgradeProposal.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 *CancelSoftwareUpgradeProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_CancelSoftwareUpgradeProposal.Merge(m, src) +} +func (m *CancelSoftwareUpgradeProposal) XXX_Size() int { + return m.Size() +} +func (m *CancelSoftwareUpgradeProposal) XXX_DiscardUnknown() { + xxx_messageInfo_CancelSoftwareUpgradeProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_CancelSoftwareUpgradeProposal proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Plan)(nil), "cosmos_sdk.x.upgrade.v1.Plan") + proto.RegisterType((*SoftwareUpgradeProposal)(nil), "cosmos_sdk.x.upgrade.v1.SoftwareUpgradeProposal") + proto.RegisterType((*CancelSoftwareUpgradeProposal)(nil), "cosmos_sdk.x.upgrade.v1.CancelSoftwareUpgradeProposal") +} + +func init() { + proto.RegisterFile("x/upgrade/internal/types/types.proto", fileDescriptor_6199ecc2c05edfcb) +} + +var fileDescriptor_6199ecc2c05edfcb = []byte{ + // 371 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x52, 0x3f, 0x0f, 0x12, 0x31, + 0x14, 0xbf, 0xca, 0x49, 0xa4, 0x6c, 0x8d, 0x91, 0x0b, 0x09, 0xe5, 0x42, 0x8c, 0x21, 0x31, 0xb6, + 0x11, 0x07, 0x9d, 0x71, 0x36, 0x21, 0xa7, 0xc6, 0xc4, 0x85, 0x94, 0xbb, 0x72, 0xd7, 0x70, 0xd7, + 0x36, 0x6d, 0x51, 0xd8, 0x9c, 0x9d, 0xf8, 0x58, 0x8c, 0x8c, 0x4c, 0x2a, 0xf0, 0x45, 0xcc, 0x5d, + 0x8f, 0xe8, 0xe2, 0xe6, 0xd2, 0xbe, 0xd7, 0xfc, 0xfe, 0xbd, 0xb6, 0xf0, 0xe9, 0x8e, 0x6e, 0x75, + 0x6e, 0x58, 0xc6, 0xa9, 0x90, 0x8e, 0x1b, 0xc9, 0x4a, 0xea, 0xf6, 0x9a, 0x5b, 0xbf, 0x12, 0x6d, + 0x94, 0x53, 0x68, 0x90, 0x2a, 0x5b, 0x29, 0xbb, 0xb4, 0xd9, 0x86, 0xec, 0x48, 0x4b, 0x20, 0x5f, + 0x5e, 0x0e, 0x9f, 0xb9, 0x42, 0x98, 0x6c, 0xa9, 0x99, 0x71, 0x7b, 0xda, 0x60, 0x69, 0xae, 0x72, + 0xf5, 0xa7, 0xf2, 0x02, 0xc3, 0x71, 0xae, 0x54, 0x5e, 0x72, 0x0f, 0x59, 0x6d, 0xd7, 0xd4, 0x89, + 0x8a, 0x5b, 0xc7, 0x2a, 0xed, 0x01, 0x93, 0x6f, 0x00, 0x86, 0x8b, 0x92, 0x49, 0x84, 0x60, 0x28, + 0x59, 0xc5, 0x23, 0x10, 0x83, 0x69, 0x2f, 0x69, 0x6a, 0xf4, 0x06, 0x86, 0x35, 0x3e, 0x7a, 0x10, + 0x83, 0x69, 0x7f, 0x36, 0x24, 0x5e, 0x8c, 0xdc, 0xc5, 0xc8, 0x87, 0xbb, 0xd8, 0xfc, 0xd1, 0xf1, + 0xc7, 0x38, 0x38, 0xfc, 0x1c, 0x83, 0xa4, 0x61, 0xa0, 0x27, 0xb0, 0x5b, 0x70, 0x91, 0x17, 0x2e, + 0xea, 0xc4, 0x60, 0xda, 0x49, 0xda, 0xae, 0x76, 0x11, 0x72, 0xad, 0xa2, 0xd0, 0xbb, 0xd4, 0xf5, + 0xe4, 0x3b, 0x80, 0x83, 0xf7, 0x6a, 0xed, 0xbe, 0x32, 0xc3, 0x3f, 0xfa, 0x11, 0x17, 0x46, 0x69, + 0x65, 0x59, 0x89, 0x1e, 0xc3, 0x87, 0x4e, 0xb8, 0xf2, 0x1e, 0xcb, 0x37, 0x28, 0x86, 0xfd, 0x8c, + 0xdb, 0xd4, 0x08, 0xed, 0x84, 0x92, 0x4d, 0xbc, 0x5e, 0xf2, 0xf7, 0x11, 0x7a, 0x0d, 0x43, 0x5d, + 0x32, 0xd9, 0xb8, 0xf7, 0x67, 0x23, 0xf2, 0x8f, 0x7b, 0x24, 0xf5, 0xe8, 0xf3, 0xb0, 0x0e, 0x9f, + 0x34, 0x84, 0xc9, 0x27, 0x38, 0x7a, 0xcb, 0x64, 0xca, 0xcb, 0xff, 0x9c, 0x68, 0xfe, 0xee, 0x78, + 0xc1, 0xc1, 0xf9, 0x82, 0x83, 0xe3, 0x15, 0x83, 0xd3, 0x15, 0x83, 0x5f, 0x57, 0x0c, 0x0e, 0x37, + 0x1c, 0x9c, 0x6e, 0x38, 0x38, 0xdf, 0x70, 0xf0, 0xf9, 0x79, 0x2e, 0x5c, 0xb1, 0x5d, 0x91, 0x54, + 0x55, 0xd4, 0xe7, 0x6d, 0xb7, 0x17, 0x36, 0xdb, 0xd0, 0x1d, 0xd5, 0xcc, 0xb0, 0xaa, 0xfd, 0x1f, + 0xab, 0x6e, 0xf3, 0x08, 0xaf, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0xad, 0x67, 0xed, 0x35, 0x48, + 0x02, 0x00, 0x00, +} + +func (m *Plan) 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 *Plan) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Plan) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Info) > 0 { + i -= len(m.Info) + copy(dAtA[i:], m.Info) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Info))) + i-- + dAtA[i] = 0x22 + } + if m.Height != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x18 + } + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Time, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.Time):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintTypes(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x12 + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SoftwareUpgradeProposal) 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 *SoftwareUpgradeProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SoftwareUpgradeProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Plan.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *CancelSoftwareUpgradeProposal) 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 *CancelSoftwareUpgradeProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CancelSoftwareUpgradeProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Title))) + 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 *Plan) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.Time) + n += 1 + l + sovTypes(uint64(l)) + if m.Height != 0 { + n += 1 + sovTypes(uint64(m.Height)) + } + l = len(m.Info) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *SoftwareUpgradeProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = m.Plan.Size() + n += 1 + l + sovTypes(uint64(l)) + return n +} + +func (m *CancelSoftwareUpgradeProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Description) + if l > 0 { + 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 *Plan) 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: Plan: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Plan: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Time", 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.Time, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Info", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Info = string(dAtA[iNdEx:postIndex]) + 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 *SoftwareUpgradeProposal) 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: SoftwareUpgradeProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SoftwareUpgradeProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Plan", 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 := m.Plan.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 *CancelSoftwareUpgradeProposal) 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: CancelSoftwareUpgradeProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CancelSoftwareUpgradeProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + 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/upgrade/types/types.proto b/x/upgrade/types/types.proto new file mode 100644 index 0000000000..8770158c4b --- /dev/null +++ b/x/upgrade/types/types.proto @@ -0,0 +1,44 @@ +syntax = "proto3"; +package cosmos_sdk.x.upgrade.v1; + +import "third_party/proto/gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/upgrade/types"; +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_getters_all) = false; + +// Plan specifies information about a planned upgrade and when it should occur +message Plan { + // Sets the name for the upgrade. This name will be used by the upgraded version of the software to apply any + // special "on-upgrade" commands during the first BeginBlock method after the upgrade is applied. It is also used + // to detect whether a software version can handle a given upgrade. If no upgrade handler with this name has been + // set in the software, it will be assumed that the software is out-of-date when the upgrade Time or Height + // is reached and the software will exit. + string name = 1; + + // The time after which the upgrade must be performed. + // Leave set to its zero value to use a pre-defined Height instead. + google.protobuf.Timestamp time = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + + // The height at which the upgrade must be performed. + // Only used if Time is not set. + int64 height = 3; + + // Any application specific upgrade info to be included on-chain + // such as a git commit that validators could automatically upgrade to + string info = 4; +} + +// SoftwareUpgradeProposal is a gov Content type for initiating a software upgrade +message SoftwareUpgradeProposal { + string title = 1; + string description = 2; + Plan plan = 3 [(gogoproto.nullable) = false]; +} + +// SoftwareUpgradeProposal is a gov Content type for cancelling a software upgrade +message CancelSoftwareUpgradeProposal { + string title = 1; + string description = 2; +}