From b7f787573b8a9810afd849a423d4427749fb1cdc Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 12 May 2021 14:43:56 -0400 Subject: [PATCH 01/19] add x/authn proto files --- proto/cosmos/authn/v1/authn.proto | 21 +++++++++++++++++++++ proto/cosmos/authn/v1/genesis.proto | 12 ++++++++++++ proto/cosmos/authn/v1/query.proto | 27 +++++++++++++++++++++++++++ proto/cosmos/authn/v1/tx.proto | 17 +++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 proto/cosmos/authn/v1/authn.proto create mode 100644 proto/cosmos/authn/v1/genesis.proto create mode 100644 proto/cosmos/authn/v1/query.proto create mode 100644 proto/cosmos/authn/v1/tx.proto diff --git a/proto/cosmos/authn/v1/authn.proto b/proto/cosmos/authn/v1/authn.proto new file mode 100644 index 000000000000..5232410f797c --- /dev/null +++ b/proto/cosmos/authn/v1/authn.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; +package cosmos.authn.v1; + +import "google/protobuf/any.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/authn"; + +message Params { + uint64 max_memo_characters = 1; + uint64 tx_sig_limit = 2; + uint64 tx_size_cost_per_byte = 3; + uint64 sig_verify_cost_ed25519 = 4; + uint64 sig_verify_cost_secp256k1 = 5; +} + +message Account { + string address = 1; + google.protobuf.Any credential = 2; + uint64 account_number = 3; + uint64 sequence = 4; +} diff --git a/proto/cosmos/authn/v1/genesis.proto b/proto/cosmos/authn/v1/genesis.proto new file mode 100644 index 000000000000..d8ccb267bec3 --- /dev/null +++ b/proto/cosmos/authn/v1/genesis.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package cosmos.authn.v1; + +import "cosmos/authn/v1/authn.proto"; + +message GenesisState { + // params defines all the parameters of the module. + Params params = 1; + + // accounts are the accounts present at genesis. + repeated Account accounts = 2; +} diff --git a/proto/cosmos/authn/v1/query.proto b/proto/cosmos/authn/v1/query.proto new file mode 100644 index 000000000000..f61105cc8aba --- /dev/null +++ b/proto/cosmos/authn/v1/query.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; +package cosmos.authn.v1; + +import "google/protobuf/any.proto"; +import "cosmos/authn/v1/authn.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/authn"; + +service Query { + rpc Config (QueryConfigRequest) returns (QueryConfigResponse) {} + + rpc Account (QueryAccountRequest) returns (QueryAccountResponse) {} +} + +message QueryConfigRequest {} + +message QueryConfigResponse { + string bech32_address_prefix = 1; +} + +message QueryAccountRequest { + string address = 1; +} + +message QueryAccountResponse { + Account account = 1; +} \ No newline at end of file diff --git a/proto/cosmos/authn/v1/tx.proto b/proto/cosmos/authn/v1/tx.proto new file mode 100644 index 000000000000..bdcda36ce2c8 --- /dev/null +++ b/proto/cosmos/authn/v1/tx.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; +package cosmos.authn.v1; + +import "google/protobuf/any.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/authn"; + +service Msg { + rpc SetCredential (MsgSetCredentialRequest) returns (MsgSetCredentialResponse) {} +} + +message MsgSetCredentialRequest { + string address = 1; + google.protobuf.Any credential = 2; +} + +message MsgSetCredentialResponse {} \ No newline at end of file From ba6e1c82c797b52b621ed301938566ee887de44f Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 12 May 2021 15:16:40 -0400 Subject: [PATCH 02/19] update APIs --- proto/cosmos/authn/v1/authn.proto | 1 + proto/cosmos/authn/v1/query.proto | 47 +++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/proto/cosmos/authn/v1/authn.proto b/proto/cosmos/authn/v1/authn.proto index 5232410f797c..a0918d1d5cd5 100644 --- a/proto/cosmos/authn/v1/authn.proto +++ b/proto/cosmos/authn/v1/authn.proto @@ -11,6 +11,7 @@ message Params { uint64 tx_size_cost_per_byte = 3; uint64 sig_verify_cost_ed25519 = 4; uint64 sig_verify_cost_secp256k1 = 5; + string bech32_address_prefix = 6; } message Account { diff --git a/proto/cosmos/authn/v1/query.proto b/proto/cosmos/authn/v1/query.proto index f61105cc8aba..ec7ece39fbf1 100644 --- a/proto/cosmos/authn/v1/query.proto +++ b/proto/cosmos/authn/v1/query.proto @@ -2,20 +2,27 @@ syntax = "proto3"; package cosmos.authn.v1; import "google/protobuf/any.proto"; +import "google/api/annotations.proto"; import "cosmos/authn/v1/authn.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; option go_package = "github.com/cosmos/cosmos-sdk/x/authn"; service Query { - rpc Config (QueryConfigRequest) returns (QueryConfigResponse) {} - - rpc Account (QueryAccountRequest) returns (QueryAccountResponse) {} -} - -message QueryConfigRequest {} - -message QueryConfigResponse { - string bech32_address_prefix = 1; + // Account returns account details based on address. + rpc Account(QueryAccountRequest) returns (QueryAccountResponse) { + option (google.api.http).get = "/cosmos/auth/v1beta1/accounts/{address}"; + } + + // Accounts returns all the existing accounts + rpc Accounts(QueryAccountsRequest) returns (QueryAccountsResponse) { + option (google.api.http).get = "/cosmos/auth/v1beta1/accounts"; + } + + // Params queries all parameters. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/cosmos/auth/v1beta1/params"; + } } message QueryAccountRequest { @@ -24,4 +31,26 @@ message QueryAccountRequest { message QueryAccountResponse { Account account = 1; +} +message QueryAccountsRequest { + // pagination defines an optional pagination for the request. + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +// QueryAccountsResponse is the response type for the Query/Accounts RPC method. +message QueryAccountsResponse { + // accounts are the existing accounts + repeated Account accounts = 1; + + // pagination defines the pagination in the response. + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +// QueryParamsRequest is the request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is the response type for the Query/Params RPC method. +message QueryParamsResponse { + // params defines the parameters of the module. + Params params = 1; } \ No newline at end of file From 4e0346b6c86377c80b7c479620b5688e9d42a847 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 26 May 2021 20:19:10 -0400 Subject: [PATCH 03/19] PoC app_config json --- .../authn/v1/{authn.proto => account.proto} | 9 --- proto/cosmos/authn/v1/genesis.proto | 7 +- proto/cosmos/authn/v1/middleware.proto | 31 ++++++++ proto/cosmos/authn/v1/module.proto | 8 ++ proto/cosmos/authn/v1/query.proto | 2 +- proto/cosmos/bank/v1beta1/middleware.proto | 7 ++ proto/cosmos/bank/v1beta1/module.proto | 8 ++ simapp/genesis.json | 75 +++++++++++++++++++ 8 files changed, 132 insertions(+), 15 deletions(-) rename proto/cosmos/authn/v1/{authn.proto => account.proto} (52%) create mode 100644 proto/cosmos/authn/v1/middleware.proto create mode 100644 proto/cosmos/authn/v1/module.proto create mode 100644 proto/cosmos/bank/v1beta1/middleware.proto create mode 100644 proto/cosmos/bank/v1beta1/module.proto create mode 100644 simapp/genesis.json diff --git a/proto/cosmos/authn/v1/authn.proto b/proto/cosmos/authn/v1/account.proto similarity index 52% rename from proto/cosmos/authn/v1/authn.proto rename to proto/cosmos/authn/v1/account.proto index a0918d1d5cd5..b525067a8ab7 100644 --- a/proto/cosmos/authn/v1/authn.proto +++ b/proto/cosmos/authn/v1/account.proto @@ -5,15 +5,6 @@ import "google/protobuf/any.proto"; option go_package = "github.com/cosmos/cosmos-sdk/x/authn"; -message Params { - uint64 max_memo_characters = 1; - uint64 tx_sig_limit = 2; - uint64 tx_size_cost_per_byte = 3; - uint64 sig_verify_cost_ed25519 = 4; - uint64 sig_verify_cost_secp256k1 = 5; - string bech32_address_prefix = 6; -} - message Account { string address = 1; google.protobuf.Any credential = 2; diff --git a/proto/cosmos/authn/v1/genesis.proto b/proto/cosmos/authn/v1/genesis.proto index d8ccb267bec3..c2a839b2b6a1 100644 --- a/proto/cosmos/authn/v1/genesis.proto +++ b/proto/cosmos/authn/v1/genesis.proto @@ -1,12 +1,9 @@ syntax = "proto3"; package cosmos.authn.v1; -import "cosmos/authn/v1/authn.proto"; +import "cosmos/authn/v1/account.proto"; message GenesisState { - // params defines all the parameters of the module. - Params params = 1; - // accounts are the accounts present at genesis. - repeated Account accounts = 2; + repeated Account accounts = 1; } diff --git a/proto/cosmos/authn/v1/middleware.proto b/proto/cosmos/authn/v1/middleware.proto new file mode 100644 index 000000000000..d5bd34a0c762 --- /dev/null +++ b/proto/cosmos/authn/v1/middleware.proto @@ -0,0 +1,31 @@ +syntax = "proto3"; +package cosmos.authn.v1; + +option go_package = "github.com/cosmos/cosmos-sdk/x/authn"; + +message ValidateMemoMiddleware { + uint64 max_memo_characters = 1; +} + +message ConsumeGasForTxSizeMiddleware { + uint64 tx_size_cost_per_byte = 1; +} + +message SetPubKeyMiddleware { +} + +message ValidateSigCountMiddleware { + uint64 tx_sig_limit = 1; +} + +message SigGasConsumeMiddleware { + uint64 sig_verify_cost_ed25519 = 1; + uint64 sig_verify_cost_secp256k1 = 2; + repeated string allowed_pub_key_types = 3; +} + +message SigVerificationMiddleware { +} + +message IncrementSequenceMiddleware { +} \ No newline at end of file diff --git a/proto/cosmos/authn/v1/module.proto b/proto/cosmos/authn/v1/module.proto new file mode 100644 index 000000000000..0e1b637e3417 --- /dev/null +++ b/proto/cosmos/authn/v1/module.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; +package cosmos.authn.v1; + +option go_package = "github.com/cosmos/cosmos-sdk/x/authn"; + +message Module { + string bech32_address_prefix = 6; +} diff --git a/proto/cosmos/authn/v1/query.proto b/proto/cosmos/authn/v1/query.proto index ec7ece39fbf1..e59c98c227d0 100644 --- a/proto/cosmos/authn/v1/query.proto +++ b/proto/cosmos/authn/v1/query.proto @@ -3,7 +3,7 @@ package cosmos.authn.v1; import "google/protobuf/any.proto"; import "google/api/annotations.proto"; -import "cosmos/authn/v1/authn.proto"; +import "cosmos/authn/v1/account.proto"; import "cosmos/base/query/v1beta1/pagination.proto"; option go_package = "github.com/cosmos/cosmos-sdk/x/authn"; diff --git a/proto/cosmos/bank/v1beta1/middleware.proto b/proto/cosmos/bank/v1beta1/middleware.proto new file mode 100644 index 000000000000..90c527a2953f --- /dev/null +++ b/proto/cosmos/bank/v1beta1/middleware.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; +package cosmos.bank.v1beta1; + +option go_package = "github.com/cosmos/cosmos-sdk/x/bank/types"; + +message DeductFeeMiddleware { +} diff --git a/proto/cosmos/bank/v1beta1/module.proto b/proto/cosmos/bank/v1beta1/module.proto new file mode 100644 index 000000000000..38ad1ee54b4b --- /dev/null +++ b/proto/cosmos/bank/v1beta1/module.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; +package cosmos.bank.v1beta1; + +option go_package = "github.com/cosmos/cosmos-sdk/x/bank/types"; + +message Module { + repeated string send_deny_list = 1; +} diff --git a/simapp/genesis.json b/simapp/genesis.json new file mode 100644 index 000000000000..bb9a1c1d939d --- /dev/null +++ b/simapp/genesis.json @@ -0,0 +1,75 @@ +{ + "genesis_time": "", + "chain_id": "test123", + "consensus_params": { + "block": { + "max_bytes": "22020096", + "max_gas": "-1", + "time_iota_ms": "1000" + }, + "evidence": { + "max_age_num_blocks": "100000", + "max_age_duration": "172800000000000", + "max_num": 50, + "proof_trial_period": "50000" + }, + "validator": { + "pub_key_types": [ + "ed25519" + ] + } + }, + "app_hash": "", + "app_state": { + "app_config": { + "modules": { + "authn": { + "@type": "cosmos.authn.v1.Module", + "bech32_address_prefix": "sim" + }, + "bank": { + "@type": "cosmos.bank.v1beta1.Module", + "send_deny_list": [] + } + }, + "tx_middleware": [ + { + "@type": "cosmos.authn.v1.ValidateMemoMiddleware", + "max_memo_characters": 256 + }, + { + "@type": "cosmos.authn.v1.ConsumeGasForTxSizeMiddleware", + "tx_size_cost_per_byte": 100 + }, + { + "@type": "cosmos.bank.v1beta1.DeductFeeMiddleware" + }, + { + "@type": "cosmos.authn.v1.SetPubKeyMiddleware" + }, + { + "@type": "cosmos.authn.v1.ValidateSigCountMiddleware", + "tx_sig_limit": 7 + }, + { + "@type": "cosmos.authn.v1.SigGasConsumeMiddleware", + "sig_verify_cost_ed25519": 1000, + "sig_verify_cost_secp256k1": 500, + "allowed_pub_key_types": [ + "cosmos.crypto.secp256k1.PubKey", + "cosmos.crypto.secp256r1.PubKey" + ] + }, + { + "@type": "cosmos.authn.v1.SigVerificationMiddleware" + }, + { + "@type": "cosmos.authn.v1.IncrementSequenceMiddleware" + } + ], + "init_genesis": [ "authn", "bank"], + "begin_block": ["authn", "bank"], + "end_block": ["bank", "authn"] + } + } +} \ No newline at end of file From b41541bc0fe22bb531ec91ae545a5288de7278b6 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 26 May 2021 20:57:20 -0400 Subject: [PATCH 04/19] WIP --- core/module/app/key.go | 33 ++++ core/module/app/middleware.go | 16 ++ core/module/app/module.go | 44 +++++ core/module/module.go | 27 +++ proto/cosmos/authn/v1/genesis.proto | 2 + proto/cosmos/authn/v1/query.proto | 14 -- .../core/app_config/v1/app_config.proto | 14 ++ simapp/genesis.json | 75 -------- simapp2/app.go | 9 + simapp2/app_config.json | 59 ++++++ types/tx/service.pb.gw.go | 169 ------------------ x/authn/module/module.go | 25 +++ x/bank/module/module.go | 37 ++++ 13 files changed, 266 insertions(+), 258 deletions(-) create mode 100644 core/module/app/key.go create mode 100644 core/module/app/middleware.go create mode 100644 core/module/app/module.go create mode 100644 core/module/module.go create mode 100644 proto/cosmos/core/app_config/v1/app_config.proto delete mode 100644 simapp/genesis.json create mode 100644 simapp2/app.go create mode 100644 simapp2/app_config.json create mode 100644 x/authn/module/module.go create mode 100644 x/bank/module/module.go diff --git a/core/module/app/key.go b/core/module/app/key.go new file mode 100644 index 000000000000..4fe95bf114ea --- /dev/null +++ b/core/module/app/key.go @@ -0,0 +1,33 @@ +package app + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "google.golang.org/grpc" +) + +type ModuleKey interface { + InvokerConn + + ModuleID() ModuleID + Address() []byte +} + +type RootModuleKey interface { + ModuleKey + sdk.StoreKey +} + +type InvokerConn interface { + grpc.ClientConnInterface + Invoker(methodName string) (Invoker, error) +} + +type Invoker func(ctx context.Context, request, response interface{}, opts ...interface{}) error + +type ModuleID struct { + ModuleName string + Path []byte +} diff --git a/core/module/app/middleware.go b/core/module/app/middleware.go new file mode 100644 index 000000000000..7e0181f929fb --- /dev/null +++ b/core/module/app/middleware.go @@ -0,0 +1,16 @@ +package app + +import ( + "context" + + "github.com/gogo/protobuf/proto" + + "github.com/cosmos/cosmos-sdk/types/tx" +) + +type TxMiddlewareHandler interface { + ConfigType() proto.Message + Init(config proto.Message) TxMiddleware +} + +type TxMiddleware func(ctx context.Context, tx tx.Tx, next TxMiddleware) error diff --git a/core/module/app/module.go b/core/module/app/module.go new file mode 100644 index 000000000000..07356110b40e --- /dev/null +++ b/core/module/app/module.go @@ -0,0 +1,44 @@ +package app + +import ( + "encoding/json" + + abci "github.com/tendermint/tendermint/abci/types" + "google.golang.org/grpc" + + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type Module interface { + RegisterTypes(codectypes.InterfaceRegistry) + + InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate + ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage + + RegisterMsgServices(grpc.ServiceRegistrar) + RegisterQueryServices(grpc.ServiceRegistrar) +} + +type BeginBlocker interface { + Module + + BeginBlock(sdk.Context, abci.RequestBeginBlock) +} + +type EndBlocker interface { + Module + + EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate +} + +type HasTxMiddleware interface { + Module + + RegisterTxMiddleware(registrar TxMiddlewareRegistrar) +} + +type TxMiddlewareRegistrar interface { + RegisterHandler(handler TxMiddlewareHandler) +} diff --git a/core/module/module.go b/core/module/module.go new file mode 100644 index 000000000000..8680cbe01d9a --- /dev/null +++ b/core/module/module.go @@ -0,0 +1,27 @@ +package module + +import ( + "fmt" + "reflect" + + "github.com/gogo/protobuf/proto" +) + +type ModuleHandler interface { + // ModuleType returns the configuration type for this module + ConfigType() proto.Message + + // New returns a new module handler + New(config proto.Message) ModuleHandler +} + +var registry map[reflect.Type]ModuleHandler + +func RegisterModuleHandler(handler ModuleHandler) { + typ := reflect.TypeOf(handler.ConfigType()) + if _, ok := registry[typ]; ok { + panic(fmt.Errorf("module handler for config type %T already registered", handler.ConfigType())) + } + + registry[typ] = handler +} diff --git a/proto/cosmos/authn/v1/genesis.proto b/proto/cosmos/authn/v1/genesis.proto index c2a839b2b6a1..aa2be9f32240 100644 --- a/proto/cosmos/authn/v1/genesis.proto +++ b/proto/cosmos/authn/v1/genesis.proto @@ -3,6 +3,8 @@ package cosmos.authn.v1; import "cosmos/authn/v1/account.proto"; +option go_package = "github.com/cosmos/cosmos-sdk/x/authn"; + message GenesisState { // accounts are the accounts present at genesis. repeated Account accounts = 1; diff --git a/proto/cosmos/authn/v1/query.proto b/proto/cosmos/authn/v1/query.proto index e59c98c227d0..678c5bb69e62 100644 --- a/proto/cosmos/authn/v1/query.proto +++ b/proto/cosmos/authn/v1/query.proto @@ -18,11 +18,6 @@ service Query { rpc Accounts(QueryAccountsRequest) returns (QueryAccountsResponse) { option (google.api.http).get = "/cosmos/auth/v1beta1/accounts"; } - - // Params queries all parameters. - rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { - option (google.api.http).get = "/cosmos/auth/v1beta1/params"; - } } message QueryAccountRequest { @@ -44,13 +39,4 @@ message QueryAccountsResponse { // pagination defines the pagination in the response. cosmos.base.query.v1beta1.PageResponse pagination = 2; -} - -// QueryParamsRequest is the request type for the Query/Params RPC method. -message QueryParamsRequest {} - -// QueryParamsResponse is the response type for the Query/Params RPC method. -message QueryParamsResponse { - // params defines the parameters of the module. - Params params = 1; } \ No newline at end of file diff --git a/proto/cosmos/core/app_config/v1/app_config.proto b/proto/cosmos/core/app_config/v1/app_config.proto new file mode 100644 index 000000000000..68bbca31cfc5 --- /dev/null +++ b/proto/cosmos/core/app_config/v1/app_config.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package cosmos.core.app_config.v1; + +import "google/protobuf/any.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/core/app_config"; + +message AppConfig { + map modules = 1; + repeated google.protobuf.Any tx_middleware = 2; + repeated string init_genesis = 3; + repeated string begin_block = 4; + repeated string end_block = 5; +} \ No newline at end of file diff --git a/simapp/genesis.json b/simapp/genesis.json deleted file mode 100644 index bb9a1c1d939d..000000000000 --- a/simapp/genesis.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - "genesis_time": "", - "chain_id": "test123", - "consensus_params": { - "block": { - "max_bytes": "22020096", - "max_gas": "-1", - "time_iota_ms": "1000" - }, - "evidence": { - "max_age_num_blocks": "100000", - "max_age_duration": "172800000000000", - "max_num": 50, - "proof_trial_period": "50000" - }, - "validator": { - "pub_key_types": [ - "ed25519" - ] - } - }, - "app_hash": "", - "app_state": { - "app_config": { - "modules": { - "authn": { - "@type": "cosmos.authn.v1.Module", - "bech32_address_prefix": "sim" - }, - "bank": { - "@type": "cosmos.bank.v1beta1.Module", - "send_deny_list": [] - } - }, - "tx_middleware": [ - { - "@type": "cosmos.authn.v1.ValidateMemoMiddleware", - "max_memo_characters": 256 - }, - { - "@type": "cosmos.authn.v1.ConsumeGasForTxSizeMiddleware", - "tx_size_cost_per_byte": 100 - }, - { - "@type": "cosmos.bank.v1beta1.DeductFeeMiddleware" - }, - { - "@type": "cosmos.authn.v1.SetPubKeyMiddleware" - }, - { - "@type": "cosmos.authn.v1.ValidateSigCountMiddleware", - "tx_sig_limit": 7 - }, - { - "@type": "cosmos.authn.v1.SigGasConsumeMiddleware", - "sig_verify_cost_ed25519": 1000, - "sig_verify_cost_secp256k1": 500, - "allowed_pub_key_types": [ - "cosmos.crypto.secp256k1.PubKey", - "cosmos.crypto.secp256r1.PubKey" - ] - }, - { - "@type": "cosmos.authn.v1.SigVerificationMiddleware" - }, - { - "@type": "cosmos.authn.v1.IncrementSequenceMiddleware" - } - ], - "init_genesis": [ "authn", "bank"], - "begin_block": ["authn", "bank"], - "end_block": ["bank", "authn"] - } - } -} \ No newline at end of file diff --git a/simapp2/app.go b/simapp2/app.go new file mode 100644 index 000000000000..0a8532fd3a5a --- /dev/null +++ b/simapp2/app.go @@ -0,0 +1,9 @@ +package main + +import _ "embed" + +//go:embed app_config.json +var defaultAppConfig []byte + +func main() { +} diff --git a/simapp2/app_config.json b/simapp2/app_config.json new file mode 100644 index 000000000000..093219e9cc3d --- /dev/null +++ b/simapp2/app_config.json @@ -0,0 +1,59 @@ +{ + "modules": { + "authn": { + "@type": "cosmos.authn.v1.Module", + "bech32_address_prefix": "sim" + }, + "bank": { + "@type": "cosmos.bank.v1beta1.Module", + "send_deny_list": [] + } + }, + "tx_middleware": [ + { + "@type": "cosmos.authn.v1.ValidateMemoMiddleware", + "max_memo_characters": 256 + }, + { + "@type": "cosmos.authn.v1.ConsumeGasForTxSizeMiddleware", + "tx_size_cost_per_byte": 100 + }, + { + "@type": "cosmos.bank.v1beta1.DeductFeeMiddleware" + }, + { + "@type": "cosmos.authn.v1.SetPubKeyMiddleware" + }, + { + "@type": "cosmos.authn.v1.ValidateSigCountMiddleware", + "tx_sig_limit": 7 + }, + { + "@type": "cosmos.authn.v1.SigGasConsumeMiddleware", + "sig_verify_cost_ed25519": 1000, + "sig_verify_cost_secp256k1": 500, + "allowed_pub_key_types": [ + "cosmos.crypto.secp256k1.PubKey", + "cosmos.crypto.secp256r1.PubKey" + ] + }, + { + "@type": "cosmos.authn.v1.SigVerificationMiddleware" + }, + { + "@type": "cosmos.authn.v1.IncrementSequenceMiddleware" + } + ], + "init_genesis": [ + "authn", + "bank" + ], + "begin_block": [ + "authn", + "bank" + ], + "end_block": [ + "bank", + "authn" + ] +} \ No newline at end of file diff --git a/types/tx/service.pb.gw.go b/types/tx/service.pb.gw.go index 25560e1cdfb2..1418a5aa9bc3 100644 --- a/types/tx/service.pb.gw.go +++ b/types/tx/service.pb.gw.go @@ -13,7 +13,6 @@ import ( "io" "net/http" - "github.com/golang/protobuf/descriptor" "github.com/golang/protobuf/proto" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/grpc-ecosystem/grpc-gateway/utilities" @@ -23,13 +22,11 @@ import ( "google.golang.org/grpc/status" ) -// Suppress "imported and not used" errors var _ codes.Code var _ io.Reader var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray -var _ = descriptor.ForMessage func request_Service_Simulate_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq SimulateRequest @@ -48,23 +45,6 @@ func request_Service_Simulate_0(ctx context.Context, marshaler runtime.Marshaler } -func local_request_Service_Simulate_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq SimulateRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Simulate(ctx, &protoReq) - return msg, metadata, err - -} - func request_Service_GetTx_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq GetTxRequest var metadata runtime.ServerMetadata @@ -92,33 +72,6 @@ func request_Service_GetTx_0(ctx context.Context, marshaler runtime.Marshaler, c } -func local_request_Service_GetTx_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetTxRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["hash"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "hash") - } - - protoReq.Hash, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "hash", err) - } - - msg, err := server.GetTx(ctx, &protoReq) - return msg, metadata, err - -} - func request_Service_BroadcastTx_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq BroadcastTxRequest var metadata runtime.ServerMetadata @@ -136,23 +89,6 @@ func request_Service_BroadcastTx_0(ctx context.Context, marshaler runtime.Marsha } -func local_request_Service_BroadcastTx_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq BroadcastTxRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.BroadcastTx(ctx, &protoReq) - return msg, metadata, err - -} - var ( filter_Service_GetTxsEvent_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} ) @@ -173,111 +109,6 @@ func request_Service_GetTxsEvent_0(ctx context.Context, marshaler runtime.Marsha } -func local_request_Service_GetTxsEvent_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetTxsEventRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Service_GetTxsEvent_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.GetTxsEvent(ctx, &protoReq) - return msg, metadata, err - -} - -// RegisterServiceHandlerServer registers the http handlers for service Service to "mux". -// UnaryRPC :call ServiceServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterServiceHandlerFromEndpoint instead. -func RegisterServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server ServiceServer) error { - - mux.Handle("POST", pattern_Service_Simulate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Service_Simulate_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Service_Simulate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Service_GetTx_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Service_GetTx_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Service_GetTx_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Service_BroadcastTx_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Service_BroadcastTx_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Service_BroadcastTx_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Service_GetTxsEvent_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Service_GetTxsEvent_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Service_GetTxsEvent_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - // RegisterServiceHandlerFromEndpoint is same as RegisterServiceHandler but // automatically dials to "endpoint" and closes the connection when "ctx" gets done. func RegisterServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { diff --git a/x/authn/module/module.go b/x/authn/module/module.go new file mode 100644 index 000000000000..e33a53012158 --- /dev/null +++ b/x/authn/module/module.go @@ -0,0 +1,25 @@ +package module + +import ( + "github.com/gogo/protobuf/proto" + + "github.com/cosmos/cosmos-sdk/core/module" + "github.com/cosmos/cosmos-sdk/x/authn" +) + +func init() { + module.RegisterModuleHandler(handler{}) +} + +type handler struct { + *authn.Module +} + +func (h handler) ConfigType() proto.Message { + return h.Module +} + +func (h handler) New(config proto.Message) module.ModuleHandler { + mod := config.(*authn.Module) + return handler{mod} +} diff --git a/x/bank/module/module.go b/x/bank/module/module.go new file mode 100644 index 000000000000..5e37259272f3 --- /dev/null +++ b/x/bank/module/module.go @@ -0,0 +1,37 @@ +package module + +import ( + "github.com/gogo/protobuf/proto" + + "github.com/cosmos/cosmos-sdk/core/module" + "github.com/cosmos/cosmos-sdk/core/module/app" + "github.com/cosmos/cosmos-sdk/x/authn" + "github.com/cosmos/cosmos-sdk/x/bank/types" +) + +func init() { + module.RegisterModuleHandler(handler{}) +} + +type handler struct { + *types.Module +} + +func (h handler) ConfigType() proto.Message { + return h.Module +} + +func (h handler) New(config proto.Message) module.ModuleHandler { + mod := config.(*types.Module) + return handler{mod} +} + +type AppModuleDeps struct { + Key app.RootModuleKey + AuthnQueryClient authn.QueryClient + AuthnMsgClient authn.MsgClient +} + +func (h handler) NewAppModule(deps AppModuleDeps) app.Module { + panic("TODO") +} From cdd2efaedada029304d36ce305a98aa012343abd Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 26 May 2021 21:05:15 -0400 Subject: [PATCH 05/19] WIP --- core/app_config/app_config.pb.go | 682 +++++++++++++++++ core/cli/cli.go | 13 + simapp2/app.go | 26 +- x/authn/account.pb.go | 451 +++++++++++ x/authn/genesis.pb.go | 327 ++++++++ x/authn/middleware.pb.go | 1224 ++++++++++++++++++++++++++++++ x/authn/module.pb.go | 315 ++++++++ x/authn/module/module.go | 10 + x/authn/query.pb.go | 1062 ++++++++++++++++++++++++++ x/authn/query.pb.gw.go | 169 +++++ x/authn/tx.pb.go | 585 ++++++++++++++ x/bank/types/middleware.pb.go | 265 +++++++ x/bank/types/module.pb.go | 319 ++++++++ 13 files changed, 5446 insertions(+), 2 deletions(-) create mode 100644 core/app_config/app_config.pb.go create mode 100644 core/cli/cli.go create mode 100644 x/authn/account.pb.go create mode 100644 x/authn/genesis.pb.go create mode 100644 x/authn/middleware.pb.go create mode 100644 x/authn/module.pb.go create mode 100644 x/authn/query.pb.go create mode 100644 x/authn/query.pb.gw.go create mode 100644 x/authn/tx.pb.go create mode 100644 x/bank/types/middleware.pb.go create mode 100644 x/bank/types/module.pb.go diff --git a/core/app_config/app_config.pb.go b/core/app_config/app_config.pb.go new file mode 100644 index 000000000000..995add976980 --- /dev/null +++ b/core/app_config/app_config.pb.go @@ -0,0 +1,682 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/core/app_config/v1/app_config.proto + +package app_config + +import ( + fmt "fmt" + types "github.com/cosmos/cosmos-sdk/codec/types" + 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 + +type AppConfig struct { + Modules map[string]*types.Any `protobuf:"bytes,1,rep,name=modules,proto3" json:"modules,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + TxMiddleware []*types.Any `protobuf:"bytes,2,rep,name=tx_middleware,json=txMiddleware,proto3" json:"tx_middleware,omitempty"` + InitGenesis []string `protobuf:"bytes,3,rep,name=init_genesis,json=initGenesis,proto3" json:"init_genesis,omitempty"` + BeginBlock []string `protobuf:"bytes,4,rep,name=begin_block,json=beginBlock,proto3" json:"begin_block,omitempty"` + EndBlock []string `protobuf:"bytes,5,rep,name=end_block,json=endBlock,proto3" json:"end_block,omitempty"` +} + +func (m *AppConfig) Reset() { *m = AppConfig{} } +func (m *AppConfig) String() string { return proto.CompactTextString(m) } +func (*AppConfig) ProtoMessage() {} +func (*AppConfig) Descriptor() ([]byte, []int) { + return fileDescriptor_67d11620ac2d3428, []int{0} +} +func (m *AppConfig) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AppConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AppConfig.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 *AppConfig) XXX_Merge(src proto.Message) { + xxx_messageInfo_AppConfig.Merge(m, src) +} +func (m *AppConfig) XXX_Size() int { + return m.Size() +} +func (m *AppConfig) XXX_DiscardUnknown() { + xxx_messageInfo_AppConfig.DiscardUnknown(m) +} + +var xxx_messageInfo_AppConfig proto.InternalMessageInfo + +func (m *AppConfig) GetModules() map[string]*types.Any { + if m != nil { + return m.Modules + } + return nil +} + +func (m *AppConfig) GetTxMiddleware() []*types.Any { + if m != nil { + return m.TxMiddleware + } + return nil +} + +func (m *AppConfig) GetInitGenesis() []string { + if m != nil { + return m.InitGenesis + } + return nil +} + +func (m *AppConfig) GetBeginBlock() []string { + if m != nil { + return m.BeginBlock + } + return nil +} + +func (m *AppConfig) GetEndBlock() []string { + if m != nil { + return m.EndBlock + } + return nil +} + +func init() { + proto.RegisterType((*AppConfig)(nil), "cosmos.core.app_config.v1.AppConfig") + proto.RegisterMapType((map[string]*types.Any)(nil), "cosmos.core.app_config.v1.AppConfig.ModulesEntry") +} + +func init() { + proto.RegisterFile("cosmos/core/app_config/v1/app_config.proto", fileDescriptor_67d11620ac2d3428) +} + +var fileDescriptor_67d11620ac2d3428 = []byte{ + // 342 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0x4f, 0x4b, 0xfb, 0x30, + 0x1c, 0xc6, 0x97, 0xf5, 0xb7, 0x9f, 0x36, 0x9b, 0x20, 0xc1, 0x43, 0x37, 0xa1, 0x4e, 0x4f, 0x63, + 0x68, 0xca, 0xf4, 0xa2, 0xde, 0x36, 0x51, 0x0f, 0x32, 0x90, 0x1e, 0xbd, 0x94, 0xfe, 0xc9, 0x6a, + 0x58, 0x9b, 0x94, 0x36, 0x9d, 0xeb, 0xbb, 0xf0, 0x55, 0x89, 0xc7, 0x1d, 0x3d, 0xca, 0xf6, 0x46, + 0x24, 0x89, 0x1b, 0x43, 0xd8, 0x29, 0xc9, 0xf3, 0x7c, 0xbe, 0x4f, 0x1e, 0xf8, 0xc2, 0x7e, 0xc8, + 0x8b, 0x94, 0x17, 0x4e, 0xc8, 0x73, 0xe2, 0xf8, 0x59, 0xe6, 0x85, 0x9c, 0x4d, 0x68, 0xec, 0xcc, + 0x06, 0x5b, 0x2f, 0x9c, 0xe5, 0x5c, 0x70, 0xd4, 0xd6, 0x2c, 0x96, 0x2c, 0xde, 0x72, 0x67, 0x83, + 0x4e, 0x3b, 0xe6, 0x3c, 0x4e, 0x88, 0xa3, 0xc0, 0xa0, 0x9c, 0x38, 0x3e, 0xab, 0xf4, 0xd4, 0xd9, + 0x47, 0x1d, 0x9a, 0xc3, 0x2c, 0xbb, 0x53, 0x2c, 0x7a, 0x82, 0x7b, 0x29, 0x8f, 0xca, 0x84, 0x14, + 0x16, 0xe8, 0x1a, 0xbd, 0xe6, 0xe5, 0x00, 0xef, 0x4c, 0xc5, 0x9b, 0x31, 0x3c, 0xd6, 0x33, 0xf7, + 0x4c, 0xe4, 0x95, 0xbb, 0x4e, 0x40, 0x37, 0xf0, 0x40, 0xcc, 0xbd, 0x94, 0x46, 0x51, 0x42, 0xde, + 0xfc, 0x9c, 0x58, 0x75, 0x15, 0x79, 0x84, 0x75, 0x1b, 0xbc, 0x6e, 0x83, 0x87, 0xac, 0x72, 0x5b, + 0x62, 0x3e, 0xde, 0x90, 0xe8, 0x14, 0xb6, 0x28, 0xa3, 0xc2, 0x8b, 0x09, 0x23, 0x05, 0x2d, 0x2c, + 0xa3, 0x6b, 0xf4, 0x4c, 0xb7, 0x29, 0xb5, 0x47, 0x2d, 0xa1, 0x13, 0xd8, 0x0c, 0x48, 0x4c, 0x99, + 0x17, 0x24, 0x3c, 0x9c, 0x5a, 0xff, 0x14, 0x01, 0x95, 0x34, 0x92, 0x0a, 0x3a, 0x86, 0x26, 0x61, + 0xd1, 0xaf, 0xdd, 0x50, 0xf6, 0x3e, 0x61, 0x91, 0x32, 0x3b, 0xcf, 0xb0, 0xb5, 0x5d, 0x1a, 0x1d, + 0x42, 0x63, 0x4a, 0x2a, 0x0b, 0x74, 0x41, 0xcf, 0x74, 0xe5, 0x15, 0xf5, 0x61, 0x63, 0xe6, 0x27, + 0xa5, 0x6c, 0x0d, 0x76, 0xb6, 0xd6, 0xc8, 0x6d, 0xfd, 0x1a, 0x8c, 0x1e, 0x3e, 0x97, 0x36, 0x58, + 0x2c, 0x6d, 0xf0, 0xbd, 0xb4, 0xc1, 0xfb, 0xca, 0xae, 0x2d, 0x56, 0x76, 0xed, 0x6b, 0x65, 0xd7, + 0x5e, 0xce, 0x63, 0x2a, 0x5e, 0xcb, 0x00, 0x87, 0x3c, 0x75, 0x36, 0xfb, 0x94, 0xc7, 0x45, 0x11, + 0x4d, 0xff, 0xae, 0x36, 0xf8, 0xaf, 0x3e, 0xb8, 0xfa, 0x09, 0x00, 0x00, 0xff, 0xff, 0x2c, 0xd8, + 0x10, 0xd6, 0xfb, 0x01, 0x00, 0x00, +} + +func (m *AppConfig) 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 *AppConfig) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AppConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.EndBlock) > 0 { + for iNdEx := len(m.EndBlock) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.EndBlock[iNdEx]) + copy(dAtA[i:], m.EndBlock[iNdEx]) + i = encodeVarintAppConfig(dAtA, i, uint64(len(m.EndBlock[iNdEx]))) + i-- + dAtA[i] = 0x2a + } + } + if len(m.BeginBlock) > 0 { + for iNdEx := len(m.BeginBlock) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.BeginBlock[iNdEx]) + copy(dAtA[i:], m.BeginBlock[iNdEx]) + i = encodeVarintAppConfig(dAtA, i, uint64(len(m.BeginBlock[iNdEx]))) + i-- + dAtA[i] = 0x22 + } + } + if len(m.InitGenesis) > 0 { + for iNdEx := len(m.InitGenesis) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.InitGenesis[iNdEx]) + copy(dAtA[i:], m.InitGenesis[iNdEx]) + i = encodeVarintAppConfig(dAtA, i, uint64(len(m.InitGenesis[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + if len(m.TxMiddleware) > 0 { + for iNdEx := len(m.TxMiddleware) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.TxMiddleware[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAppConfig(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Modules) > 0 { + for k := range m.Modules { + v := m.Modules[k] + baseI := i + if v != nil { + { + size, err := v.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAppConfig(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + i -= len(k) + copy(dAtA[i:], k) + i = encodeVarintAppConfig(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = encodeVarintAppConfig(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintAppConfig(dAtA []byte, offset int, v uint64) int { + offset -= sovAppConfig(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *AppConfig) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Modules) > 0 { + for k, v := range m.Modules { + _ = k + _ = v + l = 0 + if v != nil { + l = v.Size() + l += 1 + sovAppConfig(uint64(l)) + } + mapEntrySize := 1 + len(k) + sovAppConfig(uint64(len(k))) + l + n += mapEntrySize + 1 + sovAppConfig(uint64(mapEntrySize)) + } + } + if len(m.TxMiddleware) > 0 { + for _, e := range m.TxMiddleware { + l = e.Size() + n += 1 + l + sovAppConfig(uint64(l)) + } + } + if len(m.InitGenesis) > 0 { + for _, s := range m.InitGenesis { + l = len(s) + n += 1 + l + sovAppConfig(uint64(l)) + } + } + if len(m.BeginBlock) > 0 { + for _, s := range m.BeginBlock { + l = len(s) + n += 1 + l + sovAppConfig(uint64(l)) + } + } + if len(m.EndBlock) > 0 { + for _, s := range m.EndBlock { + l = len(s) + n += 1 + l + sovAppConfig(uint64(l)) + } + } + return n +} + +func sovAppConfig(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozAppConfig(x uint64) (n int) { + return sovAppConfig(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *AppConfig) 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 ErrIntOverflowAppConfig + } + 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: AppConfig: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AppConfig: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Modules", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAppConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthAppConfig + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthAppConfig + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Modules == nil { + m.Modules = make(map[string]*types.Any) + } + var mapkey string + var mapvalue *types.Any + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAppConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAppConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return ErrInvalidLengthAppConfig + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return ErrInvalidLengthAppConfig + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + var mapmsglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAppConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapmsglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if mapmsglen < 0 { + return ErrInvalidLengthAppConfig + } + postmsgIndex := iNdEx + mapmsglen + if postmsgIndex < 0 { + return ErrInvalidLengthAppConfig + } + if postmsgIndex > l { + return io.ErrUnexpectedEOF + } + mapvalue = &types.Any{} + if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil { + return err + } + iNdEx = postmsgIndex + } else { + iNdEx = entryPreIndex + skippy, err := skipAppConfig(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAppConfig + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.Modules[mapkey] = mapvalue + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TxMiddleware", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAppConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthAppConfig + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthAppConfig + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TxMiddleware = append(m.TxMiddleware, &types.Any{}) + if err := m.TxMiddleware[len(m.TxMiddleware)-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 InitGenesis", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAppConfig + } + 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 ErrInvalidLengthAppConfig + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAppConfig + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.InitGenesis = append(m.InitGenesis, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BeginBlock", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAppConfig + } + 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 ErrInvalidLengthAppConfig + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAppConfig + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BeginBlock = append(m.BeginBlock, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EndBlock", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAppConfig + } + 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 ErrInvalidLengthAppConfig + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAppConfig + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EndBlock = append(m.EndBlock, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipAppConfig(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAppConfig + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipAppConfig(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, ErrIntOverflowAppConfig + } + 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, ErrIntOverflowAppConfig + } + 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, ErrIntOverflowAppConfig + } + 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, ErrInvalidLengthAppConfig + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupAppConfig + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthAppConfig + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthAppConfig = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowAppConfig = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupAppConfig = fmt.Errorf("proto: unexpected end of group") +) diff --git a/core/cli/cli.go b/core/cli/cli.go new file mode 100644 index 000000000000..3822459ae047 --- /dev/null +++ b/core/cli/cli.go @@ -0,0 +1,13 @@ +package cli + +import "github.com/cosmos/cosmos-sdk/core/app_config" + +type Config struct { + DefaultAppConfig *app_config.AppConfig + DefaultHomeDir string + DefaultEnvPrefix string +} + +func Exec(config Config) { + +} diff --git a/simapp2/app.go b/simapp2/app.go index 0a8532fd3a5a..e28d6302d6be 100644 --- a/simapp2/app.go +++ b/simapp2/app.go @@ -1,9 +1,31 @@ package main -import _ "embed" +import ( + _ "embed" + + "github.com/gogo/protobuf/proto" + + "github.com/cosmos/cosmos-sdk/core/app_config" + "github.com/cosmos/cosmos-sdk/core/cli" + + // Register Modules + _ "github.com/cosmos/cosmos-sdk/x/authn/module" + _ "github.com/cosmos/cosmos-sdk/x/bank/module" +) //go:embed app_config.json -var defaultAppConfig []byte +var defaultAppConfigJson []byte func main() { + var cfg app_config.AppConfig + err := proto.Unmarshal(defaultAppConfigJson, &cfg) + if err != nil { + panic(err) + } + + cli.Exec(cli.Config{ + DefaultAppConfig: &cfg, + DefaultHomeDir: "simapp", + DefaultEnvPrefix: "SIMAPP", + }) } diff --git a/x/authn/account.pb.go b/x/authn/account.pb.go new file mode 100644 index 000000000000..d8470ff3efd6 --- /dev/null +++ b/x/authn/account.pb.go @@ -0,0 +1,451 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/authn/v1/account.proto + +package authn + +import ( + fmt "fmt" + types "github.com/cosmos/cosmos-sdk/codec/types" + 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 + +type Account struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + Credential *types.Any `protobuf:"bytes,2,opt,name=credential,proto3" json:"credential,omitempty"` + AccountNumber uint64 `protobuf:"varint,3,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty"` + Sequence uint64 `protobuf:"varint,4,opt,name=sequence,proto3" json:"sequence,omitempty"` +} + +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_36921b2acb3eecaa, []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 + +func (m *Account) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *Account) GetCredential() *types.Any { + if m != nil { + return m.Credential + } + return nil +} + +func (m *Account) GetAccountNumber() uint64 { + if m != nil { + return m.AccountNumber + } + return 0 +} + +func (m *Account) GetSequence() uint64 { + if m != nil { + return m.Sequence + } + return 0 +} + +func init() { + proto.RegisterType((*Account)(nil), "cosmos.authn.v1.Account") +} + +func init() { proto.RegisterFile("cosmos/authn/v1/account.proto", fileDescriptor_36921b2acb3eecaa) } + +var fileDescriptor_36921b2acb3eecaa = []byte{ + // 250 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4d, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0x2c, 0x2d, 0xc9, 0xc8, 0xd3, 0x2f, 0x33, 0xd4, 0x4f, 0x4c, 0x4e, 0xce, + 0x2f, 0xcd, 0x2b, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x87, 0x48, 0xeb, 0x81, 0xa5, + 0xf5, 0xca, 0x0c, 0xa5, 0x24, 0xd3, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0xc1, 0xd2, 0x49, 0xa5, + 0x69, 0xfa, 0x89, 0x79, 0x95, 0x10, 0xb5, 0x4a, 0x73, 0x18, 0xb9, 0xd8, 0x1d, 0x21, 0xba, 0x85, + 0x24, 0xb8, 0xd8, 0x13, 0x53, 0x52, 0x8a, 0x52, 0x8b, 0x8b, 0x25, 0x18, 0x15, 0x18, 0x35, 0x38, + 0x83, 0x60, 0x5c, 0x21, 0x13, 0x2e, 0xae, 0xe4, 0xa2, 0xd4, 0x94, 0xd4, 0xbc, 0x92, 0xcc, 0xc4, + 0x1c, 0x09, 0x26, 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x11, 0x3d, 0x88, 0xa9, 0x7a, 0x30, 0x53, 0xf5, + 0x1c, 0xf3, 0x2a, 0x83, 0x90, 0xd4, 0x09, 0xa9, 0x72, 0xf1, 0x41, 0x1d, 0x16, 0x9f, 0x57, 0x9a, + 0x9b, 0x94, 0x5a, 0x24, 0xc1, 0xac, 0xc0, 0xa8, 0xc1, 0x12, 0xc4, 0x0b, 0x15, 0xf5, 0x03, 0x0b, + 0x0a, 0x49, 0x71, 0x71, 0x14, 0xa7, 0x16, 0x96, 0xa6, 0xe6, 0x25, 0xa7, 0x4a, 0xb0, 0x80, 0x15, + 0xc0, 0xf9, 0x4e, 0x76, 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, 0xa5, 0x92, + 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x0f, 0x0d, 0x0e, 0x08, 0xa5, 0x5b, + 0x9c, 0x92, 0xad, 0x5f, 0x01, 0x09, 0x9b, 0x24, 0x36, 0xb0, 0xe3, 0x8c, 0x01, 0x01, 0x00, 0x00, + 0xff, 0xff, 0x7f, 0x53, 0x01, 0x7b, 0x32, 0x01, 0x00, 0x00, +} + +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.Sequence != 0 { + i = encodeVarintAccount(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x20 + } + if m.AccountNumber != 0 { + i = encodeVarintAccount(dAtA, i, uint64(m.AccountNumber)) + i-- + dAtA[i] = 0x18 + } + if m.Credential != nil { + { + size, err := m.Credential.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAccount(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintAccount(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintAccount(dAtA []byte, offset int, v uint64) int { + offset -= sovAccount(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 + l = len(m.Address) + if l > 0 { + n += 1 + l + sovAccount(uint64(l)) + } + if m.Credential != nil { + l = m.Credential.Size() + n += 1 + l + sovAccount(uint64(l)) + } + if m.AccountNumber != 0 { + n += 1 + sovAccount(uint64(m.AccountNumber)) + } + if m.Sequence != 0 { + n += 1 + sovAccount(uint64(m.Sequence)) + } + return n +} + +func sovAccount(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozAccount(x uint64) (n int) { + return sovAccount(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 ErrIntOverflowAccount + } + 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 Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAccount + } + 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 ErrInvalidLengthAccount + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAccount + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Credential", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAccount + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthAccount + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthAccount + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Credential == nil { + m.Credential = &types.Any{} + } + if err := m.Credential.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + 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 ErrIntOverflowAccount + } + 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 ErrIntOverflowAccount + } + 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 := skipAccount(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAccount + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipAccount(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, ErrIntOverflowAccount + } + 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, ErrIntOverflowAccount + } + 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, ErrIntOverflowAccount + } + 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, ErrInvalidLengthAccount + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupAccount + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthAccount + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthAccount = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowAccount = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupAccount = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/authn/genesis.pb.go b/x/authn/genesis.pb.go new file mode 100644 index 000000000000..3c8119629fa1 --- /dev/null +++ b/x/authn/genesis.pb.go @@ -0,0 +1,327 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/authn/v1/genesis.proto + +package authn + +import ( + fmt "fmt" + 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 + +type GenesisState struct { + // accounts are the accounts present at genesis. + Accounts []*Account `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_411ae9e2deff2094, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.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 *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetAccounts() []*Account { + if m != nil { + return m.Accounts + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "cosmos.authn.v1.GenesisState") +} + +func init() { proto.RegisterFile("cosmos/authn/v1/genesis.proto", fileDescriptor_411ae9e2deff2094) } + +var fileDescriptor_411ae9e2deff2094 = []byte{ + // 172 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4d, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0x2c, 0x2d, 0xc9, 0xc8, 0xd3, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, + 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x87, 0x48, 0xeb, 0x81, 0xa5, + 0xf5, 0xca, 0x0c, 0xa5, 0x30, 0xd4, 0x27, 0x26, 0x27, 0xe7, 0x97, 0xe6, 0x95, 0x40, 0xd4, 0x2b, + 0xb9, 0x70, 0xf1, 0xb8, 0x43, 0x0c, 0x08, 0x2e, 0x49, 0x2c, 0x49, 0x15, 0x32, 0xe1, 0xe2, 0x80, + 0x2a, 0x28, 0x96, 0x60, 0x54, 0x60, 0xd6, 0xe0, 0x36, 0x92, 0xd0, 0x43, 0x33, 0x52, 0xcf, 0x11, + 0xa2, 0x20, 0x08, 0xae, 0xd2, 0xc9, 0xee, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, + 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, + 0xa2, 0x54, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0xa1, 0x2e, 0x81, + 0x50, 0xba, 0xc5, 0x29, 0xd9, 0xfa, 0x15, 0x10, 0x67, 0x25, 0xb1, 0x81, 0x1d, 0x63, 0x0c, 0x08, + 0x00, 0x00, 0xff, 0xff, 0x25, 0xaa, 0xa9, 0x3f, 0xdd, 0x00, 0x00, 0x00, +} + +func (m *GenesisState) 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 *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Accounts) > 0 { + for iNdEx := len(m.Accounts) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Accounts[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Accounts) > 0 { + for _, e := range m.Accounts { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) 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 ErrIntOverflowGenesis + } + 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: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Accounts", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Accounts = append(m.Accounts, &Account{}) + if err := m.Accounts[len(m.Accounts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(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, ErrIntOverflowGenesis + } + 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, ErrIntOverflowGenesis + } + 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, ErrIntOverflowGenesis + } + 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, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/authn/middleware.pb.go b/x/authn/middleware.pb.go new file mode 100644 index 000000000000..c477a690274c --- /dev/null +++ b/x/authn/middleware.pb.go @@ -0,0 +1,1224 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/authn/v1/middleware.proto + +package authn + +import ( + fmt "fmt" + 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 + +type ValidateMemoMiddleware struct { + MaxMemoCharacters uint64 `protobuf:"varint,1,opt,name=max_memo_characters,json=maxMemoCharacters,proto3" json:"max_memo_characters,omitempty"` +} + +func (m *ValidateMemoMiddleware) Reset() { *m = ValidateMemoMiddleware{} } +func (m *ValidateMemoMiddleware) String() string { return proto.CompactTextString(m) } +func (*ValidateMemoMiddleware) ProtoMessage() {} +func (*ValidateMemoMiddleware) Descriptor() ([]byte, []int) { + return fileDescriptor_b60099c6a9247712, []int{0} +} +func (m *ValidateMemoMiddleware) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidateMemoMiddleware) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidateMemoMiddleware.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 *ValidateMemoMiddleware) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidateMemoMiddleware.Merge(m, src) +} +func (m *ValidateMemoMiddleware) XXX_Size() int { + return m.Size() +} +func (m *ValidateMemoMiddleware) XXX_DiscardUnknown() { + xxx_messageInfo_ValidateMemoMiddleware.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidateMemoMiddleware proto.InternalMessageInfo + +func (m *ValidateMemoMiddleware) GetMaxMemoCharacters() uint64 { + if m != nil { + return m.MaxMemoCharacters + } + return 0 +} + +type ConsumeGasForTxSizeMiddleware struct { + TxSizeCostPerByte uint64 `protobuf:"varint,1,opt,name=tx_size_cost_per_byte,json=txSizeCostPerByte,proto3" json:"tx_size_cost_per_byte,omitempty"` +} + +func (m *ConsumeGasForTxSizeMiddleware) Reset() { *m = ConsumeGasForTxSizeMiddleware{} } +func (m *ConsumeGasForTxSizeMiddleware) String() string { return proto.CompactTextString(m) } +func (*ConsumeGasForTxSizeMiddleware) ProtoMessage() {} +func (*ConsumeGasForTxSizeMiddleware) Descriptor() ([]byte, []int) { + return fileDescriptor_b60099c6a9247712, []int{1} +} +func (m *ConsumeGasForTxSizeMiddleware) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ConsumeGasForTxSizeMiddleware) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ConsumeGasForTxSizeMiddleware.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 *ConsumeGasForTxSizeMiddleware) XXX_Merge(src proto.Message) { + xxx_messageInfo_ConsumeGasForTxSizeMiddleware.Merge(m, src) +} +func (m *ConsumeGasForTxSizeMiddleware) XXX_Size() int { + return m.Size() +} +func (m *ConsumeGasForTxSizeMiddleware) XXX_DiscardUnknown() { + xxx_messageInfo_ConsumeGasForTxSizeMiddleware.DiscardUnknown(m) +} + +var xxx_messageInfo_ConsumeGasForTxSizeMiddleware proto.InternalMessageInfo + +func (m *ConsumeGasForTxSizeMiddleware) GetTxSizeCostPerByte() uint64 { + if m != nil { + return m.TxSizeCostPerByte + } + return 0 +} + +type SetPubKeyMiddleware struct { +} + +func (m *SetPubKeyMiddleware) Reset() { *m = SetPubKeyMiddleware{} } +func (m *SetPubKeyMiddleware) String() string { return proto.CompactTextString(m) } +func (*SetPubKeyMiddleware) ProtoMessage() {} +func (*SetPubKeyMiddleware) Descriptor() ([]byte, []int) { + return fileDescriptor_b60099c6a9247712, []int{2} +} +func (m *SetPubKeyMiddleware) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SetPubKeyMiddleware) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SetPubKeyMiddleware.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 *SetPubKeyMiddleware) XXX_Merge(src proto.Message) { + xxx_messageInfo_SetPubKeyMiddleware.Merge(m, src) +} +func (m *SetPubKeyMiddleware) XXX_Size() int { + return m.Size() +} +func (m *SetPubKeyMiddleware) XXX_DiscardUnknown() { + xxx_messageInfo_SetPubKeyMiddleware.DiscardUnknown(m) +} + +var xxx_messageInfo_SetPubKeyMiddleware proto.InternalMessageInfo + +type ValidateSigCountMiddleware struct { + TxSigLimit uint64 `protobuf:"varint,1,opt,name=tx_sig_limit,json=txSigLimit,proto3" json:"tx_sig_limit,omitempty"` +} + +func (m *ValidateSigCountMiddleware) Reset() { *m = ValidateSigCountMiddleware{} } +func (m *ValidateSigCountMiddleware) String() string { return proto.CompactTextString(m) } +func (*ValidateSigCountMiddleware) ProtoMessage() {} +func (*ValidateSigCountMiddleware) Descriptor() ([]byte, []int) { + return fileDescriptor_b60099c6a9247712, []int{3} +} +func (m *ValidateSigCountMiddleware) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidateSigCountMiddleware) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidateSigCountMiddleware.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 *ValidateSigCountMiddleware) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidateSigCountMiddleware.Merge(m, src) +} +func (m *ValidateSigCountMiddleware) XXX_Size() int { + return m.Size() +} +func (m *ValidateSigCountMiddleware) XXX_DiscardUnknown() { + xxx_messageInfo_ValidateSigCountMiddleware.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidateSigCountMiddleware proto.InternalMessageInfo + +func (m *ValidateSigCountMiddleware) GetTxSigLimit() uint64 { + if m != nil { + return m.TxSigLimit + } + return 0 +} + +type SigGasConsumeMiddleware struct { + SigVerifyCostEd25519 uint64 `protobuf:"varint,1,opt,name=sig_verify_cost_ed25519,json=sigVerifyCostEd25519,proto3" json:"sig_verify_cost_ed25519,omitempty"` + SigVerifyCostSecp256K1 uint64 `protobuf:"varint,2,opt,name=sig_verify_cost_secp256k1,json=sigVerifyCostSecp256k1,proto3" json:"sig_verify_cost_secp256k1,omitempty"` + AllowedPubKeyTypes []string `protobuf:"bytes,3,rep,name=allowed_pub_key_types,json=allowedPubKeyTypes,proto3" json:"allowed_pub_key_types,omitempty"` +} + +func (m *SigGasConsumeMiddleware) Reset() { *m = SigGasConsumeMiddleware{} } +func (m *SigGasConsumeMiddleware) String() string { return proto.CompactTextString(m) } +func (*SigGasConsumeMiddleware) ProtoMessage() {} +func (*SigGasConsumeMiddleware) Descriptor() ([]byte, []int) { + return fileDescriptor_b60099c6a9247712, []int{4} +} +func (m *SigGasConsumeMiddleware) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SigGasConsumeMiddleware) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SigGasConsumeMiddleware.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 *SigGasConsumeMiddleware) XXX_Merge(src proto.Message) { + xxx_messageInfo_SigGasConsumeMiddleware.Merge(m, src) +} +func (m *SigGasConsumeMiddleware) XXX_Size() int { + return m.Size() +} +func (m *SigGasConsumeMiddleware) XXX_DiscardUnknown() { + xxx_messageInfo_SigGasConsumeMiddleware.DiscardUnknown(m) +} + +var xxx_messageInfo_SigGasConsumeMiddleware proto.InternalMessageInfo + +func (m *SigGasConsumeMiddleware) GetSigVerifyCostEd25519() uint64 { + if m != nil { + return m.SigVerifyCostEd25519 + } + return 0 +} + +func (m *SigGasConsumeMiddleware) GetSigVerifyCostSecp256K1() uint64 { + if m != nil { + return m.SigVerifyCostSecp256K1 + } + return 0 +} + +func (m *SigGasConsumeMiddleware) GetAllowedPubKeyTypes() []string { + if m != nil { + return m.AllowedPubKeyTypes + } + return nil +} + +type SigVerificationMiddleware struct { +} + +func (m *SigVerificationMiddleware) Reset() { *m = SigVerificationMiddleware{} } +func (m *SigVerificationMiddleware) String() string { return proto.CompactTextString(m) } +func (*SigVerificationMiddleware) ProtoMessage() {} +func (*SigVerificationMiddleware) Descriptor() ([]byte, []int) { + return fileDescriptor_b60099c6a9247712, []int{5} +} +func (m *SigVerificationMiddleware) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SigVerificationMiddleware) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SigVerificationMiddleware.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 *SigVerificationMiddleware) XXX_Merge(src proto.Message) { + xxx_messageInfo_SigVerificationMiddleware.Merge(m, src) +} +func (m *SigVerificationMiddleware) XXX_Size() int { + return m.Size() +} +func (m *SigVerificationMiddleware) XXX_DiscardUnknown() { + xxx_messageInfo_SigVerificationMiddleware.DiscardUnknown(m) +} + +var xxx_messageInfo_SigVerificationMiddleware proto.InternalMessageInfo + +type IncrementSequenceMiddleware struct { +} + +func (m *IncrementSequenceMiddleware) Reset() { *m = IncrementSequenceMiddleware{} } +func (m *IncrementSequenceMiddleware) String() string { return proto.CompactTextString(m) } +func (*IncrementSequenceMiddleware) ProtoMessage() {} +func (*IncrementSequenceMiddleware) Descriptor() ([]byte, []int) { + return fileDescriptor_b60099c6a9247712, []int{6} +} +func (m *IncrementSequenceMiddleware) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *IncrementSequenceMiddleware) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_IncrementSequenceMiddleware.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 *IncrementSequenceMiddleware) XXX_Merge(src proto.Message) { + xxx_messageInfo_IncrementSequenceMiddleware.Merge(m, src) +} +func (m *IncrementSequenceMiddleware) XXX_Size() int { + return m.Size() +} +func (m *IncrementSequenceMiddleware) XXX_DiscardUnknown() { + xxx_messageInfo_IncrementSequenceMiddleware.DiscardUnknown(m) +} + +var xxx_messageInfo_IncrementSequenceMiddleware proto.InternalMessageInfo + +func init() { + proto.RegisterType((*ValidateMemoMiddleware)(nil), "cosmos.authn.v1.ValidateMemoMiddleware") + proto.RegisterType((*ConsumeGasForTxSizeMiddleware)(nil), "cosmos.authn.v1.ConsumeGasForTxSizeMiddleware") + proto.RegisterType((*SetPubKeyMiddleware)(nil), "cosmos.authn.v1.SetPubKeyMiddleware") + proto.RegisterType((*ValidateSigCountMiddleware)(nil), "cosmos.authn.v1.ValidateSigCountMiddleware") + proto.RegisterType((*SigGasConsumeMiddleware)(nil), "cosmos.authn.v1.SigGasConsumeMiddleware") + proto.RegisterType((*SigVerificationMiddleware)(nil), "cosmos.authn.v1.SigVerificationMiddleware") + proto.RegisterType((*IncrementSequenceMiddleware)(nil), "cosmos.authn.v1.IncrementSequenceMiddleware") +} + +func init() { proto.RegisterFile("cosmos/authn/v1/middleware.proto", fileDescriptor_b60099c6a9247712) } + +var fileDescriptor_b60099c6a9247712 = []byte{ + // 430 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x92, 0x4f, 0x6b, 0xd4, 0x40, + 0x18, 0xc6, 0x37, 0x56, 0x04, 0x07, 0x41, 0x4c, 0xdd, 0x76, 0x6b, 0x69, 0x58, 0x82, 0x87, 0x5e, + 0x4c, 0x4c, 0x65, 0x85, 0x5e, 0x7a, 0xe8, 0xa2, 0x55, 0xb4, 0x50, 0x9b, 0xd2, 0x83, 0x97, 0x61, + 0x32, 0x79, 0xcd, 0x0e, 0x9b, 0xc9, 0xc4, 0x99, 0x37, 0xdb, 0xa4, 0x9f, 0xc2, 0x4f, 0xe4, 0xd9, + 0x63, 0x8f, 0x1e, 0x65, 0xf7, 0x8b, 0x48, 0xfe, 0xec, 0x1a, 0x7b, 0x0a, 0xe4, 0x79, 0x7f, 0xbf, + 0x79, 0x66, 0x78, 0xc9, 0x98, 0x2b, 0x23, 0x95, 0xf1, 0x59, 0x81, 0xb3, 0xcc, 0x5f, 0x04, 0xbe, + 0x14, 0x71, 0x9c, 0xc2, 0x0d, 0xd3, 0xe0, 0xe5, 0x5a, 0xa1, 0xb2, 0x9f, 0xb6, 0x13, 0x5e, 0x33, + 0xe1, 0x2d, 0x02, 0xf7, 0x03, 0xd9, 0xb9, 0x66, 0xa9, 0x88, 0x19, 0xc2, 0x39, 0x48, 0x75, 0xbe, + 0x01, 0x6c, 0x8f, 0x6c, 0x4b, 0x56, 0x52, 0x09, 0x52, 0x51, 0x3e, 0x63, 0x9a, 0x71, 0x04, 0x6d, + 0x46, 0xd6, 0xd8, 0x3a, 0x7c, 0x78, 0xf9, 0x4c, 0xb2, 0xb2, 0x9e, 0x9f, 0x6e, 0x02, 0xf7, 0x0b, + 0x39, 0x98, 0xaa, 0xcc, 0x14, 0x12, 0xce, 0x98, 0x79, 0xaf, 0xf4, 0x55, 0x19, 0x8a, 0x5b, 0xe8, + 0x09, 0x5f, 0x93, 0x21, 0x96, 0xd4, 0x88, 0x5b, 0xa0, 0x5c, 0x19, 0xa4, 0x39, 0x68, 0x1a, 0x55, + 0x08, 0x6b, 0x25, 0x36, 0xc0, 0x54, 0x19, 0xbc, 0x00, 0x7d, 0x5a, 0x21, 0xb8, 0x43, 0xb2, 0x1d, + 0x02, 0x5e, 0x14, 0xd1, 0x27, 0xa8, 0xfe, 0x89, 0xdc, 0x13, 0xf2, 0x62, 0xdd, 0x39, 0x14, 0xc9, + 0x54, 0x15, 0x19, 0xf6, 0x8e, 0x19, 0x93, 0x27, 0xcd, 0x31, 0x09, 0x4d, 0x85, 0x14, 0xd8, 0xd9, + 0x49, 0x6d, 0x4f, 0x3e, 0xd7, 0x7f, 0xdc, 0x9f, 0x16, 0xd9, 0x0d, 0x45, 0x72, 0xc6, 0x4c, 0x57, + 0xb8, 0x47, 0x4f, 0xc8, 0x6e, 0x8d, 0x2e, 0x40, 0x8b, 0x6f, 0x55, 0xdb, 0x13, 0xe2, 0xa3, 0xc9, + 0x24, 0x38, 0xee, 0x44, 0xcf, 0x8d, 0x48, 0xae, 0x9b, 0xb4, 0x6e, 0xfa, 0xae, 0xcd, 0xec, 0x63, + 0xb2, 0x77, 0x1f, 0x33, 0xc0, 0xf3, 0xa3, 0xc9, 0xdb, 0x79, 0x30, 0x7a, 0xd0, 0x80, 0x3b, 0xff, + 0x81, 0xe1, 0x3a, 0xb5, 0x03, 0x32, 0x64, 0x69, 0xaa, 0x6e, 0x20, 0xa6, 0x79, 0x11, 0xd1, 0x39, + 0x54, 0x14, 0xab, 0x1c, 0xcc, 0x68, 0x6b, 0xbc, 0x75, 0xf8, 0xf8, 0xd2, 0xee, 0xc2, 0xf6, 0x15, + 0xae, 0xea, 0xc4, 0xdd, 0x27, 0x7b, 0x61, 0x27, 0x13, 0x9c, 0xa1, 0x50, 0x59, 0xef, 0x75, 0x0e, + 0xc8, 0xfe, 0xc7, 0x8c, 0x6b, 0x90, 0x90, 0x61, 0x08, 0xdf, 0x0b, 0xc8, 0x78, 0xef, 0x82, 0xa7, + 0x27, 0xbf, 0x96, 0x8e, 0x75, 0xb7, 0x74, 0xac, 0x3f, 0x4b, 0xc7, 0xfa, 0xb1, 0x72, 0x06, 0x77, + 0x2b, 0x67, 0xf0, 0x7b, 0xe5, 0x0c, 0xbe, 0xbe, 0x4c, 0x04, 0xce, 0x8a, 0xc8, 0xe3, 0x4a, 0xfa, + 0xdd, 0x22, 0xb5, 0x9f, 0x57, 0x26, 0x9e, 0xfb, 0x65, 0xbb, 0x55, 0xd1, 0xa3, 0x66, 0x91, 0xde, + 0xfc, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xa7, 0x90, 0x66, 0x0f, 0x6c, 0x02, 0x00, 0x00, +} + +func (m *ValidateMemoMiddleware) 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 *ValidateMemoMiddleware) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidateMemoMiddleware) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.MaxMemoCharacters != 0 { + i = encodeVarintMiddleware(dAtA, i, uint64(m.MaxMemoCharacters)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *ConsumeGasForTxSizeMiddleware) 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 *ConsumeGasForTxSizeMiddleware) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ConsumeGasForTxSizeMiddleware) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.TxSizeCostPerByte != 0 { + i = encodeVarintMiddleware(dAtA, i, uint64(m.TxSizeCostPerByte)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *SetPubKeyMiddleware) 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 *SetPubKeyMiddleware) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SetPubKeyMiddleware) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *ValidateSigCountMiddleware) 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 *ValidateSigCountMiddleware) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidateSigCountMiddleware) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.TxSigLimit != 0 { + i = encodeVarintMiddleware(dAtA, i, uint64(m.TxSigLimit)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *SigGasConsumeMiddleware) 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 *SigGasConsumeMiddleware) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SigGasConsumeMiddleware) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.AllowedPubKeyTypes) > 0 { + for iNdEx := len(m.AllowedPubKeyTypes) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.AllowedPubKeyTypes[iNdEx]) + copy(dAtA[i:], m.AllowedPubKeyTypes[iNdEx]) + i = encodeVarintMiddleware(dAtA, i, uint64(len(m.AllowedPubKeyTypes[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + if m.SigVerifyCostSecp256K1 != 0 { + i = encodeVarintMiddleware(dAtA, i, uint64(m.SigVerifyCostSecp256K1)) + i-- + dAtA[i] = 0x10 + } + if m.SigVerifyCostEd25519 != 0 { + i = encodeVarintMiddleware(dAtA, i, uint64(m.SigVerifyCostEd25519)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *SigVerificationMiddleware) 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 *SigVerificationMiddleware) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SigVerificationMiddleware) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *IncrementSequenceMiddleware) 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 *IncrementSequenceMiddleware) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *IncrementSequenceMiddleware) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintMiddleware(dAtA []byte, offset int, v uint64) int { + offset -= sovMiddleware(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ValidateMemoMiddleware) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.MaxMemoCharacters != 0 { + n += 1 + sovMiddleware(uint64(m.MaxMemoCharacters)) + } + return n +} + +func (m *ConsumeGasForTxSizeMiddleware) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.TxSizeCostPerByte != 0 { + n += 1 + sovMiddleware(uint64(m.TxSizeCostPerByte)) + } + return n +} + +func (m *SetPubKeyMiddleware) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *ValidateSigCountMiddleware) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.TxSigLimit != 0 { + n += 1 + sovMiddleware(uint64(m.TxSigLimit)) + } + return n +} + +func (m *SigGasConsumeMiddleware) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.SigVerifyCostEd25519 != 0 { + n += 1 + sovMiddleware(uint64(m.SigVerifyCostEd25519)) + } + if m.SigVerifyCostSecp256K1 != 0 { + n += 1 + sovMiddleware(uint64(m.SigVerifyCostSecp256K1)) + } + if len(m.AllowedPubKeyTypes) > 0 { + for _, s := range m.AllowedPubKeyTypes { + l = len(s) + n += 1 + l + sovMiddleware(uint64(l)) + } + } + return n +} + +func (m *SigVerificationMiddleware) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *IncrementSequenceMiddleware) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovMiddleware(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozMiddleware(x uint64) (n int) { + return sovMiddleware(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *ValidateMemoMiddleware) 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 ErrIntOverflowMiddleware + } + 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: ValidateMemoMiddleware: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidateMemoMiddleware: 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 ErrIntOverflowMiddleware + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxMemoCharacters |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipMiddleware(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthMiddleware + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ConsumeGasForTxSizeMiddleware) 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 ErrIntOverflowMiddleware + } + 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: ConsumeGasForTxSizeMiddleware: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ConsumeGasForTxSizeMiddleware: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowMiddleware + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TxSizeCostPerByte |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipMiddleware(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthMiddleware + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SetPubKeyMiddleware) 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 ErrIntOverflowMiddleware + } + 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: SetPubKeyMiddleware: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SetPubKeyMiddleware: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipMiddleware(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthMiddleware + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidateSigCountMiddleware) 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 ErrIntOverflowMiddleware + } + 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: ValidateSigCountMiddleware: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidateSigCountMiddleware: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowMiddleware + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TxSigLimit |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipMiddleware(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthMiddleware + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SigGasConsumeMiddleware) 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 ErrIntOverflowMiddleware + } + 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: SigGasConsumeMiddleware: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SigGasConsumeMiddleware: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowMiddleware + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SigVerifyCostEd25519 |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + 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 ErrIntOverflowMiddleware + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SigVerifyCostSecp256K1 |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AllowedPubKeyTypes", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMiddleware + } + 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 ErrInvalidLengthMiddleware + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthMiddleware + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AllowedPubKeyTypes = append(m.AllowedPubKeyTypes, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipMiddleware(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthMiddleware + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SigVerificationMiddleware) 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 ErrIntOverflowMiddleware + } + 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: SigVerificationMiddleware: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SigVerificationMiddleware: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipMiddleware(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthMiddleware + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *IncrementSequenceMiddleware) 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 ErrIntOverflowMiddleware + } + 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: IncrementSequenceMiddleware: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IncrementSequenceMiddleware: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipMiddleware(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthMiddleware + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipMiddleware(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, ErrIntOverflowMiddleware + } + 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, ErrIntOverflowMiddleware + } + 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, ErrIntOverflowMiddleware + } + 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, ErrInvalidLengthMiddleware + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupMiddleware + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthMiddleware + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthMiddleware = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowMiddleware = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupMiddleware = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/authn/module.pb.go b/x/authn/module.pb.go new file mode 100644 index 000000000000..094cbf86c37a --- /dev/null +++ b/x/authn/module.pb.go @@ -0,0 +1,315 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/authn/v1/module.proto + +package authn + +import ( + fmt "fmt" + 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 + +type Module struct { + Bech32AddressPrefix string `protobuf:"bytes,6,opt,name=bech32_address_prefix,json=bech32AddressPrefix,proto3" json:"bech32_address_prefix,omitempty"` +} + +func (m *Module) Reset() { *m = Module{} } +func (m *Module) String() string { return proto.CompactTextString(m) } +func (*Module) ProtoMessage() {} +func (*Module) Descriptor() ([]byte, []int) { + return fileDescriptor_2030344d366aba92, []int{0} +} +func (m *Module) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Module) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Module.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 *Module) XXX_Merge(src proto.Message) { + xxx_messageInfo_Module.Merge(m, src) +} +func (m *Module) XXX_Size() int { + return m.Size() +} +func (m *Module) XXX_DiscardUnknown() { + xxx_messageInfo_Module.DiscardUnknown(m) +} + +var xxx_messageInfo_Module proto.InternalMessageInfo + +func (m *Module) GetBech32AddressPrefix() string { + if m != nil { + return m.Bech32AddressPrefix + } + return "" +} + +func init() { + proto.RegisterType((*Module)(nil), "cosmos.authn.v1.Module") +} + +func init() { proto.RegisterFile("cosmos/authn/v1/module.proto", fileDescriptor_2030344d366aba92) } + +var fileDescriptor_2030344d366aba92 = []byte{ + // 169 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x49, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0x2c, 0x2d, 0xc9, 0xc8, 0xd3, 0x2f, 0x33, 0xd4, 0xcf, 0xcd, 0x4f, 0x29, + 0xcd, 0x49, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x87, 0xc8, 0xea, 0x81, 0x65, 0xf5, + 0xca, 0x0c, 0x95, 0x6c, 0xb8, 0xd8, 0x7c, 0xc1, 0x0a, 0x84, 0x8c, 0xb8, 0x44, 0x93, 0x52, 0x93, + 0x33, 0x8c, 0x8d, 0xe2, 0x13, 0x53, 0x52, 0x8a, 0x52, 0x8b, 0x8b, 0xe3, 0x0b, 0x8a, 0x52, 0xd3, + 0x32, 0x2b, 0x24, 0xd8, 0x14, 0x18, 0x35, 0x38, 0x83, 0x84, 0x21, 0x92, 0x8e, 0x10, 0xb9, 0x00, + 0xb0, 0x94, 0x93, 0xdd, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, + 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0xa9, 0xa4, + 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x43, 0x5d, 0x04, 0xa1, 0x74, 0x8b, + 0x53, 0xb2, 0xf5, 0x2b, 0x20, 0xce, 0x4b, 0x62, 0x03, 0xbb, 0xca, 0x18, 0x10, 0x00, 0x00, 0xff, + 0xff, 0xe8, 0x9f, 0x7f, 0x68, 0xb5, 0x00, 0x00, 0x00, +} + +func (m *Module) 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 *Module) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Module) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Bech32AddressPrefix) > 0 { + i -= len(m.Bech32AddressPrefix) + copy(dAtA[i:], m.Bech32AddressPrefix) + i = encodeVarintModule(dAtA, i, uint64(len(m.Bech32AddressPrefix))) + i-- + dAtA[i] = 0x32 + } + return len(dAtA) - i, nil +} + +func encodeVarintModule(dAtA []byte, offset int, v uint64) int { + offset -= sovModule(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Module) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Bech32AddressPrefix) + if l > 0 { + n += 1 + l + sovModule(uint64(l)) + } + return n +} + +func sovModule(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozModule(x uint64) (n int) { + return sovModule(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Module) 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 ErrIntOverflowModule + } + 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: Module: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Module: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bech32AddressPrefix", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModule + } + 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 ErrInvalidLengthModule + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthModule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Bech32AddressPrefix = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipModule(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthModule + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipModule(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, ErrIntOverflowModule + } + 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, ErrIntOverflowModule + } + 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, ErrIntOverflowModule + } + 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, ErrInvalidLengthModule + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupModule + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthModule + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthModule = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowModule = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupModule = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/authn/module/module.go b/x/authn/module/module.go index e33a53012158..bfc00baa1b28 100644 --- a/x/authn/module/module.go +++ b/x/authn/module/module.go @@ -3,6 +3,8 @@ package module import ( "github.com/gogo/protobuf/proto" + "github.com/cosmos/cosmos-sdk/core/module/app" + "github.com/cosmos/cosmos-sdk/core/module" "github.com/cosmos/cosmos-sdk/x/authn" ) @@ -23,3 +25,11 @@ func (h handler) New(config proto.Message) module.ModuleHandler { mod := config.(*authn.Module) return handler{mod} } + +type AppModuleDeps struct { + Key app.RootModuleKey +} + +func (h handler) NewAppModule(deps AppModuleDeps) app.Module { + panic("TODO") +} diff --git a/x/authn/query.pb.go b/x/authn/query.pb.go new file mode 100644 index 000000000000..43a9529b9720 --- /dev/null +++ b/x/authn/query.pb.go @@ -0,0 +1,1062 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/authn/v1/query.proto + +package authn + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/codec/types" + query "github.com/cosmos/cosmos-sdk/types/query" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + 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 + +type QueryAccountRequest struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` +} + +func (m *QueryAccountRequest) Reset() { *m = QueryAccountRequest{} } +func (m *QueryAccountRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAccountRequest) ProtoMessage() {} +func (*QueryAccountRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_0eeceb5577b206bf, []int{0} +} +func (m *QueryAccountRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAccountRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAccountRequest.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 *QueryAccountRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAccountRequest.Merge(m, src) +} +func (m *QueryAccountRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAccountRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAccountRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAccountRequest proto.InternalMessageInfo + +func (m *QueryAccountRequest) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +type QueryAccountResponse struct { + Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` +} + +func (m *QueryAccountResponse) Reset() { *m = QueryAccountResponse{} } +func (m *QueryAccountResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAccountResponse) ProtoMessage() {} +func (*QueryAccountResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_0eeceb5577b206bf, []int{1} +} +func (m *QueryAccountResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAccountResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAccountResponse.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 *QueryAccountResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAccountResponse.Merge(m, src) +} +func (m *QueryAccountResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAccountResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAccountResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAccountResponse proto.InternalMessageInfo + +func (m *QueryAccountResponse) GetAccount() *Account { + if m != nil { + return m.Account + } + return nil +} + +type QueryAccountsRequest struct { + // pagination defines an optional pagination for the request. + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAccountsRequest) Reset() { *m = QueryAccountsRequest{} } +func (m *QueryAccountsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAccountsRequest) ProtoMessage() {} +func (*QueryAccountsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_0eeceb5577b206bf, []int{2} +} +func (m *QueryAccountsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAccountsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAccountsRequest.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 *QueryAccountsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAccountsRequest.Merge(m, src) +} +func (m *QueryAccountsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAccountsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAccountsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAccountsRequest proto.InternalMessageInfo + +func (m *QueryAccountsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +// QueryAccountsResponse is the response type for the Query/Accounts RPC method. +type QueryAccountsResponse struct { + // accounts are the existing accounts + Accounts []*Account `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"` + // pagination defines the pagination in the response. + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAccountsResponse) Reset() { *m = QueryAccountsResponse{} } +func (m *QueryAccountsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAccountsResponse) ProtoMessage() {} +func (*QueryAccountsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_0eeceb5577b206bf, []int{3} +} +func (m *QueryAccountsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAccountsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAccountsResponse.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 *QueryAccountsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAccountsResponse.Merge(m, src) +} +func (m *QueryAccountsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAccountsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAccountsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAccountsResponse proto.InternalMessageInfo + +func (m *QueryAccountsResponse) GetAccounts() []*Account { + if m != nil { + return m.Accounts + } + return nil +} + +func (m *QueryAccountsResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +func init() { + proto.RegisterType((*QueryAccountRequest)(nil), "cosmos.authn.v1.QueryAccountRequest") + proto.RegisterType((*QueryAccountResponse)(nil), "cosmos.authn.v1.QueryAccountResponse") + proto.RegisterType((*QueryAccountsRequest)(nil), "cosmos.authn.v1.QueryAccountsRequest") + proto.RegisterType((*QueryAccountsResponse)(nil), "cosmos.authn.v1.QueryAccountsResponse") +} + +func init() { proto.RegisterFile("cosmos/authn/v1/query.proto", fileDescriptor_0eeceb5577b206bf) } + +var fileDescriptor_0eeceb5577b206bf = []byte{ + // 419 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x93, 0xcf, 0x4b, 0x1b, 0x41, + 0x1c, 0xc5, 0x33, 0x29, 0x6d, 0xd2, 0xe9, 0xa1, 0x30, 0x6d, 0x21, 0xdd, 0x36, 0xdb, 0xb2, 0xe4, + 0x47, 0x5b, 0xe8, 0x0c, 0x9b, 0xf6, 0x5c, 0x68, 0x0f, 0x2d, 0xf4, 0xa4, 0x39, 0x7a, 0x10, 0x66, + 0x37, 0xe3, 0x66, 0xd1, 0xcc, 0x6c, 0x32, 0xb3, 0x41, 0x11, 0x41, 0xbc, 0x78, 0x15, 0x14, 0xff, + 0x26, 0x8f, 0x01, 0x2f, 0x1e, 0x25, 0xf1, 0x0f, 0x91, 0xcc, 0x8f, 0x98, 0x44, 0x49, 0x4e, 0x21, + 0xbc, 0xf7, 0x7d, 0xef, 0xf3, 0x9d, 0x99, 0x85, 0x1f, 0x62, 0x21, 0x7b, 0x42, 0x12, 0x9a, 0xab, + 0x2e, 0x27, 0xc3, 0x90, 0xf4, 0x73, 0x36, 0x38, 0xc0, 0xd9, 0x40, 0x28, 0x81, 0x5e, 0x1b, 0x11, + 0x6b, 0x11, 0x0f, 0x43, 0xef, 0x7d, 0x22, 0x44, 0xb2, 0xc7, 0x88, 0x96, 0xa3, 0x7c, 0x87, 0x50, + 0x6e, 0xbd, 0xde, 0x47, 0x2b, 0xd1, 0x2c, 0x25, 0x94, 0x73, 0xa1, 0xa8, 0x4a, 0x05, 0x97, 0x56, + 0xad, 0x2e, 0xd7, 0xd0, 0x38, 0x16, 0x39, 0x57, 0x56, 0xfe, 0x66, 0xe5, 0x88, 0x4a, 0x66, 0x08, + 0xc8, 0x30, 0x8c, 0x98, 0xa2, 0x21, 0xc9, 0x68, 0x92, 0x72, 0x9d, 0x65, 0xbc, 0x01, 0x81, 0x6f, + 0x36, 0xa7, 0x8e, 0xdf, 0x26, 0xa1, 0xcd, 0xfa, 0x39, 0x93, 0x0a, 0x55, 0x60, 0x89, 0x76, 0x3a, + 0x03, 0x26, 0x65, 0x05, 0x7c, 0x06, 0x5f, 0x5e, 0xb6, 0xdd, 0xdf, 0xe0, 0x3f, 0x7c, 0xbb, 0x38, + 0x20, 0x33, 0xc1, 0x25, 0x43, 0x2d, 0x58, 0xb2, 0x14, 0x7a, 0xe2, 0x55, 0xab, 0x82, 0x97, 0xf6, + 0xc5, 0x6e, 0xc4, 0x19, 0x83, 0xed, 0xc5, 0x2c, 0xe9, 0xda, 0xff, 0x42, 0xf8, 0x00, 0x6a, 0xe3, + 0x1a, 0x2e, 0x6e, 0xba, 0x15, 0x36, 0xe7, 0x6a, 0xb7, 0xc2, 0x1b, 0x34, 0x61, 0x76, 0xb6, 0x3d, + 0x37, 0x19, 0x5c, 0x02, 0xf8, 0x6e, 0xa9, 0xc0, 0xd2, 0xfe, 0x84, 0x65, 0x0b, 0x31, 0x5d, 0xf0, + 0xd9, 0x4a, 0xdc, 0x99, 0x13, 0xfd, 0x5b, 0xe0, 0x2a, 0x6a, 0xae, 0xe6, 0x5a, 0x2e, 0x53, 0x39, + 0x0f, 0xd6, 0xba, 0x28, 0xc2, 0xe7, 0x1a, 0x0c, 0x9d, 0x02, 0x58, 0xb2, 0x45, 0xa8, 0xf6, 0x08, + 0xe1, 0x89, 0xab, 0xf1, 0xea, 0x6b, 0x5c, 0xa6, 0x2e, 0x20, 0x27, 0xd7, 0x77, 0xe7, 0xc5, 0xaf, + 0xa8, 0x49, 0xe6, 0x1e, 0xcb, 0xec, 0x1d, 0xb8, 0x95, 0xc8, 0xa1, 0xbd, 0xd7, 0x23, 0x74, 0x0c, + 0x60, 0xd9, 0x9d, 0x13, 0x5a, 0x5d, 0xe2, 0x2e, 0xca, 0x6b, 0xac, 0xb3, 0x59, 0x98, 0xba, 0x86, + 0xf9, 0x84, 0xaa, 0x2b, 0x61, 0xfe, 0xfc, 0xba, 0x1a, 0xfb, 0x60, 0x34, 0xf6, 0xc1, 0xed, 0xd8, + 0x07, 0x67, 0x13, 0xbf, 0x30, 0x9a, 0xf8, 0x85, 0x9b, 0x89, 0x5f, 0xd8, 0xaa, 0x25, 0xa9, 0xea, + 0xe6, 0x11, 0x8e, 0x45, 0xcf, 0x45, 0x98, 0x9f, 0xef, 0xb2, 0xb3, 0x4b, 0xf6, 0xcd, 0x97, 0x10, + 0xbd, 0xd0, 0x6f, 0xfa, 0xc7, 0x7d, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x76, 0xe7, 0xf4, 0x87, + 0x03, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Account returns account details based on address. + Account(ctx context.Context, in *QueryAccountRequest, opts ...grpc.CallOption) (*QueryAccountResponse, error) + // Accounts returns all the existing accounts + Accounts(ctx context.Context, in *QueryAccountsRequest, opts ...grpc.CallOption) (*QueryAccountsResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Account(ctx context.Context, in *QueryAccountRequest, opts ...grpc.CallOption) (*QueryAccountResponse, error) { + out := new(QueryAccountResponse) + err := c.cc.Invoke(ctx, "/cosmos.authn.v1.Query/Account", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Accounts(ctx context.Context, in *QueryAccountsRequest, opts ...grpc.CallOption) (*QueryAccountsResponse, error) { + out := new(QueryAccountsResponse) + err := c.cc.Invoke(ctx, "/cosmos.authn.v1.Query/Accounts", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Account returns account details based on address. + Account(context.Context, *QueryAccountRequest) (*QueryAccountResponse, error) + // Accounts returns all the existing accounts + Accounts(context.Context, *QueryAccountsRequest) (*QueryAccountsResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Account(ctx context.Context, req *QueryAccountRequest) (*QueryAccountResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Account not implemented") +} +func (*UnimplementedQueryServer) Accounts(ctx context.Context, req *QueryAccountsRequest) (*QueryAccountsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Accounts not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Account_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAccountRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Account(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.authn.v1.Query/Account", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Account(ctx, req.(*QueryAccountRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Accounts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAccountsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Accounts(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.authn.v1.Query/Accounts", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Accounts(ctx, req.(*QueryAccountsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "cosmos.authn.v1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Account", + Handler: _Query_Account_Handler, + }, + { + MethodName: "Accounts", + Handler: _Query_Accounts_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "cosmos/authn/v1/query.proto", +} + +func (m *QueryAccountRequest) 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 *QueryAccountRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAccountRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAccountResponse) 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 *QueryAccountResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAccountResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Account != nil { + { + size, err := m.Account.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAccountsRequest) 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 *QueryAccountsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAccountsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAccountsResponse) 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 *QueryAccountsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAccountsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Accounts) > 0 { + for iNdEx := len(m.Accounts) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Accounts[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryAccountRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAccountResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Account != nil { + l = m.Account.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAccountsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAccountsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Accounts) > 0 { + for _, e := range m.Accounts { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryAccountRequest) 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 ErrIntOverflowQuery + } + 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: QueryAccountRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAccountRequest: 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 stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAccountResponse) 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 ErrIntOverflowQuery + } + 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: QueryAccountResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAccountResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Account", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Account == nil { + m.Account = &Account{} + } + if err := m.Account.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAccountsRequest) 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 ErrIntOverflowQuery + } + 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: QueryAccountsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAccountsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAccountsResponse) 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 ErrIntOverflowQuery + } + 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: QueryAccountsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAccountsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Accounts", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Accounts = append(m.Accounts, &Account{}) + if err := m.Accounts[len(m.Accounts)-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 Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(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, ErrIntOverflowQuery + } + 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, ErrIntOverflowQuery + } + 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, ErrIntOverflowQuery + } + 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, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/authn/query.pb.gw.go b/x/authn/query.pb.gw.go new file mode 100644 index 000000000000..dd1fd442d46e --- /dev/null +++ b/x/authn/query.pb.gw.go @@ -0,0 +1,169 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: cosmos/authn/v1/query.proto + +/* +Package authn is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package authn + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/status" +) + +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray + +func request_Query_Account_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) + } + + msg, err := client.Account(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +var ( + filter_Query_Accounts_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Accounts_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Accounts_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Accounts(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Account_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Account_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Account_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Accounts_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Accounts_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Accounts_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Account_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"cosmos", "auth", "v1beta1", "accounts", "address"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Accounts_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "auth", "v1beta1", "accounts"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Account_0 = runtime.ForwardResponseMessage + + forward_Query_Accounts_0 = runtime.ForwardResponseMessage +) diff --git a/x/authn/tx.pb.go b/x/authn/tx.pb.go new file mode 100644 index 000000000000..91b5cb9d47d9 --- /dev/null +++ b/x/authn/tx.pb.go @@ -0,0 +1,585 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/authn/v1/tx.proto + +package authn + +import ( + context "context" + fmt "fmt" + types "github.com/cosmos/cosmos-sdk/codec/types" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + 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 + +type MsgSetCredentialRequest struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + Credential *types.Any `protobuf:"bytes,2,opt,name=credential,proto3" json:"credential,omitempty"` +} + +func (m *MsgSetCredentialRequest) Reset() { *m = MsgSetCredentialRequest{} } +func (m *MsgSetCredentialRequest) String() string { return proto.CompactTextString(m) } +func (*MsgSetCredentialRequest) ProtoMessage() {} +func (*MsgSetCredentialRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_6d24043d5ffd805d, []int{0} +} +func (m *MsgSetCredentialRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSetCredentialRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSetCredentialRequest.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 *MsgSetCredentialRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSetCredentialRequest.Merge(m, src) +} +func (m *MsgSetCredentialRequest) XXX_Size() int { + return m.Size() +} +func (m *MsgSetCredentialRequest) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSetCredentialRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSetCredentialRequest proto.InternalMessageInfo + +func (m *MsgSetCredentialRequest) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *MsgSetCredentialRequest) GetCredential() *types.Any { + if m != nil { + return m.Credential + } + return nil +} + +type MsgSetCredentialResponse struct { +} + +func (m *MsgSetCredentialResponse) Reset() { *m = MsgSetCredentialResponse{} } +func (m *MsgSetCredentialResponse) String() string { return proto.CompactTextString(m) } +func (*MsgSetCredentialResponse) ProtoMessage() {} +func (*MsgSetCredentialResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_6d24043d5ffd805d, []int{1} +} +func (m *MsgSetCredentialResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSetCredentialResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSetCredentialResponse.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 *MsgSetCredentialResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSetCredentialResponse.Merge(m, src) +} +func (m *MsgSetCredentialResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgSetCredentialResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSetCredentialResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSetCredentialResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgSetCredentialRequest)(nil), "cosmos.authn.v1.MsgSetCredentialRequest") + proto.RegisterType((*MsgSetCredentialResponse)(nil), "cosmos.authn.v1.MsgSetCredentialResponse") +} + +func init() { proto.RegisterFile("cosmos/authn/v1/tx.proto", fileDescriptor_6d24043d5ffd805d) } + +var fileDescriptor_6d24043d5ffd805d = []byte{ + // 256 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x48, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0x2c, 0x2d, 0xc9, 0xc8, 0xd3, 0x2f, 0x33, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, + 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x87, 0xc8, 0xe8, 0x81, 0x65, 0xf4, 0xca, 0x0c, 0xa5, 0x24, + 0xd3, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0xc1, 0xd2, 0x49, 0xa5, 0x69, 0xfa, 0x89, 0x79, 0x95, + 0x10, 0xb5, 0x4a, 0x99, 0x5c, 0xe2, 0xbe, 0xc5, 0xe9, 0xc1, 0xa9, 0x25, 0xce, 0x45, 0xa9, 0x29, + 0xa9, 0x79, 0x25, 0x99, 0x89, 0x39, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x42, 0x12, 0x5c, + 0xec, 0x89, 0x29, 0x29, 0x45, 0xa9, 0xc5, 0xc5, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x30, + 0xae, 0x90, 0x09, 0x17, 0x57, 0x32, 0x5c, 0xb9, 0x04, 0x93, 0x02, 0xa3, 0x06, 0xb7, 0x91, 0x88, + 0x1e, 0xc4, 0x12, 0x3d, 0x98, 0x25, 0x7a, 0x8e, 0x79, 0x95, 0x41, 0x48, 0xea, 0x94, 0xa4, 0xb8, + 0x24, 0x30, 0xad, 0x2a, 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0x35, 0xca, 0xe5, 0x62, 0xf6, 0x2d, 0x4e, + 0x17, 0x4a, 0xe3, 0xe2, 0x45, 0x91, 0x17, 0xd2, 0xd0, 0x43, 0xf3, 0x8b, 0x1e, 0x0e, 0xd7, 0x4a, + 0x69, 0x12, 0xa1, 0x12, 0x62, 0x99, 0x12, 0x83, 0x93, 0xdd, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, + 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, + 0x1e, 0xcb, 0x31, 0x44, 0xa9, 0xa4, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, + 0x43, 0x03, 0x18, 0x42, 0xe9, 0x16, 0xa7, 0x64, 0xeb, 0x57, 0x40, 0x42, 0x3b, 0x89, 0x0d, 0xec, + 0x49, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2d, 0x36, 0xe4, 0xe5, 0x84, 0x01, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + SetCredential(ctx context.Context, in *MsgSetCredentialRequest, opts ...grpc.CallOption) (*MsgSetCredentialResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) SetCredential(ctx context.Context, in *MsgSetCredentialRequest, opts ...grpc.CallOption) (*MsgSetCredentialResponse, error) { + out := new(MsgSetCredentialResponse) + err := c.cc.Invoke(ctx, "/cosmos.authn.v1.Msg/SetCredential", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + SetCredential(context.Context, *MsgSetCredentialRequest) (*MsgSetCredentialResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) SetCredential(ctx context.Context, req *MsgSetCredentialRequest) (*MsgSetCredentialResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SetCredential not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_SetCredential_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgSetCredentialRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).SetCredential(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.authn.v1.Msg/SetCredential", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).SetCredential(ctx, req.(*MsgSetCredentialRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "cosmos.authn.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "SetCredential", + Handler: _Msg_SetCredential_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "cosmos/authn/v1/tx.proto", +} + +func (m *MsgSetCredentialRequest) 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 *MsgSetCredentialRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSetCredentialRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Credential != nil { + { + size, err := m.Credential.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintTx(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgSetCredentialResponse) 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 *MsgSetCredentialResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSetCredentialResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgSetCredentialRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Credential != nil { + l = m.Credential.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgSetCredentialResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgSetCredentialRequest) 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 ErrIntOverflowTx + } + 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: MsgSetCredentialRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSetCredentialRequest: 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 stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Credential", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Credential == nil { + m.Credential = &types.Any{} + } + if err := m.Credential.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgSetCredentialResponse) 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 ErrIntOverflowTx + } + 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: MsgSetCredentialResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSetCredentialResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/bank/types/middleware.pb.go b/x/bank/types/middleware.pb.go new file mode 100644 index 000000000000..cec2eeca60d8 --- /dev/null +++ b/x/bank/types/middleware.pb.go @@ -0,0 +1,265 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/bank/v1beta1/middleware.proto + +package types + +import ( + fmt "fmt" + 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 + +type DeductFeeMiddleware struct { +} + +func (m *DeductFeeMiddleware) Reset() { *m = DeductFeeMiddleware{} } +func (m *DeductFeeMiddleware) String() string { return proto.CompactTextString(m) } +func (*DeductFeeMiddleware) ProtoMessage() {} +func (*DeductFeeMiddleware) Descriptor() ([]byte, []int) { + return fileDescriptor_94643f1e5ddc348a, []int{0} +} +func (m *DeductFeeMiddleware) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DeductFeeMiddleware) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DeductFeeMiddleware.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 *DeductFeeMiddleware) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeductFeeMiddleware.Merge(m, src) +} +func (m *DeductFeeMiddleware) XXX_Size() int { + return m.Size() +} +func (m *DeductFeeMiddleware) XXX_DiscardUnknown() { + xxx_messageInfo_DeductFeeMiddleware.DiscardUnknown(m) +} + +var xxx_messageInfo_DeductFeeMiddleware proto.InternalMessageInfo + +func init() { + proto.RegisterType((*DeductFeeMiddleware)(nil), "cosmos.bank.v1beta1.DeductFeeMiddleware") +} + +func init() { + proto.RegisterFile("cosmos/bank/v1beta1/middleware.proto", fileDescriptor_94643f1e5ddc348a) +} + +var fileDescriptor_94643f1e5ddc348a = []byte{ + // 151 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x49, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0x4a, 0xcc, 0xcb, 0xd6, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, + 0xcf, 0xcd, 0x4c, 0x49, 0xc9, 0x49, 0x2d, 0x4f, 0x2c, 0x4a, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x12, 0x86, 0xa8, 0xd2, 0x03, 0xa9, 0xd2, 0x83, 0xaa, 0x52, 0x12, 0xe5, 0x12, 0x76, 0x49, + 0x4d, 0x29, 0x4d, 0x2e, 0x71, 0x4b, 0x4d, 0xf5, 0x85, 0xeb, 0x70, 0x72, 0x3e, 0xf1, 0x48, 0x8e, + 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, + 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xcd, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, + 0xfc, 0x5c, 0x7d, 0xa8, 0xb5, 0x10, 0x4a, 0xb7, 0x38, 0x25, 0x5b, 0xbf, 0x02, 0xe2, 0x86, 0x92, + 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0xb0, 0xbd, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x72, + 0x9f, 0xf1, 0x59, 0x9f, 0x00, 0x00, 0x00, +} + +func (m *DeductFeeMiddleware) 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 *DeductFeeMiddleware) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DeductFeeMiddleware) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintMiddleware(dAtA []byte, offset int, v uint64) int { + offset -= sovMiddleware(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *DeductFeeMiddleware) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovMiddleware(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozMiddleware(x uint64) (n int) { + return sovMiddleware(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *DeductFeeMiddleware) 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 ErrIntOverflowMiddleware + } + 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: DeductFeeMiddleware: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DeductFeeMiddleware: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipMiddleware(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthMiddleware + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipMiddleware(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, ErrIntOverflowMiddleware + } + 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, ErrIntOverflowMiddleware + } + 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, ErrIntOverflowMiddleware + } + 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, ErrInvalidLengthMiddleware + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupMiddleware + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthMiddleware + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthMiddleware = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowMiddleware = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupMiddleware = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/bank/types/module.pb.go b/x/bank/types/module.pb.go new file mode 100644 index 000000000000..6d56edf55ea9 --- /dev/null +++ b/x/bank/types/module.pb.go @@ -0,0 +1,319 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/bank/v1beta1/module.proto + +package types + +import ( + fmt "fmt" + 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 + +type Module struct { + SendDenyList []string `protobuf:"bytes,1,rep,name=send_deny_list,json=sendDenyList,proto3" json:"send_deny_list,omitempty"` +} + +func (m *Module) Reset() { *m = Module{} } +func (m *Module) String() string { return proto.CompactTextString(m) } +func (*Module) ProtoMessage() {} +func (*Module) Descriptor() ([]byte, []int) { + return fileDescriptor_2d644efccd29e8d3, []int{0} +} +func (m *Module) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Module) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Module.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 *Module) XXX_Merge(src proto.Message) { + xxx_messageInfo_Module.Merge(m, src) +} +func (m *Module) XXX_Size() int { + return m.Size() +} +func (m *Module) XXX_DiscardUnknown() { + xxx_messageInfo_Module.DiscardUnknown(m) +} + +var xxx_messageInfo_Module proto.InternalMessageInfo + +func (m *Module) GetSendDenyList() []string { + if m != nil { + return m.SendDenyList + } + return nil +} + +func init() { + proto.RegisterType((*Module)(nil), "cosmos.bank.v1beta1.Module") +} + +func init() { proto.RegisterFile("cosmos/bank/v1beta1/module.proto", fileDescriptor_2d644efccd29e8d3) } + +var fileDescriptor_2d644efccd29e8d3 = []byte{ + // 174 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0x4a, 0xcc, 0xcb, 0xd6, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, + 0xcf, 0xcd, 0x4f, 0x29, 0xcd, 0x49, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, 0xa8, + 0xd0, 0x03, 0xa9, 0xd0, 0x83, 0xaa, 0x50, 0xd2, 0xe3, 0x62, 0xf3, 0x05, 0x2b, 0x12, 0x52, 0xe1, + 0xe2, 0x2b, 0x4e, 0xcd, 0x4b, 0x89, 0x4f, 0x49, 0xcd, 0xab, 0x8c, 0xcf, 0xc9, 0x2c, 0x2e, 0x91, + 0x60, 0x54, 0x60, 0xd6, 0xe0, 0x0c, 0xe2, 0x01, 0x89, 0xba, 0xa4, 0xe6, 0x55, 0xfa, 0x64, 0x16, + 0x97, 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, 0x66, 0x7a, + 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0xd4, 0x2d, 0x10, 0x4a, 0xb7, 0x38, + 0x25, 0x5b, 0xbf, 0x02, 0xe2, 0xb0, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0xb0, 0x83, 0x8c, + 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x06, 0x38, 0xca, 0x0a, 0xb4, 0x00, 0x00, 0x00, +} + +func (m *Module) 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 *Module) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Module) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.SendDenyList) > 0 { + for iNdEx := len(m.SendDenyList) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.SendDenyList[iNdEx]) + copy(dAtA[i:], m.SendDenyList[iNdEx]) + i = encodeVarintModule(dAtA, i, uint64(len(m.SendDenyList[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintModule(dAtA []byte, offset int, v uint64) int { + offset -= sovModule(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Module) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.SendDenyList) > 0 { + for _, s := range m.SendDenyList { + l = len(s) + n += 1 + l + sovModule(uint64(l)) + } + } + return n +} + +func sovModule(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozModule(x uint64) (n int) { + return sovModule(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Module) 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 ErrIntOverflowModule + } + 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: Module: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Module: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SendDenyList", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModule + } + 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 ErrInvalidLengthModule + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthModule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SendDenyList = append(m.SendDenyList, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipModule(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthModule + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipModule(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, ErrIntOverflowModule + } + 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, ErrIntOverflowModule + } + 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, ErrIntOverflowModule + } + 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, ErrInvalidLengthModule + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupModule + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthModule + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthModule = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowModule = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupModule = fmt.Errorf("proto: unexpected end of group") +) From 232b9378a78bc367ae06dee12fbbd88e3ce333a4 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 26 May 2021 21:12:37 -0400 Subject: [PATCH 06/19] add middleware example --- core/module/app/middleware.go | 7 +--- core/module/app/module.go | 4 ++- x/authn/app/module.go | 62 +++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 x/authn/app/module.go diff --git a/core/module/app/middleware.go b/core/module/app/middleware.go index 7e0181f929fb..24e786e8c8d6 100644 --- a/core/module/app/middleware.go +++ b/core/module/app/middleware.go @@ -3,14 +3,9 @@ package app import ( "context" - "github.com/gogo/protobuf/proto" - "github.com/cosmos/cosmos-sdk/types/tx" ) -type TxMiddlewareHandler interface { - ConfigType() proto.Message - Init(config proto.Message) TxMiddleware -} +type TxMiddlewareFactory func(interface{}) TxMiddleware type TxMiddleware func(ctx context.Context, tx tx.Tx, next TxMiddleware) error diff --git a/core/module/app/module.go b/core/module/app/module.go index 07356110b40e..24e7680b5ab6 100644 --- a/core/module/app/module.go +++ b/core/module/app/module.go @@ -3,6 +3,8 @@ package app import ( "encoding/json" + "github.com/gogo/protobuf/proto" + abci "github.com/tendermint/tendermint/abci/types" "google.golang.org/grpc" @@ -40,5 +42,5 @@ type HasTxMiddleware interface { } type TxMiddlewareRegistrar interface { - RegisterHandler(handler TxMiddlewareHandler) + RegisterTxMiddlewareFactory(configType proto.Message, factory TxMiddlewareFactory) } diff --git a/x/authn/app/module.go b/x/authn/app/module.go new file mode 100644 index 000000000000..4a9f076848fe --- /dev/null +++ b/x/authn/app/module.go @@ -0,0 +1,62 @@ +package app + +import ( + "context" + "encoding/json" + + abci "github.com/tendermint/tendermint/abci/types" + "google.golang.org/grpc" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/core/module/app" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/x/authn" +) + +type Module struct { + *authn.Module + Key app.RootModuleKey +} + +var _ app.Module = &Module{} +var _ app.HasTxMiddleware = &Module{} + +func (m *Module) RegisterTypes(registry types.InterfaceRegistry) { + panic("implement me") +} + +func (m *Module) InitGenesis(context sdk.Context, codec codec.JSONCodec, message json.RawMessage) []abci.ValidatorUpdate { + panic("implement me") +} + +func (m *Module) ExportGenesis(context sdk.Context, codec codec.JSONCodec) json.RawMessage { + panic("implement me") +} + +func (m *Module) RegisterMsgServices(registrar grpc.ServiceRegistrar) { + panic("implement me") +} + +func (m *Module) RegisterQueryServices(registrar grpc.ServiceRegistrar) { + panic("implement me") +} + +func (m *Module) RegisterTxMiddleware(registrar app.TxMiddlewareRegistrar) { + registrar.RegisterTxMiddlewareFactory(&authn.ValidateMemoMiddleware{}, func(i interface{}) app.TxMiddleware { + cfg := i.(*authn.ValidateMemoMiddleware) + return func(ctx context.Context, tx tx.Tx, next app.TxMiddleware) error { + memoLength := len(tx.Body.Memo) + if uint64(memoLength) > cfg.MaxMemoCharacters { + return sdkerrors.Wrapf(sdkerrors.ErrMemoTooLarge, + "maximum number of characters is %d but received %d characters", + cfg.MaxMemoCharacters, memoLength, + ) + } + + return nil + } + }) +} From 0e0db4a053abe5f23654f48ede302cb64dd1eae6 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 26 May 2021 21:48:54 -0400 Subject: [PATCH 07/19] update middleware example --- core/module/app/middleware.go | 26 +++++++++++++++++-- core/module/app/module.go | 12 --------- core/module/app/plugins.go | 13 ++++++++++ x/authn/app/middleware.go | 48 +++++++++++++++++++++++++++++++++++ x/authn/app/module.go | 18 ++----------- 5 files changed, 87 insertions(+), 30 deletions(-) create mode 100644 core/module/app/plugins.go create mode 100644 x/authn/app/middleware.go diff --git a/core/module/app/middleware.go b/core/module/app/middleware.go index 24e786e8c8d6..431c5038ff43 100644 --- a/core/module/app/middleware.go +++ b/core/module/app/middleware.go @@ -3,9 +3,31 @@ package app import ( "context" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/gogo/protobuf/proto" + "github.com/cosmos/cosmos-sdk/types/tx" ) -type TxMiddlewareFactory func(interface{}) TxMiddleware +type HasTxMiddleware interface { + Module + + RegisterTxMiddleware(registrar TxMiddlewareRegistrar) +} + +type TxMiddlewareRegistrar interface { + RegisterTxMiddlewareFactory(configType proto.Message, factory TxMiddlewareFactory) +} + +type TxMiddlewareFactory func(config interface{}) TxMiddleware + +type TxMiddleware interface { + OnCheckTx(ctx context.Context, tx tx.Tx, req abci.RequestCheckTx, next TxHandler) (abci.ResponseCheckTx, error) + OnDeliverTx(ctx context.Context, tx tx.Tx, req abci.RequestDeliverTx, next TxHandler) (abci.ResponseDeliverTx, error) +} -type TxMiddleware func(ctx context.Context, tx tx.Tx, next TxMiddleware) error +type TxHandler interface { + CheckTx(ctx context.Context, tx tx.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) + DeliverTx(ctx context.Context, tx tx.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) +} diff --git a/core/module/app/module.go b/core/module/app/module.go index 24e7680b5ab6..f67c5ce1a03d 100644 --- a/core/module/app/module.go +++ b/core/module/app/module.go @@ -3,8 +3,6 @@ package app import ( "encoding/json" - "github.com/gogo/protobuf/proto" - abci "github.com/tendermint/tendermint/abci/types" "google.golang.org/grpc" @@ -34,13 +32,3 @@ type EndBlocker interface { EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate } - -type HasTxMiddleware interface { - Module - - RegisterTxMiddleware(registrar TxMiddlewareRegistrar) -} - -type TxMiddlewareRegistrar interface { - RegisterTxMiddlewareFactory(configType proto.Message, factory TxMiddlewareFactory) -} diff --git a/core/module/app/plugins.go b/core/module/app/plugins.go new file mode 100644 index 000000000000..9231999d0fca --- /dev/null +++ b/core/module/app/plugins.go @@ -0,0 +1,13 @@ +package app + +import "google.golang.org/grpc" + +type HasPlugins interface { + Module + + RegisterPlugins(registrar grpc.ServiceRegistrar) +} + +type PluginRegistrar interface { + RegisterPluginService(desc *grpc.ServiceDesc, impl interface{}) +} diff --git a/x/authn/app/middleware.go b/x/authn/app/middleware.go new file mode 100644 index 000000000000..c8775725e6b7 --- /dev/null +++ b/x/authn/app/middleware.go @@ -0,0 +1,48 @@ +package app + +import ( + "context" + + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/core/module/app" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/x/authn" +) + +type validateMemoMiddlewareHandler struct { + *authn.ValidateMemoMiddleware +} + +func (v validateMemoMiddlewareHandler) validate(tx tx.Tx) error { + memoLength := len(tx.Body.Memo) + if uint64(memoLength) > v.MaxMemoCharacters { + return sdkerrors.Wrapf(sdkerrors.ErrMemoTooLarge, + "maximum number of characters is %d but received %d characters", + v.MaxMemoCharacters, memoLength, + ) + } + + return nil +} + +func (v validateMemoMiddlewareHandler) OnCheckTx(ctx context.Context, tx tx.Tx, req abci.RequestCheckTx, next app.TxHandler) (abci.ResponseCheckTx, error) { + err := v.validate(tx) + if err != nil { + return abci.ResponseCheckTx{}, err + } + + return next.CheckTx(ctx, tx, req) +} + +func (v validateMemoMiddlewareHandler) OnDeliverTx(ctx context.Context, tx tx.Tx, req abci.RequestDeliverTx, next app.TxHandler) (abci.ResponseDeliverTx, error) { + err := v.validate(tx) + if err != nil { + return abci.ResponseDeliverTx{}, err + } + + return next.DeliverTx(ctx, tx, req) +} + +var _ app.TxMiddleware = validateMemoMiddlewareHandler{} diff --git a/x/authn/app/module.go b/x/authn/app/module.go index 4a9f076848fe..db6f171e3a4d 100644 --- a/x/authn/app/module.go +++ b/x/authn/app/module.go @@ -1,7 +1,6 @@ package app import ( - "context" "encoding/json" abci "github.com/tendermint/tendermint/abci/types" @@ -11,8 +10,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/core/module/app" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/authn" ) @@ -45,18 +42,7 @@ func (m *Module) RegisterQueryServices(registrar grpc.ServiceRegistrar) { } func (m *Module) RegisterTxMiddleware(registrar app.TxMiddlewareRegistrar) { - registrar.RegisterTxMiddlewareFactory(&authn.ValidateMemoMiddleware{}, func(i interface{}) app.TxMiddleware { - cfg := i.(*authn.ValidateMemoMiddleware) - return func(ctx context.Context, tx tx.Tx, next app.TxMiddleware) error { - memoLength := len(tx.Body.Memo) - if uint64(memoLength) > cfg.MaxMemoCharacters { - return sdkerrors.Wrapf(sdkerrors.ErrMemoTooLarge, - "maximum number of characters is %d but received %d characters", - cfg.MaxMemoCharacters, memoLength, - ) - } - - return nil - } + registrar.RegisterTxMiddlewareFactory(&authn.ValidateMemoMiddleware{}, func(config interface{}) app.TxMiddleware { + return validateMemoMiddlewareHandler{config.(*authn.ValidateMemoMiddleware)} }) } From 62b1c9ff86df6ae0d3d1a70a606c5825bf6d178c Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 26 May 2021 21:51:09 -0400 Subject: [PATCH 08/19] add event listeners --- core/module/app/events.go | 15 +++++++++++++++ core/module/app/middleware.go | 4 +--- 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 core/module/app/events.go diff --git a/core/module/app/events.go b/core/module/app/events.go new file mode 100644 index 000000000000..0bdac82a67aa --- /dev/null +++ b/core/module/app/events.go @@ -0,0 +1,15 @@ +package app + +import ( + "context" +) + +type EventListener interface { + Module + + RegisterEventListeners(EventListenerRegistrar) +} + +type EventListenerRegistrar interface { + OnEvent(eventType interface{}, listener func(ctx context.Context, event interface{})) +} diff --git a/core/module/app/middleware.go b/core/module/app/middleware.go index 431c5038ff43..76d4c2af9bbe 100644 --- a/core/module/app/middleware.go +++ b/core/module/app/middleware.go @@ -5,8 +5,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" - "github.com/gogo/protobuf/proto" - "github.com/cosmos/cosmos-sdk/types/tx" ) @@ -17,7 +15,7 @@ type HasTxMiddleware interface { } type TxMiddlewareRegistrar interface { - RegisterTxMiddlewareFactory(configType proto.Message, factory TxMiddlewareFactory) + RegisterTxMiddlewareFactory(configType interface{}, factory TxMiddlewareFactory) } type TxMiddlewareFactory func(config interface{}) TxMiddleware From 777c85ab18117d8876306b982ec5e0b477ddf5d3 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 26 May 2021 21:52:45 -0400 Subject: [PATCH 09/19] add plugin support --- core/module/app/plugins.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/module/app/plugins.go b/core/module/app/plugins.go index 9231999d0fca..3265c7940bf0 100644 --- a/core/module/app/plugins.go +++ b/core/module/app/plugins.go @@ -5,9 +5,13 @@ import "google.golang.org/grpc" type HasPlugins interface { Module - RegisterPlugins(registrar grpc.ServiceRegistrar) + RegisterPlugins(registrar PluginRegistrar) } type PluginRegistrar interface { - RegisterPluginService(desc *grpc.ServiceDesc, impl interface{}) + RegisterPluginService(paramType interface{}, desc *grpc.ServiceDesc, impl interface{}) +} + +func PluginClient(pluginParam interface{}) grpc.ClientConnInterface { + panic("TODO") } From c93b20ed5a0948ed58cec7cc12e9e40a63efd43f Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 26 May 2021 22:02:22 -0400 Subject: [PATCH 10/19] start plugin example --- proto/cosmos/bank/v1beta1/denom_manager.proto | 36 +++++++++++++++++++ proto/cosmos/bank/v1beta1/module.proto | 3 ++ .../cosmos/collectible/v1alpha1/plugin.proto | 6 ++++ simapp2/app_config.json | 7 +++- 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 proto/cosmos/bank/v1beta1/denom_manager.proto create mode 100644 proto/cosmos/collectible/v1alpha1/plugin.proto diff --git a/proto/cosmos/bank/v1beta1/denom_manager.proto b/proto/cosmos/bank/v1beta1/denom_manager.proto new file mode 100644 index 000000000000..6c3bea323bdd --- /dev/null +++ b/proto/cosmos/bank/v1beta1/denom_manager.proto @@ -0,0 +1,36 @@ +syntax = "proto3"; +package cosmos.bank.v1beta1; + +option go_package = "github.com/cosmos/cosmos-sdk/x/bank/types"; + +service DenomManager { + rpc OnMint(OnMintRequest) returns (OnMintResponse); + rpc OnSend(OnSendRequest) returns (OnSendResponse); + rpc OnBurn(OnBurnRequest) returns (OnBurnResponse); +} + +message OnMintRequest { + string minter = 1; + string receiver = 2; + string denom = 3; + string amount = 4; +} + +message OnMintResponse {} + +message OnSendRequest { + string sender = 1; + string receiver = 2; + string denom = 3; + string amount = 4; +} + +message OnSendResponse {} + +message OnBurnRequest { + string burner = 1; + string denom = 2; + string amount = 3; +} + +message OnBurnResponse {} diff --git a/proto/cosmos/bank/v1beta1/module.proto b/proto/cosmos/bank/v1beta1/module.proto index 38ad1ee54b4b..94b805f32b32 100644 --- a/proto/cosmos/bank/v1beta1/module.proto +++ b/proto/cosmos/bank/v1beta1/module.proto @@ -1,8 +1,11 @@ syntax = "proto3"; package cosmos.bank.v1beta1; +import "google/protobuf/any.proto"; + option go_package = "github.com/cosmos/cosmos-sdk/x/bank/types"; message Module { repeated string send_deny_list = 1; + map denom_managers = 3; } diff --git a/proto/cosmos/collectible/v1alpha1/plugin.proto b/proto/cosmos/collectible/v1alpha1/plugin.proto new file mode 100644 index 000000000000..5da7ac588e5d --- /dev/null +++ b/proto/cosmos/collectible/v1alpha1/plugin.proto @@ -0,0 +1,6 @@ +syntax = "proto3"; +package cosmos.collectible.v1alpha1; + +option go_package = "github.com/cosmos/cosmos-sdk/x/collectible"; + +message CollectibleDenomManager {} diff --git a/simapp2/app_config.json b/simapp2/app_config.json index 093219e9cc3d..62e88caae5d4 100644 --- a/simapp2/app_config.json +++ b/simapp2/app_config.json @@ -6,7 +6,12 @@ }, "bank": { "@type": "cosmos.bank.v1beta1.Module", - "send_deny_list": [] + "send_deny_list": [], + "denom_managers": { + "coll": { + "@type": "cosmos.collectible.v1alpha1.CollectibleDenomManager" + } + } } }, "tx_middleware": [ From 66ce4718f706d5be1cfa56691217097817c3d838 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 27 May 2021 12:30:03 -0400 Subject: [PATCH 11/19] WIP --- core/app_config/app.go | 73 + core/app_config/app_config.go | 38 + core/app_config/app_config.pb.go | 385 +++- core/module/app/module.go | 10 +- core/module/module.go | 14 + core/tx/module.pb.go | 328 ++++ docs/core/proto-docs.md | 739 +++++++- .../core/app_config/v1/app_config.proto | 13 +- proto/cosmos/core/tx/v1/module.proto | 11 + simapp2/app_config.json | 100 +- types/tx/service.pb.gw.go | 169 ++ x/authn/query.pb.gw.go | 95 + x/bank/types/denom_manager.pb.go | 1590 +++++++++++++++++ x/bank/types/module.pb.go | 212 ++- x/collectible/plugin.pb.go | 265 +++ 15 files changed, 3880 insertions(+), 162 deletions(-) create mode 100644 core/app_config/app.go create mode 100644 core/app_config/app_config.go create mode 100644 core/tx/module.pb.go create mode 100644 proto/cosmos/core/tx/v1/module.proto create mode 100644 x/bank/types/denom_manager.pb.go create mode 100644 x/collectible/plugin.pb.go diff --git a/core/app_config/app.go b/core/app_config/app.go new file mode 100644 index 000000000000..243fefcd332e --- /dev/null +++ b/core/app_config/app.go @@ -0,0 +1,73 @@ +package app_config + +import ( + "context" + + "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/core/module/app" +) + +type baseApp struct { + ctx context.Context + + appModules map[string]app.Module + beginBlockers []app.BeginBlocker + endBlockers []app.EndBlocker +} + +var _ types.Application = &baseApp{} + +func (a baseApp) Info(info types.RequestInfo) types.ResponseInfo { + panic("implement me") +} + +func (a baseApp) SetOption(option types.RequestSetOption) types.ResponseSetOption { + panic("implement me") +} + +func (a baseApp) Query(query types.RequestQuery) types.ResponseQuery { + panic("implement me") +} + +func (a baseApp) CheckTx(tx types.RequestCheckTx) types.ResponseCheckTx { + panic("implement me") +} + +func (a baseApp) InitChain(chain types.RequestInitChain) types.ResponseInitChain { + panic("implement me") +} + +func (a baseApp) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginBlock { + for _, bb := range a.beginBlockers { + bb.BeginBlock(a.ctx, req) + } +} + +func (a baseApp) DeliverTx(tx types.RequestDeliverTx) types.ResponseDeliverTx { + panic("implement me") +} + +func (a baseApp) EndBlock(block types.RequestEndBlock) types.ResponseEndBlock { + panic("implement me") +} + +func (a baseApp) Commit() types.ResponseCommit { + panic("implement me") +} + +func (a baseApp) ListSnapshots(snapshots types.RequestListSnapshots) types.ResponseListSnapshots { + panic("implement me") +} + +func (a baseApp) OfferSnapshot(snapshot types.RequestOfferSnapshot) types.ResponseOfferSnapshot { + panic("implement me") +} + +func (a baseApp) LoadSnapshotChunk(chunk types.RequestLoadSnapshotChunk) types.ResponseLoadSnapshotChunk { + panic("implement me") +} + +func (a baseApp) ApplySnapshotChunk(chunk types.RequestApplySnapshotChunk) types.ResponseApplySnapshotChunk { + panic("implement me") +} diff --git a/core/app_config/app_config.go b/core/app_config/app_config.go new file mode 100644 index 000000000000..6117b6f8476d --- /dev/null +++ b/core/app_config/app_config.go @@ -0,0 +1,38 @@ +package app_config + +import ( + "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/core/module" + "github.com/cosmos/cosmos-sdk/core/module/app" +) + +func Compose(config AppConfig) (types.Application, error) { + moduleSet := module.NewModuleSet(config.Modules) + + appModules := make(map[string]app.Module) + moduleSet.Each(func(name string, handler module.ModuleHandler) { + // TODO + }) + + bapp := &baseApp{} + + var beginBlockers []app.BeginBlocker + for _, m := range config.Abci.BeginBlock { + mod, ok := appModules[m] + if !ok { + panic("TODO") + } + + beginBlocker, ok := mod.(app.BeginBlocker) + if !ok { + panic("TODO") + } + + beginBlockers = append(beginBlockers, beginBlocker) + } + + bapp.beginBlockers = beginBlockers + + return bapp, nil +} diff --git a/core/app_config/app_config.pb.go b/core/app_config/app_config.pb.go index 995add976980..0f6a6197ef4f 100644 --- a/core/app_config/app_config.pb.go +++ b/core/app_config/app_config.pb.go @@ -24,11 +24,8 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type AppConfig struct { - Modules map[string]*types.Any `protobuf:"bytes,1,rep,name=modules,proto3" json:"modules,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - TxMiddleware []*types.Any `protobuf:"bytes,2,rep,name=tx_middleware,json=txMiddleware,proto3" json:"tx_middleware,omitempty"` - InitGenesis []string `protobuf:"bytes,3,rep,name=init_genesis,json=initGenesis,proto3" json:"init_genesis,omitempty"` - BeginBlock []string `protobuf:"bytes,4,rep,name=begin_block,json=beginBlock,proto3" json:"begin_block,omitempty"` - EndBlock []string `protobuf:"bytes,5,rep,name=end_block,json=endBlock,proto3" json:"end_block,omitempty"` + Modules map[string]*types.Any `protobuf:"bytes,1,rep,name=modules,proto3" json:"modules,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Abci *ABCIHandlers `protobuf:"bytes,2,opt,name=abci,proto3" json:"abci,omitempty"` } func (m *AppConfig) Reset() { *m = AppConfig{} } @@ -71,37 +68,93 @@ func (m *AppConfig) GetModules() map[string]*types.Any { return nil } -func (m *AppConfig) GetTxMiddleware() []*types.Any { +func (m *AppConfig) GetAbci() *ABCIHandlers { if m != nil { - return m.TxMiddleware + return m.Abci } return nil } -func (m *AppConfig) GetInitGenesis() []string { +type ABCIHandlers struct { + InitGenesis []string `protobuf:"bytes,1,rep,name=init_genesis,json=initGenesis,proto3" json:"init_genesis,omitempty"` + BeginBlock []string `protobuf:"bytes,2,rep,name=begin_block,json=beginBlock,proto3" json:"begin_block,omitempty"` + EndBlock []string `protobuf:"bytes,3,rep,name=end_block,json=endBlock,proto3" json:"end_block,omitempty"` + TxHandler string `protobuf:"bytes,4,opt,name=tx_handler,json=txHandler,proto3" json:"tx_handler,omitempty"` + InfoHandler string `protobuf:"bytes,5,opt,name=info_handler,json=infoHandler,proto3" json:"info_handler,omitempty"` +} + +func (m *ABCIHandlers) Reset() { *m = ABCIHandlers{} } +func (m *ABCIHandlers) String() string { return proto.CompactTextString(m) } +func (*ABCIHandlers) ProtoMessage() {} +func (*ABCIHandlers) Descriptor() ([]byte, []int) { + return fileDescriptor_67d11620ac2d3428, []int{1} +} +func (m *ABCIHandlers) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ABCIHandlers) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ABCIHandlers.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 *ABCIHandlers) XXX_Merge(src proto.Message) { + xxx_messageInfo_ABCIHandlers.Merge(m, src) +} +func (m *ABCIHandlers) XXX_Size() int { + return m.Size() +} +func (m *ABCIHandlers) XXX_DiscardUnknown() { + xxx_messageInfo_ABCIHandlers.DiscardUnknown(m) +} + +var xxx_messageInfo_ABCIHandlers proto.InternalMessageInfo + +func (m *ABCIHandlers) GetInitGenesis() []string { if m != nil { return m.InitGenesis } return nil } -func (m *AppConfig) GetBeginBlock() []string { +func (m *ABCIHandlers) GetBeginBlock() []string { if m != nil { return m.BeginBlock } return nil } -func (m *AppConfig) GetEndBlock() []string { +func (m *ABCIHandlers) GetEndBlock() []string { if m != nil { return m.EndBlock } return nil } +func (m *ABCIHandlers) GetTxHandler() string { + if m != nil { + return m.TxHandler + } + return "" +} + +func (m *ABCIHandlers) GetInfoHandler() string { + if m != nil { + return m.InfoHandler + } + return "" +} + func init() { proto.RegisterType((*AppConfig)(nil), "cosmos.core.app_config.v1.AppConfig") proto.RegisterMapType((map[string]*types.Any)(nil), "cosmos.core.app_config.v1.AppConfig.ModulesEntry") + proto.RegisterType((*ABCIHandlers)(nil), "cosmos.core.app_config.v1.ABCIHandlers") } func init() { @@ -109,29 +162,31 @@ func init() { } var fileDescriptor_67d11620ac2d3428 = []byte{ - // 342 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0x4f, 0x4b, 0xfb, 0x30, - 0x1c, 0xc6, 0x97, 0xf5, 0xb7, 0x9f, 0x36, 0x9b, 0x20, 0xc1, 0x43, 0x37, 0xa1, 0x4e, 0x4f, 0x63, - 0x68, 0xca, 0xf4, 0xa2, 0xde, 0x36, 0x51, 0x0f, 0x32, 0x90, 0x1e, 0xbd, 0x94, 0xfe, 0xc9, 0x6a, - 0x58, 0x9b, 0x94, 0x36, 0x9d, 0xeb, 0xbb, 0xf0, 0x55, 0x89, 0xc7, 0x1d, 0x3d, 0xca, 0xf6, 0x46, - 0x24, 0x89, 0x1b, 0x43, 0xd8, 0x29, 0xc9, 0xf3, 0x7c, 0xbe, 0x4f, 0x1e, 0xf8, 0xc2, 0x7e, 0xc8, - 0x8b, 0x94, 0x17, 0x4e, 0xc8, 0x73, 0xe2, 0xf8, 0x59, 0xe6, 0x85, 0x9c, 0x4d, 0x68, 0xec, 0xcc, - 0x06, 0x5b, 0x2f, 0x9c, 0xe5, 0x5c, 0x70, 0xd4, 0xd6, 0x2c, 0x96, 0x2c, 0xde, 0x72, 0x67, 0x83, - 0x4e, 0x3b, 0xe6, 0x3c, 0x4e, 0x88, 0xa3, 0xc0, 0xa0, 0x9c, 0x38, 0x3e, 0xab, 0xf4, 0xd4, 0xd9, - 0x47, 0x1d, 0x9a, 0xc3, 0x2c, 0xbb, 0x53, 0x2c, 0x7a, 0x82, 0x7b, 0x29, 0x8f, 0xca, 0x84, 0x14, - 0x16, 0xe8, 0x1a, 0xbd, 0xe6, 0xe5, 0x00, 0xef, 0x4c, 0xc5, 0x9b, 0x31, 0x3c, 0xd6, 0x33, 0xf7, - 0x4c, 0xe4, 0x95, 0xbb, 0x4e, 0x40, 0x37, 0xf0, 0x40, 0xcc, 0xbd, 0x94, 0x46, 0x51, 0x42, 0xde, - 0xfc, 0x9c, 0x58, 0x75, 0x15, 0x79, 0x84, 0x75, 0x1b, 0xbc, 0x6e, 0x83, 0x87, 0xac, 0x72, 0x5b, - 0x62, 0x3e, 0xde, 0x90, 0xe8, 0x14, 0xb6, 0x28, 0xa3, 0xc2, 0x8b, 0x09, 0x23, 0x05, 0x2d, 0x2c, - 0xa3, 0x6b, 0xf4, 0x4c, 0xb7, 0x29, 0xb5, 0x47, 0x2d, 0xa1, 0x13, 0xd8, 0x0c, 0x48, 0x4c, 0x99, - 0x17, 0x24, 0x3c, 0x9c, 0x5a, 0xff, 0x14, 0x01, 0x95, 0x34, 0x92, 0x0a, 0x3a, 0x86, 0x26, 0x61, - 0xd1, 0xaf, 0xdd, 0x50, 0xf6, 0x3e, 0x61, 0x91, 0x32, 0x3b, 0xcf, 0xb0, 0xb5, 0x5d, 0x1a, 0x1d, - 0x42, 0x63, 0x4a, 0x2a, 0x0b, 0x74, 0x41, 0xcf, 0x74, 0xe5, 0x15, 0xf5, 0x61, 0x63, 0xe6, 0x27, - 0xa5, 0x6c, 0x0d, 0x76, 0xb6, 0xd6, 0xc8, 0x6d, 0xfd, 0x1a, 0x8c, 0x1e, 0x3e, 0x97, 0x36, 0x58, - 0x2c, 0x6d, 0xf0, 0xbd, 0xb4, 0xc1, 0xfb, 0xca, 0xae, 0x2d, 0x56, 0x76, 0xed, 0x6b, 0x65, 0xd7, - 0x5e, 0xce, 0x63, 0x2a, 0x5e, 0xcb, 0x00, 0x87, 0x3c, 0x75, 0x36, 0xfb, 0x94, 0xc7, 0x45, 0x11, - 0x4d, 0xff, 0xae, 0x36, 0xf8, 0xaf, 0x3e, 0xb8, 0xfa, 0x09, 0x00, 0x00, 0xff, 0xff, 0x2c, 0xd8, - 0x10, 0xd6, 0xfb, 0x01, 0x00, 0x00, + // 381 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xcb, 0x4e, 0xea, 0x40, + 0x1c, 0xc6, 0x19, 0x2e, 0xe7, 0x9c, 0x4e, 0x59, 0x9c, 0x4c, 0xce, 0xa2, 0x70, 0x62, 0x45, 0x36, + 0x12, 0xa2, 0xd3, 0x80, 0x1b, 0xa3, 0x2b, 0x20, 0xde, 0x62, 0x4c, 0x4c, 0x97, 0x6e, 0x9a, 0x5e, + 0x86, 0x32, 0xa1, 0xcc, 0x34, 0xbd, 0x10, 0xfa, 0x16, 0xbe, 0x8a, 0x6f, 0xe1, 0x92, 0xa5, 0x4b, + 0x03, 0x0b, 0x5f, 0xc3, 0x74, 0xa6, 0x90, 0xc6, 0x44, 0x57, 0x6d, 0xbf, 0xef, 0xf7, 0x7d, 0xff, + 0xf9, 0x37, 0x03, 0xfb, 0x2e, 0x8f, 0x17, 0x3c, 0x36, 0x5c, 0x1e, 0x11, 0xc3, 0x0e, 0x43, 0xcb, + 0xe5, 0x6c, 0x4a, 0x7d, 0x63, 0x39, 0x28, 0x7d, 0xe1, 0x30, 0xe2, 0x09, 0x47, 0x2d, 0xc9, 0xe2, + 0x9c, 0xc5, 0x25, 0x77, 0x39, 0x68, 0xb7, 0x7c, 0xce, 0xfd, 0x80, 0x18, 0x02, 0x74, 0xd2, 0xa9, + 0x61, 0xb3, 0x4c, 0xa6, 0xba, 0x1f, 0x00, 0x2a, 0xa3, 0x30, 0x9c, 0x08, 0x16, 0xdd, 0xc3, 0xdf, + 0x0b, 0xee, 0xa5, 0x01, 0x89, 0x35, 0xd0, 0xa9, 0xf5, 0xd4, 0xe1, 0x00, 0x7f, 0xdb, 0x8a, 0xf7, + 0x31, 0xfc, 0x20, 0x33, 0x57, 0x2c, 0x89, 0x32, 0x73, 0xd7, 0x80, 0x2e, 0x61, 0xdd, 0x76, 0x5c, + 0xaa, 0x55, 0x3b, 0xa0, 0xa7, 0x0e, 0x8f, 0x7f, 0x6a, 0x1a, 0x4f, 0xee, 0x6e, 0x6d, 0xe6, 0x05, + 0x24, 0x8a, 0x4d, 0x11, 0x6a, 0x3f, 0xc2, 0x66, 0xb9, 0x15, 0xfd, 0x85, 0xb5, 0x39, 0xc9, 0x34, + 0xd0, 0x01, 0x3d, 0xc5, 0xcc, 0x5f, 0x51, 0x1f, 0x36, 0x96, 0x76, 0x90, 0x92, 0xa2, 0xff, 0x1f, + 0x96, 0x4b, 0xe2, 0xdd, 0x92, 0x78, 0xc4, 0x32, 0x53, 0x22, 0x17, 0xd5, 0x73, 0xd0, 0x7d, 0x01, + 0xb0, 0x59, 0x1e, 0x84, 0x8e, 0x60, 0x93, 0x32, 0x9a, 0x58, 0x3e, 0x61, 0x24, 0xa6, 0x72, 0x63, + 0xc5, 0x54, 0x73, 0xed, 0x46, 0x4a, 0xe8, 0x10, 0xaa, 0x0e, 0xf1, 0x29, 0xb3, 0x9c, 0x80, 0xbb, + 0x73, 0xad, 0x2a, 0x08, 0x28, 0xa4, 0x71, 0xae, 0xa0, 0xff, 0x50, 0x21, 0xcc, 0x2b, 0xec, 0x9a, + 0xb0, 0xff, 0x10, 0xe6, 0x49, 0xf3, 0x00, 0xc2, 0x64, 0x65, 0xcd, 0xe4, 0x3c, 0xad, 0x2e, 0x8e, + 0xae, 0x24, 0xab, 0xe2, 0x00, 0x72, 0xfe, 0x94, 0xef, 0x81, 0x86, 0x00, 0xd4, 0x5c, 0x2b, 0x90, + 0xf1, 0xf5, 0xeb, 0x46, 0x07, 0xeb, 0x8d, 0x0e, 0xde, 0x37, 0x3a, 0x78, 0xde, 0xea, 0x95, 0xf5, + 0x56, 0xaf, 0xbc, 0x6d, 0xf5, 0xca, 0xd3, 0x89, 0x4f, 0x93, 0x59, 0xea, 0x60, 0x97, 0x2f, 0x8c, + 0xfd, 0x25, 0xc9, 0x1f, 0xa7, 0xb1, 0x37, 0xff, 0x7a, 0x5f, 0x9c, 0x5f, 0xe2, 0xa7, 0x9c, 0x7d, + 0x06, 0x00, 0x00, 0xff, 0xff, 0x86, 0x7e, 0x44, 0xf1, 0x50, 0x02, 0x00, 0x00, } func (m *AppConfig) Marshal() (dAtA []byte, err error) { @@ -154,46 +209,17 @@ func (m *AppConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.EndBlock) > 0 { - for iNdEx := len(m.EndBlock) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.EndBlock[iNdEx]) - copy(dAtA[i:], m.EndBlock[iNdEx]) - i = encodeVarintAppConfig(dAtA, i, uint64(len(m.EndBlock[iNdEx]))) - i-- - dAtA[i] = 0x2a - } - } - if len(m.BeginBlock) > 0 { - for iNdEx := len(m.BeginBlock) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.BeginBlock[iNdEx]) - copy(dAtA[i:], m.BeginBlock[iNdEx]) - i = encodeVarintAppConfig(dAtA, i, uint64(len(m.BeginBlock[iNdEx]))) - i-- - dAtA[i] = 0x22 - } - } - if len(m.InitGenesis) > 0 { - for iNdEx := len(m.InitGenesis) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.InitGenesis[iNdEx]) - copy(dAtA[i:], m.InitGenesis[iNdEx]) - i = encodeVarintAppConfig(dAtA, i, uint64(len(m.InitGenesis[iNdEx]))) - i-- - dAtA[i] = 0x1a - } - } - if len(m.TxMiddleware) > 0 { - for iNdEx := len(m.TxMiddleware) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.TxMiddleware[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintAppConfig(dAtA, i, uint64(size)) + if m.Abci != nil { + { + size, err := m.Abci.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x12 + i -= size + i = encodeVarintAppConfig(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x12 } if len(m.Modules) > 0 { for k := range m.Modules { @@ -224,6 +250,70 @@ func (m *AppConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *ABCIHandlers) 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 *ABCIHandlers) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ABCIHandlers) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.InfoHandler) > 0 { + i -= len(m.InfoHandler) + copy(dAtA[i:], m.InfoHandler) + i = encodeVarintAppConfig(dAtA, i, uint64(len(m.InfoHandler))) + i-- + dAtA[i] = 0x2a + } + if len(m.TxHandler) > 0 { + i -= len(m.TxHandler) + copy(dAtA[i:], m.TxHandler) + i = encodeVarintAppConfig(dAtA, i, uint64(len(m.TxHandler))) + i-- + dAtA[i] = 0x22 + } + if len(m.EndBlock) > 0 { + for iNdEx := len(m.EndBlock) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.EndBlock[iNdEx]) + copy(dAtA[i:], m.EndBlock[iNdEx]) + i = encodeVarintAppConfig(dAtA, i, uint64(len(m.EndBlock[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + if len(m.BeginBlock) > 0 { + for iNdEx := len(m.BeginBlock) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.BeginBlock[iNdEx]) + copy(dAtA[i:], m.BeginBlock[iNdEx]) + i = encodeVarintAppConfig(dAtA, i, uint64(len(m.BeginBlock[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } + if len(m.InitGenesis) > 0 { + for iNdEx := len(m.InitGenesis) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.InitGenesis[iNdEx]) + copy(dAtA[i:], m.InitGenesis[iNdEx]) + i = encodeVarintAppConfig(dAtA, i, uint64(len(m.InitGenesis[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func encodeVarintAppConfig(dAtA []byte, offset int, v uint64) int { offset -= sovAppConfig(v) base := offset @@ -254,12 +344,19 @@ func (m *AppConfig) Size() (n int) { n += mapEntrySize + 1 + sovAppConfig(uint64(mapEntrySize)) } } - if len(m.TxMiddleware) > 0 { - for _, e := range m.TxMiddleware { - l = e.Size() - n += 1 + l + sovAppConfig(uint64(l)) - } + if m.Abci != nil { + l = m.Abci.Size() + n += 1 + l + sovAppConfig(uint64(l)) + } + return n +} + +func (m *ABCIHandlers) Size() (n int) { + if m == nil { + return 0 } + var l int + _ = l if len(m.InitGenesis) > 0 { for _, s := range m.InitGenesis { l = len(s) @@ -278,6 +375,14 @@ func (m *AppConfig) Size() (n int) { n += 1 + l + sovAppConfig(uint64(l)) } } + l = len(m.TxHandler) + if l > 0 { + n += 1 + l + sovAppConfig(uint64(l)) + } + l = len(m.InfoHandler) + if l > 0 { + n += 1 + l + sovAppConfig(uint64(l)) + } return n } @@ -447,7 +552,7 @@ func (m *AppConfig) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TxMiddleware", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Abci", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -474,12 +579,64 @@ func (m *AppConfig) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.TxMiddleware = append(m.TxMiddleware, &types.Any{}) - if err := m.TxMiddleware[len(m.TxMiddleware)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if m.Abci == nil { + m.Abci = &ABCIHandlers{} + } + if err := m.Abci.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 3: + default: + iNdEx = preIndex + skippy, err := skipAppConfig(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAppConfig + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ABCIHandlers) 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 ErrIntOverflowAppConfig + } + 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: ABCIHandlers: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ABCIHandlers: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field InitGenesis", wireType) } @@ -511,7 +668,7 @@ func (m *AppConfig) Unmarshal(dAtA []byte) error { } m.InitGenesis = append(m.InitGenesis, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex - case 4: + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field BeginBlock", wireType) } @@ -543,7 +700,7 @@ func (m *AppConfig) Unmarshal(dAtA []byte) error { } m.BeginBlock = append(m.BeginBlock, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex - case 5: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field EndBlock", wireType) } @@ -575,6 +732,70 @@ func (m *AppConfig) Unmarshal(dAtA []byte) error { } m.EndBlock = append(m.EndBlock, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TxHandler", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAppConfig + } + 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 ErrInvalidLengthAppConfig + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAppConfig + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TxHandler = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InfoHandler", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAppConfig + } + 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 ErrInvalidLengthAppConfig + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAppConfig + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.InfoHandler = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipAppConfig(dAtA[iNdEx:]) diff --git a/core/module/app/module.go b/core/module/app/module.go index f67c5ce1a03d..551020bc8c49 100644 --- a/core/module/app/module.go +++ b/core/module/app/module.go @@ -1,6 +1,7 @@ package app import ( + "context" "encoding/json" abci "github.com/tendermint/tendermint/abci/types" @@ -8,14 +9,13 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) type Module interface { RegisterTypes(codectypes.InterfaceRegistry) - InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate - ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage + InitGenesis(context.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate + ExportGenesis(context.Context, codec.JSONCodec) json.RawMessage RegisterMsgServices(grpc.ServiceRegistrar) RegisterQueryServices(grpc.ServiceRegistrar) @@ -24,11 +24,11 @@ type Module interface { type BeginBlocker interface { Module - BeginBlock(sdk.Context, abci.RequestBeginBlock) + BeginBlock(context.Context, abci.RequestBeginBlock) } type EndBlocker interface { Module - EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate + EndBlock(context.Context, abci.RequestEndBlock) []abci.ValidatorUpdate } diff --git a/core/module/module.go b/core/module/module.go index 8680cbe01d9a..22fb3a26f4c6 100644 --- a/core/module/module.go +++ b/core/module/module.go @@ -4,6 +4,8 @@ import ( "fmt" "reflect" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/gogo/protobuf/proto" ) @@ -25,3 +27,15 @@ func RegisterModuleHandler(handler ModuleHandler) { registry[typ] = handler } + +type ModuleSet struct { + handlers map[string]ModuleHandler +} + +func NewModuleSet(moduleConfigs map[string]*types.Any) *ModuleSet { + panic("TODO") +} + +func (ms *ModuleSet) Each(f func(name string, handler ModuleHandler)) { + panic("TODO") +} diff --git a/core/tx/module.pb.go b/core/tx/module.pb.go new file mode 100644 index 000000000000..2163713df4b3 --- /dev/null +++ b/core/tx/module.pb.go @@ -0,0 +1,328 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/core/tx/v1/module.proto + +package tx + +import ( + fmt "fmt" + types "github.com/cosmos/cosmos-sdk/codec/types" + 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 + +type Module struct { + Middleware []*types.Any `protobuf:"bytes,1,rep,name=middleware,proto3" json:"middleware,omitempty"` +} + +func (m *Module) Reset() { *m = Module{} } +func (m *Module) String() string { return proto.CompactTextString(m) } +func (*Module) ProtoMessage() {} +func (*Module) Descriptor() ([]byte, []int) { + return fileDescriptor_925c5026f4810198, []int{0} +} +func (m *Module) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Module) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Module.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 *Module) XXX_Merge(src proto.Message) { + xxx_messageInfo_Module.Merge(m, src) +} +func (m *Module) XXX_Size() int { + return m.Size() +} +func (m *Module) XXX_DiscardUnknown() { + xxx_messageInfo_Module.DiscardUnknown(m) +} + +var xxx_messageInfo_Module proto.InternalMessageInfo + +func (m *Module) GetMiddleware() []*types.Any { + if m != nil { + return m.Middleware + } + return nil +} + +func init() { + proto.RegisterType((*Module)(nil), "cosmos.core.tx.v1.Module") +} + +func init() { proto.RegisterFile("cosmos/core/tx/v1/module.proto", fileDescriptor_925c5026f4810198) } + +var fileDescriptor_925c5026f4810198 = []byte{ + // 187 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4b, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0xa9, 0xd0, 0x2f, 0x33, 0xd4, 0xcf, 0xcd, + 0x4f, 0x29, 0xcd, 0x49, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x84, 0xc8, 0xeb, 0x81, + 0xe4, 0xf5, 0x4a, 0x2a, 0xf4, 0xca, 0x0c, 0xa5, 0x24, 0xd3, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, + 0xc1, 0x0a, 0x92, 0x4a, 0xd3, 0xf4, 0x13, 0xf3, 0x2a, 0x21, 0xaa, 0x95, 0xec, 0xb8, 0xd8, 0x7c, + 0xc1, 0xba, 0x85, 0x4c, 0xb8, 0xb8, 0x72, 0x33, 0x53, 0x52, 0x72, 0x52, 0xcb, 0x13, 0x8b, 0x52, + 0x25, 0x18, 0x15, 0x98, 0x35, 0xb8, 0x8d, 0x44, 0xf4, 0x20, 0x3a, 0xf5, 0x60, 0x3a, 0xf5, 0x1c, + 0xf3, 0x2a, 0x83, 0x90, 0xd4, 0x39, 0xd9, 0x9d, 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, 0x4a, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0xdc, 0xc9, + 0x20, 0x4a, 0xb7, 0x38, 0x25, 0x1b, 0xe6, 0xfa, 0x24, 0x36, 0xb0, 0xc9, 0xc6, 0x80, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x06, 0x5a, 0xe1, 0xee, 0xd6, 0x00, 0x00, 0x00, +} + +func (m *Module) 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 *Module) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Module) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Middleware) > 0 { + for iNdEx := len(m.Middleware) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Middleware[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintModule(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintModule(dAtA []byte, offset int, v uint64) int { + offset -= sovModule(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Module) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Middleware) > 0 { + for _, e := range m.Middleware { + l = e.Size() + n += 1 + l + sovModule(uint64(l)) + } + } + return n +} + +func sovModule(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozModule(x uint64) (n int) { + return sovModule(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Module) 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 ErrIntOverflowModule + } + 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: Module: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Module: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Middleware", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthModule + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthModule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Middleware = append(m.Middleware, &types.Any{}) + if err := m.Middleware[len(m.Middleware)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipModule(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthModule + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipModule(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, ErrIntOverflowModule + } + 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, ErrIntOverflowModule + } + 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, ErrIntOverflowModule + } + 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, ErrInvalidLengthModule + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupModule + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthModule + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthModule = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowModule = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupModule = fmt.Errorf("proto: unexpected end of group") +) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 254ce496c89c..da9ef63e8049 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -26,6 +26,38 @@ - [Query](#cosmos.auth.v1beta1.Query) +- [cosmos/authn/v1/account.proto](#cosmos/authn/v1/account.proto) + - [Account](#cosmos.authn.v1.Account) + +- [cosmos/authn/v1/genesis.proto](#cosmos/authn/v1/genesis.proto) + - [GenesisState](#cosmos.authn.v1.GenesisState) + +- [cosmos/authn/v1/middleware.proto](#cosmos/authn/v1/middleware.proto) + - [ConsumeGasForTxSizeMiddleware](#cosmos.authn.v1.ConsumeGasForTxSizeMiddleware) + - [IncrementSequenceMiddleware](#cosmos.authn.v1.IncrementSequenceMiddleware) + - [SetPubKeyMiddleware](#cosmos.authn.v1.SetPubKeyMiddleware) + - [SigGasConsumeMiddleware](#cosmos.authn.v1.SigGasConsumeMiddleware) + - [SigVerificationMiddleware](#cosmos.authn.v1.SigVerificationMiddleware) + - [ValidateMemoMiddleware](#cosmos.authn.v1.ValidateMemoMiddleware) + - [ValidateSigCountMiddleware](#cosmos.authn.v1.ValidateSigCountMiddleware) + +- [cosmos/authn/v1/module.proto](#cosmos/authn/v1/module.proto) + - [Module](#cosmos.authn.v1.Module) + +- [cosmos/authn/v1/query.proto](#cosmos/authn/v1/query.proto) + - [QueryAccountRequest](#cosmos.authn.v1.QueryAccountRequest) + - [QueryAccountResponse](#cosmos.authn.v1.QueryAccountResponse) + - [QueryAccountsRequest](#cosmos.authn.v1.QueryAccountsRequest) + - [QueryAccountsResponse](#cosmos.authn.v1.QueryAccountsResponse) + + - [Query](#cosmos.authn.v1.Query) + +- [cosmos/authn/v1/tx.proto](#cosmos/authn/v1/tx.proto) + - [MsgSetCredentialRequest](#cosmos.authn.v1.MsgSetCredentialRequest) + - [MsgSetCredentialResponse](#cosmos.authn.v1.MsgSetCredentialResponse) + + - [Msg](#cosmos.authn.v1.Msg) + - [cosmos/authz/v1beta1/authz.proto](#cosmos/authz/v1beta1/authz.proto) - [GenericAuthorization](#cosmos.authz.v1beta1.GenericAuthorization) - [Grant](#cosmos.authz.v1beta1.Grant) @@ -84,10 +116,27 @@ - [SendEnabled](#cosmos.bank.v1beta1.SendEnabled) - [Supply](#cosmos.bank.v1beta1.Supply) +- [cosmos/bank/v1beta1/denom_manager.proto](#cosmos/bank/v1beta1/denom_manager.proto) + - [OnBurnRequest](#cosmos.bank.v1beta1.OnBurnRequest) + - [OnBurnResponse](#cosmos.bank.v1beta1.OnBurnResponse) + - [OnMintRequest](#cosmos.bank.v1beta1.OnMintRequest) + - [OnMintResponse](#cosmos.bank.v1beta1.OnMintResponse) + - [OnSendRequest](#cosmos.bank.v1beta1.OnSendRequest) + - [OnSendResponse](#cosmos.bank.v1beta1.OnSendResponse) + + - [DenomManager](#cosmos.bank.v1beta1.DenomManager) + - [cosmos/bank/v1beta1/genesis.proto](#cosmos/bank/v1beta1/genesis.proto) - [Balance](#cosmos.bank.v1beta1.Balance) - [GenesisState](#cosmos.bank.v1beta1.GenesisState) +- [cosmos/bank/v1beta1/middleware.proto](#cosmos/bank/v1beta1/middleware.proto) + - [DeductFeeMiddleware](#cosmos.bank.v1beta1.DeductFeeMiddleware) + +- [cosmos/bank/v1beta1/module.proto](#cosmos/bank/v1beta1/module.proto) + - [Module](#cosmos.bank.v1beta1.Module) + - [Module.DenomManagersEntry](#cosmos.bank.v1beta1.Module.DenomManagersEntry) + - [cosmos/bank/v1beta1/query.proto](#cosmos/bank/v1beta1/query.proto) - [QueryAllBalancesRequest](#cosmos.bank.v1beta1.QueryAllBalancesRequest) - [QueryAllBalancesResponse](#cosmos.bank.v1beta1.QueryAllBalancesResponse) @@ -201,6 +250,17 @@ - [GenesisOwners](#cosmos.capability.v1beta1.GenesisOwners) - [GenesisState](#cosmos.capability.v1beta1.GenesisState) +- [cosmos/collectible/v1alpha1/plugin.proto](#cosmos/collectible/v1alpha1/plugin.proto) + - [CollectibleDenomManager](#cosmos.collectible.v1alpha1.CollectibleDenomManager) + +- [cosmos/core/app_config/v1/app_config.proto](#cosmos/core/app_config/v1/app_config.proto) + - [ABCIHandlers](#cosmos.core.app_config.v1.ABCIHandlers) + - [AppConfig](#cosmos.core.app_config.v1.AppConfig) + - [AppConfig.ModulesEntry](#cosmos.core.app_config.v1.AppConfig.ModulesEntry) + +- [cosmos/core/tx/v1/module.proto](#cosmos/core/tx/v1/module.proto) + - [Module](#cosmos.core.tx.v1.Module) + - [cosmos/crisis/v1beta1/genesis.proto](#cosmos/crisis/v1beta1/genesis.proto) - [GenesisState](#cosmos.crisis.v1beta1.GenesisState) @@ -854,14 +914,358 @@ QueryParamsResponse is the response type for the Query/Params RPC method. -### Query -Query defines the gRPC querier service. +### Query +Query defines the gRPC querier service. + +| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | +| ----------- | ------------ | ------------- | ------------| ------- | -------- | +| `Accounts` | [QueryAccountsRequest](#cosmos.auth.v1beta1.QueryAccountsRequest) | [QueryAccountsResponse](#cosmos.auth.v1beta1.QueryAccountsResponse) | Accounts returns all the existing accounts | GET|/cosmos/auth/v1beta1/accounts| +| `Account` | [QueryAccountRequest](#cosmos.auth.v1beta1.QueryAccountRequest) | [QueryAccountResponse](#cosmos.auth.v1beta1.QueryAccountResponse) | Account returns account details based on address. | GET|/cosmos/auth/v1beta1/accounts/{address}| +| `Params` | [QueryParamsRequest](#cosmos.auth.v1beta1.QueryParamsRequest) | [QueryParamsResponse](#cosmos.auth.v1beta1.QueryParamsResponse) | Params queries all parameters. | GET|/cosmos/auth/v1beta1/params| + + + + + + +

Top

+ +## cosmos/authn/v1/account.proto + + + + + +### Account + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `address` | [string](#string) | | | +| `credential` | [google.protobuf.Any](#google.protobuf.Any) | | | +| `account_number` | [uint64](#uint64) | | | +| `sequence` | [uint64](#uint64) | | | + + + + + + + + + + + + + + + + +

Top

+ +## cosmos/authn/v1/genesis.proto + + + + + +### GenesisState + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `accounts` | [Account](#cosmos.authn.v1.Account) | repeated | accounts are the accounts present at genesis. | + + + + + + + + + + + + + + + + +

Top

+ +## cosmos/authn/v1/middleware.proto + + + + + +### ConsumeGasForTxSizeMiddleware + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `tx_size_cost_per_byte` | [uint64](#uint64) | | | + + + + + + + + +### IncrementSequenceMiddleware + + + + + + + + + +### SetPubKeyMiddleware + + + + + + + + + +### SigGasConsumeMiddleware + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `sig_verify_cost_ed25519` | [uint64](#uint64) | | | +| `sig_verify_cost_secp256k1` | [uint64](#uint64) | | | +| `allowed_pub_key_types` | [string](#string) | repeated | | + + + + + + + + +### SigVerificationMiddleware + + + + + + + + + +### ValidateMemoMiddleware + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `max_memo_characters` | [uint64](#uint64) | | | + + + + + + + + +### ValidateSigCountMiddleware + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `tx_sig_limit` | [uint64](#uint64) | | | + + + + + + + + + + + + + + + + +

Top

+ +## cosmos/authn/v1/module.proto + + + + + +### Module + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `bech32_address_prefix` | [string](#string) | | | + + + + + + + + + + + + + + + + +

Top

+ +## cosmos/authn/v1/query.proto + + + + + +### QueryAccountRequest + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `address` | [string](#string) | | | + + + + + + + + +### QueryAccountResponse + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `account` | [Account](#cosmos.authn.v1.Account) | | | + + + + + + + + +### QueryAccountsRequest + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `pagination` | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | pagination defines an optional pagination for the request. | + + + + + + + + +### QueryAccountsResponse +QueryAccountsResponse is the response type for the Query/Accounts RPC method. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `accounts` | [Account](#cosmos.authn.v1.Account) | repeated | accounts are the existing accounts | +| `pagination` | [cosmos.base.query.v1beta1.PageResponse](#cosmos.base.query.v1beta1.PageResponse) | | pagination defines the pagination in the response. | + + + + + + + + + + + + + + +### Query + + +| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | +| ----------- | ------------ | ------------- | ------------| ------- | -------- | +| `Account` | [QueryAccountRequest](#cosmos.authn.v1.QueryAccountRequest) | [QueryAccountResponse](#cosmos.authn.v1.QueryAccountResponse) | Account returns account details based on address. | GET|/cosmos/auth/v1beta1/accounts/{address}| +| `Accounts` | [QueryAccountsRequest](#cosmos.authn.v1.QueryAccountsRequest) | [QueryAccountsResponse](#cosmos.authn.v1.QueryAccountsResponse) | Accounts returns all the existing accounts | GET|/cosmos/auth/v1beta1/accounts| + + + + + + +

Top

+ +## cosmos/authn/v1/tx.proto + + + + + +### MsgSetCredentialRequest + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `address` | [string](#string) | | | +| `credential` | [google.protobuf.Any](#google.protobuf.Any) | | | + + + + + + + + +### MsgSetCredentialResponse + + + + + + + + + + + + + + + +### Msg + | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `Accounts` | [QueryAccountsRequest](#cosmos.auth.v1beta1.QueryAccountsRequest) | [QueryAccountsResponse](#cosmos.auth.v1beta1.QueryAccountsResponse) | Accounts returns all the existing accounts | GET|/cosmos/auth/v1beta1/accounts| -| `Account` | [QueryAccountRequest](#cosmos.auth.v1beta1.QueryAccountRequest) | [QueryAccountResponse](#cosmos.auth.v1beta1.QueryAccountResponse) | Account returns account details based on address. | GET|/cosmos/auth/v1beta1/accounts/{address}| -| `Params` | [QueryParamsRequest](#cosmos.auth.v1beta1.QueryParamsRequest) | [QueryParamsResponse](#cosmos.auth.v1beta1.QueryParamsResponse) | Params queries all parameters. | GET|/cosmos/auth/v1beta1/params| +| `SetCredential` | [MsgSetCredentialRequest](#cosmos.authn.v1.MsgSetCredentialRequest) | [MsgSetCredentialResponse](#cosmos.authn.v1.MsgSetCredentialResponse) | | | @@ -1642,6 +2046,117 @@ This message is deprecated now that supply is indexed by denom. + +

Top

+ +## cosmos/bank/v1beta1/denom_manager.proto + + + + + +### OnBurnRequest + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `burner` | [string](#string) | | | +| `denom` | [string](#string) | | | +| `amount` | [string](#string) | | | + + + + + + + + +### OnBurnResponse + + + + + + + + + +### OnMintRequest + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `minter` | [string](#string) | | | +| `receiver` | [string](#string) | | | +| `denom` | [string](#string) | | | +| `amount` | [string](#string) | | | + + + + + + + + +### OnMintResponse + + + + + + + + + +### OnSendRequest + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `sender` | [string](#string) | | | +| `receiver` | [string](#string) | | | +| `denom` | [string](#string) | | | +| `amount` | [string](#string) | | | + + + + + + + + +### OnSendResponse + + + + + + + + + + + + + + + +### DenomManager + + +| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | +| ----------- | ------------ | ------------- | ------------| ------- | -------- | +| `OnMint` | [OnMintRequest](#cosmos.bank.v1beta1.OnMintRequest) | [OnMintResponse](#cosmos.bank.v1beta1.OnMintResponse) | | | +| `OnSend` | [OnSendRequest](#cosmos.bank.v1beta1.OnSendRequest) | [OnSendResponse](#cosmos.bank.v1beta1.OnSendResponse) | | | +| `OnBurn` | [OnBurnRequest](#cosmos.bank.v1beta1.OnBurnRequest) | [OnBurnResponse](#cosmos.bank.v1beta1.OnBurnResponse) | | | + + + + +

Top

@@ -1683,6 +2198,80 @@ GenesisState defines the bank module's genesis state. + + + + + + + + + + + +

Top

+ +## cosmos/bank/v1beta1/middleware.proto + + + + + +### DeductFeeMiddleware + + + + + + + + + + + + + + + + + +

Top

+ +## cosmos/bank/v1beta1/module.proto + + + + + +### Module + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `send_deny_list` | [string](#string) | repeated | | +| `denom_managers` | [Module.DenomManagersEntry](#cosmos.bank.v1beta1.Module.DenomManagersEntry) | repeated | | + + + + + + + + +### Module.DenomManagersEntry + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `key` | [string](#string) | | | +| `value` | [google.protobuf.Any](#google.protobuf.Any) | | | + + + + + @@ -3145,6 +3734,130 @@ GenesisState defines the capability module's genesis state. + + + + + + + + + + + +

Top

+ +## cosmos/collectible/v1alpha1/plugin.proto + + + + + +### CollectibleDenomManager + + + + + + + + + + + + + + + + + +

Top

+ +## cosmos/core/app_config/v1/app_config.proto + + + + + +### ABCIHandlers + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `init_genesis` | [string](#string) | repeated | | +| `begin_block` | [string](#string) | repeated | | +| `end_block` | [string](#string) | repeated | | +| `tx_handler` | [string](#string) | | | +| `info_handler` | [string](#string) | | | + + + + + + + + +### AppConfig + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `modules` | [AppConfig.ModulesEntry](#cosmos.core.app_config.v1.AppConfig.ModulesEntry) | repeated | | +| `abci` | [ABCIHandlers](#cosmos.core.app_config.v1.ABCIHandlers) | | | + + + + + + + + +### AppConfig.ModulesEntry + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `key` | [string](#string) | | | +| `value` | [google.protobuf.Any](#google.protobuf.Any) | | | + + + + + + + + + + + + + + + + +

Top

+ +## cosmos/core/tx/v1/module.proto + + + + + +### Module + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `middleware` | [google.protobuf.Any](#google.protobuf.Any) | repeated | | + + + + + @@ -6182,9 +6895,9 @@ AuthorizationType defines the type of staking module authorization type | Name | Number | Description | | ---- | ------ | ----------- | | AUTHORIZATION_TYPE_UNSPECIFIED | 0 | AUTHORIZATION_TYPE_UNSPECIFIED specifies an unknown authorization type | -| AUTHORIZATION_TYPE_DELEGATE | 1 | AUTHORIZATION_TYPE_DELEGATE defines an authorization type for MsgDelegate | -| AUTHORIZATION_TYPE_UNDELEGATE | 2 | AUTHORIZATION_TYPE_UNDELEGATE defines an authorization type for MsgUndelegate | -| AUTHORIZATION_TYPE_REDELEGATE | 3 | AUTHORIZATION_TYPE_REDELEGATE defines an authorization type for MsgBeginRedelegate | +| AUTHORIZATION_TYPE_DELEGATE | 1 | AUTHORIZATION_TYPE_DELEGATE defines an authorization type for Msg/Delegate | +| AUTHORIZATION_TYPE_UNDELEGATE | 2 | AUTHORIZATION_TYPE_UNDELEGATE defines an authorization type for Msg/Undelegate | +| AUTHORIZATION_TYPE_REDELEGATE | 3 | AUTHORIZATION_TYPE_REDELEGATE defines an authorization type for Msg/BeginRedelegate | @@ -7167,7 +7880,7 @@ of coins from a delegator and source validator to a destination validator. ### MsgBeginRedelegateResponse -MsgBeginRedelegateResponse defines the MsgBeginRedelegate response type. +MsgBeginRedelegateResponse defines the Msg/BeginRedelegate response type. | Field | Type | Label | Description | @@ -7203,7 +7916,7 @@ MsgCreateValidator defines a SDK message for creating a new validator. ### MsgCreateValidatorResponse -MsgCreateValidatorResponse defines the MsgCreateValidator response type. +MsgCreateValidatorResponse defines the Msg/CreateValidator response type. @@ -7231,7 +7944,7 @@ from a delegator to a validator. ### MsgDelegateResponse -MsgDelegateResponse defines the MsgDelegate response type. +MsgDelegateResponse defines the Msg/Delegate response type. @@ -7259,7 +7972,7 @@ MsgEditValidator defines a SDK message for editing an existing validator. ### MsgEditValidatorResponse -MsgEditValidatorResponse defines the MsgEditValidator response type. +MsgEditValidatorResponse defines the Msg/EditValidator response type. @@ -7287,7 +8000,7 @@ delegate and a validator. ### MsgUndelegateResponse -MsgUndelegateResponse defines the MsgUndelegate response type. +MsgUndelegateResponse defines the Msg/Undelegate response type. | Field | Type | Label | Description | diff --git a/proto/cosmos/core/app_config/v1/app_config.proto b/proto/cosmos/core/app_config/v1/app_config.proto index 68bbca31cfc5..2d77389be1d6 100644 --- a/proto/cosmos/core/app_config/v1/app_config.proto +++ b/proto/cosmos/core/app_config/v1/app_config.proto @@ -7,8 +7,13 @@ option go_package = "github.com/cosmos/cosmos-sdk/core/app_config"; message AppConfig { map modules = 1; - repeated google.protobuf.Any tx_middleware = 2; - repeated string init_genesis = 3; - repeated string begin_block = 4; - repeated string end_block = 5; + ABCIHandlers abci = 2; +} + +message ABCIHandlers { + repeated string init_genesis = 1; + repeated string begin_block = 2; + repeated string end_block = 3; + string tx_handler = 4; + string info_handler = 5; } \ No newline at end of file diff --git a/proto/cosmos/core/tx/v1/module.proto b/proto/cosmos/core/tx/v1/module.proto new file mode 100644 index 000000000000..c9abd72a0887 --- /dev/null +++ b/proto/cosmos/core/tx/v1/module.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package cosmos.core.tx.v1; + +import "google/protobuf/any.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/core/tx"; + +message Module { + repeated google.protobuf.Any middleware = 1; +} + diff --git a/simapp2/app_config.json b/simapp2/app_config.json index 62e88caae5d4..8f6d1d473d3e 100644 --- a/simapp2/app_config.json +++ b/simapp2/app_config.json @@ -12,53 +12,63 @@ "@type": "cosmos.collectible.v1alpha1.CollectibleDenomManager" } } - } - }, - "tx_middleware": [ - { - "@type": "cosmos.authn.v1.ValidateMemoMiddleware", - "max_memo_characters": 256 - }, - { - "@type": "cosmos.authn.v1.ConsumeGasForTxSizeMiddleware", - "tx_size_cost_per_byte": 100 - }, - { - "@type": "cosmos.bank.v1beta1.DeductFeeMiddleware" - }, - { - "@type": "cosmos.authn.v1.SetPubKeyMiddleware" }, - { - "@type": "cosmos.authn.v1.ValidateSigCountMiddleware", - "tx_sig_limit": 7 + "upgrade": { + "@type": "cosmos.upgrade.v1beta1.Module" }, - { - "@type": "cosmos.authn.v1.SigGasConsumeMiddleware", - "sig_verify_cost_ed25519": 1000, - "sig_verify_cost_secp256k1": 500, - "allowed_pub_key_types": [ - "cosmos.crypto.secp256k1.PubKey", - "cosmos.crypto.secp256r1.PubKey" + "tx": { + "@type": "cosmos.core.tx.v1.Module", + "middleware": [ + { + "@type": "cosmos.authn.v1.ValidateMemoMiddleware", + "max_memo_characters": 256 + }, + { + "@type": "cosmos.authn.v1.ConsumeGasForTxSizeMiddleware", + "tx_size_cost_per_byte": 100 + }, + { + "@type": "cosmos.bank.v1beta1.DeductFeeMiddleware" + }, + { + "@type": "cosmos.authn.v1.SetPubKeyMiddleware" + }, + { + "@type": "cosmos.authn.v1.ValidateSigCountMiddleware", + "tx_sig_limit": 7 + }, + { + "@type": "cosmos.authn.v1.SigGasConsumeMiddleware", + "sig_verify_cost_ed25519": 1000, + "sig_verify_cost_secp256k1": 500, + "allowed_pub_key_types": [ + "cosmos.crypto.secp256k1.PubKey", + "cosmos.crypto.secp256r1.PubKey" + ] + }, + { + "@type": "cosmos.authn.v1.SigVerificationMiddleware" + }, + { + "@type": "cosmos.authn.v1.IncrementSequenceMiddleware" + } ] - }, - { - "@type": "cosmos.authn.v1.SigVerificationMiddleware" - }, - { - "@type": "cosmos.authn.v1.IncrementSequenceMiddleware" } - ], - "init_genesis": [ - "authn", - "bank" - ], - "begin_block": [ - "authn", - "bank" - ], - "end_block": [ - "bank", - "authn" - ] + }, + "abci": { + "init_genesis": [ + "authn", + "bank" + ], + "begin_block": [ + "authn", + "bank" + ], + "end_block": [ + "bank", + "authn" + ], + "tx_handler": "tx", + "info_handler": "upgrade" + } } \ No newline at end of file diff --git a/types/tx/service.pb.gw.go b/types/tx/service.pb.gw.go index 1418a5aa9bc3..25560e1cdfb2 100644 --- a/types/tx/service.pb.gw.go +++ b/types/tx/service.pb.gw.go @@ -13,6 +13,7 @@ import ( "io" "net/http" + "github.com/golang/protobuf/descriptor" "github.com/golang/protobuf/proto" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/grpc-ecosystem/grpc-gateway/utilities" @@ -22,11 +23,13 @@ import ( "google.golang.org/grpc/status" ) +// Suppress "imported and not used" errors var _ codes.Code var _ io.Reader var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage func request_Service_Simulate_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq SimulateRequest @@ -45,6 +48,23 @@ func request_Service_Simulate_0(ctx context.Context, marshaler runtime.Marshaler } +func local_request_Service_Simulate_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq SimulateRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Simulate(ctx, &protoReq) + return msg, metadata, err + +} + func request_Service_GetTx_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq GetTxRequest var metadata runtime.ServerMetadata @@ -72,6 +92,33 @@ func request_Service_GetTx_0(ctx context.Context, marshaler runtime.Marshaler, c } +func local_request_Service_GetTx_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetTxRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["hash"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "hash") + } + + protoReq.Hash, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "hash", err) + } + + msg, err := server.GetTx(ctx, &protoReq) + return msg, metadata, err + +} + func request_Service_BroadcastTx_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq BroadcastTxRequest var metadata runtime.ServerMetadata @@ -89,6 +136,23 @@ func request_Service_BroadcastTx_0(ctx context.Context, marshaler runtime.Marsha } +func local_request_Service_BroadcastTx_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq BroadcastTxRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.BroadcastTx(ctx, &protoReq) + return msg, metadata, err + +} + var ( filter_Service_GetTxsEvent_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} ) @@ -109,6 +173,111 @@ func request_Service_GetTxsEvent_0(ctx context.Context, marshaler runtime.Marsha } +func local_request_Service_GetTxsEvent_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetTxsEventRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Service_GetTxsEvent_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.GetTxsEvent(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterServiceHandlerServer registers the http handlers for service Service to "mux". +// UnaryRPC :call ServiceServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterServiceHandlerFromEndpoint instead. +func RegisterServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server ServiceServer) error { + + mux.Handle("POST", pattern_Service_Simulate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Service_Simulate_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Service_Simulate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Service_GetTx_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Service_GetTx_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Service_GetTx_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Service_BroadcastTx_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Service_BroadcastTx_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Service_BroadcastTx_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Service_GetTxsEvent_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Service_GetTxsEvent_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Service_GetTxsEvent_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + // RegisterServiceHandlerFromEndpoint is same as RegisterServiceHandler but // automatically dials to "endpoint" and closes the connection when "ctx" gets done. func RegisterServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { diff --git a/x/authn/query.pb.gw.go b/x/authn/query.pb.gw.go index dd1fd442d46e..6c8fac71f68e 100644 --- a/x/authn/query.pb.gw.go +++ b/x/authn/query.pb.gw.go @@ -13,6 +13,7 @@ import ( "io" "net/http" + "github.com/golang/protobuf/descriptor" "github.com/golang/protobuf/proto" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/grpc-ecosystem/grpc-gateway/utilities" @@ -22,11 +23,13 @@ import ( "google.golang.org/grpc/status" ) +// Suppress "imported and not used" errors var _ codes.Code var _ io.Reader var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage func request_Query_Account_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryAccountRequest @@ -55,6 +58,33 @@ func request_Query_Account_0(ctx context.Context, marshaler runtime.Marshaler, c } +func local_request_Query_Account_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) + } + + msg, err := server.Account(ctx, &protoReq) + return msg, metadata, err + +} + var ( filter_Query_Accounts_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} ) @@ -75,6 +105,71 @@ func request_Query_Accounts_0(ctx context.Context, marshaler runtime.Marshaler, } +func local_request_Query_Accounts_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAccountsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Accounts_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Accounts(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Account_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Account_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Account_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Accounts_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Accounts_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Accounts_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + // RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but // automatically dials to "endpoint" and closes the connection when "ctx" gets done. func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { diff --git a/x/bank/types/denom_manager.pb.go b/x/bank/types/denom_manager.pb.go new file mode 100644 index 000000000000..cb24d21cc745 --- /dev/null +++ b/x/bank/types/denom_manager.pb.go @@ -0,0 +1,1590 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/bank/v1beta1/denom_manager.proto + +package types + +import ( + context "context" + fmt "fmt" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + 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 + +type OnMintRequest struct { + Minter string `protobuf:"bytes,1,opt,name=minter,proto3" json:"minter,omitempty"` + Receiver string `protobuf:"bytes,2,opt,name=receiver,proto3" json:"receiver,omitempty"` + Denom string `protobuf:"bytes,3,opt,name=denom,proto3" json:"denom,omitempty"` + Amount string `protobuf:"bytes,4,opt,name=amount,proto3" json:"amount,omitempty"` +} + +func (m *OnMintRequest) Reset() { *m = OnMintRequest{} } +func (m *OnMintRequest) String() string { return proto.CompactTextString(m) } +func (*OnMintRequest) ProtoMessage() {} +func (*OnMintRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ee4f62ba26b381ad, []int{0} +} +func (m *OnMintRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *OnMintRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_OnMintRequest.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 *OnMintRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_OnMintRequest.Merge(m, src) +} +func (m *OnMintRequest) XXX_Size() int { + return m.Size() +} +func (m *OnMintRequest) XXX_DiscardUnknown() { + xxx_messageInfo_OnMintRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_OnMintRequest proto.InternalMessageInfo + +func (m *OnMintRequest) GetMinter() string { + if m != nil { + return m.Minter + } + return "" +} + +func (m *OnMintRequest) GetReceiver() string { + if m != nil { + return m.Receiver + } + return "" +} + +func (m *OnMintRequest) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +func (m *OnMintRequest) GetAmount() string { + if m != nil { + return m.Amount + } + return "" +} + +type OnMintResponse struct { +} + +func (m *OnMintResponse) Reset() { *m = OnMintResponse{} } +func (m *OnMintResponse) String() string { return proto.CompactTextString(m) } +func (*OnMintResponse) ProtoMessage() {} +func (*OnMintResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ee4f62ba26b381ad, []int{1} +} +func (m *OnMintResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *OnMintResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_OnMintResponse.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 *OnMintResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_OnMintResponse.Merge(m, src) +} +func (m *OnMintResponse) XXX_Size() int { + return m.Size() +} +func (m *OnMintResponse) XXX_DiscardUnknown() { + xxx_messageInfo_OnMintResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_OnMintResponse proto.InternalMessageInfo + +type OnSendRequest struct { + Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` + Receiver string `protobuf:"bytes,2,opt,name=receiver,proto3" json:"receiver,omitempty"` + Denom string `protobuf:"bytes,3,opt,name=denom,proto3" json:"denom,omitempty"` + Amount string `protobuf:"bytes,4,opt,name=amount,proto3" json:"amount,omitempty"` +} + +func (m *OnSendRequest) Reset() { *m = OnSendRequest{} } +func (m *OnSendRequest) String() string { return proto.CompactTextString(m) } +func (*OnSendRequest) ProtoMessage() {} +func (*OnSendRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ee4f62ba26b381ad, []int{2} +} +func (m *OnSendRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *OnSendRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_OnSendRequest.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 *OnSendRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_OnSendRequest.Merge(m, src) +} +func (m *OnSendRequest) XXX_Size() int { + return m.Size() +} +func (m *OnSendRequest) XXX_DiscardUnknown() { + xxx_messageInfo_OnSendRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_OnSendRequest proto.InternalMessageInfo + +func (m *OnSendRequest) GetSender() string { + if m != nil { + return m.Sender + } + return "" +} + +func (m *OnSendRequest) GetReceiver() string { + if m != nil { + return m.Receiver + } + return "" +} + +func (m *OnSendRequest) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +func (m *OnSendRequest) GetAmount() string { + if m != nil { + return m.Amount + } + return "" +} + +type OnSendResponse struct { +} + +func (m *OnSendResponse) Reset() { *m = OnSendResponse{} } +func (m *OnSendResponse) String() string { return proto.CompactTextString(m) } +func (*OnSendResponse) ProtoMessage() {} +func (*OnSendResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ee4f62ba26b381ad, []int{3} +} +func (m *OnSendResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *OnSendResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_OnSendResponse.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 *OnSendResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_OnSendResponse.Merge(m, src) +} +func (m *OnSendResponse) XXX_Size() int { + return m.Size() +} +func (m *OnSendResponse) XXX_DiscardUnknown() { + xxx_messageInfo_OnSendResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_OnSendResponse proto.InternalMessageInfo + +type OnBurnRequest struct { + Burner string `protobuf:"bytes,1,opt,name=burner,proto3" json:"burner,omitempty"` + Denom string `protobuf:"bytes,2,opt,name=denom,proto3" json:"denom,omitempty"` + Amount string `protobuf:"bytes,3,opt,name=amount,proto3" json:"amount,omitempty"` +} + +func (m *OnBurnRequest) Reset() { *m = OnBurnRequest{} } +func (m *OnBurnRequest) String() string { return proto.CompactTextString(m) } +func (*OnBurnRequest) ProtoMessage() {} +func (*OnBurnRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ee4f62ba26b381ad, []int{4} +} +func (m *OnBurnRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *OnBurnRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_OnBurnRequest.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 *OnBurnRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_OnBurnRequest.Merge(m, src) +} +func (m *OnBurnRequest) XXX_Size() int { + return m.Size() +} +func (m *OnBurnRequest) XXX_DiscardUnknown() { + xxx_messageInfo_OnBurnRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_OnBurnRequest proto.InternalMessageInfo + +func (m *OnBurnRequest) GetBurner() string { + if m != nil { + return m.Burner + } + return "" +} + +func (m *OnBurnRequest) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +func (m *OnBurnRequest) GetAmount() string { + if m != nil { + return m.Amount + } + return "" +} + +type OnBurnResponse struct { +} + +func (m *OnBurnResponse) Reset() { *m = OnBurnResponse{} } +func (m *OnBurnResponse) String() string { return proto.CompactTextString(m) } +func (*OnBurnResponse) ProtoMessage() {} +func (*OnBurnResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ee4f62ba26b381ad, []int{5} +} +func (m *OnBurnResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *OnBurnResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_OnBurnResponse.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 *OnBurnResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_OnBurnResponse.Merge(m, src) +} +func (m *OnBurnResponse) XXX_Size() int { + return m.Size() +} +func (m *OnBurnResponse) XXX_DiscardUnknown() { + xxx_messageInfo_OnBurnResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_OnBurnResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*OnMintRequest)(nil), "cosmos.bank.v1beta1.OnMintRequest") + proto.RegisterType((*OnMintResponse)(nil), "cosmos.bank.v1beta1.OnMintResponse") + proto.RegisterType((*OnSendRequest)(nil), "cosmos.bank.v1beta1.OnSendRequest") + proto.RegisterType((*OnSendResponse)(nil), "cosmos.bank.v1beta1.OnSendResponse") + proto.RegisterType((*OnBurnRequest)(nil), "cosmos.bank.v1beta1.OnBurnRequest") + proto.RegisterType((*OnBurnResponse)(nil), "cosmos.bank.v1beta1.OnBurnResponse") +} + +func init() { + proto.RegisterFile("cosmos/bank/v1beta1/denom_manager.proto", fileDescriptor_ee4f62ba26b381ad) +} + +var fileDescriptor_ee4f62ba26b381ad = []byte{ + // 340 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x92, 0xb1, 0x4e, 0xc3, 0x30, + 0x10, 0x86, 0x9b, 0x16, 0x2a, 0xb0, 0x00, 0xa1, 0x80, 0x50, 0xd4, 0x21, 0x42, 0x65, 0x00, 0x06, + 0x1c, 0x15, 0xde, 0xa0, 0xb0, 0x56, 0x88, 0x22, 0x16, 0x16, 0x94, 0x34, 0xa7, 0x12, 0x55, 0x3e, + 0xb7, 0xb6, 0x53, 0xc1, 0x13, 0xb0, 0xf2, 0x58, 0x8c, 0x1d, 0x19, 0x51, 0xfb, 0x22, 0xc8, 0xb9, + 0x40, 0x8d, 0x68, 0x98, 0x98, 0xa2, 0x5f, 0xbe, 0x7c, 0xff, 0xef, 0xdf, 0xc7, 0x8e, 0x07, 0x52, + 0x0b, 0xa9, 0xa3, 0x24, 0xc6, 0x51, 0x34, 0xed, 0x24, 0x60, 0xe2, 0x4e, 0x94, 0x02, 0x4a, 0xf1, + 0x20, 0x62, 0x8c, 0x87, 0xa0, 0xf8, 0x58, 0x49, 0x23, 0xfd, 0x3d, 0x1a, 0xe4, 0x76, 0x90, 0x97, + 0x83, 0xed, 0x09, 0xdb, 0xbe, 0xc6, 0x5e, 0x86, 0xa6, 0x0f, 0x93, 0x1c, 0xb4, 0xf1, 0x0f, 0x58, + 0x53, 0x64, 0x68, 0x40, 0x05, 0xde, 0xa1, 0x77, 0xb2, 0xd9, 0x2f, 0x95, 0xdf, 0x62, 0x1b, 0x0a, + 0x06, 0x90, 0x4d, 0x41, 0x05, 0xf5, 0xe2, 0xe4, 0x5b, 0xfb, 0xfb, 0x6c, 0xbd, 0x30, 0x0c, 0x1a, + 0xc5, 0x01, 0x09, 0x4b, 0x8a, 0x85, 0xcc, 0xd1, 0x04, 0x6b, 0x44, 0x22, 0xd5, 0xde, 0x65, 0x3b, + 0x5f, 0x96, 0x7a, 0x2c, 0x51, 0x03, 0x85, 0xb8, 0x05, 0x4c, 0x9d, 0x10, 0x1a, 0x30, 0x5d, 0x86, + 0x20, 0xf5, 0xdf, 0x21, 0xc8, 0xb2, 0x0c, 0x71, 0x67, 0x43, 0x74, 0x73, 0x85, 0x4e, 0x88, 0x24, + 0x57, 0xb8, 0x0c, 0x41, 0x6a, 0x69, 0x54, 0x5f, 0x6d, 0xd4, 0xf8, 0x6d, 0x44, 0x58, 0x32, 0x3a, + 0x7f, 0xa9, 0xb3, 0xad, 0x2b, 0xfb, 0x4f, 0x8f, 0x9e, 0xc7, 0xbf, 0x61, 0x4d, 0x2a, 0xc4, 0x6f, + 0xf3, 0x15, 0x6f, 0xc4, 0x7f, 0x3c, 0x50, 0xeb, 0xe8, 0xcf, 0x19, 0xf2, 0x20, 0xa4, 0xbd, 0x5e, + 0x25, 0xd2, 0xa9, 0xbb, 0x12, 0xe9, 0xf6, 0x43, 0x48, 0x7b, 0x91, 0x4a, 0xa4, 0x53, 0x5e, 0x25, + 0xd2, 0x6d, 0xa2, 0x7b, 0xf9, 0x36, 0x0f, 0xbd, 0xd9, 0x3c, 0xf4, 0x3e, 0xe6, 0xa1, 0xf7, 0xba, + 0x08, 0x6b, 0xb3, 0x45, 0x58, 0x7b, 0x5f, 0x84, 0xb5, 0xfb, 0xd3, 0x61, 0x66, 0x1e, 0xf3, 0x84, + 0x0f, 0xa4, 0x88, 0xca, 0xfd, 0xa6, 0xcf, 0x99, 0x4e, 0x47, 0xd1, 0x13, 0x2d, 0xbb, 0x79, 0x1e, + 0x83, 0x4e, 0x9a, 0xc5, 0x76, 0x5f, 0x7c, 0x06, 0x00, 0x00, 0xff, 0xff, 0x71, 0xec, 0x5d, 0xc9, + 0x08, 0x03, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// DenomManagerClient is the client API for DenomManager service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type DenomManagerClient interface { + OnMint(ctx context.Context, in *OnMintRequest, opts ...grpc.CallOption) (*OnMintResponse, error) + OnSend(ctx context.Context, in *OnSendRequest, opts ...grpc.CallOption) (*OnSendResponse, error) + OnBurn(ctx context.Context, in *OnBurnRequest, opts ...grpc.CallOption) (*OnBurnResponse, error) +} + +type denomManagerClient struct { + cc grpc1.ClientConn +} + +func NewDenomManagerClient(cc grpc1.ClientConn) DenomManagerClient { + return &denomManagerClient{cc} +} + +func (c *denomManagerClient) OnMint(ctx context.Context, in *OnMintRequest, opts ...grpc.CallOption) (*OnMintResponse, error) { + out := new(OnMintResponse) + err := c.cc.Invoke(ctx, "/cosmos.bank.v1beta1.DenomManager/OnMint", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *denomManagerClient) OnSend(ctx context.Context, in *OnSendRequest, opts ...grpc.CallOption) (*OnSendResponse, error) { + out := new(OnSendResponse) + err := c.cc.Invoke(ctx, "/cosmos.bank.v1beta1.DenomManager/OnSend", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *denomManagerClient) OnBurn(ctx context.Context, in *OnBurnRequest, opts ...grpc.CallOption) (*OnBurnResponse, error) { + out := new(OnBurnResponse) + err := c.cc.Invoke(ctx, "/cosmos.bank.v1beta1.DenomManager/OnBurn", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// DenomManagerServer is the server API for DenomManager service. +type DenomManagerServer interface { + OnMint(context.Context, *OnMintRequest) (*OnMintResponse, error) + OnSend(context.Context, *OnSendRequest) (*OnSendResponse, error) + OnBurn(context.Context, *OnBurnRequest) (*OnBurnResponse, error) +} + +// UnimplementedDenomManagerServer can be embedded to have forward compatible implementations. +type UnimplementedDenomManagerServer struct { +} + +func (*UnimplementedDenomManagerServer) OnMint(ctx context.Context, req *OnMintRequest) (*OnMintResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method OnMint not implemented") +} +func (*UnimplementedDenomManagerServer) OnSend(ctx context.Context, req *OnSendRequest) (*OnSendResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method OnSend not implemented") +} +func (*UnimplementedDenomManagerServer) OnBurn(ctx context.Context, req *OnBurnRequest) (*OnBurnResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method OnBurn not implemented") +} + +func RegisterDenomManagerServer(s grpc1.Server, srv DenomManagerServer) { + s.RegisterService(&_DenomManager_serviceDesc, srv) +} + +func _DenomManager_OnMint_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(OnMintRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DenomManagerServer).OnMint(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.bank.v1beta1.DenomManager/OnMint", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DenomManagerServer).OnMint(ctx, req.(*OnMintRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _DenomManager_OnSend_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(OnSendRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DenomManagerServer).OnSend(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.bank.v1beta1.DenomManager/OnSend", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DenomManagerServer).OnSend(ctx, req.(*OnSendRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _DenomManager_OnBurn_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(OnBurnRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DenomManagerServer).OnBurn(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.bank.v1beta1.DenomManager/OnBurn", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DenomManagerServer).OnBurn(ctx, req.(*OnBurnRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _DenomManager_serviceDesc = grpc.ServiceDesc{ + ServiceName: "cosmos.bank.v1beta1.DenomManager", + HandlerType: (*DenomManagerServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "OnMint", + Handler: _DenomManager_OnMint_Handler, + }, + { + MethodName: "OnSend", + Handler: _DenomManager_OnSend_Handler, + }, + { + MethodName: "OnBurn", + Handler: _DenomManager_OnBurn_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "cosmos/bank/v1beta1/denom_manager.proto", +} + +func (m *OnMintRequest) 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 *OnMintRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *OnMintRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Amount) > 0 { + i -= len(m.Amount) + copy(dAtA[i:], m.Amount) + i = encodeVarintDenomManager(dAtA, i, uint64(len(m.Amount))) + i-- + dAtA[i] = 0x22 + } + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintDenomManager(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0x1a + } + if len(m.Receiver) > 0 { + i -= len(m.Receiver) + copy(dAtA[i:], m.Receiver) + i = encodeVarintDenomManager(dAtA, i, uint64(len(m.Receiver))) + i-- + dAtA[i] = 0x12 + } + if len(m.Minter) > 0 { + i -= len(m.Minter) + copy(dAtA[i:], m.Minter) + i = encodeVarintDenomManager(dAtA, i, uint64(len(m.Minter))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *OnMintResponse) 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 *OnMintResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *OnMintResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *OnSendRequest) 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 *OnSendRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *OnSendRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Amount) > 0 { + i -= len(m.Amount) + copy(dAtA[i:], m.Amount) + i = encodeVarintDenomManager(dAtA, i, uint64(len(m.Amount))) + i-- + dAtA[i] = 0x22 + } + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintDenomManager(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0x1a + } + if len(m.Receiver) > 0 { + i -= len(m.Receiver) + copy(dAtA[i:], m.Receiver) + i = encodeVarintDenomManager(dAtA, i, uint64(len(m.Receiver))) + i-- + dAtA[i] = 0x12 + } + if len(m.Sender) > 0 { + i -= len(m.Sender) + copy(dAtA[i:], m.Sender) + i = encodeVarintDenomManager(dAtA, i, uint64(len(m.Sender))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *OnSendResponse) 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 *OnSendResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *OnSendResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *OnBurnRequest) 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 *OnBurnRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *OnBurnRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Amount) > 0 { + i -= len(m.Amount) + copy(dAtA[i:], m.Amount) + i = encodeVarintDenomManager(dAtA, i, uint64(len(m.Amount))) + i-- + dAtA[i] = 0x1a + } + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintDenomManager(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0x12 + } + if len(m.Burner) > 0 { + i -= len(m.Burner) + copy(dAtA[i:], m.Burner) + i = encodeVarintDenomManager(dAtA, i, uint64(len(m.Burner))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *OnBurnResponse) 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 *OnBurnResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *OnBurnResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintDenomManager(dAtA []byte, offset int, v uint64) int { + offset -= sovDenomManager(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *OnMintRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Minter) + if l > 0 { + n += 1 + l + sovDenomManager(uint64(l)) + } + l = len(m.Receiver) + if l > 0 { + n += 1 + l + sovDenomManager(uint64(l)) + } + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovDenomManager(uint64(l)) + } + l = len(m.Amount) + if l > 0 { + n += 1 + l + sovDenomManager(uint64(l)) + } + return n +} + +func (m *OnMintResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *OnSendRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovDenomManager(uint64(l)) + } + l = len(m.Receiver) + if l > 0 { + n += 1 + l + sovDenomManager(uint64(l)) + } + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovDenomManager(uint64(l)) + } + l = len(m.Amount) + if l > 0 { + n += 1 + l + sovDenomManager(uint64(l)) + } + return n +} + +func (m *OnSendResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *OnBurnRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Burner) + if l > 0 { + n += 1 + l + sovDenomManager(uint64(l)) + } + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovDenomManager(uint64(l)) + } + l = len(m.Amount) + if l > 0 { + n += 1 + l + sovDenomManager(uint64(l)) + } + return n +} + +func (m *OnBurnResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovDenomManager(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozDenomManager(x uint64) (n int) { + return sovDenomManager(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *OnMintRequest) 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 ErrIntOverflowDenomManager + } + 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: OnMintRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OnMintRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Minter", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDenomManager + } + 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 ErrInvalidLengthDenomManager + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDenomManager + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Minter = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Receiver", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDenomManager + } + 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 ErrInvalidLengthDenomManager + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDenomManager + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Receiver = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDenomManager + } + 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 ErrInvalidLengthDenomManager + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDenomManager + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDenomManager + } + 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 ErrInvalidLengthDenomManager + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDenomManager + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Amount = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDenomManager(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDenomManager + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OnMintResponse) 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 ErrIntOverflowDenomManager + } + 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: OnMintResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OnMintResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipDenomManager(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDenomManager + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OnSendRequest) 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 ErrIntOverflowDenomManager + } + 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: OnSendRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OnSendRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDenomManager + } + 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 ErrInvalidLengthDenomManager + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDenomManager + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sender = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Receiver", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDenomManager + } + 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 ErrInvalidLengthDenomManager + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDenomManager + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Receiver = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDenomManager + } + 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 ErrInvalidLengthDenomManager + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDenomManager + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDenomManager + } + 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 ErrInvalidLengthDenomManager + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDenomManager + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Amount = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDenomManager(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDenomManager + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OnSendResponse) 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 ErrIntOverflowDenomManager + } + 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: OnSendResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OnSendResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipDenomManager(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDenomManager + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OnBurnRequest) 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 ErrIntOverflowDenomManager + } + 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: OnBurnRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OnBurnRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Burner", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDenomManager + } + 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 ErrInvalidLengthDenomManager + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDenomManager + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Burner = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDenomManager + } + 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 ErrInvalidLengthDenomManager + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDenomManager + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDenomManager + } + 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 ErrInvalidLengthDenomManager + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDenomManager + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Amount = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDenomManager(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDenomManager + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OnBurnResponse) 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 ErrIntOverflowDenomManager + } + 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: OnBurnResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OnBurnResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipDenomManager(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDenomManager + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipDenomManager(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, ErrIntOverflowDenomManager + } + 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, ErrIntOverflowDenomManager + } + 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, ErrIntOverflowDenomManager + } + 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, ErrInvalidLengthDenomManager + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupDenomManager + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthDenomManager + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthDenomManager = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowDenomManager = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupDenomManager = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/bank/types/module.pb.go b/x/bank/types/module.pb.go index 6d56edf55ea9..dbf811f59974 100644 --- a/x/bank/types/module.pb.go +++ b/x/bank/types/module.pb.go @@ -5,6 +5,7 @@ package types import ( fmt "fmt" + types "github.com/cosmos/cosmos-sdk/codec/types" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -23,7 +24,8 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Module struct { - SendDenyList []string `protobuf:"bytes,1,rep,name=send_deny_list,json=sendDenyList,proto3" json:"send_deny_list,omitempty"` + SendDenyList []string `protobuf:"bytes,1,rep,name=send_deny_list,json=sendDenyList,proto3" json:"send_deny_list,omitempty"` + DenomManagers map[string]*types.Any `protobuf:"bytes,3,rep,name=denom_managers,json=denomManagers,proto3" json:"denom_managers,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (m *Module) Reset() { *m = Module{} } @@ -66,25 +68,41 @@ func (m *Module) GetSendDenyList() []string { return nil } +func (m *Module) GetDenomManagers() map[string]*types.Any { + if m != nil { + return m.DenomManagers + } + return nil +} + func init() { proto.RegisterType((*Module)(nil), "cosmos.bank.v1beta1.Module") + proto.RegisterMapType((map[string]*types.Any)(nil), "cosmos.bank.v1beta1.Module.DenomManagersEntry") } func init() { proto.RegisterFile("cosmos/bank/v1beta1/module.proto", fileDescriptor_2d644efccd29e8d3) } var fileDescriptor_2d644efccd29e8d3 = []byte{ - // 174 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce, - 0xcd, 0x2f, 0xd6, 0x4f, 0x4a, 0xcc, 0xcb, 0xd6, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, - 0xcf, 0xcd, 0x4f, 0x29, 0xcd, 0x49, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, 0xa8, - 0xd0, 0x03, 0xa9, 0xd0, 0x83, 0xaa, 0x50, 0xd2, 0xe3, 0x62, 0xf3, 0x05, 0x2b, 0x12, 0x52, 0xe1, - 0xe2, 0x2b, 0x4e, 0xcd, 0x4b, 0x89, 0x4f, 0x49, 0xcd, 0xab, 0x8c, 0xcf, 0xc9, 0x2c, 0x2e, 0x91, - 0x60, 0x54, 0x60, 0xd6, 0xe0, 0x0c, 0xe2, 0x01, 0x89, 0xba, 0xa4, 0xe6, 0x55, 0xfa, 0x64, 0x16, - 0x97, 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, 0x66, 0x7a, - 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0xd4, 0x2d, 0x10, 0x4a, 0xb7, 0x38, - 0x25, 0x5b, 0xbf, 0x02, 0xe2, 0xb0, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0xb0, 0x83, 0x8c, - 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x06, 0x38, 0xca, 0x0a, 0xb4, 0x00, 0x00, 0x00, + // 297 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0x41, 0x4b, 0xc3, 0x30, + 0x1c, 0xc5, 0x97, 0x15, 0x07, 0xcb, 0x74, 0x48, 0xf4, 0x50, 0x77, 0x08, 0x45, 0x3c, 0x54, 0xc1, + 0x84, 0xcd, 0x8b, 0x78, 0x53, 0xe7, 0xcd, 0x5d, 0x0a, 0x7a, 0xf0, 0x32, 0xd2, 0x25, 0xd6, 0xb1, + 0x36, 0x19, 0x4d, 0x3a, 0xcc, 0xb7, 0xf0, 0x63, 0x79, 0xdc, 0xd1, 0x8b, 0x20, 0xed, 0x17, 0x91, + 0x36, 0x15, 0x04, 0x3d, 0x25, 0x3c, 0x7e, 0xef, 0xfd, 0x79, 0x0f, 0x06, 0x0b, 0xa5, 0x33, 0xa5, + 0x69, 0xcc, 0xe4, 0x8a, 0x6e, 0xc6, 0xb1, 0x30, 0x6c, 0x4c, 0x33, 0xc5, 0x8b, 0x54, 0x90, 0x75, + 0xae, 0x8c, 0x42, 0x07, 0x8e, 0x20, 0x35, 0x41, 0x5a, 0x62, 0x74, 0x94, 0x28, 0x95, 0xa4, 0x82, + 0x36, 0x48, 0x5c, 0x3c, 0x53, 0x26, 0xad, 0xe3, 0x8f, 0x3f, 0x01, 0xec, 0xcd, 0x9a, 0x00, 0x74, + 0x02, 0x87, 0x5a, 0x48, 0x3e, 0xe7, 0x42, 0xda, 0x79, 0xba, 0xd4, 0xc6, 0x07, 0x81, 0x17, 0xf6, + 0xa3, 0xdd, 0x5a, 0x9d, 0x0a, 0x69, 0xef, 0x97, 0xda, 0xa0, 0x07, 0x38, 0xe4, 0x42, 0xaa, 0x6c, + 0x9e, 0x31, 0xc9, 0x12, 0x91, 0x6b, 0xdf, 0x0b, 0xbc, 0x70, 0x30, 0x21, 0xe4, 0x9f, 0xcb, 0xc4, + 0x45, 0x93, 0x69, 0xed, 0x98, 0xb5, 0x86, 0x3b, 0x69, 0x72, 0x1b, 0xed, 0xf1, 0xdf, 0xda, 0xe8, + 0x11, 0xa2, 0xbf, 0x10, 0xda, 0x87, 0xde, 0x4a, 0x58, 0x1f, 0x04, 0x20, 0xec, 0x47, 0xf5, 0x17, + 0x9d, 0xc1, 0x9d, 0x0d, 0x4b, 0x0b, 0xe1, 0x77, 0x03, 0x10, 0x0e, 0x26, 0x87, 0xc4, 0x55, 0x23, + 0x3f, 0xd5, 0xc8, 0xb5, 0xb4, 0x91, 0x43, 0xae, 0xba, 0x97, 0xe0, 0xe6, 0xf6, 0xbd, 0xc4, 0x60, + 0x5b, 0x62, 0xf0, 0x55, 0x62, 0xf0, 0x56, 0xe1, 0xce, 0xb6, 0xc2, 0x9d, 0x8f, 0x0a, 0x77, 0x9e, + 0x4e, 0x93, 0xa5, 0x79, 0x29, 0x62, 0xb2, 0x50, 0x19, 0x6d, 0x67, 0x75, 0xcf, 0xb9, 0xe6, 0x2b, + 0xfa, 0xea, 0x36, 0x36, 0x76, 0x2d, 0x74, 0xdc, 0x6b, 0xd2, 0x2f, 0xbe, 0x03, 0x00, 0x00, 0xff, + 0xff, 0x00, 0x18, 0xe7, 0xe9, 0x7f, 0x01, 0x00, 0x00, } func (m *Module) Marshal() (dAtA []byte, err error) { @@ -107,6 +125,32 @@ func (m *Module) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.DenomManagers) > 0 { + for k := range m.DenomManagers { + v := m.DenomManagers[k] + baseI := i + if v != nil { + { + size, err := v.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintModule(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + i -= len(k) + copy(dAtA[i:], k) + i = encodeVarintModule(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = encodeVarintModule(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x1a + } + } if len(m.SendDenyList) > 0 { for iNdEx := len(m.SendDenyList) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.SendDenyList[iNdEx]) @@ -142,6 +186,19 @@ func (m *Module) Size() (n int) { n += 1 + l + sovModule(uint64(l)) } } + if len(m.DenomManagers) > 0 { + for k, v := range m.DenomManagers { + _ = k + _ = v + l = 0 + if v != nil { + l = v.Size() + l += 1 + sovModule(uint64(l)) + } + mapEntrySize := 1 + len(k) + sovModule(uint64(len(k))) + l + n += mapEntrySize + 1 + sovModule(uint64(mapEntrySize)) + } + } return n } @@ -212,6 +269,135 @@ func (m *Module) Unmarshal(dAtA []byte) error { } m.SendDenyList = append(m.SendDenyList, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DenomManagers", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthModule + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthModule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.DenomManagers == nil { + m.DenomManagers = make(map[string]*types.Any) + } + var mapkey string + var mapvalue *types.Any + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return ErrInvalidLengthModule + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return ErrInvalidLengthModule + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + var mapmsglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapmsglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if mapmsglen < 0 { + return ErrInvalidLengthModule + } + postmsgIndex := iNdEx + mapmsglen + if postmsgIndex < 0 { + return ErrInvalidLengthModule + } + if postmsgIndex > l { + return io.ErrUnexpectedEOF + } + mapvalue = &types.Any{} + if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil { + return err + } + iNdEx = postmsgIndex + } else { + iNdEx = entryPreIndex + skippy, err := skipModule(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthModule + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.DenomManagers[mapkey] = mapvalue + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipModule(dAtA[iNdEx:]) diff --git a/x/collectible/plugin.pb.go b/x/collectible/plugin.pb.go new file mode 100644 index 000000000000..48d7d99832f3 --- /dev/null +++ b/x/collectible/plugin.pb.go @@ -0,0 +1,265 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/collectible/v1alpha1/plugin.proto + +package collectible + +import ( + fmt "fmt" + 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 + +type CollectibleDenomManager struct { +} + +func (m *CollectibleDenomManager) Reset() { *m = CollectibleDenomManager{} } +func (m *CollectibleDenomManager) String() string { return proto.CompactTextString(m) } +func (*CollectibleDenomManager) ProtoMessage() {} +func (*CollectibleDenomManager) Descriptor() ([]byte, []int) { + return fileDescriptor_e1eb5ddf6f742047, []int{0} +} +func (m *CollectibleDenomManager) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CollectibleDenomManager) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CollectibleDenomManager.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 *CollectibleDenomManager) XXX_Merge(src proto.Message) { + xxx_messageInfo_CollectibleDenomManager.Merge(m, src) +} +func (m *CollectibleDenomManager) XXX_Size() int { + return m.Size() +} +func (m *CollectibleDenomManager) XXX_DiscardUnknown() { + xxx_messageInfo_CollectibleDenomManager.DiscardUnknown(m) +} + +var xxx_messageInfo_CollectibleDenomManager proto.InternalMessageInfo + +func init() { + proto.RegisterType((*CollectibleDenomManager)(nil), "cosmos.collectible.v1alpha1.CollectibleDenomManager") +} + +func init() { + proto.RegisterFile("cosmos/collectible/v1alpha1/plugin.proto", fileDescriptor_e1eb5ddf6f742047) +} + +var fileDescriptor_e1eb5ddf6f742047 = []byte{ + // 153 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x48, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0xce, 0xcf, 0xc9, 0x49, 0x4d, 0x2e, 0xc9, 0x4c, 0xca, 0x49, 0xd5, 0x2f, + 0x33, 0x4c, 0xcc, 0x29, 0xc8, 0x48, 0x34, 0xd4, 0x2f, 0xc8, 0x29, 0x4d, 0xcf, 0xcc, 0xd3, 0x2b, + 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x86, 0xa8, 0xd4, 0x43, 0x52, 0xa9, 0x07, 0x53, 0xa9, 0x24, + 0xc9, 0x25, 0xee, 0x8c, 0x10, 0x77, 0x49, 0xcd, 0xcb, 0xcf, 0xf5, 0x4d, 0xcc, 0x4b, 0x4c, 0x4f, + 0x2d, 0x72, 0x72, 0x39, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, + 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xad, 0xf4, + 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0xb8, 0x33, 0x40, 0x94, 0x6e, 0x71, + 0x4a, 0xb6, 0x7e, 0x05, 0xb2, 0x9b, 0x92, 0xd8, 0xc0, 0x8e, 0x30, 0x06, 0x04, 0x00, 0x00, 0xff, + 0xff, 0xf2, 0x17, 0xe7, 0x67, 0xb0, 0x00, 0x00, 0x00, +} + +func (m *CollectibleDenomManager) 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 *CollectibleDenomManager) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CollectibleDenomManager) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintPlugin(dAtA []byte, offset int, v uint64) int { + offset -= sovPlugin(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *CollectibleDenomManager) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovPlugin(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPlugin(x uint64) (n int) { + return sovPlugin(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *CollectibleDenomManager) 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 ErrIntOverflowPlugin + } + 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: CollectibleDenomManager: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CollectibleDenomManager: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipPlugin(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPlugin + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPlugin(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, ErrIntOverflowPlugin + } + 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, ErrIntOverflowPlugin + } + 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, ErrIntOverflowPlugin + } + 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, ErrInvalidLengthPlugin + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPlugin + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPlugin + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPlugin = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPlugin = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPlugin = fmt.Errorf("proto: unexpected end of group") +) From ed3dc542de1d175e9b78fd42b57913a99e8ec21a Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 28 May 2021 15:18:50 -0400 Subject: [PATCH 12/19] WIP --- core/app_config/app_config.go | 50 +- core/app_config/default_middleware.go | 1 + core/app_config/default_middleware.pb.go | 508 ++++++++++++++++++ core/app_config/tx.go | 31 ++ core/{app_config => baseapp}/app.go | 14 +- core/baseapp/gas.go | 62 +++ core/baseapp/header.go | 115 ++++ core/baseapp/middleware.go | 44 ++ core/baseapp/store.go | 97 ++++ core/codec/registry.go | 34 ++ core/module/app/events.go | 2 +- core/module/app/middleware.go | 31 -- core/module/app/module.go | 21 +- core/module/app/plugins.go | 4 +- core/module/app/registry.go | 54 ++ core/module/module.go | 71 ++- core/module/registry.go | 40 ++ core/msg.go | 6 + core/store/store.go | 62 +++ core/tx/module/module.go | 88 +++ docs/core/proto-docs.md | 39 ++ .../core/app_config/v1/app_config.proto | 2 +- .../app_config/v1/default_middleware.proto | 13 + simapp2/app_config.json | 35 +- x/authn/app/handler.go | 124 +++++ x/authn/app/middleware.go | 6 +- x/authn/app/module.go | 48 -- x/authn/codec.go | 8 + x/authn/credential.go | 5 + x/authn/module/module.go | 30 +- x/bank/module/module.go | 2 +- 31 files changed, 1428 insertions(+), 219 deletions(-) create mode 100644 core/app_config/default_middleware.go create mode 100644 core/app_config/default_middleware.pb.go create mode 100644 core/app_config/tx.go rename core/{app_config => baseapp}/app.go (85%) create mode 100644 core/baseapp/gas.go create mode 100644 core/baseapp/header.go create mode 100644 core/baseapp/middleware.go create mode 100644 core/baseapp/store.go create mode 100644 core/codec/registry.go delete mode 100644 core/module/app/middleware.go create mode 100644 core/module/app/registry.go create mode 100644 core/module/registry.go create mode 100644 core/msg.go create mode 100644 core/store/store.go create mode 100644 core/tx/module/module.go create mode 100644 proto/cosmos/core/app_config/v1/default_middleware.proto create mode 100644 x/authn/app/handler.go delete mode 100644 x/authn/app/module.go create mode 100644 x/authn/codec.go create mode 100644 x/authn/credential.go diff --git a/core/app_config/app_config.go b/core/app_config/app_config.go index 6117b6f8476d..7cd046d1bcd1 100644 --- a/core/app_config/app_config.go +++ b/core/app_config/app_config.go @@ -2,37 +2,27 @@ package app_config import ( "github.com/tendermint/tendermint/abci/types" - - "github.com/cosmos/cosmos-sdk/core/module" - "github.com/cosmos/cosmos-sdk/core/module/app" ) func Compose(config AppConfig) (types.Application, error) { - moduleSet := module.NewModuleSet(config.Modules) - - appModules := make(map[string]app.Module) - moduleSet.Each(func(name string, handler module.ModuleHandler) { - // TODO - }) - - bapp := &baseApp{} - - var beginBlockers []app.BeginBlocker - for _, m := range config.Abci.BeginBlock { - mod, ok := appModules[m] - if !ok { - panic("TODO") - } - - beginBlocker, ok := mod.(app.BeginBlocker) - if !ok { - panic("TODO") - } - - beginBlockers = append(beginBlockers, beginBlocker) - } - - bapp.beginBlockers = beginBlockers - - return bapp, nil + //moduleSet := module.NewModuleSet(config.Modules) + + //appModules := make(map[string]app.Module) + //moduleSet.Each(func(name string, handler module.ModuleHandler) { + // // TODO + //}) + + //bapp := &baseapp.baseApp{} + // + //for _, m := range config.Abci.BeginBlock { + // bapp.beginBlockers = append(bapp.beginBlockers, appModules[m].(app.BeginBlocker)) + //} + // + //for _, m := range config.Abci.EndBlock { + // bapp.endBlockers = append(bapp.endBlockers, appModules[m].(app.EndBlocker)) + //} + // + //return bapp, nil + + panic("TODO") } diff --git a/core/app_config/default_middleware.go b/core/app_config/default_middleware.go new file mode 100644 index 000000000000..d4a058bca85c --- /dev/null +++ b/core/app_config/default_middleware.go @@ -0,0 +1 @@ +package app_config diff --git a/core/app_config/default_middleware.pb.go b/core/app_config/default_middleware.pb.go new file mode 100644 index 000000000000..ec1f5af42331 --- /dev/null +++ b/core/app_config/default_middleware.pb.go @@ -0,0 +1,508 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/core/app_config/v1/default_middleware.proto + +package app_config + +import ( + fmt "fmt" + 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 + +type DefaultTxMiddleware struct { + MaxMemoCharacters uint64 `protobuf:"varint,1,opt,name=max_memo_characters,json=maxMemoCharacters,proto3" json:"max_memo_characters,omitempty"` + TxSizeCostPerByte uint64 `protobuf:"varint,2,opt,name=tx_size_cost_per_byte,json=txSizeCostPerByte,proto3" json:"tx_size_cost_per_byte,omitempty"` + TxSigLimit uint64 `protobuf:"varint,3,opt,name=tx_sig_limit,json=txSigLimit,proto3" json:"tx_sig_limit,omitempty"` + SigVerifyCostEd25519 uint64 `protobuf:"varint,4,opt,name=sig_verify_cost_ed25519,json=sigVerifyCostEd25519,proto3" json:"sig_verify_cost_ed25519,omitempty"` + SigVerifyCostSecp256K1 uint64 `protobuf:"varint,5,opt,name=sig_verify_cost_secp256k1,json=sigVerifyCostSecp256k1,proto3" json:"sig_verify_cost_secp256k1,omitempty"` + AllowedPubKeyTypes []string `protobuf:"bytes,6,rep,name=allowed_pub_key_types,json=allowedPubKeyTypes,proto3" json:"allowed_pub_key_types,omitempty"` +} + +func (m *DefaultTxMiddleware) Reset() { *m = DefaultTxMiddleware{} } +func (m *DefaultTxMiddleware) String() string { return proto.CompactTextString(m) } +func (*DefaultTxMiddleware) ProtoMessage() {} +func (*DefaultTxMiddleware) Descriptor() ([]byte, []int) { + return fileDescriptor_98b7f521c81e3c2e, []int{0} +} +func (m *DefaultTxMiddleware) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DefaultTxMiddleware) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DefaultTxMiddleware.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 *DefaultTxMiddleware) XXX_Merge(src proto.Message) { + xxx_messageInfo_DefaultTxMiddleware.Merge(m, src) +} +func (m *DefaultTxMiddleware) XXX_Size() int { + return m.Size() +} +func (m *DefaultTxMiddleware) XXX_DiscardUnknown() { + xxx_messageInfo_DefaultTxMiddleware.DiscardUnknown(m) +} + +var xxx_messageInfo_DefaultTxMiddleware proto.InternalMessageInfo + +func (m *DefaultTxMiddleware) GetMaxMemoCharacters() uint64 { + if m != nil { + return m.MaxMemoCharacters + } + return 0 +} + +func (m *DefaultTxMiddleware) GetTxSizeCostPerByte() uint64 { + if m != nil { + return m.TxSizeCostPerByte + } + return 0 +} + +func (m *DefaultTxMiddleware) GetTxSigLimit() uint64 { + if m != nil { + return m.TxSigLimit + } + return 0 +} + +func (m *DefaultTxMiddleware) GetSigVerifyCostEd25519() uint64 { + if m != nil { + return m.SigVerifyCostEd25519 + } + return 0 +} + +func (m *DefaultTxMiddleware) GetSigVerifyCostSecp256K1() uint64 { + if m != nil { + return m.SigVerifyCostSecp256K1 + } + return 0 +} + +func (m *DefaultTxMiddleware) GetAllowedPubKeyTypes() []string { + if m != nil { + return m.AllowedPubKeyTypes + } + return nil +} + +func init() { + proto.RegisterType((*DefaultTxMiddleware)(nil), "cosmos.core.app_config.v1.DefaultTxMiddleware") +} + +func init() { + proto.RegisterFile("cosmos/core/app_config/v1/default_middleware.proto", fileDescriptor_98b7f521c81e3c2e) +} + +var fileDescriptor_98b7f521c81e3c2e = []byte{ + // 356 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0xd1, 0x31, 0x8f, 0xda, 0x30, + 0x14, 0xc0, 0x71, 0x02, 0x14, 0xa9, 0x56, 0x97, 0x9a, 0xd2, 0x86, 0x25, 0x42, 0x9d, 0x18, 0xda, + 0xa4, 0xa1, 0x4a, 0x25, 0x56, 0x68, 0xbb, 0xb4, 0x48, 0x08, 0x50, 0x87, 0x2e, 0x96, 0xe3, 0x3c, + 0x82, 0x45, 0x5c, 0x47, 0xb6, 0x03, 0x09, 0x9f, 0xa2, 0x9f, 0xe8, 0xe6, 0x1b, 0x19, 0x6f, 0x3c, + 0xc1, 0x17, 0x39, 0x25, 0xb9, 0xe3, 0x74, 0x4c, 0x96, 0xfc, 0x7f, 0xbf, 0xb7, 0x3c, 0x34, 0x62, + 0x52, 0x0b, 0xa9, 0x3d, 0x26, 0x15, 0x78, 0x34, 0x4d, 0x09, 0x93, 0xff, 0xd6, 0x3c, 0xf6, 0x76, + 0xbe, 0x17, 0xc1, 0x9a, 0x66, 0x89, 0x21, 0x82, 0x47, 0x51, 0x02, 0x7b, 0xaa, 0xc0, 0x4d, 0x95, + 0x34, 0x12, 0xf7, 0x6b, 0xe3, 0x96, 0xc6, 0x7d, 0x36, 0xee, 0xce, 0xff, 0x78, 0xd3, 0x44, 0xdd, + 0xef, 0xb5, 0x5b, 0xe5, 0xb3, 0x0b, 0xc4, 0x2e, 0xea, 0x0a, 0x9a, 0x13, 0x01, 0x42, 0x12, 0xb6, + 0xa1, 0x8a, 0x32, 0x03, 0x4a, 0xdb, 0xd6, 0xc0, 0x1a, 0xb6, 0x17, 0x6f, 0x05, 0xcd, 0x67, 0x20, + 0xe4, 0xf4, 0x12, 0xf0, 0x17, 0xd4, 0x33, 0x39, 0xd1, 0xfc, 0x00, 0x84, 0x49, 0x6d, 0x48, 0x0a, + 0x8a, 0x84, 0x85, 0x01, 0xbb, 0x59, 0x0b, 0x93, 0x2f, 0xf9, 0x01, 0xa6, 0x52, 0x9b, 0x39, 0xa8, + 0x49, 0x61, 0x00, 0x0f, 0xd0, 0x9b, 0x4a, 0xc4, 0x24, 0xe1, 0x82, 0x1b, 0xbb, 0x55, 0x0d, 0xa2, + 0x72, 0x30, 0xfe, 0x5d, 0xfe, 0xe0, 0x00, 0x7d, 0x28, 0xf3, 0x0e, 0x14, 0x5f, 0x17, 0xf5, 0x5a, + 0x88, 0x46, 0x41, 0xe0, 0x8f, 0xed, 0x76, 0x35, 0xfc, 0x4e, 0xf3, 0xf8, 0x4f, 0x55, 0xcb, 0xc5, + 0x3f, 0xea, 0x86, 0xc7, 0xa8, 0x7f, 0xcd, 0x34, 0xb0, 0x74, 0x14, 0x7c, 0xdb, 0xfa, 0xf6, 0xab, + 0x0a, 0xbe, 0x7f, 0x01, 0x97, 0x4f, 0x15, 0xfb, 0xa8, 0x47, 0x93, 0x44, 0xee, 0x21, 0x22, 0x69, + 0x16, 0x92, 0x2d, 0x14, 0xc4, 0x14, 0x29, 0x68, 0xbb, 0x33, 0x68, 0x0d, 0x5f, 0x2f, 0xf0, 0x63, + 0x9c, 0x67, 0xe1, 0x2f, 0x28, 0x56, 0x65, 0x99, 0xfc, 0xbc, 0x3d, 0x39, 0xd6, 0xf1, 0xe4, 0x58, + 0xf7, 0x27, 0xc7, 0xfa, 0x7f, 0x76, 0x1a, 0xc7, 0xb3, 0xd3, 0xb8, 0x3b, 0x3b, 0x8d, 0xbf, 0x9f, + 0x62, 0x6e, 0x36, 0x59, 0xe8, 0x32, 0x29, 0xbc, 0xcb, 0xd1, 0xca, 0xe7, 0xb3, 0x8e, 0xb6, 0xd7, + 0xf7, 0x0b, 0x3b, 0xd5, 0xa9, 0xbe, 0x3e, 0x04, 0x00, 0x00, 0xff, 0xff, 0x45, 0x07, 0x42, 0x80, + 0xe0, 0x01, 0x00, 0x00, +} + +func (m *DefaultTxMiddleware) 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 *DefaultTxMiddleware) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DefaultTxMiddleware) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.AllowedPubKeyTypes) > 0 { + for iNdEx := len(m.AllowedPubKeyTypes) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.AllowedPubKeyTypes[iNdEx]) + copy(dAtA[i:], m.AllowedPubKeyTypes[iNdEx]) + i = encodeVarintDefaultMiddleware(dAtA, i, uint64(len(m.AllowedPubKeyTypes[iNdEx]))) + i-- + dAtA[i] = 0x32 + } + } + if m.SigVerifyCostSecp256K1 != 0 { + i = encodeVarintDefaultMiddleware(dAtA, i, uint64(m.SigVerifyCostSecp256K1)) + i-- + dAtA[i] = 0x28 + } + if m.SigVerifyCostEd25519 != 0 { + i = encodeVarintDefaultMiddleware(dAtA, i, uint64(m.SigVerifyCostEd25519)) + i-- + dAtA[i] = 0x20 + } + if m.TxSigLimit != 0 { + i = encodeVarintDefaultMiddleware(dAtA, i, uint64(m.TxSigLimit)) + i-- + dAtA[i] = 0x18 + } + if m.TxSizeCostPerByte != 0 { + i = encodeVarintDefaultMiddleware(dAtA, i, uint64(m.TxSizeCostPerByte)) + i-- + dAtA[i] = 0x10 + } + if m.MaxMemoCharacters != 0 { + i = encodeVarintDefaultMiddleware(dAtA, i, uint64(m.MaxMemoCharacters)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintDefaultMiddleware(dAtA []byte, offset int, v uint64) int { + offset -= sovDefaultMiddleware(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *DefaultTxMiddleware) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.MaxMemoCharacters != 0 { + n += 1 + sovDefaultMiddleware(uint64(m.MaxMemoCharacters)) + } + if m.TxSizeCostPerByte != 0 { + n += 1 + sovDefaultMiddleware(uint64(m.TxSizeCostPerByte)) + } + if m.TxSigLimit != 0 { + n += 1 + sovDefaultMiddleware(uint64(m.TxSigLimit)) + } + if m.SigVerifyCostEd25519 != 0 { + n += 1 + sovDefaultMiddleware(uint64(m.SigVerifyCostEd25519)) + } + if m.SigVerifyCostSecp256K1 != 0 { + n += 1 + sovDefaultMiddleware(uint64(m.SigVerifyCostSecp256K1)) + } + if len(m.AllowedPubKeyTypes) > 0 { + for _, s := range m.AllowedPubKeyTypes { + l = len(s) + n += 1 + l + sovDefaultMiddleware(uint64(l)) + } + } + return n +} + +func sovDefaultMiddleware(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozDefaultMiddleware(x uint64) (n int) { + return sovDefaultMiddleware(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *DefaultTxMiddleware) 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 ErrIntOverflowDefaultMiddleware + } + 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: DefaultTxMiddleware: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DefaultTxMiddleware: 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 ErrIntOverflowDefaultMiddleware + } + 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 TxSizeCostPerByte", wireType) + } + m.TxSizeCostPerByte = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDefaultMiddleware + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TxSizeCostPerByte |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + 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 ErrIntOverflowDefaultMiddleware + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TxSigLimit |= 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 ErrIntOverflowDefaultMiddleware + } + 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 ErrIntOverflowDefaultMiddleware + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SigVerifyCostSecp256K1 |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AllowedPubKeyTypes", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDefaultMiddleware + } + 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 ErrInvalidLengthDefaultMiddleware + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDefaultMiddleware + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AllowedPubKeyTypes = append(m.AllowedPubKeyTypes, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDefaultMiddleware(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDefaultMiddleware + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipDefaultMiddleware(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, ErrIntOverflowDefaultMiddleware + } + 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, ErrIntOverflowDefaultMiddleware + } + 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, ErrIntOverflowDefaultMiddleware + } + 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, ErrInvalidLengthDefaultMiddleware + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupDefaultMiddleware + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthDefaultMiddleware + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthDefaultMiddleware = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowDefaultMiddleware = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupDefaultMiddleware = fmt.Errorf("proto: unexpected end of group") +) diff --git a/core/app_config/tx.go b/core/app_config/tx.go new file mode 100644 index 000000000000..1a03ce349edc --- /dev/null +++ b/core/app_config/tx.go @@ -0,0 +1,31 @@ +package app_config + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/core" + "github.com/cosmos/cosmos-sdk/core/module/app" + + "github.com/gogo/protobuf/proto" + + abci "github.com/tendermint/tendermint/abci/types" +) + +type TxHandler interface { + CheckTx(ctx context.Context, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) + DeliverTx(ctx context.Context, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) +} + +type TxHandlerParams struct { + MsgRouter MsgRouter +} + +type MsgRouter interface { + RouteMsg(core.Msg) (proto.Message, error) +} + +type HasTxHandler interface { + app.Handler + + TxHandler(TxHandlerParams) TxHandler +} diff --git a/core/app_config/app.go b/core/baseapp/app.go similarity index 85% rename from core/app_config/app.go rename to core/baseapp/app.go index 243fefcd332e..81e38d250750 100644 --- a/core/app_config/app.go +++ b/core/baseapp/app.go @@ -1,19 +1,13 @@ -package app_config +package baseapp import ( "context" "github.com/tendermint/tendermint/abci/types" - - "github.com/cosmos/cosmos-sdk/core/module/app" ) type baseApp struct { ctx context.Context - - appModules map[string]app.Module - beginBlockers []app.BeginBlocker - endBlockers []app.EndBlocker } var _ types.Application = &baseApp{} @@ -23,7 +17,7 @@ func (a baseApp) Info(info types.RequestInfo) types.ResponseInfo { } func (a baseApp) SetOption(option types.RequestSetOption) types.ResponseSetOption { - panic("implement me") + return types.ResponseSetOption{} } func (a baseApp) Query(query types.RequestQuery) types.ResponseQuery { @@ -39,9 +33,7 @@ func (a baseApp) InitChain(chain types.RequestInitChain) types.ResponseInitChain } func (a baseApp) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginBlock { - for _, bb := range a.beginBlockers { - bb.BeginBlock(a.ctx, req) - } + panic("TODO") } func (a baseApp) DeliverTx(tx types.RequestDeliverTx) types.ResponseDeliverTx { diff --git a/core/baseapp/gas.go b/core/baseapp/gas.go new file mode 100644 index 000000000000..05759bd8efee --- /dev/null +++ b/core/baseapp/gas.go @@ -0,0 +1,62 @@ +package baseapp + +import ( + "context" + + "github.com/tendermint/tendermint/abci/types" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func GetConsensusParams(ctx context.Context) types.ConsensusParams { + panic("TODO") +} + +func getMaximumBlockGas(ctx context.Context) uint64 { + panic("TODO") +} + +type gasMiddleware struct{} + +type gasKeyTy string + +const gasKey gasKeyTy = "gas" + +func (g gasMiddleware) CheckTx(ctx context.Context, tx types.RequestCheckTx, handler ABCIMempoolHandler) types.ResponseCheckTx { + panic("implement me") +} + +func (g gasMiddleware) OnInitChain(ctx context.Context, chain types.RequestInitChain, handler ABCIConsensusHandler) types.ResponseInitChain { + panic("implement me") +} + +func (g gasMiddleware) OnBeginBlock(ctx context.Context, block types.RequestBeginBlock, handler ABCIConsensusHandler) types.ResponseBeginBlock { + var gasMeter sdk.GasMeter + if maxGas := getMaximumBlockGas(ctx); maxGas > 0 { + gasMeter = sdk.NewGasMeter(maxGas) + } else { + gasMeter = sdk.NewInfiniteGasMeter() + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + sdkCtx = sdkCtx.WithBlockGasMeter(gasMeter) + + ctx = context.WithValue(ctx, sdk.SdkContextKey, sdkCtx) + + return handler.BeginBlock(ctx, block) +} + +func (g gasMiddleware) OnDeliverTx(ctx context.Context, tx types.RequestDeliverTx, handler ABCIConsensusHandler) types.ResponseDeliverTx { + panic("implement me") +} + +func (g gasMiddleware) OnEndBlock(ctx context.Context, block types.RequestEndBlock, handler ABCIConsensusHandler) types.ResponseEndBlock { + panic("implement me") +} + +func (g gasMiddleware) OnCommit(ctx context.Context, handler ABCIConsensusHandler) types.ResponseCommit { + panic("implement me") +} + +var _ ABCIConsensusMiddleware = gasMiddleware{} +var _ ABCIMempoolMiddleware = gasMiddleware{} diff --git a/core/baseapp/header.go b/core/baseapp/header.go new file mode 100644 index 000000000000..0e4398da27f8 --- /dev/null +++ b/core/baseapp/header.go @@ -0,0 +1,115 @@ +package baseapp + +import ( + "context" + + abci "github.com/tendermint/tendermint/abci/types" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type HeaderMiddleware struct { + initialHeight int64 +} + +var _ ABCIConsensusMiddleware = &HeaderMiddleware{} +var _ ABCIMempoolMiddleware = &HeaderMiddleware{} + +func (h *HeaderMiddleware) OnInitChain(ctx context.Context, req abci.RequestInitChain, next ABCIConsensusHandler) abci.ResponseInitChain { + // On a new chain, we consider the init chain block height as 0, even though + // req.InitialHeight is 1 by default. + initHeader := tmproto.Header{ChainID: req.ChainId, Time: req.Time} + + // If req.InitialHeight is > 1, then we set the initial version in the + // stores. + if req.InitialHeight > 1 { + h.initialHeight = req.InitialHeight + initHeader = tmproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time} + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + sdkCtx = sdkCtx.WithBlockHeader(initHeader) + ctx = context.WithValue(ctx, sdk.SdkContextKey, sdkCtx) + + return next.InitChain(ctx, req) +} + +func (h HeaderMiddleware) CheckTx(ctx context.Context, tx abci.RequestCheckTx, handler ABCIMempoolHandler) abci.ResponseCheckTx { + panic("implement me") +} + +func (h HeaderMiddleware) validateHeight(req abci.RequestBeginBlock) error { + panic("TODO") +} + +func (h HeaderMiddleware) OnBeginBlock(ctx context.Context, req abci.RequestBeginBlock, next ABCIConsensusHandler) abci.ResponseBeginBlock { + if err := h.validateHeight(req); err != nil { + panic(err) + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + sdkCtx = sdkCtx. + WithBlockHeader(req.Header). + WithBlockHeight(req.Header.Height) + ctx = context.WithValue(ctx, sdk.SdkContextKey, sdkCtx) + + return next.BeginBlock(ctx, req) +} + +func (h HeaderMiddleware) OnDeliverTx(ctx context.Context, tx abci.RequestDeliverTx, handler ABCIConsensusHandler) abci.ResponseDeliverTx { + panic("implement me") +} + +func (h HeaderMiddleware) OnEndBlock(ctx context.Context, block abci.RequestEndBlock, handler ABCIConsensusHandler) abci.ResponseEndBlock { + panic("implement me") +} + +func (h HeaderMiddleware) OnCommit(ctx context.Context, handler ABCIConsensusHandler) abci.ResponseCommit { + //header := sdk.UnwrapSDKContext(ctx).BlockHeader() + //retainHeight := app.GetBlockRetentionHeight(header.Height) + // + //// Write the DeliverTx state into branched storage and commit the MultiStore. + //// The write to the DeliverTx state writes all state transitions to the root + //// MultiStore (app.cms) so when Commit() is called is persists those values. + //app.deliverState.ms.Write() + //commitID := app.cms.Commit() + //app.logger.Info("commit synced", "commit", fmt.Sprintf("%X", commitID)) + // + //// Reset the Check state to the latest committed. + //// + //// NOTE: This is safe because Tendermint holds a lock on the mempool for + //// Commit. Use the header from this latest block. + //app.setCheckState(header) + // + //// empty/reset the deliver state + //app.deliverState = nil + // + //var halt bool + // + //switch { + //case app.haltHeight > 0 && uint64(header.Height) >= app.haltHeight: + // halt = true + // + //case app.haltTime > 0 && header.Time.Unix() >= int64(app.haltTime): + // halt = true + //} + // + //if halt { + // // Halt the binary and allow Tendermint to receive the ResponseCommit + // // response with the commit ID hash. This will allow the node to successfully + // // restart and process blocks assuming the halt configuration has been + // // reset or moved to a more distant value. + // app.halt() + //} + // + //if app.snapshotInterval > 0 && uint64(header.Height)%app.snapshotInterval == 0 { + // go app.snapshot(header.Height) + //} + // + //return abci.ResponseCommit{ + // Data: commitID.Hash, + // RetainHeight: retainHeight, + //} + panic("TODO") +} diff --git a/core/baseapp/middleware.go b/core/baseapp/middleware.go new file mode 100644 index 000000000000..e5f01649abe5 --- /dev/null +++ b/core/baseapp/middleware.go @@ -0,0 +1,44 @@ +package baseapp + +import ( + "context" + + "github.com/tendermint/tendermint/abci/types" +) + +type ABCIConsensusHandler interface { + InitChain(context.Context, types.RequestInitChain) types.ResponseInitChain // Initialize blockchain w validators/other info from TendermintCore + BeginBlock(context.Context, types.RequestBeginBlock) types.ResponseBeginBlock // Signals the beginning of a block + DeliverTx(context.Context, types.RequestDeliverTx) types.ResponseDeliverTx // Deliver a tx for full processing + EndBlock(context.Context, types.RequestEndBlock) types.ResponseEndBlock // Signals the end of a block, returns changes to the validator set + Commit(context.Context) types.ResponseCommit // Commit the state and return the application Merkle root hash +} + +type ABCIConsensusMiddleware interface { + OnInitChain(context.Context, types.RequestInitChain, ABCIConsensusHandler) types.ResponseInitChain // Initialize blockchain w validators/other info from TendermintCore + OnBeginBlock(context.Context, types.RequestBeginBlock, ABCIConsensusHandler) types.ResponseBeginBlock // Signals the beginning of a block + OnDeliverTx(context.Context, types.RequestDeliverTx, ABCIConsensusHandler) types.ResponseDeliverTx // Deliver a tx for full processing + OnEndBlock(context.Context, types.RequestEndBlock, ABCIConsensusHandler) types.ResponseEndBlock // Signals the end of a block, returns changes to the validator set + OnCommit(context.Context, ABCIConsensusHandler) types.ResponseCommit // Commit the state and return the application Merkle root hash +} + +type ABCIMempoolHandler interface { + CheckTx(context.Context, types.RequestCheckTx) types.ResponseCheckTx // Validate a tx for the mempool +} + +type ABCIMempoolMiddleware interface { + CheckTx(context.Context, types.RequestCheckTx, ABCIMempoolHandler) types.ResponseCheckTx // Validate a tx for the mempool +} + +type ABCIQueryMiddleware interface { + OnInfo(context.Context, types.RequestInfo, types.Application) types.ResponseInfo // Return application info + OnSetOption(context.Context, types.RequestSetOption, types.Application) types.ResponseSetOption // Set application option + OnQuery(context.Context, types.RequestQuery, types.Application) types.ResponseQuery // Query for state +} + +type ABCIStateSyncMiddleware interface { + OnListSnapshots(context.Context, types.RequestListSnapshots, types.Application) types.ResponseListSnapshots // List available snapshots + OnOfferSnapshot(context.Context, types.RequestOfferSnapshot, types.Application) types.ResponseOfferSnapshot // Offer a snapshot to the application + OnLoadSnapshotChunk(context.Context, types.RequestLoadSnapshotChunk, types.Application) types.ResponseLoadSnapshotChunk // Load a snapshot chunk + OnApplySnapshotChunk(context.Context, types.RequestApplySnapshotChunk, types.Application) types.ResponseApplySnapshotChunk // Apply a shapshot chunk +} diff --git a/core/baseapp/store.go b/core/baseapp/store.go new file mode 100644 index 000000000000..69dfb613fee9 --- /dev/null +++ b/core/baseapp/store.go @@ -0,0 +1,97 @@ +package baseapp + +import ( + "context" + "crypto/sha256" + + "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + abci "github.com/tendermint/tendermint/abci/types" +) + +type StoreMiddleware struct { + cms sdk.CommitMultiStore + deliverMs types.CacheMultiStore + checkMs types.CacheMultiStore +} + +var _ ABCIConsensusMiddleware = &StoreMiddleware{} +var _ ABCIMempoolMiddleware = &StoreMiddleware{} + +func (s *StoreMiddleware) OnInitChain(ctx context.Context, req abci.RequestInitChain, next ABCIConsensusHandler) abci.ResponseInitChain { + if req.InitialHeight > 1 { + err := s.cms.SetInitialVersion(req.InitialHeight) + if err != nil { + panic(err) + } + } + + s.deliverMs = s.cms.CacheMultiStore() + s.checkMs = s.cms.CacheMultiStore() + + // TODO add ms to ctx + + res := next.InitChain(ctx, req) + + if lastCommitId := s.cms.LastCommitID(); !lastCommitId.IsZero() { + res.AppHash = lastCommitId.Hash + } else { + // $ echo -n '' | sha256sum + // e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + emptyHash := sha256.Sum256([]byte{}) + res.AppHash = emptyHash[:] + } + + return res +} + +func (s StoreMiddleware) OnBeginBlock(ctx context.Context, req abci.RequestBeginBlock, next ABCIConsensusHandler) abci.ResponseBeginBlock { + if s.cms.TracingEnabled() { + s.cms.SetTracingContext(sdk.TraceContext( + map[string]interface{}{"blockHeight": req.Header.Height}, + )) + } + + if s.deliverMs == nil { + s.deliverMs = s.cms.CacheMultiStore() + } + + return next.BeginBlock(ctx, req) +} + +func (s StoreMiddleware) CheckTx(ctx context.Context, tx abci.RequestCheckTx, handler ABCIMempoolHandler) abci.ResponseCheckTx { + panic("implement me") +} + +func (s StoreMiddleware) OnDeliverTx(ctx context.Context, tx abci.RequestDeliverTx, handler ABCIConsensusHandler) abci.ResponseDeliverTx { + panic("implement me") +} + +func (s StoreMiddleware) OnEndBlock(ctx context.Context, block abci.RequestEndBlock, handler ABCIConsensusHandler) abci.ResponseEndBlock { + panic("implement me") +} + +func (s StoreMiddleware) OnCommit(ctx context.Context, next ABCIConsensusHandler) abci.ResponseCommit { + // Write the DeliverTx state into branched storage and commit the MultiStore. + // The write to the DeliverTx state writes all state transitions to the root + // MultiStore (app.cms) so when Commit() is called is persists those values. + s.deliverMs.Write() + commitID := s.cms.Commit() + //app.logger.Info("commit synced", "commit", fmt.Sprintf("%X", commitID)) + + // Reset the Check state to the latest committed. + // + // NOTE: This is safe because Tendermint holds a lock on the mempool for + // Commit. Use the header from this latest block. + s.checkMs = s.cms.CacheMultiStore() + + // empty/reset the deliver state + s.deliverMs = nil + + res := next.Commit(ctx) + + res.Data = commitID.Hash + + return res +} diff --git a/core/codec/registry.go b/core/codec/registry.go new file mode 100644 index 000000000000..fdccdd4d5f00 --- /dev/null +++ b/core/codec/registry.go @@ -0,0 +1,34 @@ +package codec + +import ( + "github.com/gogo/protobuf/proto" + "google.golang.org/grpc" +) + +type TypeProvider interface { + RegisterTypes(TypeRegistry) +} + +type TypeRegistry interface { + // RegisterInterface associates protoName as the public name for the + // interface passed in as iface. This is to be used primarily to create + // a public facing registry of interface implementations for clients. + // protoName should be a well-chosen public facing name that remains stable. + // RegisterInterface takes an optional list of impls to be registered + // as implementations of iface. + // + // Ex: + // registry.RegisterInterface("cosmos.base.v1beta1.Msg", (*sdk.Msg)(nil)) + RegisterInterface(protoName string, iface interface{}, impls ...proto.Message) + + // RegisterImplementations registers impls as concrete implementations of + // the interface iface. + // + // Ex: + // registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSend{}, &MsgMultiSend{}) + RegisterImplementations(iface interface{}, impls ...proto.Message) + + RegisterMsgServiceDesc(sd grpc.ServiceDesc, clientFactory interface{}) + + RegisterQueryServiceDesc(sd grpc.ServiceDesc, clientFactory interface{}) +} diff --git a/core/module/app/events.go b/core/module/app/events.go index 0bdac82a67aa..6a2a8af54bf8 100644 --- a/core/module/app/events.go +++ b/core/module/app/events.go @@ -5,7 +5,7 @@ import ( ) type EventListener interface { - Module + Handler RegisterEventListeners(EventListenerRegistrar) } diff --git a/core/module/app/middleware.go b/core/module/app/middleware.go deleted file mode 100644 index 76d4c2af9bbe..000000000000 --- a/core/module/app/middleware.go +++ /dev/null @@ -1,31 +0,0 @@ -package app - -import ( - "context" - - abci "github.com/tendermint/tendermint/abci/types" - - "github.com/cosmos/cosmos-sdk/types/tx" -) - -type HasTxMiddleware interface { - Module - - RegisterTxMiddleware(registrar TxMiddlewareRegistrar) -} - -type TxMiddlewareRegistrar interface { - RegisterTxMiddlewareFactory(configType interface{}, factory TxMiddlewareFactory) -} - -type TxMiddlewareFactory func(config interface{}) TxMiddleware - -type TxMiddleware interface { - OnCheckTx(ctx context.Context, tx tx.Tx, req abci.RequestCheckTx, next TxHandler) (abci.ResponseCheckTx, error) - OnDeliverTx(ctx context.Context, tx tx.Tx, req abci.RequestDeliverTx, next TxHandler) (abci.ResponseDeliverTx, error) -} - -type TxHandler interface { - CheckTx(ctx context.Context, tx tx.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) - DeliverTx(ctx context.Context, tx tx.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) -} diff --git a/core/module/app/module.go b/core/module/app/module.go index 551020bc8c49..b5a0a1dc7288 100644 --- a/core/module/app/module.go +++ b/core/module/app/module.go @@ -4,31 +4,30 @@ import ( "context" "encoding/json" + "github.com/cosmos/cosmos-sdk/codec" abci "github.com/tendermint/tendermint/abci/types" "google.golang.org/grpc" - - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" ) -type Module interface { - RegisterTypes(codectypes.InterfaceRegistry) - +type GenesisHandler interface { InitGenesis(context.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate ExportGenesis(context.Context, codec.JSONCodec) json.RawMessage +} - RegisterMsgServices(grpc.ServiceRegistrar) +type QueryHandler interface { RegisterQueryServices(grpc.ServiceRegistrar) } -type BeginBlocker interface { - Module +type Handler interface { + QueryHandler + + RegisterMsgServices(grpc.ServiceRegistrar) +} +type BeginBlocker interface { BeginBlock(context.Context, abci.RequestBeginBlock) } type EndBlocker interface { - Module - EndBlock(context.Context, abci.RequestEndBlock) []abci.ValidatorUpdate } diff --git a/core/module/app/plugins.go b/core/module/app/plugins.go index 3265c7940bf0..bfb193b5b6ee 100644 --- a/core/module/app/plugins.go +++ b/core/module/app/plugins.go @@ -2,9 +2,7 @@ package app import "google.golang.org/grpc" -type HasPlugins interface { - Module - +type PluginProvider interface { RegisterPlugins(registrar PluginRegistrar) } diff --git a/core/module/app/registry.go b/core/module/app/registry.go new file mode 100644 index 000000000000..351a7ce0de97 --- /dev/null +++ b/core/module/app/registry.go @@ -0,0 +1,54 @@ +package app + +import ( + "fmt" + "reflect" + + "github.com/cosmos/cosmos-sdk/core/module" +) + +var registry map[reflect.Type]Handler + +func RegisterAppModule(constructor interface{}) { + typ := reflect.TypeOf(constructor) + if typ.Kind() != reflect.Func { + panic("TODO") + } + + if typ.NumIn() < 1 { + panic("TODO") + } + + typ.In(1) + + configField, ok := typ.FieldByName("Config") + if !ok { + panic(fmt.Errorf("module handler struct %T does not contain a Config field", handler)) + } + + if existing, ok := registry[configField.Type]; ok { + panic(fmt.Errorf("module handler %T already registered for config type %T, trying to register new handler type %T", existing, configField.Type, handler)) + } + + registry[configField.Type] = handler +} + +type ModuleSet struct { + modMap map[string]Handler +} + +func NewModuleSet(configMap module.ModuleConfigSet) (ModuleSet, error) { + // TODO deterministic order + modMap := make(map[string]Handler) + for k, v := range configMap { + mod, ok := registry[reflect.TypeOf(v)] + if !ok { + panic("TODO") + } + + mod = mod.New() + modMap[k] = mod + } + + return ModuleSet{modMap: modMap}, nil +} diff --git a/core/module/module.go b/core/module/module.go index 22fb3a26f4c6..de6557e95d94 100644 --- a/core/module/module.go +++ b/core/module/module.go @@ -1,41 +1,34 @@ package module -import ( - "fmt" - "reflect" - - "github.com/cosmos/cosmos-sdk/codec/types" - - "github.com/gogo/protobuf/proto" -) - -type ModuleHandler interface { - // ModuleType returns the configuration type for this module - ConfigType() proto.Message - - // New returns a new module handler - New(config proto.Message) ModuleHandler -} - -var registry map[reflect.Type]ModuleHandler - -func RegisterModuleHandler(handler ModuleHandler) { - typ := reflect.TypeOf(handler.ConfigType()) - if _, ok := registry[typ]; ok { - panic(fmt.Errorf("module handler for config type %T already registered", handler.ConfigType())) - } - - registry[typ] = handler -} - -type ModuleSet struct { - handlers map[string]ModuleHandler -} - -func NewModuleSet(moduleConfigs map[string]*types.Any) *ModuleSet { - panic("TODO") -} - -func (ms *ModuleSet) Each(f func(name string, handler ModuleHandler)) { - panic("TODO") -} +//type ModuleHandler interface { +// // ModuleType returns the configuration type for this module +// ConfigType() proto.Message +// +// // New returns a new module handler +// New(config proto.Message) ModuleHandler +//} +// +//var registry map[reflect.Type]ModuleHandler +// +//func RegisterModuleHandler(handler ModuleHandler) { +// typ := reflect.TypeOf(handler.ConfigType()) +// if _, ok := registry[typ]; ok { +// panic(fmt.Errorf("module handler for config type %T already registered", handler.ConfigType())) +// } +// +// registry[typ] = handler +//} +// +//type ModuleSet struct { +// handlers map[string]ModuleHandler +//} +// +//type ModuleConfigSet = map[string]*types.Any +// +//func NewModuleSet(moduleConfigs ModuleConfigSet) *ModuleSet { +// panic("TODO") +//} +// +//func (ms *ModuleSet) Each(f func(name string, handler ModuleHandler)) { +// panic("TODO") +//} diff --git a/core/module/registry.go b/core/module/registry.go new file mode 100644 index 000000000000..65ece987129b --- /dev/null +++ b/core/module/registry.go @@ -0,0 +1,40 @@ +package module + +import ( + "reflect" +) + +type registry struct { + hmap map[reflect.Type]interface{} + handlerType reflect.Type +} + +func (r *registry) Register(constructor interface{}) { + typ := reflect.TypeOf(constructor) + if typ.Kind() != reflect.Func { + panic("TODO") + } + + if typ.NumIn() < 1 { + panic("TODO") + } + + configArg := typ.In(0) + + if _, ok := r.hmap[configArg]; ok { + panic("TODO") + } + + if typ.NumOut() < 1 { + panic("TODO") + } + + handlerOut := typ.Out(0) + if !handlerOut.AssignableTo(r.handlerType) { + panic("TODO") + } + + r.hmap[configArg] = constructor +} + +type container \ No newline at end of file diff --git a/core/msg.go b/core/msg.go new file mode 100644 index 000000000000..886e37529de1 --- /dev/null +++ b/core/msg.go @@ -0,0 +1,6 @@ +package core + +type Msg interface { + GetSigners() []string + ValidateBasic() error +} diff --git a/core/store/store.go b/core/store/store.go new file mode 100644 index 000000000000..36e9f29c38ba --- /dev/null +++ b/core/store/store.go @@ -0,0 +1,62 @@ +package store + +import ( + "context" + + dbm "github.com/tendermint/tm-db" +) + +type BasicKVStore interface { + // Get returns nil iff key doesn't exist. Panics on nil key. + Get(key []byte) []byte + + // Has checks if a key exists. Panics on nil key. + Has(key []byte) bool + + // Set sets the key. Panics on nil key or value. + Set(key, value []byte) + + // Delete deletes the key. Panics on nil key. + Delete(key []byte) +} + +type KVStore interface { + BasicKVStore + + // Iterator over a domain of keys in ascending order. End is exclusive. + // Start must be less than end, or the Iterator is invalid. + // Iterator must be closed by caller. + // To iterate over entire domain, use store.Iterator(nil, nil) + // CONTRACT: No writes may happen within a domain while an iterator exists over it. + // Exceptionally allowed for cachekv.Store, safe to write in the modules. + Iterator(start, end []byte) Iterator + + // Iterator over a domain of keys in descending order. End is exclusive. + // Start must be less than end, or the Iterator is invalid. + // Iterator must be closed by caller. + // CONTRACT: No writes may happen within a domain while an iterator exists over it. + // Exceptionally allowed for cachekv.Store, safe to write in the modules. + ReverseIterator(start, end []byte) Iterator +} + +// Iterator is an alias db's Iterator for convenience. +type Iterator = dbm.Iterator + +type StoreKey interface { + Open(ctx context.Context) KVStore +} + +type KVStoreKey interface { + StoreKey + kvStoreKey() +} + +type LowLevelSCStoreKey interface { + Open(ctx context.Context) BasicKVStore + scStoreKey() +} + +type LowLevelSSStoreKey interface { + StoreKey + ssStoreKey() +} diff --git a/core/tx/module/module.go b/core/tx/module/module.go new file mode 100644 index 000000000000..02481439ec3e --- /dev/null +++ b/core/tx/module/module.go @@ -0,0 +1,88 @@ +package module + +import ( + "context" + "encoding/json" + + "github.com/cosmos/cosmos-sdk/core/app_config" + + tx2 "github.com/cosmos/cosmos-sdk/types/tx" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/core/module/app" + "github.com/cosmos/cosmos-sdk/core/tx" + abci "github.com/tendermint/tendermint/abci/types" + "google.golang.org/grpc" +) + +func init() { + app.RegisterAppModule(appModule{}) +} + +type appModule struct { + Config *tx.Module + Codec codec.Codec +} + +func (a appModule) New() app.Handler { + return appModule{} +} + +var _ app_config.HasTxHandler = appModule{} + +func (a appModule) RegisterTypes(registry types.InterfaceRegistry) { + panic("implement me") +} + +func (a appModule) InitGenesis(ctx context.Context, codec codec.JSONCodec, message json.RawMessage) []abci.ValidatorUpdate { + panic("implement me") +} + +func (a appModule) ExportGenesis(ctx context.Context, codec codec.JSONCodec) json.RawMessage { + panic("implement me") +} + +func (a appModule) RegisterMsgServices(registrar grpc.ServiceRegistrar) {} + +func (a appModule) RegisterQueryServices(registrar grpc.ServiceRegistrar) {} + +func (a appModule) TxHandler(params app_config.TxHandlerParams) app_config.TxHandler { + return txHandler{ + Module: a.Module, + msgRouter: params.MsgRouter, + } +} + +type HasMiddleware interface { + RegisterTxMiddleware(registrar MiddlewareRegistrar) +} + +type MiddlewareRegistrar interface { + RegisterTxMiddlewareFactory(configType interface{}, factory MiddlewareFactory) +} + +type MiddlewareFactory func(config interface{}) Middleware + +type Middleware interface { + OnCheckTx(ctx context.Context, tx tx2.Tx, req abci.RequestCheckTx, next TxHandler) (abci.ResponseCheckTx, error) + OnDeliverTx(ctx context.Context, tx tx2.Tx, req abci.RequestDeliverTx, next TxHandler) (abci.ResponseDeliverTx, error) +} + +type TxHandler interface { + CheckTx(ctx context.Context, tx tx2.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) + DeliverTx(ctx context.Context, tx tx2.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) +} + +type txHandler struct { + *tx.Module + msgRouter app_config.MsgRouter +} + +func (t txHandler) CheckTx(ctx context.Context, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { + panic("implement me") +} + +func (t txHandler) DeliverTx(ctx context.Context, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { + panic("implement me") +} diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index da9ef63e8049..5980b8c2f2b1 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -258,6 +258,9 @@ - [AppConfig](#cosmos.core.app_config.v1.AppConfig) - [AppConfig.ModulesEntry](#cosmos.core.app_config.v1.AppConfig.ModulesEntry) +- [cosmos/core/app_config/v1/default_middleware.proto](#cosmos/core/app_config/v1/default_middleware.proto) + - [DefaultTxMiddleware](#cosmos.core.app_config.v1.DefaultTxMiddleware) + - [cosmos/core/tx/v1/module.proto](#cosmos/core/tx/v1/module.proto) - [Module](#cosmos.core.tx.v1.Module) @@ -3827,6 +3830,42 @@ GenesisState defines the capability module's genesis state. + + + + + + + + + + + +

Top

+ +## cosmos/core/app_config/v1/default_middleware.proto + + + + + +### DefaultTxMiddleware + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `max_memo_characters` | [uint64](#uint64) | | | +| `tx_size_cost_per_byte` | [uint64](#uint64) | | | +| `tx_sig_limit` | [uint64](#uint64) | | | +| `sig_verify_cost_ed25519` | [uint64](#uint64) | | | +| `sig_verify_cost_secp256k1` | [uint64](#uint64) | | | +| `allowed_pub_key_types` | [string](#string) | repeated | | + + + + + diff --git a/proto/cosmos/core/app_config/v1/app_config.proto b/proto/cosmos/core/app_config/v1/app_config.proto index 2d77389be1d6..ecf3fc68e8e9 100644 --- a/proto/cosmos/core/app_config/v1/app_config.proto +++ b/proto/cosmos/core/app_config/v1/app_config.proto @@ -14,6 +14,6 @@ message ABCIHandlers { repeated string init_genesis = 1; repeated string begin_block = 2; repeated string end_block = 3; - string tx_handler = 4; + google.protobuf.Any tx_module = 4; string info_handler = 5; } \ No newline at end of file diff --git a/proto/cosmos/core/app_config/v1/default_middleware.proto b/proto/cosmos/core/app_config/v1/default_middleware.proto new file mode 100644 index 000000000000..c3a7fd0752c2 --- /dev/null +++ b/proto/cosmos/core/app_config/v1/default_middleware.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; +package cosmos.core.app_config.v1; + +option go_package = "github.com/cosmos/cosmos-sdk/core/app_config"; + +message DefaultTxMiddleware { + uint64 max_memo_characters = 1; + uint64 tx_size_cost_per_byte = 2; + uint64 tx_sig_limit = 3; + uint64 sig_verify_cost_ed25519 = 4; + uint64 sig_verify_cost_secp256k1 = 5; + repeated string allowed_pub_key_types = 6; +} diff --git a/simapp2/app_config.json b/simapp2/app_config.json index 8f6d1d473d3e..ad1617d40d3e 100644 --- a/simapp2/app_config.json +++ b/simapp2/app_config.json @@ -15,8 +15,22 @@ }, "upgrade": { "@type": "cosmos.upgrade.v1beta1.Module" - }, - "tx": { + } + }, + "abci": { + "init_genesis": [ + "authn", + "bank" + ], + "begin_block": [ + "authn", + "bank" + ], + "end_block": [ + "bank", + "authn" + ], + "tx_module": { "@type": "cosmos.core.tx.v1.Module", "middleware": [ { @@ -53,22 +67,7 @@ "@type": "cosmos.authn.v1.IncrementSequenceMiddleware" } ] - } - }, - "abci": { - "init_genesis": [ - "authn", - "bank" - ], - "begin_block": [ - "authn", - "bank" - ], - "end_block": [ - "bank", - "authn" - ], - "tx_handler": "tx", + }, "info_handler": "upgrade" } } \ No newline at end of file diff --git a/x/authn/app/handler.go b/x/authn/app/handler.go new file mode 100644 index 000000000000..41e8e6eaee7e --- /dev/null +++ b/x/authn/app/handler.go @@ -0,0 +1,124 @@ +package app + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "strings" + + "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/cosmos-sdk/core/store" + + "github.com/cosmos/cosmos-sdk/x/authn" + + "github.com/cosmos/cosmos-sdk/core/tx/module" + + abci "github.com/tendermint/tendermint/abci/types" + "google.golang.org/grpc" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/core/module/app" +) + +type handler struct { + *authn.Module + cdc codec.BinaryCodec + kvStoreKey store.KVStoreKey +} + +var _ app.Handler = &handler{} +var _ authn.MsgServer = &handler{} +var _ authn.QueryServer = &handler{} + +const ( + CredentialPrefix = 0x0 + AccNumPrefix = 0x1 + SeqPrefix = 0x2 + NextAccNumKey = 0x3 +) + +func CredentialKey(addrBz []byte) []byte { + return append([]byte{CredentialPrefix}, addrBz...) +} + +func AccNumKey(addrBz []byte) []byte { + return append([]byte{AccNumPrefix}, addrBz...) +} + +func SeqKey(addrBz []byte) []byte { + return append([]byte{SeqPrefix}, addrBz...) +} + +func (m *handler) addrStrToBz(addr string) ([]byte, error) { + if len(strings.TrimSpace(addr)) == 0 { + return nil, fmt.Errorf("empty address string is not allowed") + } + + return types.GetFromBech32(addr, m.Bech32AddressPrefix) +} + +func (m *handler) SetCredential(ctx context.Context, request *authn.MsgSetCredentialRequest) (*authn.MsgSetCredentialResponse, error) { + addrBz, err := m.addrStrToBz(request.Address) + if err != nil { + return nil, err + } + + var cred authn.Credential + if request.Credential != nil { + err = m.cdc.UnpackAny(request.Credential, &cred) + if err != nil { + return nil, err + } + } + + kvStore := m.kvStoreKey.Open(ctx) + credKey := CredentialKey(addrBz) + if !kvStore.Has(credKey) { + if cred != nil { + if !bytes.Equal(addrBz, cred.Address()) { + return nil, fmt.Errorf("address must equal credential address when initializing a new account explicitly") + } + } + + // initialize new account + } else { + if cred == nil { + return nil, fmt.Errorf("credential cannot be nil when initializing a new account") + } + // replace key + } + + return &authn.MsgSetCredentialResponse{}, nil +} + +func (m *handler) Account(ctx context.Context, request *authn.QueryAccountRequest) (*authn.QueryAccountResponse, error) { + panic("implement me") +} + +func (m *handler) Accounts(ctx context.Context, request *authn.QueryAccountsRequest) (*authn.QueryAccountsResponse, error) { + panic("implement me") +} + +func (m *handler) InitGenesis(ctx context.Context, jsonCodec codec.JSONCodec, message json.RawMessage) []abci.ValidatorUpdate { + panic("implement me") +} + +func (m *handler) ExportGenesis(ctx context.Context, jsonCodec codec.JSONCodec) json.RawMessage { + panic("implement me") +} + +func (m *handler) RegisterMsgServices(registrar grpc.ServiceRegistrar) { + panic("implement me") +} + +func (m *handler) RegisterQueryServices(registrar grpc.ServiceRegistrar) { + panic("implement me") +} + +func (m *handler) RegisterTxMiddleware(registrar module.MiddlewareRegistrar) { + //registrar.RegisterTxMiddlewareFactory(&authn.ValidateMemoMiddleware{}, func(config interface{}) app.TxMiddleware { + // return validateMemoMiddlewareHandler{config.(*authn.ValidateMemoMiddleware)} + //}) +} diff --git a/x/authn/app/middleware.go b/x/authn/app/middleware.go index c8775725e6b7..f358ec69e884 100644 --- a/x/authn/app/middleware.go +++ b/x/authn/app/middleware.go @@ -3,6 +3,8 @@ package app import ( "context" + "github.com/cosmos/cosmos-sdk/core/app_config" + abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/core/module/app" @@ -27,7 +29,7 @@ func (v validateMemoMiddlewareHandler) validate(tx tx.Tx) error { return nil } -func (v validateMemoMiddlewareHandler) OnCheckTx(ctx context.Context, tx tx.Tx, req abci.RequestCheckTx, next app.TxHandler) (abci.ResponseCheckTx, error) { +func (v validateMemoMiddlewareHandler) OnCheckTx(ctx context.Context, tx tx.Tx, req abci.RequestCheckTx, next app_config.TxHandler) (abci.ResponseCheckTx, error) { err := v.validate(tx) if err != nil { return abci.ResponseCheckTx{}, err @@ -36,7 +38,7 @@ func (v validateMemoMiddlewareHandler) OnCheckTx(ctx context.Context, tx tx.Tx, return next.CheckTx(ctx, tx, req) } -func (v validateMemoMiddlewareHandler) OnDeliverTx(ctx context.Context, tx tx.Tx, req abci.RequestDeliverTx, next app.TxHandler) (abci.ResponseDeliverTx, error) { +func (v validateMemoMiddlewareHandler) OnDeliverTx(ctx context.Context, tx tx.Tx, req abci.RequestDeliverTx, next app_config.TxHandler) (abci.ResponseDeliverTx, error) { err := v.validate(tx) if err != nil { return abci.ResponseDeliverTx{}, err diff --git a/x/authn/app/module.go b/x/authn/app/module.go deleted file mode 100644 index db6f171e3a4d..000000000000 --- a/x/authn/app/module.go +++ /dev/null @@ -1,48 +0,0 @@ -package app - -import ( - "encoding/json" - - abci "github.com/tendermint/tendermint/abci/types" - "google.golang.org/grpc" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/core/module/app" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/authn" -) - -type Module struct { - *authn.Module - Key app.RootModuleKey -} - -var _ app.Module = &Module{} -var _ app.HasTxMiddleware = &Module{} - -func (m *Module) RegisterTypes(registry types.InterfaceRegistry) { - panic("implement me") -} - -func (m *Module) InitGenesis(context sdk.Context, codec codec.JSONCodec, message json.RawMessage) []abci.ValidatorUpdate { - panic("implement me") -} - -func (m *Module) ExportGenesis(context sdk.Context, codec codec.JSONCodec) json.RawMessage { - panic("implement me") -} - -func (m *Module) RegisterMsgServices(registrar grpc.ServiceRegistrar) { - panic("implement me") -} - -func (m *Module) RegisterQueryServices(registrar grpc.ServiceRegistrar) { - panic("implement me") -} - -func (m *Module) RegisterTxMiddleware(registrar app.TxMiddlewareRegistrar) { - registrar.RegisterTxMiddlewareFactory(&authn.ValidateMemoMiddleware{}, func(config interface{}) app.TxMiddleware { - return validateMemoMiddlewareHandler{config.(*authn.ValidateMemoMiddleware)} - }) -} diff --git a/x/authn/codec.go b/x/authn/codec.go new file mode 100644 index 000000000000..19bff18e166e --- /dev/null +++ b/x/authn/codec.go @@ -0,0 +1,8 @@ +package authn + +import "github.com/cosmos/cosmos-sdk/core/codec" + +func RegisterTypes(registry codec.TypeRegistry) { + registry.RegisterMsgServiceDesc(_Msg_serviceDesc, NewMsgClient) + registry.RegisterQueryServiceDesc(_Query_serviceDesc, NewQueryClient) +} diff --git a/x/authn/credential.go b/x/authn/credential.go new file mode 100644 index 000000000000..ca3e7ec6d6c2 --- /dev/null +++ b/x/authn/credential.go @@ -0,0 +1,5 @@ +package authn + +type Credential interface { + Address() []byte +} diff --git a/x/authn/module/module.go b/x/authn/module/module.go index bfc00baa1b28..f5ee367e0fc5 100644 --- a/x/authn/module/module.go +++ b/x/authn/module/module.go @@ -1,35 +1,19 @@ package module import ( - "github.com/gogo/protobuf/proto" - + codec2 "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/core/codec" "github.com/cosmos/cosmos-sdk/core/module/app" - - "github.com/cosmos/cosmos-sdk/core/module" + "github.com/cosmos/cosmos-sdk/core/store" "github.com/cosmos/cosmos-sdk/x/authn" ) -func init() { - module.RegisterModuleHandler(handler{}) -} - -type handler struct { - *authn.Module -} - -func (h handler) ConfigType() proto.Message { - return h.Module -} +var _ codec.TypeProvider = Module{} -func (h handler) New(config proto.Message) module.ModuleHandler { - mod := config.(*authn.Module) - return handler{mod} +func (m Module) RegisterTypes(registry codec.TypeRegistry) { + authn.RegisterTypes(registry) } -type AppModuleDeps struct { - Key app.RootModuleKey -} +func (m Module) NewAppHandler(cdc codec2.Codec, storeKey store.KVStoreKey) app.Handler { -func (h handler) NewAppModule(deps AppModuleDeps) app.Module { - panic("TODO") } diff --git a/x/bank/module/module.go b/x/bank/module/module.go index 5e37259272f3..c4dd859c9f33 100644 --- a/x/bank/module/module.go +++ b/x/bank/module/module.go @@ -32,6 +32,6 @@ type AppModuleDeps struct { AuthnMsgClient authn.MsgClient } -func (h handler) NewAppModule(deps AppModuleDeps) app.Module { +func (h handler) NewAppModule(deps AppModuleDeps) app.Handler { panic("TODO") } From 70be5b0883eb9d42579111d77a0994098f64dc7f Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 28 May 2021 17:43:53 -0400 Subject: [PATCH 13/19] add DI container --- core/module/container.go | 221 ++++++++++++++++++ core/module/container_test.go | 119 ++++++++++ core/module/registry.go | 2 - .../core/app_config/v1/app_config.proto | 7 +- simapp2/app_config.json | 35 +-- x/bank/module/module.go | 33 ++- 6 files changed, 383 insertions(+), 34 deletions(-) create mode 100644 core/module/container.go create mode 100644 core/module/container_test.go diff --git a/core/module/container.go b/core/module/container.go new file mode 100644 index 000000000000..5c360b06a3ae --- /dev/null +++ b/core/module/container.go @@ -0,0 +1,221 @@ +package module + +import ( + "fmt" +) + +type container struct { + providers map[Key]*node + scopeProviders map[Key]*scopeNode + nodes []*node + scopeNodes []*scopeNode + + values map[Key]interface{} + scopedValues map[string]map[Key]interface{} +} + +type Key struct { + Type interface{} +} + +type Value struct { + Key Key + Value interface{} +} + +type node struct { + Provider + called bool + values []Value + err error +} + +type Provider struct { + Constructor func(deps []interface{}) ([]interface{}, error) + Needs []Key + Provides []Key + Scope string +} + +type scopeNode struct { + ScopedProvider + calledForScope map[string]bool + valuesForScope map[string][]Value + errsForScope map[string]error +} + +type ScopedProvider struct { + Constructor func(scope string, deps []interface{}) ([]interface{}, error) + Needs []Key + Provides []Key +} + +func (c *container) Provide(provider Provider) error { + n := &node{ + Provider: provider, + called: false, + } + + c.nodes = append(c.nodes, n) + + for _, key := range provider.Provides { + if c.providers[key] != nil { + return fmt.Errorf("TODO") + } + + c.providers[key] = n + } + + return nil +} + +func (c *container) ProvideForScope(provider ScopedProvider) error { + n := &scopeNode{ + ScopedProvider: provider, + calledForScope: map[string]bool{}, + valuesForScope: map[string][]Value{}, + errsForScope: map[string]error{}, + } + + c.scopeNodes = append(c.scopeNodes, n) + + for _, key := range provider.Provides { + if c.scopeProviders[key] != nil { + return fmt.Errorf("TODO") + } + + c.scopeProviders[key] = n + } + + return nil +} + +func (c *container) resolve(scope string, key Key, stack map[interface{}]bool) (interface{}, error) { + if scope != "" { + if val, ok := c.scopedValues[scope][key]; ok { + return val, nil + } + + if provider, ok := c.scopeProviders[key]; ok { + if stack[provider] { + return nil, fmt.Errorf("fatal: cycle detected") + } + + if provider.calledForScope[scope] { + return nil, fmt.Errorf("error: %v", provider.errsForScope[scope]) + } + + var deps []interface{} + for _, need := range provider.Needs { + stack[provider] = true + res, err := c.resolve(scope, need, stack) + delete(stack, provider) + + if err != nil { + return nil, err + } + + deps = append(deps, res) + } + + res, err := provider.Constructor(scope, deps) + provider.calledForScope[scope] = true + if err != nil { + provider.errsForScope[scope] = err + return nil, err + } + + for i, val := range res { + p := provider.Provides[i] + if _, ok := c.scopedValues[scope][p]; ok { + return nil, fmt.Errorf("value provided twice") + } + + if c.scopedValues[scope] == nil { + c.scopedValues[scope] = map[Key]interface{}{} + } + c.scopedValues[scope][p] = val + } + + val, ok := c.scopedValues[scope][key] + if !ok { + return nil, fmt.Errorf("internal error: bug") + } + + return val, nil + } + } + + if val, ok := c.values[key]; ok { + return val, nil + } + + if provider, ok := c.providers[key]; ok { + if stack[provider] { + return nil, fmt.Errorf("fatal: cycle detected") + } + + if provider.called { + return nil, fmt.Errorf("error: %v", provider.err) + } + + var deps []interface{} + for _, need := range provider.Needs { + stack[provider] = true + res, err := c.resolve(provider.Scope, need, stack) + delete(stack, provider) + + if err != nil { + return nil, err + } + + deps = append(deps, res) + } + + res, err := provider.Constructor(deps) + provider.called = true + if err != nil { + provider.err = err + return nil, err + } + + for i, val := range res { + p := provider.Provides[i] + if _, ok := c.values[p]; ok { + return nil, fmt.Errorf("value provided twice") + } + + c.values[p] = val + } + + val, ok := c.values[key] + if !ok { + return nil, fmt.Errorf("internal error: bug") + } + + return val, nil + } + + return nil, fmt.Errorf("no provider") +} + +func (c *container) Resolve(scope string, key Key) (interface{}, error) { + return c.resolve(scope, key, map[interface{}]bool{}) +} + +type Container interface { + Provide(provider Provider) error + ProvideForScope(provider ScopedProvider) error + Resolve(scope string, key Key) (interface{}, error) +} + +func NewContainer() Container { + return &container{ + providers: map[Key]*node{}, + scopeProviders: map[Key]*scopeNode{}, + nodes: nil, + scopeNodes: nil, + values: map[Key]interface{}{}, + scopedValues: map[string]map[Key]interface{}{}, + } +} diff --git a/core/module/container_test.go b/core/module/container_test.go new file mode 100644 index 000000000000..f0c72136a74c --- /dev/null +++ b/core/module/container_test.go @@ -0,0 +1,119 @@ +package module + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +type storeKey struct { + name string +} + +type keeperA struct { + key storeKey +} + +type keeperB struct { + key storeKey + a keeperA +} + +func TestContainer(t *testing.T) { + c := NewContainer() + require.NoError(t, c.Provide(Provider{ + Constructor: func(deps []interface{}) ([]interface{}, error) { + return []interface{}{keeperA{deps[0].(storeKey)}}, nil + }, + Needs: []Key{ + { + Type: storeKey{}, + }, + }, + Provides: []Key{ + { + Type: (*keeperA)(nil), + }, + }, + Scope: "a", + })) + require.NoError(t, c.Provide(Provider{ + Constructor: func(deps []interface{}) ([]interface{}, error) { + return []interface{}{keeperB{ + key: deps[0].(storeKey), + a: deps[1].(keeperA), + }}, nil + }, + Needs: []Key{ + { + Type: storeKey{}, + }, + { + Type: (*keeperA)(nil), + }, + }, + Provides: []Key{ + { + Type: (*keeperB)(nil), + }, + }, + Scope: "b", + })) + require.NoError(t, c.ProvideForScope( + ScopedProvider{ + Constructor: func(scope string, deps []interface{}) ([]interface{}, error) { + return []interface{}{storeKey{name: scope}}, nil + }, + Needs: nil, + Provides: []Key{ + { + Type: storeKey{}, + }, + }, + }, + )) + + res, err := c.Resolve("b", Key{Type: (*keeperB)(nil)}) + require.NoError(t, err) + b := res.(keeperB) + t.Logf("%+v", b) + require.Equal(t, "b", b.key.name) + require.Equal(t, "a", b.a.key.name) +} + +func TestCycle(t *testing.T) { + c := NewContainer() + require.NoError(t, c.Provide(Provider{ + Constructor: func(deps []interface{}) ([]interface{}, error) { + return nil, nil + }, + Needs: []Key{ + { + Type: (*keeperB)(nil), + }, + }, + Provides: []Key{ + { + Type: (*keeperA)(nil), + }, + }, + })) + require.NoError(t, c.Provide(Provider{ + Constructor: func(deps []interface{}) ([]interface{}, error) { + return nil, nil + }, + Needs: []Key{ + { + Type: (*keeperA)(nil), + }, + }, + Provides: []Key{ + { + Type: (*keeperB)(nil), + }, + }, + })) + + _, err := c.Resolve("b", Key{Type: (*keeperB)(nil)}) + require.EqualError(t, err, "fatal: cycle detected") +} diff --git a/core/module/registry.go b/core/module/registry.go index 65ece987129b..c0a4dc948950 100644 --- a/core/module/registry.go +++ b/core/module/registry.go @@ -36,5 +36,3 @@ func (r *registry) Register(constructor interface{}) { r.hmap[configArg] = constructor } - -type container \ No newline at end of file diff --git a/proto/cosmos/core/app_config/v1/app_config.proto b/proto/cosmos/core/app_config/v1/app_config.proto index ecf3fc68e8e9..66de09317b36 100644 --- a/proto/cosmos/core/app_config/v1/app_config.proto +++ b/proto/cosmos/core/app_config/v1/app_config.proto @@ -6,10 +6,15 @@ import "google/protobuf/any.proto"; option go_package = "github.com/cosmos/cosmos-sdk/core/app_config"; message AppConfig { - map modules = 1; + repeated ModuleConfig modules = 1; ABCIHandlers abci = 2; } +message ModuleConfig { + google.protobuf.Any module = 1; + string name = 2; +} + message ABCIHandlers { repeated string init_genesis = 1; repeated string begin_block = 2; diff --git a/simapp2/app_config.json b/simapp2/app_config.json index ad1617d40d3e..266ab039fe93 100644 --- a/simapp2/app_config.json +++ b/simapp2/app_config.json @@ -1,22 +1,31 @@ { - "modules": { - "authn": { - "@type": "cosmos.authn.v1.Module", - "bech32_address_prefix": "sim" + "modules": [ + { + "name": "authn", + "module": { + "@type": "cosmos.authn.v1.Module", + "bech32_address_prefix": "sim" + } }, - "bank": { - "@type": "cosmos.bank.v1beta1.Module", - "send_deny_list": [], - "denom_managers": { - "coll": { - "@type": "cosmos.collectible.v1alpha1.CollectibleDenomManager" + { + "name": "bank", + "module": { + "@type": "cosmos.bank.v1beta1.Module", + "send_deny_list": [], + "denom_managers": { + "coll": { + "@type": "cosmos.collectible.v1alpha1.CollectibleDenomManager" + } } } }, - "upgrade": { - "@type": "cosmos.upgrade.v1beta1.Module" + { + "name": "upgrade", + "module": { + "@type": "cosmos.upgrade.v1beta1.Module" + } } - }, + ], "abci": { "init_genesis": [ "authn", diff --git a/x/bank/module/module.go b/x/bank/module/module.go index c4dd859c9f33..a67f4f74a59f 100644 --- a/x/bank/module/module.go +++ b/x/bank/module/module.go @@ -3,14 +3,11 @@ package module import ( "github.com/gogo/protobuf/proto" - "github.com/cosmos/cosmos-sdk/core/module" - "github.com/cosmos/cosmos-sdk/core/module/app" - "github.com/cosmos/cosmos-sdk/x/authn" "github.com/cosmos/cosmos-sdk/x/bank/types" ) func init() { - module.RegisterModuleHandler(handler{}) + //module.RegisterModuleHandler(handler{}) } type handler struct { @@ -21,17 +18,17 @@ func (h handler) ConfigType() proto.Message { return h.Module } -func (h handler) New(config proto.Message) module.ModuleHandler { - mod := config.(*types.Module) - return handler{mod} -} - -type AppModuleDeps struct { - Key app.RootModuleKey - AuthnQueryClient authn.QueryClient - AuthnMsgClient authn.MsgClient -} - -func (h handler) NewAppModule(deps AppModuleDeps) app.Handler { - panic("TODO") -} +//func (h handler) New(config proto.Message) module.ModuleHandler { +// mod := config.(*types.Module) +// return handler{mod} +//} +// +//type AppModuleDeps struct { +// Key app.RootModuleKey +// AuthnQueryClient authn.QueryClient +// AuthnMsgClient authn.MsgClient +//} +// +//func (h handler) NewAppModule(deps AppModuleDeps) app.Handler { +// panic("TODO") +//} From b66c2beb10bc875702fab022dda85971d1f0fe20 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 28 May 2021 20:54:39 -0400 Subject: [PATCH 14/19] wire up DI container --- core/app_config/app_config.go | 126 +++++++- core/app_config/app_config.pb.go | 485 +++++++++++++++++++------------ core/module/app/registry.go | 68 ++--- core/module/container.go | 191 +++++++----- core/module/container_test.go | 49 ++-- core/module/module.go | 2 - core/module/registry.go | 15 +- docs/core/proto-docs.md | 14 +- 8 files changed, 615 insertions(+), 335 deletions(-) diff --git a/core/app_config/app_config.go b/core/app_config/app_config.go index 7cd046d1bcd1..92c83bc329ae 100644 --- a/core/app_config/app_config.go +++ b/core/app_config/app_config.go @@ -1,11 +1,44 @@ package app_config import ( + "fmt" + "reflect" + + "github.com/gogo/protobuf/proto" "github.com/tendermint/tendermint/abci/types" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/core/module" + "github.com/cosmos/cosmos-sdk/core/module/app" ) -func Compose(config AppConfig) (types.Application, error) { - //moduleSet := module.NewModuleSet(config.Modules) +func Compose(config AppConfig, moduleRegistry *module.Registry) (types.Application, error) { + interfaceRegistry := codectypes.NewInterfaceRegistry() + container := module.NewContainer() + modSet := &moduleSet{ + container: container, + modMap: map[string]app.Handler{}, + } + + for _, mod := range config.Modules { + err := modSet.addModule(interfaceRegistry, moduleRegistry, mod) + if err != nil { + return nil, err + } + } + + err := modSet.addModule(interfaceRegistry, moduleRegistry, &ModuleConfig{ + Module: config.Abci.TxModule, + Name: "tx", + }) + if err != nil { + return nil, err + } + + err = modSet.initialize() + if err != nil { + return nil, err + } //appModules := make(map[string]app.Module) //moduleSet.Each(func(name string, handler module.ModuleHandler) { @@ -26,3 +59,92 @@ func Compose(config AppConfig) (types.Application, error) { panic("TODO") } + +type moduleSet struct { + container *module.Container + modMap map[string]app.Handler +} + +func (ms *moduleSet) addModule(interfaceRegistry codectypes.InterfaceRegistry, registry *module.Registry, config *ModuleConfig) error { + msg, err := interfaceRegistry.Resolve(config.Module.TypeUrl) + if err != nil { + return err + } + + err = proto.Unmarshal(config.Module.Value, msg) + if err != nil { + return err + } + + ctr := registry.Resolve(msg) + if ctr == nil { + return fmt.Errorf("TODO") + } + + ctrVal := reflect.ValueOf(ctr) + ctrTyp := ctrVal.Type() + + numIn := ctrTyp.NumIn() + var needs []module.Key + for i := 1; i < numIn; i++ { + argTy := ctrTyp.In(i) + needs = append(needs, module.Key{ + Type: argTy, + }) + } + + numOut := ctrTyp.NumIn() + var provides []module.Key + for i := 1; i < numOut; i++ { + argTy := ctrTyp.Out(i) + + // check if is error type + if isErrorTyp(argTy) { + continue + } + + provides = append(provides, module.Key{ + Type: argTy, + }) + } + + return ms.container.Provide(module.Provider{ + Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { + args := []reflect.Value{reflect.ValueOf(msg)} + args = append(args, deps...) + res := ctrVal.Call(args) + if len(res) < 1 { + return nil, fmt.Errorf("expected at least one return value") + } + + handler, ok := res[0].Interface().(app.Handler) + if !ok { + return nil, fmt.Errorf("expected handler got %+v", res[0]) + } + + var provides []reflect.Value + for i := 1; i < len(res); i++ { + if isErrorTyp(res[i].Type()) { + continue + } + + provides = append(provides, res[i]) + } + + ms.modMap[config.Name] = handler + + return provides, nil + }, + Needs: needs, + Provides: provides, + Scope: config.Name, + }) +} + +func (ms *moduleSet) initialize() error { + return ms.container.InitializeAll() +} + +func isErrorTyp(ty reflect.Type) bool { + return ty.Implements(reflect.TypeOf((*error)(nil)).Elem()) +} diff --git a/core/app_config/app_config.pb.go b/core/app_config/app_config.pb.go index 0f6a6197ef4f..3b82a7714970 100644 --- a/core/app_config/app_config.pb.go +++ b/core/app_config/app_config.pb.go @@ -24,8 +24,8 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type AppConfig struct { - Modules map[string]*types.Any `protobuf:"bytes,1,rep,name=modules,proto3" json:"modules,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - Abci *ABCIHandlers `protobuf:"bytes,2,opt,name=abci,proto3" json:"abci,omitempty"` + Modules []*ModuleConfig `protobuf:"bytes,1,rep,name=modules,proto3" json:"modules,omitempty"` + Abci *ABCIHandlers `protobuf:"bytes,2,opt,name=abci,proto3" json:"abci,omitempty"` } func (m *AppConfig) Reset() { *m = AppConfig{} } @@ -61,7 +61,7 @@ func (m *AppConfig) XXX_DiscardUnknown() { var xxx_messageInfo_AppConfig proto.InternalMessageInfo -func (m *AppConfig) GetModules() map[string]*types.Any { +func (m *AppConfig) GetModules() []*ModuleConfig { if m != nil { return m.Modules } @@ -75,19 +75,71 @@ func (m *AppConfig) GetAbci() *ABCIHandlers { return nil } +type ModuleConfig struct { + Module *types.Any `protobuf:"bytes,1,opt,name=module,proto3" json:"module,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` +} + +func (m *ModuleConfig) Reset() { *m = ModuleConfig{} } +func (m *ModuleConfig) String() string { return proto.CompactTextString(m) } +func (*ModuleConfig) ProtoMessage() {} +func (*ModuleConfig) Descriptor() ([]byte, []int) { + return fileDescriptor_67d11620ac2d3428, []int{1} +} +func (m *ModuleConfig) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ModuleConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ModuleConfig.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 *ModuleConfig) XXX_Merge(src proto.Message) { + xxx_messageInfo_ModuleConfig.Merge(m, src) +} +func (m *ModuleConfig) XXX_Size() int { + return m.Size() +} +func (m *ModuleConfig) XXX_DiscardUnknown() { + xxx_messageInfo_ModuleConfig.DiscardUnknown(m) +} + +var xxx_messageInfo_ModuleConfig proto.InternalMessageInfo + +func (m *ModuleConfig) GetModule() *types.Any { + if m != nil { + return m.Module + } + return nil +} + +func (m *ModuleConfig) GetName() string { + if m != nil { + return m.Name + } + return "" +} + type ABCIHandlers struct { - InitGenesis []string `protobuf:"bytes,1,rep,name=init_genesis,json=initGenesis,proto3" json:"init_genesis,omitempty"` - BeginBlock []string `protobuf:"bytes,2,rep,name=begin_block,json=beginBlock,proto3" json:"begin_block,omitempty"` - EndBlock []string `protobuf:"bytes,3,rep,name=end_block,json=endBlock,proto3" json:"end_block,omitempty"` - TxHandler string `protobuf:"bytes,4,opt,name=tx_handler,json=txHandler,proto3" json:"tx_handler,omitempty"` - InfoHandler string `protobuf:"bytes,5,opt,name=info_handler,json=infoHandler,proto3" json:"info_handler,omitempty"` + InitGenesis []string `protobuf:"bytes,1,rep,name=init_genesis,json=initGenesis,proto3" json:"init_genesis,omitempty"` + BeginBlock []string `protobuf:"bytes,2,rep,name=begin_block,json=beginBlock,proto3" json:"begin_block,omitempty"` + EndBlock []string `protobuf:"bytes,3,rep,name=end_block,json=endBlock,proto3" json:"end_block,omitempty"` + TxModule *types.Any `protobuf:"bytes,4,opt,name=tx_module,json=txModule,proto3" json:"tx_module,omitempty"` + InfoHandler string `protobuf:"bytes,5,opt,name=info_handler,json=infoHandler,proto3" json:"info_handler,omitempty"` } func (m *ABCIHandlers) Reset() { *m = ABCIHandlers{} } func (m *ABCIHandlers) String() string { return proto.CompactTextString(m) } func (*ABCIHandlers) ProtoMessage() {} func (*ABCIHandlers) Descriptor() ([]byte, []int) { - return fileDescriptor_67d11620ac2d3428, []int{1} + return fileDescriptor_67d11620ac2d3428, []int{2} } func (m *ABCIHandlers) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -137,11 +189,11 @@ func (m *ABCIHandlers) GetEndBlock() []string { return nil } -func (m *ABCIHandlers) GetTxHandler() string { +func (m *ABCIHandlers) GetTxModule() *types.Any { if m != nil { - return m.TxHandler + return m.TxModule } - return "" + return nil } func (m *ABCIHandlers) GetInfoHandler() string { @@ -153,7 +205,7 @@ func (m *ABCIHandlers) GetInfoHandler() string { func init() { proto.RegisterType((*AppConfig)(nil), "cosmos.core.app_config.v1.AppConfig") - proto.RegisterMapType((map[string]*types.Any)(nil), "cosmos.core.app_config.v1.AppConfig.ModulesEntry") + proto.RegisterType((*ModuleConfig)(nil), "cosmos.core.app_config.v1.ModuleConfig") proto.RegisterType((*ABCIHandlers)(nil), "cosmos.core.app_config.v1.ABCIHandlers") } @@ -162,31 +214,30 @@ func init() { } var fileDescriptor_67d11620ac2d3428 = []byte{ - // 381 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xcb, 0x4e, 0xea, 0x40, - 0x1c, 0xc6, 0x19, 0x2e, 0xe7, 0x9c, 0x4e, 0x59, 0x9c, 0x4c, 0xce, 0xa2, 0x70, 0x62, 0x45, 0x36, - 0x12, 0xa2, 0xd3, 0x80, 0x1b, 0xa3, 0x2b, 0x20, 0xde, 0x62, 0x4c, 0x4c, 0x97, 0x6e, 0x9a, 0x5e, - 0x86, 0x32, 0xa1, 0xcc, 0x34, 0xbd, 0x10, 0xfa, 0x16, 0xbe, 0x8a, 0x6f, 0xe1, 0x92, 0xa5, 0x4b, - 0x03, 0x0b, 0x5f, 0xc3, 0x74, 0xa6, 0x90, 0xc6, 0x44, 0x57, 0x6d, 0xbf, 0xef, 0xf7, 0x7d, 0xff, - 0xf9, 0x37, 0x03, 0xfb, 0x2e, 0x8f, 0x17, 0x3c, 0x36, 0x5c, 0x1e, 0x11, 0xc3, 0x0e, 0x43, 0xcb, - 0xe5, 0x6c, 0x4a, 0x7d, 0x63, 0x39, 0x28, 0x7d, 0xe1, 0x30, 0xe2, 0x09, 0x47, 0x2d, 0xc9, 0xe2, - 0x9c, 0xc5, 0x25, 0x77, 0x39, 0x68, 0xb7, 0x7c, 0xce, 0xfd, 0x80, 0x18, 0x02, 0x74, 0xd2, 0xa9, - 0x61, 0xb3, 0x4c, 0xa6, 0xba, 0x1f, 0x00, 0x2a, 0xa3, 0x30, 0x9c, 0x08, 0x16, 0xdd, 0xc3, 0xdf, - 0x0b, 0xee, 0xa5, 0x01, 0x89, 0x35, 0xd0, 0xa9, 0xf5, 0xd4, 0xe1, 0x00, 0x7f, 0xdb, 0x8a, 0xf7, - 0x31, 0xfc, 0x20, 0x33, 0x57, 0x2c, 0x89, 0x32, 0x73, 0xd7, 0x80, 0x2e, 0x61, 0xdd, 0x76, 0x5c, - 0xaa, 0x55, 0x3b, 0xa0, 0xa7, 0x0e, 0x8f, 0x7f, 0x6a, 0x1a, 0x4f, 0xee, 0x6e, 0x6d, 0xe6, 0x05, - 0x24, 0x8a, 0x4d, 0x11, 0x6a, 0x3f, 0xc2, 0x66, 0xb9, 0x15, 0xfd, 0x85, 0xb5, 0x39, 0xc9, 0x34, - 0xd0, 0x01, 0x3d, 0xc5, 0xcc, 0x5f, 0x51, 0x1f, 0x36, 0x96, 0x76, 0x90, 0x92, 0xa2, 0xff, 0x1f, - 0x96, 0x4b, 0xe2, 0xdd, 0x92, 0x78, 0xc4, 0x32, 0x53, 0x22, 0x17, 0xd5, 0x73, 0xd0, 0x7d, 0x01, - 0xb0, 0x59, 0x1e, 0x84, 0x8e, 0x60, 0x93, 0x32, 0x9a, 0x58, 0x3e, 0x61, 0x24, 0xa6, 0x72, 0x63, - 0xc5, 0x54, 0x73, 0xed, 0x46, 0x4a, 0xe8, 0x10, 0xaa, 0x0e, 0xf1, 0x29, 0xb3, 0x9c, 0x80, 0xbb, - 0x73, 0xad, 0x2a, 0x08, 0x28, 0xa4, 0x71, 0xae, 0xa0, 0xff, 0x50, 0x21, 0xcc, 0x2b, 0xec, 0x9a, - 0xb0, 0xff, 0x10, 0xe6, 0x49, 0xf3, 0x00, 0xc2, 0x64, 0x65, 0xcd, 0xe4, 0x3c, 0xad, 0x2e, 0x8e, - 0xae, 0x24, 0xab, 0xe2, 0x00, 0x72, 0xfe, 0x94, 0xef, 0x81, 0x86, 0x00, 0xd4, 0x5c, 0x2b, 0x90, - 0xf1, 0xf5, 0xeb, 0x46, 0x07, 0xeb, 0x8d, 0x0e, 0xde, 0x37, 0x3a, 0x78, 0xde, 0xea, 0x95, 0xf5, - 0x56, 0xaf, 0xbc, 0x6d, 0xf5, 0xca, 0xd3, 0x89, 0x4f, 0x93, 0x59, 0xea, 0x60, 0x97, 0x2f, 0x8c, - 0xfd, 0x25, 0xc9, 0x1f, 0xa7, 0xb1, 0x37, 0xff, 0x7a, 0x5f, 0x9c, 0x5f, 0xe2, 0xa7, 0x9c, 0x7d, - 0x06, 0x00, 0x00, 0xff, 0xff, 0x86, 0x7e, 0x44, 0xf1, 0x50, 0x02, 0x00, 0x00, + // 361 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x52, 0x3d, 0x4f, 0xfa, 0x40, + 0x1c, 0xe6, 0x80, 0x3f, 0x7f, 0xfa, 0x2b, 0xd3, 0xc5, 0xa1, 0x68, 0x52, 0x91, 0x45, 0x63, 0xf0, + 0x1a, 0x74, 0x74, 0x2a, 0x24, 0xbe, 0x0c, 0x26, 0xa6, 0xa3, 0x4b, 0xd3, 0x97, 0xa3, 0x5c, 0x68, + 0xef, 0x1a, 0x5a, 0x08, 0x7c, 0x06, 0x17, 0xbf, 0x94, 0x89, 0x23, 0xa3, 0xa3, 0x81, 0x2f, 0x62, + 0x7a, 0x57, 0x4c, 0x63, 0xa2, 0x4e, 0xed, 0x3d, 0x6f, 0xf7, 0x3c, 0xc9, 0xc1, 0x79, 0x20, 0xb2, + 0x44, 0x64, 0x56, 0x20, 0xe6, 0xd4, 0xf2, 0xd2, 0xd4, 0x0d, 0x04, 0x9f, 0xb0, 0xc8, 0x5a, 0x0e, + 0x2b, 0x27, 0x92, 0xce, 0x45, 0x2e, 0x70, 0x57, 0x69, 0x49, 0xa1, 0x25, 0x15, 0x76, 0x39, 0x3c, + 0xec, 0x46, 0x42, 0x44, 0x31, 0xb5, 0xa4, 0xd0, 0x5f, 0x4c, 0x2c, 0x8f, 0xaf, 0x95, 0xab, 0xff, + 0x8c, 0x40, 0xb3, 0xd3, 0x74, 0x2c, 0xb5, 0xd8, 0x86, 0xff, 0x89, 0x08, 0x17, 0x31, 0xcd, 0x0c, + 0xd4, 0x6b, 0x9c, 0xe9, 0x97, 0xa7, 0xe4, 0xc7, 0x54, 0xf2, 0x20, 0x95, 0xca, 0xe9, 0xec, 0x7d, + 0xf8, 0x1a, 0x9a, 0x9e, 0x1f, 0x30, 0xa3, 0xde, 0x43, 0x7f, 0xf8, 0xed, 0xd1, 0xf8, 0xfe, 0xce, + 0xe3, 0x61, 0x4c, 0xe7, 0x99, 0x23, 0x4d, 0xfd, 0x47, 0xe8, 0x54, 0x53, 0xf1, 0x00, 0x5a, 0x2a, + 0xd7, 0x40, 0x32, 0xee, 0x80, 0xa8, 0x25, 0x64, 0xbf, 0x84, 0xd8, 0x7c, 0xed, 0x94, 0x1a, 0x8c, + 0xa1, 0xc9, 0xbd, 0x84, 0xca, 0xab, 0x35, 0x47, 0xfe, 0xf7, 0x5f, 0x11, 0x74, 0xaa, 0x17, 0xe1, + 0x13, 0xe8, 0x30, 0xce, 0x72, 0x37, 0xa2, 0x9c, 0x66, 0x4c, 0xed, 0xd4, 0x1c, 0xbd, 0xc0, 0x6e, + 0x15, 0x84, 0x8f, 0x41, 0xf7, 0x69, 0xc4, 0xb8, 0xeb, 0xc7, 0x22, 0x98, 0x19, 0x75, 0xa9, 0x00, + 0x09, 0x8d, 0x0a, 0x04, 0x1f, 0x81, 0x46, 0x79, 0x58, 0xd2, 0x0d, 0x49, 0xb7, 0x29, 0x0f, 0x15, + 0x39, 0x04, 0x2d, 0x5f, 0xb9, 0x65, 0xed, 0xe6, 0x2f, 0xb5, 0xdb, 0xf9, 0x4a, 0x8d, 0x55, 0x9d, + 0x26, 0xc2, 0x9d, 0xaa, 0x92, 0xc6, 0x3f, 0x39, 0x40, 0x2f, 0xb0, 0xb2, 0xf7, 0xe8, 0xe6, 0x6d, + 0x6b, 0xa2, 0xcd, 0xd6, 0x44, 0x1f, 0x5b, 0x13, 0xbd, 0xec, 0xcc, 0xda, 0x66, 0x67, 0xd6, 0xde, + 0x77, 0x66, 0xed, 0x69, 0x10, 0xb1, 0x7c, 0xba, 0xf0, 0x49, 0x20, 0x12, 0xeb, 0xeb, 0xb9, 0x14, + 0x9f, 0x8b, 0x2c, 0x9c, 0x7d, 0x7f, 0x39, 0x7e, 0x4b, 0x56, 0xb8, 0xfa, 0x0c, 0x00, 0x00, 0xff, + 0xff, 0xaf, 0xe3, 0x53, 0x2a, 0x5a, 0x02, 0x00, 0x00, } func (m *AppConfig) Marshal() (dAtA []byte, err error) { @@ -222,27 +273,15 @@ func (m *AppConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x12 } if len(m.Modules) > 0 { - for k := range m.Modules { - v := m.Modules[k] - baseI := i - if v != nil { - { - size, err := v.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintAppConfig(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - i -= len(k) - copy(dAtA[i:], k) - i = encodeVarintAppConfig(dAtA, i, uint64(len(k))) - i-- - dAtA[i] = 0xa - i = encodeVarintAppConfig(dAtA, i, uint64(baseI-i)) + for iNdEx := len(m.Modules) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Modules[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAppConfig(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0xa } @@ -250,6 +289,48 @@ func (m *AppConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *ModuleConfig) 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 *ModuleConfig) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ModuleConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintAppConfig(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x12 + } + if m.Module != nil { + { + size, err := m.Module.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAppConfig(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *ABCIHandlers) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -277,10 +358,15 @@ func (m *ABCIHandlers) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x2a } - if len(m.TxHandler) > 0 { - i -= len(m.TxHandler) - copy(dAtA[i:], m.TxHandler) - i = encodeVarintAppConfig(dAtA, i, uint64(len(m.TxHandler))) + if m.TxModule != nil { + { + size, err := m.TxModule.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAppConfig(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0x22 } @@ -332,16 +418,9 @@ func (m *AppConfig) Size() (n int) { var l int _ = l if len(m.Modules) > 0 { - for k, v := range m.Modules { - _ = k - _ = v - l = 0 - if v != nil { - l = v.Size() - l += 1 + sovAppConfig(uint64(l)) - } - mapEntrySize := 1 + len(k) + sovAppConfig(uint64(len(k))) + l - n += mapEntrySize + 1 + sovAppConfig(uint64(mapEntrySize)) + for _, e := range m.Modules { + l = e.Size() + n += 1 + l + sovAppConfig(uint64(l)) } } if m.Abci != nil { @@ -351,6 +430,23 @@ func (m *AppConfig) Size() (n int) { return n } +func (m *ModuleConfig) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Module != nil { + l = m.Module.Size() + n += 1 + l + sovAppConfig(uint64(l)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovAppConfig(uint64(l)) + } + return n +} + func (m *ABCIHandlers) Size() (n int) { if m == nil { return 0 @@ -375,8 +471,8 @@ func (m *ABCIHandlers) Size() (n int) { n += 1 + l + sovAppConfig(uint64(l)) } } - l = len(m.TxHandler) - if l > 0 { + if m.TxModule != nil { + l = m.TxModule.Size() n += 1 + l + sovAppConfig(uint64(l)) } l = len(m.InfoHandler) @@ -450,105 +546,10 @@ func (m *AppConfig) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Modules == nil { - m.Modules = make(map[string]*types.Any) - } - var mapkey string - var mapvalue *types.Any - for iNdEx < postIndex { - entryPreIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAppConfig - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - if fieldNum == 1 { - var stringLenmapkey uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAppConfig - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLenmapkey |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLenmapkey := int(stringLenmapkey) - if intStringLenmapkey < 0 { - return ErrInvalidLengthAppConfig - } - postStringIndexmapkey := iNdEx + intStringLenmapkey - if postStringIndexmapkey < 0 { - return ErrInvalidLengthAppConfig - } - if postStringIndexmapkey > l { - return io.ErrUnexpectedEOF - } - mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) - iNdEx = postStringIndexmapkey - } else if fieldNum == 2 { - var mapmsglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowAppConfig - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - mapmsglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if mapmsglen < 0 { - return ErrInvalidLengthAppConfig - } - postmsgIndex := iNdEx + mapmsglen - if postmsgIndex < 0 { - return ErrInvalidLengthAppConfig - } - if postmsgIndex > l { - return io.ErrUnexpectedEOF - } - mapvalue = &types.Any{} - if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil { - return err - } - iNdEx = postmsgIndex - } else { - iNdEx = entryPreIndex - skippy, err := skipAppConfig(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthAppConfig - } - if (iNdEx + skippy) > postIndex { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - m.Modules[mapkey] = mapvalue + m.Modules = append(m.Modules, &ModuleConfig{}) + if err := m.Modules[len(m.Modules)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 2: if wireType != 2 { @@ -607,6 +608,124 @@ func (m *AppConfig) Unmarshal(dAtA []byte) error { } return nil } +func (m *ModuleConfig) 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 ErrIntOverflowAppConfig + } + 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: ModuleConfig: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ModuleConfig: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Module", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAppConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthAppConfig + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthAppConfig + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Module == nil { + m.Module = &types.Any{} + } + if err := m.Module.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 ErrIntOverflowAppConfig + } + 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 ErrInvalidLengthAppConfig + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAppConfig + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipAppConfig(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAppConfig + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *ABCIHandlers) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -734,9 +853,9 @@ func (m *ABCIHandlers) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TxHandler", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field TxModule", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowAppConfig @@ -746,23 +865,27 @@ func (m *ABCIHandlers) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthAppConfig } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthAppConfig } if postIndex > l { return io.ErrUnexpectedEOF } - m.TxHandler = string(dAtA[iNdEx:postIndex]) + if m.TxModule == nil { + m.TxModule = &types.Any{} + } + if err := m.TxModule.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 5: if wireType != 2 { diff --git a/core/module/app/registry.go b/core/module/app/registry.go index 351a7ce0de97..446322209b3d 100644 --- a/core/module/app/registry.go +++ b/core/module/app/registry.go @@ -1,54 +1,26 @@ package app -import ( - "fmt" - "reflect" +import "github.com/cosmos/cosmos-sdk/core/module" - "github.com/cosmos/cosmos-sdk/core/module" -) +var defaultRegistry = module.NewRegistry((*Handler)(nil)) -var registry map[reflect.Type]Handler - -func RegisterAppModule(constructor interface{}) { - typ := reflect.TypeOf(constructor) - if typ.Kind() != reflect.Func { - panic("TODO") - } - - if typ.NumIn() < 1 { - panic("TODO") - } - - typ.In(1) - - configField, ok := typ.FieldByName("Config") - if !ok { - panic(fmt.Errorf("module handler struct %T does not contain a Config field", handler)) - } - - if existing, ok := registry[configField.Type]; ok { - panic(fmt.Errorf("module handler %T already registered for config type %T, trying to register new handler type %T", existing, configField.Type, handler)) - } - - registry[configField.Type] = handler +func DefaultRegistry() *module.Registry { + return defaultRegistry } -type ModuleSet struct { - modMap map[string]Handler -} - -func NewModuleSet(configMap module.ModuleConfigSet) (ModuleSet, error) { - // TODO deterministic order - modMap := make(map[string]Handler) - for k, v := range configMap { - mod, ok := registry[reflect.TypeOf(v)] - if !ok { - panic("TODO") - } - - mod = mod.New() - modMap[k] = mod - } - - return ModuleSet{modMap: modMap}, nil -} +//var registry map[reflect.Type]Handler +// +//func RegisterAppModule(constructor interface{}) { +// typ := reflect.TypeOf(constructor) +// if typ.Kind() != reflect.Func { +// panic("TODO") +// } +// +// if typ.NumIn() < 1 { +// panic("TODO") +// } +// +// typ.In(1) +// +//} +// diff --git a/core/module/container.go b/core/module/container.go index 5c360b06a3ae..551d52171df7 100644 --- a/core/module/container.go +++ b/core/module/container.go @@ -2,55 +2,62 @@ package module import ( "fmt" + "reflect" ) -type container struct { +type Container struct { providers map[Key]*node scopeProviders map[Key]*scopeNode nodes []*node scopeNodes []*scopeNode - values map[Key]interface{} - scopedValues map[string]map[Key]interface{} + values map[Key]secureValue + scopedValues map[Scope]map[Key]reflect.Value } -type Key struct { - Type interface{} +type secureValue struct { + value reflect.Value + securityChecker SecurityChecker } -type Value struct { - Key Key - Value interface{} +type SecurityChecker func(scope Scope) error + +type Key struct { + Type reflect.Type } +type Scope = string + type node struct { Provider called bool - values []Value + values []reflect.Value err error } type Provider struct { - Constructor func(deps []interface{}) ([]interface{}, error) - Needs []Key - Provides []Key - Scope string + Constructor func(deps []reflect.Value) ([]reflect.Value, error) + Needs []Key + Provides []Key + Scope Scope + SecurityCheckers []SecurityChecker } type scopeNode struct { ScopedProvider - calledForScope map[string]bool - valuesForScope map[string][]Value - errsForScope map[string]error + calledForScope map[Scope]bool + valuesForScope map[Scope][]reflect.Value + errsForScope map[Scope]error } type ScopedProvider struct { - Constructor func(scope string, deps []interface{}) ([]interface{}, error) + Constructor func(scope Scope, deps []reflect.Value) ([]reflect.Value, error) Needs []Key Provides []Key + Scope Scope } -func (c *container) Provide(provider Provider) error { +func (c *Container) Provide(provider Provider) error { n := &node{ Provider: provider, called: false, @@ -69,12 +76,12 @@ func (c *container) Provide(provider Provider) error { return nil } -func (c *container) ProvideForScope(provider ScopedProvider) error { +func (c *Container) ProvideForScope(provider ScopedProvider) error { n := &scopeNode{ ScopedProvider: provider, - calledForScope: map[string]bool{}, - valuesForScope: map[string][]Value{}, - errsForScope: map[string]error{}, + calledForScope: map[Scope]bool{}, + valuesForScope: map[Scope][]reflect.Value{}, + errsForScope: map[Scope]error{}, } c.scopeNodes = append(c.scopeNodes, n) @@ -90,7 +97,7 @@ func (c *container) ProvideForScope(provider ScopedProvider) error { return nil } -func (c *container) resolve(scope string, key Key, stack map[interface{}]bool) (interface{}, error) { +func (c *Container) resolve(scope Scope, key Key, stack map[interface{}]bool) (reflect.Value, error) { if scope != "" { if val, ok := c.scopedValues[scope][key]; ok { return val, nil @@ -98,21 +105,21 @@ func (c *container) resolve(scope string, key Key, stack map[interface{}]bool) ( if provider, ok := c.scopeProviders[key]; ok { if stack[provider] { - return nil, fmt.Errorf("fatal: cycle detected") + return reflect.Value{}, fmt.Errorf("fatal: cycle detected") } if provider.calledForScope[scope] { - return nil, fmt.Errorf("error: %v", provider.errsForScope[scope]) + return reflect.Value{}, fmt.Errorf("error: %v", provider.errsForScope[scope]) } - var deps []interface{} + var deps []reflect.Value for _, need := range provider.Needs { stack[provider] = true - res, err := c.resolve(scope, need, stack) + res, err := c.resolve(provider.Scope, need, stack) delete(stack, provider) if err != nil { - return nil, err + return reflect.Value{}, err } deps = append(deps, res) @@ -122,24 +129,26 @@ func (c *container) resolve(scope string, key Key, stack map[interface{}]bool) ( provider.calledForScope[scope] = true if err != nil { provider.errsForScope[scope] = err - return nil, err + return reflect.Value{}, err } + provider.valuesForScope[scope] = res + for i, val := range res { p := provider.Provides[i] if _, ok := c.scopedValues[scope][p]; ok { - return nil, fmt.Errorf("value provided twice") + return reflect.Value{}, fmt.Errorf("value provided twice") } if c.scopedValues[scope] == nil { - c.scopedValues[scope] = map[Key]interface{}{} + c.scopedValues[scope] = map[Key]reflect.Value{} } c.scopedValues[scope][p] = val } val, ok := c.scopedValues[scope][key] if !ok { - return nil, fmt.Errorf("internal error: bug") + return reflect.Value{}, fmt.Errorf("internal error: bug") } return val, nil @@ -147,75 +156,119 @@ func (c *container) resolve(scope string, key Key, stack map[interface{}]bool) ( } if val, ok := c.values[key]; ok { - return val, nil + if val.securityChecker != nil { + if err := val.securityChecker(scope); err != nil { + return reflect.Value{}, err + } + } + + return val.value, nil } if provider, ok := c.providers[key]; ok { if stack[provider] { - return nil, fmt.Errorf("fatal: cycle detected") + return reflect.Value{}, fmt.Errorf("fatal: cycle detected") } if provider.called { - return nil, fmt.Errorf("error: %v", provider.err) + return reflect.Value{}, fmt.Errorf("error: %v", provider.err) } - var deps []interface{} - for _, need := range provider.Needs { - stack[provider] = true - res, err := c.resolve(provider.Scope, need, stack) - delete(stack, provider) + err := c.execNode(provider, stack) + if err != nil { + return reflect.Value{}, err + } - if err != nil { - return nil, err - } + val, ok := c.values[key] + if !ok { + return reflect.Value{}, fmt.Errorf("internal error: bug") + } - deps = append(deps, res) + if val.securityChecker != nil { + if err := val.securityChecker(scope); err != nil { + return reflect.Value{}, err + } } - res, err := provider.Constructor(deps) - provider.called = true + return val.value, nil + } + + return reflect.Value{}, fmt.Errorf("no provider") +} + +func (c *Container) execNode(provider *node, stack map[interface{}]bool) error { + if provider.called { + return provider.err + } + + var deps []reflect.Value + for _, need := range provider.Needs { + stack[provider] = true + res, err := c.resolve(provider.Scope, need, stack) + delete(stack, provider) + if err != nil { - provider.err = err - return nil, err + return err } - for i, val := range res { - p := provider.Provides[i] - if _, ok := c.values[p]; ok { - return nil, fmt.Errorf("value provided twice") - } + deps = append(deps, res) + } + + res, err := provider.Constructor(deps) + provider.called = true + if err != nil { + provider.err = err + return err + } + + provider.values = res - c.values[p] = val + for i, val := range res { + p := provider.Provides[i] + if _, ok := c.values[p]; ok { + return fmt.Errorf("value provided twice") } - val, ok := c.values[key] - if !ok { - return nil, fmt.Errorf("internal error: bug") + var secChecker SecurityChecker + if i < len(provider.SecurityCheckers) { + secChecker = provider.SecurityCheckers[i] } - return val, nil + c.values[p] = secureValue{ + value: val, + securityChecker: secChecker, + } } - return nil, fmt.Errorf("no provider") + return nil } -func (c *container) Resolve(scope string, key Key) (interface{}, error) { - return c.resolve(scope, key, map[interface{}]bool{}) +func (c *Container) Resolve(scope Scope, key Key) (reflect.Value, error) { + val, err := c.resolve(scope, key, map[interface{}]bool{}) + if err != nil { + return reflect.Value{}, err + } + return val, nil } -type Container interface { - Provide(provider Provider) error - ProvideForScope(provider ScopedProvider) error - Resolve(scope string, key Key) (interface{}, error) +// InitializeAll attempts to call all providers instantiating the dependencies they provide +func (c *Container) InitializeAll() error { + for _, node := range c.nodes { + err := c.execNode(node, map[interface{}]bool{}) + if err != nil { + return err + } + } + return nil } -func NewContainer() Container { - return &container{ +func NewContainer() *Container { + return &Container{ providers: map[Key]*node{}, scopeProviders: map[Key]*scopeNode{}, nodes: nil, scopeNodes: nil, - values: map[Key]interface{}{}, - scopedValues: map[string]map[Key]interface{}{}, + values: map[Key]secureValue{}, + scopedValues: map[Scope]map[Key]reflect.Value{}, } } diff --git a/core/module/container_test.go b/core/module/container_test.go index f0c72136a74c..3a497f1882ad 100644 --- a/core/module/container_test.go +++ b/core/module/container_test.go @@ -1,6 +1,7 @@ package module import ( + "reflect" "testing" "github.com/stretchr/testify/require" @@ -22,60 +23,60 @@ type keeperB struct { func TestContainer(t *testing.T) { c := NewContainer() require.NoError(t, c.Provide(Provider{ - Constructor: func(deps []interface{}) ([]interface{}, error) { - return []interface{}{keeperA{deps[0].(storeKey)}}, nil + Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { + return []reflect.Value{reflect.ValueOf(keeperA{deps[0].Interface().(storeKey)})}, nil }, Needs: []Key{ { - Type: storeKey{}, + Type: reflect.TypeOf(storeKey{}), }, }, Provides: []Key{ { - Type: (*keeperA)(nil), + Type: reflect.TypeOf((*keeperA)(nil)), }, }, Scope: "a", })) require.NoError(t, c.Provide(Provider{ - Constructor: func(deps []interface{}) ([]interface{}, error) { - return []interface{}{keeperB{ - key: deps[0].(storeKey), - a: deps[1].(keeperA), - }}, nil + Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { + return []reflect.Value{reflect.ValueOf(keeperB{ + key: deps[0].Interface().(storeKey), + a: deps[1].Interface().(keeperA), + })}, nil }, Needs: []Key{ { - Type: storeKey{}, + Type: reflect.TypeOf(storeKey{}), }, { - Type: (*keeperA)(nil), + Type: reflect.TypeOf((*keeperA)(nil)), }, }, Provides: []Key{ { - Type: (*keeperB)(nil), + Type: reflect.TypeOf((*keeperB)(nil)), }, }, Scope: "b", })) require.NoError(t, c.ProvideForScope( ScopedProvider{ - Constructor: func(scope string, deps []interface{}) ([]interface{}, error) { - return []interface{}{storeKey{name: scope}}, nil + Constructor: func(scope Scope, deps []reflect.Value) ([]reflect.Value, error) { + return []reflect.Value{reflect.ValueOf(storeKey{name: scope})}, nil }, Needs: nil, Provides: []Key{ { - Type: storeKey{}, + Type: reflect.TypeOf(storeKey{}), }, }, }, )) - res, err := c.Resolve("b", Key{Type: (*keeperB)(nil)}) + res, err := c.Resolve("b", Key{Type: reflect.TypeOf((*keeperB)(nil))}) require.NoError(t, err) - b := res.(keeperB) + b := res.Interface().(keeperB) t.Logf("%+v", b) require.Equal(t, "b", b.key.name) require.Equal(t, "a", b.a.key.name) @@ -84,36 +85,36 @@ func TestContainer(t *testing.T) { func TestCycle(t *testing.T) { c := NewContainer() require.NoError(t, c.Provide(Provider{ - Constructor: func(deps []interface{}) ([]interface{}, error) { + Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { return nil, nil }, Needs: []Key{ { - Type: (*keeperB)(nil), + Type: reflect.TypeOf((*keeperB)(nil)), }, }, Provides: []Key{ { - Type: (*keeperA)(nil), + Type: reflect.TypeOf((*keeperA)(nil)), }, }, })) require.NoError(t, c.Provide(Provider{ - Constructor: func(deps []interface{}) ([]interface{}, error) { + Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { return nil, nil }, Needs: []Key{ { - Type: (*keeperA)(nil), + Type: reflect.TypeOf((*keeperA)(nil)), }, }, Provides: []Key{ { - Type: (*keeperB)(nil), + Type: reflect.TypeOf((*keeperB)(nil)), }, }, })) - _, err := c.Resolve("b", Key{Type: (*keeperB)(nil)}) + _, err := c.Resolve("b", Key{Type: reflect.TypeOf((*keeperB)(nil))}) require.EqualError(t, err, "fatal: cycle detected") } diff --git a/core/module/module.go b/core/module/module.go index de6557e95d94..798a8059a1b4 100644 --- a/core/module/module.go +++ b/core/module/module.go @@ -23,8 +23,6 @@ package module // handlers map[string]ModuleHandler //} // -//type ModuleConfigSet = map[string]*types.Any -// //func NewModuleSet(moduleConfigs ModuleConfigSet) *ModuleSet { // panic("TODO") //} diff --git a/core/module/registry.go b/core/module/registry.go index c0a4dc948950..86755e80adbf 100644 --- a/core/module/registry.go +++ b/core/module/registry.go @@ -4,12 +4,19 @@ import ( "reflect" ) -type registry struct { +type Registry struct { hmap map[reflect.Type]interface{} handlerType reflect.Type } -func (r *registry) Register(constructor interface{}) { +func NewRegistry(handlerType interface{}) *Registry { + return &Registry{ + hmap: map[reflect.Type]interface{}{}, + handlerType: reflect.TypeOf(handlerType), + } +} + +func (r *Registry) Register(constructor interface{}) { typ := reflect.TypeOf(constructor) if typ.Kind() != reflect.Func { panic("TODO") @@ -36,3 +43,7 @@ func (r *registry) Register(constructor interface{}) { r.hmap[configArg] = constructor } + +func (r *Registry) Resolve(configType interface{}) interface{} { + return r.hmap[reflect.TypeOf(configType)] +} diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 5980b8c2f2b1..d5c3593f1ff6 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -256,7 +256,7 @@ - [cosmos/core/app_config/v1/app_config.proto](#cosmos/core/app_config/v1/app_config.proto) - [ABCIHandlers](#cosmos.core.app_config.v1.ABCIHandlers) - [AppConfig](#cosmos.core.app_config.v1.AppConfig) - - [AppConfig.ModulesEntry](#cosmos.core.app_config.v1.AppConfig.ModulesEntry) + - [ModuleConfig](#cosmos.core.app_config.v1.ModuleConfig) - [cosmos/core/app_config/v1/default_middleware.proto](#cosmos/core/app_config/v1/default_middleware.proto) - [DefaultTxMiddleware](#cosmos.core.app_config.v1.DefaultTxMiddleware) @@ -3791,7 +3791,7 @@ GenesisState defines the capability module's genesis state. | `init_genesis` | [string](#string) | repeated | | | `begin_block` | [string](#string) | repeated | | | `end_block` | [string](#string) | repeated | | -| `tx_handler` | [string](#string) | | | +| `tx_module` | [google.protobuf.Any](#google.protobuf.Any) | | | | `info_handler` | [string](#string) | | | @@ -3807,7 +3807,7 @@ GenesisState defines the capability module's genesis state. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `modules` | [AppConfig.ModulesEntry](#cosmos.core.app_config.v1.AppConfig.ModulesEntry) | repeated | | +| `modules` | [ModuleConfig](#cosmos.core.app_config.v1.ModuleConfig) | repeated | | | `abci` | [ABCIHandlers](#cosmos.core.app_config.v1.ABCIHandlers) | | | @@ -3815,16 +3815,16 @@ GenesisState defines the capability module's genesis state. - + -### AppConfig.ModulesEntry +### ModuleConfig | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `key` | [string](#string) | | | -| `value` | [google.protobuf.Any](#google.protobuf.Any) | | | +| `module` | [google.protobuf.Any](#google.protobuf.Any) | | | +| `name` | [string](#string) | | | From f0c8283ca39d5f3b2d6999d8476a3c0fb926d6dc Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 28 May 2021 21:07:28 -0400 Subject: [PATCH 15/19] add docs --- core/module/container.go | 48 ++++++++++++++++++++++------------- core/module/container_test.go | 2 +- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/core/module/container.go b/core/module/container.go index 551d52171df7..0e559dda4079 100644 --- a/core/module/container.go +++ b/core/module/container.go @@ -5,6 +5,10 @@ import ( "reflect" ) +// Container is a low-level dependency injection container which manages dependencies +// based on scopes and security policies. All providers can be run in a scope which +// may provide certain dependencies specifically for that scope or provide/deny access +// to dependencies based on that scope. type Container struct { providers map[Key]*node scopeProviders map[Key]*scopeNode @@ -15,13 +19,17 @@ type Container struct { scopedValues map[Scope]map[Key]reflect.Value } -type secureValue struct { - value reflect.Value - securityChecker SecurityChecker +func NewContainer() *Container { + return &Container{ + providers: map[Key]*node{}, + scopeProviders: map[Key]*scopeNode{}, + nodes: nil, + scopeNodes: nil, + values: map[Key]secureValue{}, + scopedValues: map[Scope]map[Key]reflect.Value{}, + } } -type SecurityChecker func(scope Scope) error - type Key struct { Type reflect.Type } @@ -35,6 +43,10 @@ type node struct { err error } +// Provider is a general dependency provider. Its scope parameter is used +// to receive scoped dependencies and gain access to general dependencies within +// its security policy. Access to dependencies provided by this provider can optionally +// be restricted to certain scopes based on SecurityCheckers. type Provider struct { Constructor func(deps []reflect.Value) ([]reflect.Value, error) Needs []Key @@ -50,6 +62,12 @@ type scopeNode struct { errsForScope map[Scope]error } +// ScopedProvider provides scoped dependencies. Its constructor function will provide +// dependencies specific to the scope parameter. Instead of providing general dependencies +// with restricted access based on security checkers, ScopedProvider provides potentially different +// dependency instances to different scopes. It is assumed that a scoped provider +// can provide a dependency for any valid scope passed to it, although it can return an error +// to deny access. type ScopedProvider struct { Constructor func(scope Scope, deps []reflect.Value) ([]reflect.Value, error) Needs []Key @@ -57,6 +75,13 @@ type ScopedProvider struct { Scope Scope } +type secureValue struct { + value reflect.Value + securityChecker SecurityChecker +} + +type SecurityChecker func(scope Scope) error + func (c *Container) Provide(provider Provider) error { n := &node{ Provider: provider, @@ -76,7 +101,7 @@ func (c *Container) Provide(provider Provider) error { return nil } -func (c *Container) ProvideForScope(provider ScopedProvider) error { +func (c *Container) ProvideScoped(provider ScopedProvider) error { n := &scopeNode{ ScopedProvider: provider, calledForScope: map[Scope]bool{}, @@ -261,14 +286,3 @@ func (c *Container) InitializeAll() error { } return nil } - -func NewContainer() *Container { - return &Container{ - providers: map[Key]*node{}, - scopeProviders: map[Key]*scopeNode{}, - nodes: nil, - scopeNodes: nil, - values: map[Key]secureValue{}, - scopedValues: map[Scope]map[Key]reflect.Value{}, - } -} diff --git a/core/module/container_test.go b/core/module/container_test.go index 3a497f1882ad..5d6daaab31e2 100644 --- a/core/module/container_test.go +++ b/core/module/container_test.go @@ -60,7 +60,7 @@ func TestContainer(t *testing.T) { }, Scope: "b", })) - require.NoError(t, c.ProvideForScope( + require.NoError(t, c.ProvideScoped( ScopedProvider{ Constructor: func(scope Scope, deps []reflect.Value) ([]reflect.Value, error) { return []reflect.Value{reflect.ValueOf(storeKey{name: scope})}, nil From d30a7e1fad893afbcd5cc8eb5bb320b1f2efe247 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 28 May 2021 21:13:59 -0400 Subject: [PATCH 16/19] add docs, refactoring --- core/module/container.go | 66 +++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/core/module/container.go b/core/module/container.go index 0e559dda4079..b33f8df0d063 100644 --- a/core/module/container.go +++ b/core/module/container.go @@ -48,10 +48,20 @@ type node struct { // its security policy. Access to dependencies provided by this provider can optionally // be restricted to certain scopes based on SecurityCheckers. type Provider struct { - Constructor func(deps []reflect.Value) ([]reflect.Value, error) - Needs []Key - Provides []Key - Scope Scope + // Constructor provides the dependencies + Constructor func(deps []reflect.Value) ([]reflect.Value, error) + + // Needs are the keys for dependencies the constructor needs + Needs []Key + + // Needs are the keys for dependencies the constructor provides + Provides []Key + + // Scope is the scope within which the constructor runs + Scope Scope + + // SecurityCheckers are optional security checker functions for the dependencies provided + // by the constructor. SecurityCheckers []SecurityChecker } @@ -69,10 +79,18 @@ type scopeNode struct { // can provide a dependency for any valid scope passed to it, although it can return an error // to deny access. type ScopedProvider struct { + + // Constructor provides dependencies for the provided scope Constructor func(scope Scope, deps []reflect.Value) ([]reflect.Value, error) - Needs []Key - Provides []Key - Scope Scope + + // Needs are the keys for dependencies the constructor needs + Needs []Key + + // Needs are the keys for dependencies the constructor provides + Provides []Key + + // Scope is the scope within which the constructor runs + Scope Scope } type secureValue struct { @@ -180,14 +198,12 @@ func (c *Container) resolve(scope Scope, key Key, stack map[interface{}]bool) (r } } - if val, ok := c.values[key]; ok { - if val.securityChecker != nil { - if err := val.securityChecker(scope); err != nil { - return reflect.Value{}, err - } + if val, ok, err := c.getValue(scope, key); ok { + if err != nil { + return reflect.Value{}, err } - return val.value, nil + return val, nil } if provider, ok := c.providers[key]; ok { @@ -204,18 +220,12 @@ func (c *Container) resolve(scope Scope, key Key, stack map[interface{}]bool) (r return reflect.Value{}, err } - val, ok := c.values[key] + val, ok, err := c.getValue(scope, key) if !ok { return reflect.Value{}, fmt.Errorf("internal error: bug") } - if val.securityChecker != nil { - if err := val.securityChecker(scope); err != nil { - return reflect.Value{}, err - } - } - - return val.value, nil + return val, err } return reflect.Value{}, fmt.Errorf("no provider") @@ -268,6 +278,20 @@ func (c *Container) execNode(provider *node, stack map[interface{}]bool) error { return nil } +func (c *Container) getValue(scope Scope, key Key) (reflect.Value, bool, error) { + if val, ok := c.values[key]; ok { + if val.securityChecker != nil { + if err := val.securityChecker(scope); err != nil { + return reflect.Value{}, true, err + } + } + + return val.value, true, nil + } + + return reflect.Value{}, false, nil +} + func (c *Container) Resolve(scope Scope, key Key) (reflect.Value, error) { val, err := c.resolve(scope, key, map[interface{}]bool{}) if err != nil { From ce46d86a78c3d9ff2fcc997179ec223c54dbc0e8 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 28 May 2021 21:24:11 -0400 Subject: [PATCH 17/19] WIP --- core/app_config/app_config.go | 23 ++++++++++++++++++++++- core/module/app/registry.go | 2 +- core/module/registry.go | 13 +++++++++---- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/core/app_config/app_config.go b/core/app_config/app_config.go index 92c83bc329ae..1aec4b665ff1 100644 --- a/core/app_config/app_config.go +++ b/core/app_config/app_config.go @@ -18,6 +18,7 @@ func Compose(config AppConfig, moduleRegistry *module.Registry) (types.Applicati modSet := &moduleSet{ container: container, modMap: map[string]app.Handler{}, + configMap: map[string]*ModuleConfig{}, } for _, mod := range config.Modules { @@ -63,14 +64,23 @@ func Compose(config AppConfig, moduleRegistry *module.Registry) (types.Applicati type moduleSet struct { container *module.Container modMap map[string]app.Handler + configMap map[string]*ModuleConfig } func (ms *moduleSet) addModule(interfaceRegistry codectypes.InterfaceRegistry, registry *module.Registry, config *ModuleConfig) error { + ms.configMap[config.Name] = config + msg, err := interfaceRegistry.Resolve(config.Module.TypeUrl) if err != nil { return err } + // TODO: + //typeProvider, ok := msg.(codec.TypeProvider) + //if !ok { + // typeProvider.RegisterTypes(interfaceRegistry) + //} + err = proto.Unmarshal(config.Module.Value, msg) if err != nil { return err @@ -142,7 +152,18 @@ func (ms *moduleSet) addModule(interfaceRegistry codectypes.InterfaceRegistry, r } func (ms *moduleSet) initialize() error { - return ms.container.InitializeAll() + err := ms.container.InitializeAll() + if err != nil { + return err + } + + for name := range ms.configMap { + if ms.modMap[name] == nil { + return fmt.Errorf("module %s failed to initialize", name) + } + } + + return nil } func isErrorTyp(ty reflect.Type) bool { diff --git a/core/module/app/registry.go b/core/module/app/registry.go index 446322209b3d..b49bba371042 100644 --- a/core/module/app/registry.go +++ b/core/module/app/registry.go @@ -2,7 +2,7 @@ package app import "github.com/cosmos/cosmos-sdk/core/module" -var defaultRegistry = module.NewRegistry((*Handler)(nil)) +var defaultRegistry = module.NewRegistry((interface{})(nil), (*Handler)(nil)) func DefaultRegistry() *module.Registry { return defaultRegistry diff --git a/core/module/registry.go b/core/module/registry.go index 86755e80adbf..51fc886d9025 100644 --- a/core/module/registry.go +++ b/core/module/registry.go @@ -6,12 +6,14 @@ import ( type Registry struct { hmap map[reflect.Type]interface{} + configType reflect.Type handlerType reflect.Type } -func NewRegistry(handlerType interface{}) *Registry { +func NewRegistry(configType interface{}, handlerType interface{}) *Registry { return &Registry{ hmap: map[reflect.Type]interface{}{}, + configType: reflect.TypeOf(configType), handlerType: reflect.TypeOf(handlerType), } } @@ -26,9 +28,12 @@ func (r *Registry) Register(constructor interface{}) { panic("TODO") } - configArg := typ.In(0) + configType := typ.In(0) + if !configType.AssignableTo(r.configType) { + panic("TODO") + } - if _, ok := r.hmap[configArg]; ok { + if _, ok := r.hmap[configType]; ok { panic("TODO") } @@ -41,7 +46,7 @@ func (r *Registry) Register(constructor interface{}) { panic("TODO") } - r.hmap[configArg] = constructor + r.hmap[configType] = constructor } func (r *Registry) Resolve(configType interface{}) interface{} { From da9ea7926a5e72410621a37384864aa5c4cbbfe5 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Sat, 29 May 2021 14:12:55 -0400 Subject: [PATCH 18/19] WIP --- core/app_config/app_config.go | 16 +- core/container/container.go | 547 +++++++++++++++++++ core/{module => container}/container_test.go | 30 +- core/module/container.go | 312 ----------- 4 files changed, 574 insertions(+), 331 deletions(-) create mode 100644 core/container/container.go rename core/{module => container}/container_test.go (79%) delete mode 100644 core/module/container.go diff --git a/core/app_config/app_config.go b/core/app_config/app_config.go index 1aec4b665ff1..7b655571b1a5 100644 --- a/core/app_config/app_config.go +++ b/core/app_config/app_config.go @@ -4,6 +4,8 @@ import ( "fmt" "reflect" + container2 "github.com/cosmos/cosmos-sdk/core/container" + "github.com/gogo/protobuf/proto" "github.com/tendermint/tendermint/abci/types" @@ -14,7 +16,7 @@ import ( func Compose(config AppConfig, moduleRegistry *module.Registry) (types.Application, error) { interfaceRegistry := codectypes.NewInterfaceRegistry() - container := module.NewContainer() + container := container2.NewContainer() modSet := &moduleSet{ container: container, modMap: map[string]app.Handler{}, @@ -62,7 +64,7 @@ func Compose(config AppConfig, moduleRegistry *module.Registry) (types.Applicati } type moduleSet struct { - container *module.Container + container *container2.Container modMap map[string]app.Handler configMap map[string]*ModuleConfig } @@ -95,16 +97,16 @@ func (ms *moduleSet) addModule(interfaceRegistry codectypes.InterfaceRegistry, r ctrTyp := ctrVal.Type() numIn := ctrTyp.NumIn() - var needs []module.Key + var needs []container2.Key for i := 1; i < numIn; i++ { argTy := ctrTyp.In(i) - needs = append(needs, module.Key{ + needs = append(needs, container2.Key{ Type: argTy, }) } numOut := ctrTyp.NumIn() - var provides []module.Key + var provides []container2.Key for i := 1; i < numOut; i++ { argTy := ctrTyp.Out(i) @@ -113,12 +115,12 @@ func (ms *moduleSet) addModule(interfaceRegistry codectypes.InterfaceRegistry, r continue } - provides = append(provides, module.Key{ + provides = append(provides, container2.Key{ Type: argTy, }) } - return ms.container.Provide(module.Provider{ + return ms.container.RegisterProvider(container2.Provider{ Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { args := []reflect.Value{reflect.ValueOf(msg)} args = append(args, deps...) diff --git a/core/container/container.go b/core/container/container.go new file mode 100644 index 000000000000..ef1d32840eee --- /dev/null +++ b/core/container/container.go @@ -0,0 +1,547 @@ +package container + +import ( + "fmt" + "reflect" +) + +// Container is a low-level dependency injection container which manages dependencies +// based on scopes and security policies. All providers can be run in a scope which +// may provide certain dependencies specifically for that scope or provide/deny access +// to dependencies based on that scope. +type Container struct { + providers map[Key]*node + scopeProviders map[Key]*scopeNode + nodes []*node + scopeNodes []*scopeNode + + values map[Key]secureValue + scopedValues map[Scope]map[Key]reflect.Value + securityContext func(scope Scope, tag string) error +} + +func NewContainer() *Container { + return &Container{ + providers: map[Key]*node{}, + scopeProviders: map[Key]*scopeNode{}, + nodes: nil, + scopeNodes: nil, + values: map[Key]secureValue{}, + scopedValues: map[Scope]map[Key]reflect.Value{}, + } +} + +type Input struct { + Key Key + Optional bool +} + +type SecureOutput struct { + Key + SecurityChecker SecurityChecker +} + +type Key struct { + Type reflect.Type +} + +type Scope string + +type node struct { + *Provider + called bool + values []reflect.Value + err error +} + +// Provider is a general dependency provider. Its scope parameter is used +// to receive scoped dependencies and gain access to general dependencies within +// its security policy. Access to dependencies provided by this provider can optionally +// be restricted to certain scopes based on SecurityCheckers. +type Provider struct { + // Constructor provides the dependencies + Constructor func(deps []reflect.Value) ([]reflect.Value, error) + + // Needs are the keys for dependencies the constructor needs + Needs []Input + + // Needs are the keys for dependencies the constructor provides + Provides []SecureOutput + + // Scope is the scope within which the constructor runs + Scope Scope +} + +type scopeNode struct { + *ScopeProvider + calledForScope map[Scope]bool + valuesForScope map[Scope][]reflect.Value + errsForScope map[Scope]error +} + +// ScopeProvider provides scoped dependencies. Its constructor function will provide +// dependencies specific to the scope parameter. Instead of providing general dependencies +// with restricted access based on security checkers, ScopeProvider provides potentially different +// dependency instances to different scopes. It is assumed that a scoped provider +// can provide a dependency for any valid scope passed to it, although it can return an error +// to deny access. +type ScopeProvider struct { + + // Constructor provides dependencies for the provided scope + Constructor func(scope Scope, deps []reflect.Value) ([]reflect.Value, error) + + // Needs are the keys for dependencies the constructor needs + Needs []Input + + // Needs are the keys for dependencies the constructor provides + Provides []Key + + // Scope is the scope within which the constructor runs, if it is left empty, + // the constructor runs in the scope it was called with (this only applies to ScopeProvider). + Scope Scope +} + +type secureValue struct { + value reflect.Value + securityChecker SecurityChecker +} + +type SecurityChecker func(scope Scope) error + +func (c *Container) RegisterProvider(provider *Provider) error { + n := &node{ + Provider: provider, + called: false, + } + + c.nodes = append(c.nodes, n) + + for _, key := range provider.Provides { + if c.providers[key.Key] != nil { + return fmt.Errorf("TODO") + } + + c.providers[key.Key] = n + } + + return nil +} + +func (c *Container) RegisterScopeProvider(provider *ScopeProvider) error { + n := &scopeNode{ + ScopeProvider: provider, + calledForScope: map[Scope]bool{}, + valuesForScope: map[Scope][]reflect.Value{}, + errsForScope: map[Scope]error{}, + } + + c.scopeNodes = append(c.scopeNodes, n) + + for _, key := range provider.Provides { + if c.scopeProviders[key] != nil { + return fmt.Errorf("TODO") + } + + c.scopeProviders[key] = n + } + + return nil +} + +func (c *Container) resolve(scope Scope, input Input, stack map[interface{}]bool) (reflect.Value, error) { + if scope != "" { + if val, ok := c.scopedValues[scope][input.Key]; ok { + return val, nil + } + + if provider, ok := c.scopeProviders[input.Key]; ok { + if stack[provider] { + return reflect.Value{}, fmt.Errorf("fatal: cycle detected") + } + + if provider.calledForScope[scope] { + return reflect.Value{}, fmt.Errorf("error: %v", provider.errsForScope[scope]) + } + + var deps []reflect.Value + for _, need := range provider.Needs { + subScope := provider.Scope + // for ScopeProvider we default to the calling scope + if subScope == "" { + subScope = scope + } + stack[provider] = true + res, err := c.resolve(subScope, need, stack) + delete(stack, provider) + + if err != nil { + return reflect.Value{}, err + } + + deps = append(deps, res) + } + + res, err := provider.Constructor(scope, deps) + provider.calledForScope[scope] = true + if err != nil { + provider.errsForScope[scope] = err + return reflect.Value{}, err + } + + provider.valuesForScope[scope] = res + + for i, val := range res { + p := provider.Provides[i] + if _, ok := c.scopedValues[scope][p]; ok { + return reflect.Value{}, fmt.Errorf("value provided twice") + } + + if c.scopedValues[scope] == nil { + c.scopedValues[scope] = map[Key]reflect.Value{} + } + c.scopedValues[scope][p] = val + } + + val, ok := c.scopedValues[scope][input.Key] + if !ok { + return reflect.Value{}, fmt.Errorf("internal error: bug") + } + + return val, nil + } + } + + if val, ok, err := c.getValue(scope, input.Key); ok { + if err != nil { + return reflect.Value{}, err + } + + return val, nil + } + + if provider, ok := c.providers[input.Key]; ok { + if stack[provider] { + return reflect.Value{}, fmt.Errorf("fatal: cycle detected") + } + + if provider.called { + return reflect.Value{}, fmt.Errorf("error: %v", provider.err) + } + + err := c.execNode(provider, stack) + if err != nil { + return reflect.Value{}, err + } + + val, ok, err := c.getValue(scope, input.Key) + if !ok { + return reflect.Value{}, fmt.Errorf("internal error: bug") + } + + return val, err + } + + return reflect.Value{}, fmt.Errorf("no provider") +} + +func (c *Container) execNode(provider *node, stack map[interface{}]bool) error { + if provider.called { + return provider.err + } + + var deps []reflect.Value + for _, need := range provider.Needs { + stack[provider] = true + res, err := c.resolve(provider.Scope, need, stack) + delete(stack, provider) + + if err != nil { + return err + } + + deps = append(deps, res) + } + + res, err := provider.Constructor(deps) + provider.called = true + if err != nil { + provider.err = err + return err + } + + provider.values = res + + for i, val := range res { + p := provider.Provides[i] + if _, ok := c.values[p.Key]; ok { + return fmt.Errorf("value provided twice") + } + + c.values[p.Key] = secureValue{ + value: val, + securityChecker: p.SecurityChecker, + } + } + + return nil +} + +func (c *Container) getValue(scope Scope, key Key) (reflect.Value, bool, error) { + if val, ok := c.values[key]; ok { + if val.securityChecker != nil { + if err := val.securityChecker(scope); err != nil { + return reflect.Value{}, true, err + } + } + + return val.value, true, nil + } + + return reflect.Value{}, false, nil +} + +func (c *Container) Resolve(scope Scope, key Key) (reflect.Value, error) { + val, err := c.resolve(scope, Input{ + Key: key, + Optional: false, + }, map[interface{}]bool{}) + if err != nil { + return reflect.Value{}, err + } + return val, nil +} + +// InitializeAll attempts to call all providers instantiating the dependencies they provide +func (c *Container) InitializeAll() error { + for _, node := range c.nodes { + err := c.execNode(node, map[interface{}]bool{}) + if err != nil { + return err + } + } + return nil +} + +type StructArgs struct{} + +func (StructArgs) isStructArgs() {} + +type isStructArgs interface{ isStructArgs() } + +var isStructArgsTyp = reflect.TypeOf((*isStructArgs)(nil)) + +var scopeTyp = reflect.TypeOf(Scope("")) + +type InMarshaler func([]reflect.Value) reflect.Value + +type inFieldMarshaler struct { + n int + inMarshaler InMarshaler +} + +type OutMarshaler func(reflect.Value) []reflect.Value + +func TypeToInput(typ reflect.Type) ([]Input, InMarshaler, error) { + if typ.AssignableTo(isStructArgsTyp) && typ.Kind() == reflect.Struct { + nFields := typ.NumField() + var res []Input + + var marshalers []inFieldMarshaler + + for i := 0; i < nFields; i++ { + field := typ.Field(i) + fieldInputs, m, err := TypeToInput(field.Type) + if err != nil { + return nil, nil, err + } + + optionalTag, ok := field.Tag.Lookup("optional") + if ok { + if len(fieldInputs) == 1 { + if optionalTag != "true" { + return nil, nil, fmt.Errorf("true is the only valid value for the optional tag, got %s", optionalTag) + } + fieldInputs[0].Optional = true + } else if len(fieldInputs) > 1 { + return nil, nil, fmt.Errorf("optional tag cannot be applied to nested StructArgs") + } + } + + res = append(res, fieldInputs...) + marshalers = append(marshalers, inFieldMarshaler{ + n: len(fieldInputs), + inMarshaler: m, + }) + } + + return res, structMarshaler(typ, marshalers), nil + } else if typ == scopeTyp { + return nil, nil, fmt.Errorf("can't convert type %T to %T", Scope(""), Input{}) + } else { + return []Input{{ + Key: Key{ + Type: typ, + }, + }}, func(values []reflect.Value) reflect.Value { + return values[0] + }, nil + } +} + +func TypeToOutput(typ reflect.Type, securityContext func(scope Scope, tag string) error) ([]SecureOutput, OutMarshaler, error) { + if typ.AssignableTo(isStructArgsTyp) && typ.Kind() == reflect.Struct { + nFields := typ.NumField() + var res []SecureOutput + var marshalers []OutMarshaler + + for i := 0; i < nFields; i++ { + field := typ.Field(i) + fieldOutputs, fieldMarshaler, err := TypeToOutput(field.Type, securityContext) + if err != nil { + return nil, nil, err + } + + securityTag, ok := field.Tag.Lookup("security") + if ok { + if len(fieldOutputs) == 1 { + if securityContext == nil { + return nil, nil, fmt.Errorf("security tag is invalid in this context") + } + fieldOutputs[0].SecurityChecker = func(scope Scope) error { + return securityContext(scope, securityTag) + } + } else if len(fieldOutputs) > 1 { + return nil, nil, fmt.Errorf("security tag cannot be applied to nested StructArgs") + } + } + + res = append(res, fieldOutputs...) + marshalers = append(marshalers, fieldMarshaler) + } + return res, func(value reflect.Value) []reflect.Value { + var vals []reflect.Value + for i := 0; i < nFields; i++ { + val := value.Field(i) + vals = append(vals, marshalers[i](val)...) + } + return vals + }, nil + } else if typ == scopeTyp { + return nil, nil, fmt.Errorf("can't convert type %T to %T", Scope(""), Input{}) + } else { + return []SecureOutput{{ + Key: Key{ + Type: typ, + }, + }}, func(val reflect.Value) []reflect.Value { + return []reflect.Value{val} + }, nil + } +} + +func structMarshaler(typ reflect.Type, marshalers []inFieldMarshaler) func([]reflect.Value) reflect.Value { + return func(values []reflect.Value) reflect.Value { + structInst := reflect.New(typ) + + for i, m := range marshalers { + val := m.inMarshaler(values[:m.n]) + structInst.Field(i).Set(val) + values = values[m.n:] + } + + return structInst + } +} + +func (c *Container) Provide(constructor interface{}) error { + return c.ProvideWithScope(constructor, "") +} + +func (c *Container) ProvideWithScope(constructor interface{}, scope Scope) error { + p, sp, err := ConstructorToProvider(constructor, scope, c.securityContext) + if err != nil { + return err + } + + if p != nil { + return c.RegisterProvider(p) + } + + if sp != nil { + return c.RegisterScopeProvider(sp) + } + + return fmt.Errorf("unexpected case") +} + +func ConstructorToProvider(constructor interface{}, scope Scope, securityContext func(scope Scope, tag string) error) (*Provider, *ScopeProvider, error) { + ctrTyp := reflect.TypeOf(constructor) + if ctrTyp.Kind() != reflect.Func { + return nil, nil, fmt.Errorf("expected function got %T", constructor) + } + + numIn := ctrTyp.NumIn() + numOut := ctrTyp.NumIn() + + var scopeProvider bool + if numIn >= 1 { + if in0 := ctrTyp.In(0); in0 == scopeTyp { + scopeProvider = true + } + } + + if !scopeProvider { + var inputs []Input + var inMarshalers []inFieldMarshaler + for i := 0; i < numIn; i++ { + in, inMarshaler, err := TypeToInput(ctrTyp.In(i)) + if err != nil { + return nil, nil, err + } + inputs = append(inputs, in...) + inMarshalers = append(inMarshalers, inFieldMarshaler{ + n: len(in), + inMarshaler: inMarshaler, + }) + } + + var outputs []SecureOutput + var outMarshalers []OutMarshaler + for i := 0; i < numOut; i++ { + out, outMarshaler, err := TypeToOutput(ctrTyp.Out(i), securityContext) + if err != nil { + return nil, nil, err + } + outputs = append(outputs, out...) + outMarshalers = append(outMarshalers, outMarshaler) + } + + ctrVal := reflect.ValueOf(constructor) + provideCtr := func(deps []reflect.Value) ([]reflect.Value, error) { + inVals := make([]reflect.Value, numIn) + for i := 0; i < numIn; i++ { + m := inMarshalers[i] + inVals[i] = m.inMarshaler(deps[m.n:]) + deps = deps[:m.n] + } + + outVals := ctrVal.Call(inVals) + + var provides []reflect.Value + for i := 0; i < numOut; i++ { + provides = append(provides, outMarshalers[i](outVals[i])...) + } + + return outVals, nil + } + + return &Provider{ + Constructor: provideCtr, + Needs: inputs, + Provides: outputs, + Scope: scope, + }, nil, nil + } else { + + } +} diff --git a/core/module/container_test.go b/core/container/container_test.go similarity index 79% rename from core/module/container_test.go rename to core/container/container_test.go index 5d6daaab31e2..5300a759d74e 100644 --- a/core/module/container_test.go +++ b/core/container/container_test.go @@ -1,4 +1,4 @@ -package module +package container import ( "reflect" @@ -22,7 +22,7 @@ type keeperB struct { func TestContainer(t *testing.T) { c := NewContainer() - require.NoError(t, c.Provide(Provider{ + require.NoError(t, c.RegisterProvider(Provider{ Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { return []reflect.Value{reflect.ValueOf(keeperA{deps[0].Interface().(storeKey)})}, nil }, @@ -38,30 +38,36 @@ func TestContainer(t *testing.T) { }, Scope: "a", })) - require.NoError(t, c.Provide(Provider{ + require.NoError(t, c.RegisterProvider(Provider{ Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { return []reflect.Value{reflect.ValueOf(keeperB{ key: deps[0].Interface().(storeKey), a: deps[1].Interface().(keeperA), })}, nil }, - Needs: []Key{ + Needs: []Input{ { - Type: reflect.TypeOf(storeKey{}), + Key: Key{ + Type: reflect.TypeOf(storeKey{}), + }, }, { - Type: reflect.TypeOf((*keeperA)(nil)), + Key: Key{ + Type: reflect.TypeOf((*keeperA)(nil)), + }, }, }, - Provides: []Key{ + Provides: []SecureOutput{ { - Type: reflect.TypeOf((*keeperB)(nil)), + Key: Key{ + Type: reflect.TypeOf((*keeperB)(nil)), + }, }, }, Scope: "b", })) - require.NoError(t, c.ProvideScoped( - ScopedProvider{ + require.NoError(t, c.RegisterScopeProvider( + ScopeProvider{ Constructor: func(scope Scope, deps []reflect.Value) ([]reflect.Value, error) { return []reflect.Value{reflect.ValueOf(storeKey{name: scope})}, nil }, @@ -84,7 +90,7 @@ func TestContainer(t *testing.T) { func TestCycle(t *testing.T) { c := NewContainer() - require.NoError(t, c.Provide(Provider{ + require.NoError(t, c.RegisterProvider(Provider{ Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { return nil, nil }, @@ -99,7 +105,7 @@ func TestCycle(t *testing.T) { }, }, })) - require.NoError(t, c.Provide(Provider{ + require.NoError(t, c.RegisterProvider(Provider{ Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { return nil, nil }, diff --git a/core/module/container.go b/core/module/container.go deleted file mode 100644 index b33f8df0d063..000000000000 --- a/core/module/container.go +++ /dev/null @@ -1,312 +0,0 @@ -package module - -import ( - "fmt" - "reflect" -) - -// Container is a low-level dependency injection container which manages dependencies -// based on scopes and security policies. All providers can be run in a scope which -// may provide certain dependencies specifically for that scope or provide/deny access -// to dependencies based on that scope. -type Container struct { - providers map[Key]*node - scopeProviders map[Key]*scopeNode - nodes []*node - scopeNodes []*scopeNode - - values map[Key]secureValue - scopedValues map[Scope]map[Key]reflect.Value -} - -func NewContainer() *Container { - return &Container{ - providers: map[Key]*node{}, - scopeProviders: map[Key]*scopeNode{}, - nodes: nil, - scopeNodes: nil, - values: map[Key]secureValue{}, - scopedValues: map[Scope]map[Key]reflect.Value{}, - } -} - -type Key struct { - Type reflect.Type -} - -type Scope = string - -type node struct { - Provider - called bool - values []reflect.Value - err error -} - -// Provider is a general dependency provider. Its scope parameter is used -// to receive scoped dependencies and gain access to general dependencies within -// its security policy. Access to dependencies provided by this provider can optionally -// be restricted to certain scopes based on SecurityCheckers. -type Provider struct { - // Constructor provides the dependencies - Constructor func(deps []reflect.Value) ([]reflect.Value, error) - - // Needs are the keys for dependencies the constructor needs - Needs []Key - - // Needs are the keys for dependencies the constructor provides - Provides []Key - - // Scope is the scope within which the constructor runs - Scope Scope - - // SecurityCheckers are optional security checker functions for the dependencies provided - // by the constructor. - SecurityCheckers []SecurityChecker -} - -type scopeNode struct { - ScopedProvider - calledForScope map[Scope]bool - valuesForScope map[Scope][]reflect.Value - errsForScope map[Scope]error -} - -// ScopedProvider provides scoped dependencies. Its constructor function will provide -// dependencies specific to the scope parameter. Instead of providing general dependencies -// with restricted access based on security checkers, ScopedProvider provides potentially different -// dependency instances to different scopes. It is assumed that a scoped provider -// can provide a dependency for any valid scope passed to it, although it can return an error -// to deny access. -type ScopedProvider struct { - - // Constructor provides dependencies for the provided scope - Constructor func(scope Scope, deps []reflect.Value) ([]reflect.Value, error) - - // Needs are the keys for dependencies the constructor needs - Needs []Key - - // Needs are the keys for dependencies the constructor provides - Provides []Key - - // Scope is the scope within which the constructor runs - Scope Scope -} - -type secureValue struct { - value reflect.Value - securityChecker SecurityChecker -} - -type SecurityChecker func(scope Scope) error - -func (c *Container) Provide(provider Provider) error { - n := &node{ - Provider: provider, - called: false, - } - - c.nodes = append(c.nodes, n) - - for _, key := range provider.Provides { - if c.providers[key] != nil { - return fmt.Errorf("TODO") - } - - c.providers[key] = n - } - - return nil -} - -func (c *Container) ProvideScoped(provider ScopedProvider) error { - n := &scopeNode{ - ScopedProvider: provider, - calledForScope: map[Scope]bool{}, - valuesForScope: map[Scope][]reflect.Value{}, - errsForScope: map[Scope]error{}, - } - - c.scopeNodes = append(c.scopeNodes, n) - - for _, key := range provider.Provides { - if c.scopeProviders[key] != nil { - return fmt.Errorf("TODO") - } - - c.scopeProviders[key] = n - } - - return nil -} - -func (c *Container) resolve(scope Scope, key Key, stack map[interface{}]bool) (reflect.Value, error) { - if scope != "" { - if val, ok := c.scopedValues[scope][key]; ok { - return val, nil - } - - if provider, ok := c.scopeProviders[key]; ok { - if stack[provider] { - return reflect.Value{}, fmt.Errorf("fatal: cycle detected") - } - - if provider.calledForScope[scope] { - return reflect.Value{}, fmt.Errorf("error: %v", provider.errsForScope[scope]) - } - - var deps []reflect.Value - for _, need := range provider.Needs { - stack[provider] = true - res, err := c.resolve(provider.Scope, need, stack) - delete(stack, provider) - - if err != nil { - return reflect.Value{}, err - } - - deps = append(deps, res) - } - - res, err := provider.Constructor(scope, deps) - provider.calledForScope[scope] = true - if err != nil { - provider.errsForScope[scope] = err - return reflect.Value{}, err - } - - provider.valuesForScope[scope] = res - - for i, val := range res { - p := provider.Provides[i] - if _, ok := c.scopedValues[scope][p]; ok { - return reflect.Value{}, fmt.Errorf("value provided twice") - } - - if c.scopedValues[scope] == nil { - c.scopedValues[scope] = map[Key]reflect.Value{} - } - c.scopedValues[scope][p] = val - } - - val, ok := c.scopedValues[scope][key] - if !ok { - return reflect.Value{}, fmt.Errorf("internal error: bug") - } - - return val, nil - } - } - - if val, ok, err := c.getValue(scope, key); ok { - if err != nil { - return reflect.Value{}, err - } - - return val, nil - } - - if provider, ok := c.providers[key]; ok { - if stack[provider] { - return reflect.Value{}, fmt.Errorf("fatal: cycle detected") - } - - if provider.called { - return reflect.Value{}, fmt.Errorf("error: %v", provider.err) - } - - err := c.execNode(provider, stack) - if err != nil { - return reflect.Value{}, err - } - - val, ok, err := c.getValue(scope, key) - if !ok { - return reflect.Value{}, fmt.Errorf("internal error: bug") - } - - return val, err - } - - return reflect.Value{}, fmt.Errorf("no provider") -} - -func (c *Container) execNode(provider *node, stack map[interface{}]bool) error { - if provider.called { - return provider.err - } - - var deps []reflect.Value - for _, need := range provider.Needs { - stack[provider] = true - res, err := c.resolve(provider.Scope, need, stack) - delete(stack, provider) - - if err != nil { - return err - } - - deps = append(deps, res) - } - - res, err := provider.Constructor(deps) - provider.called = true - if err != nil { - provider.err = err - return err - } - - provider.values = res - - for i, val := range res { - p := provider.Provides[i] - if _, ok := c.values[p]; ok { - return fmt.Errorf("value provided twice") - } - - var secChecker SecurityChecker - if i < len(provider.SecurityCheckers) { - secChecker = provider.SecurityCheckers[i] - } - - c.values[p] = secureValue{ - value: val, - securityChecker: secChecker, - } - } - - return nil -} - -func (c *Container) getValue(scope Scope, key Key) (reflect.Value, bool, error) { - if val, ok := c.values[key]; ok { - if val.securityChecker != nil { - if err := val.securityChecker(scope); err != nil { - return reflect.Value{}, true, err - } - } - - return val.value, true, nil - } - - return reflect.Value{}, false, nil -} - -func (c *Container) Resolve(scope Scope, key Key) (reflect.Value, error) { - val, err := c.resolve(scope, key, map[interface{}]bool{}) - if err != nil { - return reflect.Value{}, err - } - return val, nil -} - -// InitializeAll attempts to call all providers instantiating the dependencies they provide -func (c *Container) InitializeAll() error { - for _, node := range c.nodes { - err := c.execNode(node, map[interface{}]bool{}) - if err != nil { - return err - } - } - return nil -} From b0a93479520730d576e94e11716d4f9b603c6a31 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Sat, 29 May 2021 17:25:42 -0400 Subject: [PATCH 19/19] WIP --- core/abci/app_base.go | 67 +++++++ core/abci/config/config.go | 5 + core/abci/handler.go | 30 ++++ core/abci/handler_base.go | 63 +++++++ core/abci/header/header.go | 88 +++++++++ core/abci/middleware.go | 3 + core/app_config/app_config.go | 96 ++++++++-- core/container/container.go | 294 +++++++++++++++++++------------ core/container/container_test.go | 275 +++++++++++++++++++---------- core/store/kv/kv.go | 20 +++ core/store/sc/sc.go | 18 ++ core/store/ss/ss.go | 18 ++ core/tx/module/module.go | 23 +-- x/authn/app/middleware.go | 37 ++-- x/authn/module/module.go | 26 +-- 15 files changed, 792 insertions(+), 271 deletions(-) create mode 100644 core/abci/app_base.go create mode 100644 core/abci/config/config.go create mode 100644 core/abci/handler.go create mode 100644 core/abci/handler_base.go create mode 100644 core/abci/header/header.go create mode 100644 core/abci/middleware.go create mode 100644 core/store/kv/kv.go create mode 100644 core/store/sc/sc.go create mode 100644 core/store/ss/ss.go diff --git a/core/abci/app_base.go b/core/abci/app_base.go new file mode 100644 index 000000000000..815f0b23ede0 --- /dev/null +++ b/core/abci/app_base.go @@ -0,0 +1,67 @@ +package abci + +import ( + "context" + + "github.com/tendermint/tendermint/abci/types" +) + +type AppBase struct { + handler Handler + checkCtx context.Context + deliverCtx context.Context +} + +var _ types.Application = AppBase{} + +func (a AppBase) Info(info types.RequestInfo) types.ResponseInfo { + return a.handler.Info(a.checkCtx, info) +} + +func (a AppBase) SetOption(option types.RequestSetOption) types.ResponseSetOption { + return a.handler.SetOption(a.checkCtx, option) +} + +func (a AppBase) Query(query types.RequestQuery) types.ResponseQuery { + return a.handler.Query(a.checkCtx, query) +} + +func (a AppBase) CheckTx(tx types.RequestCheckTx) types.ResponseCheckTx { + return a.handler.CheckTx(a.checkCtx, tx) +} + +func (a AppBase) InitChain(chain types.RequestInitChain) types.ResponseInitChain { + return a.handler.InitChain(a.deliverCtx, chain) +} + +func (a AppBase) BeginBlock(block types.RequestBeginBlock) types.ResponseBeginBlock { + return a.handler.BeginBlock(a.deliverCtx, block) +} + +func (a AppBase) DeliverTx(tx types.RequestDeliverTx) types.ResponseDeliverTx { + return a.handler.DeliverTx(a.deliverCtx, tx) +} + +func (a AppBase) EndBlock(block types.RequestEndBlock) types.ResponseEndBlock { + return a.handler.EndBlock(a.deliverCtx, block) +} + +func (a AppBase) Commit() types.ResponseCommit { + return a.handler.Commit(a.deliverCtx) +} + +func (a AppBase) ListSnapshots(snapshots types.RequestListSnapshots) types.ResponseListSnapshots { + return a.handler.ListSnapshots(a.checkCtx, snapshots) +} + +func (a AppBase) OfferSnapshot(snapshot types.RequestOfferSnapshot) types.ResponseOfferSnapshot { + return a.handler.OfferSnapshot(a.checkCtx, snapshot) +} + +func (a AppBase) LoadSnapshotChunk(chunk types.RequestLoadSnapshotChunk) types.ResponseLoadSnapshotChunk { + return a.handler.LoadSnapshotChunk(a.checkCtx, chunk) +} + +func (a AppBase) ApplySnapshotChunk(chunk types.RequestApplySnapshotChunk) types.ResponseApplySnapshotChunk { + return a.handler.ApplySnapshotChunk(a.checkCtx, chunk) +} diff --git a/core/abci/config/config.go b/core/abci/config/config.go new file mode 100644 index 000000000000..fcb83e34f52b --- /dev/null +++ b/core/abci/config/config.go @@ -0,0 +1,5 @@ +package config + +type Config struct { + Middleware []interface{} +} diff --git a/core/abci/handler.go b/core/abci/handler.go new file mode 100644 index 000000000000..b827047e3c0c --- /dev/null +++ b/core/abci/handler.go @@ -0,0 +1,30 @@ +package abci + +import ( + "context" + + types "github.com/tendermint/tendermint/abci/types" +) + +type Handler interface { + // Info/Query Connection + Info(ctx context.Context, req types.RequestInfo) types.ResponseInfo // Return application info + SetOption(ctx context.Context, req types.RequestSetOption) types.ResponseSetOption // Set application option + Query(ctx context.Context, req types.RequestQuery) types.ResponseQuery // Query for state + + // Mempool Connection + CheckTx(ctx context.Context, req types.RequestCheckTx) types.ResponseCheckTx // Validate a tx for the mempool + + // Consensus Connection + InitChain(ctx context.Context, req types.RequestInitChain) types.ResponseInitChain // Initialize blockchain w validators/other info from TendermintCore + BeginBlock(ctx context.Context, req types.RequestBeginBlock) types.ResponseBeginBlock // Signals the beginning of a block + DeliverTx(ctx context.Context, req types.RequestDeliverTx) types.ResponseDeliverTx // Deliver a tx for full processing + EndBlock(ctx context.Context, req types.RequestEndBlock) types.ResponseEndBlock // Signals the end of a block, returns changes to the validator set + Commit(context.Context) types.ResponseCommit // Commit the state and return the application Merkle root hash + + // State Sync Connection + ListSnapshots(ctx context.Context, req types.RequestListSnapshots) types.ResponseListSnapshots // List available snapshots + OfferSnapshot(ctx context.Context, req types.RequestOfferSnapshot) types.ResponseOfferSnapshot // Offer a snapshot to the application + LoadSnapshotChunk(ctx context.Context, req types.RequestLoadSnapshotChunk) types.ResponseLoadSnapshotChunk // Load a snapshot chunk + ApplySnapshotChunk(ctx context.Context, req types.RequestApplySnapshotChunk) types.ResponseApplySnapshotChunk // Apply a shapshot chunk +} diff --git a/core/abci/handler_base.go b/core/abci/handler_base.go new file mode 100644 index 000000000000..800d07158ffd --- /dev/null +++ b/core/abci/handler_base.go @@ -0,0 +1,63 @@ +package abci + +import ( + "context" + + "github.com/tendermint/tendermint/abci/types" +) + +type HandlerBase struct{} + +func (h HandlerBase) Info(context.Context, types.RequestInfo) types.ResponseInfo { + return types.ResponseInfo{} +} + +func (h HandlerBase) SetOption(context.Context, types.RequestSetOption) types.ResponseSetOption { + return types.ResponseSetOption{} +} + +func (h HandlerBase) Query(context.Context, types.RequestQuery) types.ResponseQuery { + return types.ResponseQuery{} +} + +func (h HandlerBase) CheckTx(context.Context, types.RequestCheckTx) types.ResponseCheckTx { + return types.ResponseCheckTx{} +} + +func (h HandlerBase) InitChain(context.Context, types.RequestInitChain) types.ResponseInitChain { + return types.ResponseInitChain{} +} + +func (h HandlerBase) BeginBlock(context.Context, types.RequestBeginBlock) types.ResponseBeginBlock { + return types.ResponseBeginBlock{} +} + +func (h HandlerBase) DeliverTx(context.Context, types.RequestDeliverTx) types.ResponseDeliverTx { + return types.ResponseDeliverTx{} +} + +func (h HandlerBase) EndBlock(context.Context, types.RequestEndBlock) types.ResponseEndBlock { + return types.ResponseEndBlock{} +} + +func (h HandlerBase) Commit(context.Context) types.ResponseCommit { + return types.ResponseCommit{} +} + +func (h HandlerBase) ListSnapshots(context.Context, types.RequestListSnapshots) types.ResponseListSnapshots { + return types.ResponseListSnapshots{} +} + +func (h HandlerBase) OfferSnapshot(context.Context, types.RequestOfferSnapshot) types.ResponseOfferSnapshot { + return types.ResponseOfferSnapshot{} +} + +func (h HandlerBase) LoadSnapshotChunk(context.Context, types.RequestLoadSnapshotChunk) types.ResponseLoadSnapshotChunk { + return types.ResponseLoadSnapshotChunk{} +} + +func (h HandlerBase) ApplySnapshotChunk(context.Context, types.RequestApplySnapshotChunk) types.ResponseApplySnapshotChunk { + return types.ResponseApplySnapshotChunk{} +} + +var _ Handler = HandlerBase{} diff --git a/core/abci/header/header.go b/core/abci/header/header.go new file mode 100644 index 000000000000..54169619a09b --- /dev/null +++ b/core/abci/header/header.go @@ -0,0 +1,88 @@ +package header + +import ( + "context" + "fmt" + + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/core/abci" +) + +var Middleware abci.Middleware = func(handler abci.Handler) abci.Handler { + return &middleware{ + Handler: handler, + } +} + +type middleware struct { + abci.Handler + initialHeight int64 + lastBlockHeight int64 +} + +func (m *middleware) InitChain(ctx context.Context, req types.RequestInitChain) types.ResponseInitChain { + // On a new chain, we consider the init chain block height as 0, even though + // req.InitialHeight is 1 by default. + initHeader := tmproto.Header{ChainID: req.ChainId, Time: req.Time} + + // If req.InitialHeight is > 1, then we set the initial version in the + // stores. + if req.InitialHeight > 1 { + m.initialHeight = req.InitialHeight + initHeader = tmproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time} + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + sdkCtx = sdkCtx.WithBlockHeader(initHeader) + ctx = context.WithValue(ctx, sdk.SdkContextKey, sdkCtx) + + return m.Handler.InitChain(ctx, req) +} + +func (m *middleware) BeginBlock(ctx context.Context, req types.RequestBeginBlock) types.ResponseBeginBlock { + if err := m.validateHeight(req); err != nil { + panic(err) + } + + m.lastBlockHeight = req.Header.Height + + sdkCtx := sdk.UnwrapSDKContext(ctx) + sdkCtx = sdkCtx. + WithBlockHeader(req.Header). + WithBlockHeight(req.Header.Height) + ctx = context.WithValue(ctx, sdk.SdkContextKey, sdkCtx) + + return m.Handler.BeginBlock(ctx, req) +} + +func (m middleware) validateHeight(req types.RequestBeginBlock) error { + if req.Header.Height < 1 { + return fmt.Errorf("invalid height: %d", req.Header.Height) + } + + // expectedHeight holds the expected height to validate. + var expectedHeight int64 + if m.lastBlockHeight == 0 && m.initialHeight > 1 { + // In this case, we're validating the first block of the chain (no + // previous commit). The height we're expecting is the initial height. + expectedHeight = m.initialHeight + } else { + // This case can means two things: + // - either there was already a previous commit in the store, in which + // case we increment the version from there, + // - or there was no previous commit, and initial version was not set, + // in which case we start at version 1. + expectedHeight = m.lastBlockHeight + 1 + } + + if req.Header.Height != expectedHeight { + return fmt.Errorf("invalid height: %d; expected: %d", req.Header.Height, expectedHeight) + } + + return nil +} diff --git a/core/abci/middleware.go b/core/abci/middleware.go new file mode 100644 index 000000000000..f82f0f4bf86d --- /dev/null +++ b/core/abci/middleware.go @@ -0,0 +1,3 @@ +package abci + +type Middleware func(Handler) Handler diff --git a/core/app_config/app_config.go b/core/app_config/app_config.go index 7b655571b1a5..0c6c13ad08f8 100644 --- a/core/app_config/app_config.go +++ b/core/app_config/app_config.go @@ -1,24 +1,28 @@ package app_config import ( + "context" "fmt" "reflect" - container2 "github.com/cosmos/cosmos-sdk/core/container" + "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/core/abci" + + "github.com/cosmos/cosmos-sdk/core/container" "github.com/gogo/protobuf/proto" - "github.com/tendermint/tendermint/abci/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/core/module" "github.com/cosmos/cosmos-sdk/core/module/app" ) -func Compose(config AppConfig, moduleRegistry *module.Registry) (types.Application, error) { +func Compose(config AppConfig, moduleRegistry *module.Registry) (abci.Handler, error) { interfaceRegistry := codectypes.NewInterfaceRegistry() - container := container2.NewContainer() + cont := container.NewContainer() modSet := &moduleSet{ - container: container, + container: cont, modMap: map[string]app.Handler{}, configMap: map[string]*ModuleConfig{}, } @@ -64,11 +68,65 @@ func Compose(config AppConfig, moduleRegistry *module.Registry) (types.Applicati } type moduleSet struct { - container *container2.Container + container *container.Container modMap map[string]app.Handler configMap map[string]*ModuleConfig } +func (ms *moduleSet) Info(ctx context.Context, req types.RequestInfo) types.ResponseInfo { + panic("implement me") +} + +func (ms *moduleSet) SetOption(ctx context.Context, req types.RequestSetOption) types.ResponseSetOption { + panic("implement me") +} + +func (ms *moduleSet) Query(ctx context.Context, req types.RequestQuery) types.ResponseQuery { + panic("implement me") +} + +func (ms *moduleSet) CheckTx(ctx context.Context, req types.RequestCheckTx) types.ResponseCheckTx { + panic("implement me") +} + +func (ms *moduleSet) InitChain(ctx context.Context, req types.RequestInitChain) types.ResponseInitChain { + panic("implement me") +} + +func (ms *moduleSet) BeginBlock(ctx context.Context, req types.RequestBeginBlock) types.ResponseBeginBlock { + panic("implement me") +} + +func (ms *moduleSet) DeliverTx(ctx context.Context, req types.RequestDeliverTx) types.ResponseDeliverTx { + panic("implement me") +} + +func (ms *moduleSet) EndBlock(ctx context.Context, req types.RequestEndBlock) types.ResponseEndBlock { + panic("implement me") +} + +func (ms *moduleSet) Commit(ctx context.Context) types.ResponseCommit { + panic("implement me") +} + +func (ms *moduleSet) ListSnapshots(ctx context.Context, req types.RequestListSnapshots) types.ResponseListSnapshots { + panic("implement me") +} + +func (ms *moduleSet) OfferSnapshot(ctx context.Context, req types.RequestOfferSnapshot) types.ResponseOfferSnapshot { + panic("implement me") +} + +func (ms *moduleSet) LoadSnapshotChunk(ctx context.Context, req types.RequestLoadSnapshotChunk) types.ResponseLoadSnapshotChunk { + panic("implement me") +} + +func (ms *moduleSet) ApplySnapshotChunk(ctx context.Context, req types.RequestApplySnapshotChunk) types.ResponseApplySnapshotChunk { + panic("implement me") +} + +var _ abci.Handler = &moduleSet{} + func (ms *moduleSet) addModule(interfaceRegistry codectypes.InterfaceRegistry, registry *module.Registry, config *ModuleConfig) error { ms.configMap[config.Name] = config @@ -97,16 +155,18 @@ func (ms *moduleSet) addModule(interfaceRegistry codectypes.InterfaceRegistry, r ctrTyp := ctrVal.Type() numIn := ctrTyp.NumIn() - var needs []container2.Key + var needs []container.Input for i := 1; i < numIn; i++ { argTy := ctrTyp.In(i) - needs = append(needs, container2.Key{ - Type: argTy, + needs = append(needs, container.Input{ + Key: container.Key{ + Type: argTy, + }, }) } numOut := ctrTyp.NumIn() - var provides []container2.Key + var provides []container.Output for i := 1; i < numOut; i++ { argTy := ctrTyp.Out(i) @@ -115,13 +175,17 @@ func (ms *moduleSet) addModule(interfaceRegistry codectypes.InterfaceRegistry, r continue } - provides = append(provides, container2.Key{ - Type: argTy, - }) + provides = append(provides, + container.Output{ + Key: container.Key{ + Type: argTy, + }, + }, + ) } - return ms.container.RegisterProvider(container2.Provider{ - Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { + return ms.container.RegisterProvider(container.Provider{ + Constructor: func(deps []reflect.Value, _ container.Scope) ([]reflect.Value, error) { args := []reflect.Value{reflect.ValueOf(msg)} args = append(args, deps...) res := ctrVal.Call(args) @@ -149,7 +213,7 @@ func (ms *moduleSet) addModule(interfaceRegistry codectypes.InterfaceRegistry, r }, Needs: needs, Provides: provides, - Scope: config.Name, + Scope: container.Scope(config.Name), }) } diff --git a/core/container/container.go b/core/container/container.go index ef1d32840eee..69bdc0f5fb1c 100644 --- a/core/container/container.go +++ b/core/container/container.go @@ -32,11 +32,11 @@ func NewContainer() *Container { } type Input struct { - Key Key + Key Optional bool } -type SecureOutput struct { +type Output struct { Key SecurityChecker SecurityChecker } @@ -48,7 +48,7 @@ type Key struct { type Scope string type node struct { - *Provider + Provider called bool values []reflect.Value err error @@ -60,20 +60,22 @@ type node struct { // be restricted to certain scopes based on SecurityCheckers. type Provider struct { // Constructor provides the dependencies - Constructor func(deps []reflect.Value) ([]reflect.Value, error) + Constructor func(deps []reflect.Value, scope Scope) ([]reflect.Value, error) // Needs are the keys for dependencies the constructor needs Needs []Input // Needs are the keys for dependencies the constructor provides - Provides []SecureOutput + Provides []Output // Scope is the scope within which the constructor runs Scope Scope + + IsScopeProvider bool } type scopeNode struct { - *ScopeProvider + Provider calledForScope map[Scope]bool valuesForScope map[Scope][]reflect.Value errsForScope map[Scope]error @@ -108,46 +110,75 @@ type secureValue struct { type SecurityChecker func(scope Scope) error -func (c *Container) RegisterProvider(provider *Provider) error { - n := &node{ - Provider: provider, - called: false, - } +func (c *Container) RegisterProvider(provider Provider) error { + if !provider.IsScopeProvider { + n := &node{ + Provider: provider, + called: false, + } - c.nodes = append(c.nodes, n) + c.nodes = append(c.nodes, n) - for _, key := range provider.Provides { - if c.providers[key.Key] != nil { - return fmt.Errorf("TODO") - } + for _, key := range provider.Provides { + if c.providers[key.Key] != nil { + return fmt.Errorf("TODO") + } - c.providers[key.Key] = n - } + if c.scopeProviders[key.Key] != nil { + return fmt.Errorf("TODO") + } - return nil -} + c.providers[key.Key] = n + } + } else { + n := &scopeNode{ + Provider: provider, + calledForScope: map[Scope]bool{}, + valuesForScope: map[Scope][]reflect.Value{}, + errsForScope: map[Scope]error{}, + } -func (c *Container) RegisterScopeProvider(provider *ScopeProvider) error { - n := &scopeNode{ - ScopeProvider: provider, - calledForScope: map[Scope]bool{}, - valuesForScope: map[Scope][]reflect.Value{}, - errsForScope: map[Scope]error{}, - } + c.scopeNodes = append(c.scopeNodes, n) - c.scopeNodes = append(c.scopeNodes, n) + for _, key := range provider.Provides { + if c.providers[key.Key] != nil { + return fmt.Errorf("TODO") + } - for _, key := range provider.Provides { - if c.scopeProviders[key] != nil { - return fmt.Errorf("TODO") + if c.scopeProviders[key.Key] != nil { + return fmt.Errorf("TODO") + } + + c.scopeProviders[key.Key] = n } - c.scopeProviders[key] = n + return nil } return nil } +//func (c *Container) RegisterScopeProvider(provider *ScopeProvider) error { +// n := &scopeNode{ +// ScopeProvider: provider, +// calledForScope: map[Scope]bool{}, +// valuesForScope: map[Scope][]reflect.Value{}, +// errsForScope: map[Scope]error{}, +// } +// +// c.scopeNodes = append(c.scopeNodes, n) +// +// for _, key := range provider.Provides { +// if c.scopeProviders[key] != nil { +// return fmt.Errorf("TODO") +// } +// +// c.scopeProviders[key] = n +// } +// +// return nil +//} + func (c *Container) resolve(scope Scope, input Input, stack map[interface{}]bool) (reflect.Value, error) { if scope != "" { if val, ok := c.scopedValues[scope][input.Key]; ok { @@ -181,7 +212,7 @@ func (c *Container) resolve(scope Scope, input Input, stack map[interface{}]bool deps = append(deps, res) } - res, err := provider.Constructor(scope, deps) + res, err := provider.Constructor(deps, scope) provider.calledForScope[scope] = true if err != nil { provider.errsForScope[scope] = err @@ -192,14 +223,14 @@ func (c *Container) resolve(scope Scope, input Input, stack map[interface{}]bool for i, val := range res { p := provider.Provides[i] - if _, ok := c.scopedValues[scope][p]; ok { + if _, ok := c.scopedValues[scope][p.Key]; ok { return reflect.Value{}, fmt.Errorf("value provided twice") } if c.scopedValues[scope] == nil { c.scopedValues[scope] = map[Key]reflect.Value{} } - c.scopedValues[scope][p] = val + c.scopedValues[scope][p.Key] = val } val, ok := c.scopedValues[scope][input.Key] @@ -241,6 +272,10 @@ func (c *Container) resolve(scope Scope, input Input, stack map[interface{}]bool return val, err } + if input.Optional { + return reflect.Zero(input.Type), nil + } + return reflect.Value{}, fmt.Errorf("no provider") } @@ -262,7 +297,7 @@ func (c *Container) execNode(provider *node, stack map[interface{}]bool) error { deps = append(deps, res) } - res, err := provider.Constructor(deps) + res, err := provider.Constructor(deps, "") provider.called = true if err != nil { provider.err = err @@ -328,7 +363,9 @@ func (StructArgs) isStructArgs() {} type isStructArgs interface{ isStructArgs() } -var isStructArgsTyp = reflect.TypeOf((*isStructArgs)(nil)) +var structArgsType = reflect.TypeOf(StructArgs{}) + +var isStructArgsTyp = reflect.TypeOf((*isStructArgs)(nil)).Elem() var scopeTyp = reflect.TypeOf(Scope("")) @@ -350,28 +387,37 @@ func TypeToInput(typ reflect.Type) ([]Input, InMarshaler, error) { for i := 0; i < nFields; i++ { field := typ.Field(i) - fieldInputs, m, err := TypeToInput(field.Type) - if err != nil { - return nil, nil, err - } + if field.Type == structArgsType { + marshalers = append(marshalers, inFieldMarshaler{ + n: 0, + inMarshaler: func(values []reflect.Value) reflect.Value { + return reflect.ValueOf(StructArgs{}) + }, + }) + } else { + fieldInputs, m, err := TypeToInput(field.Type) + if err != nil { + return nil, nil, err + } - optionalTag, ok := field.Tag.Lookup("optional") - if ok { - if len(fieldInputs) == 1 { - if optionalTag != "true" { - return nil, nil, fmt.Errorf("true is the only valid value for the optional tag, got %s", optionalTag) + optionalTag, ok := field.Tag.Lookup("optional") + if ok { + if len(fieldInputs) == 1 { + if optionalTag != "true" { + return nil, nil, fmt.Errorf("true is the only valid value for the optional tag, got %s", optionalTag) + } + fieldInputs[0].Optional = true + } else if len(fieldInputs) > 1 { + return nil, nil, fmt.Errorf("optional tag cannot be applied to nested StructArgs") } - fieldInputs[0].Optional = true - } else if len(fieldInputs) > 1 { - return nil, nil, fmt.Errorf("optional tag cannot be applied to nested StructArgs") } - } - res = append(res, fieldInputs...) - marshalers = append(marshalers, inFieldMarshaler{ - n: len(fieldInputs), - inMarshaler: m, - }) + res = append(res, fieldInputs...) + marshalers = append(marshalers, inFieldMarshaler{ + n: len(fieldInputs), + inMarshaler: m, + }) + } } return res, structMarshaler(typ, marshalers), nil @@ -388,10 +434,10 @@ func TypeToInput(typ reflect.Type) ([]Input, InMarshaler, error) { } } -func TypeToOutput(typ reflect.Type, securityContext func(scope Scope, tag string) error) ([]SecureOutput, OutMarshaler, error) { +func TypeToOutput(typ reflect.Type, securityContext func(scope Scope, tag string) error) ([]Output, OutMarshaler, error) { if typ.AssignableTo(isStructArgsTyp) && typ.Kind() == reflect.Struct { nFields := typ.NumField() - var res []SecureOutput + var res []Output var marshalers []OutMarshaler for i := 0; i < nFields; i++ { @@ -429,7 +475,7 @@ func TypeToOutput(typ reflect.Type, securityContext func(scope Scope, tag string } else if typ == scopeTyp { return nil, nil, fmt.Errorf("can't convert type %T to %T", Scope(""), Input{}) } else { - return []SecureOutput{{ + return []Output{{ Key: Key{ Type: typ, }, @@ -441,7 +487,7 @@ func TypeToOutput(typ reflect.Type, securityContext func(scope Scope, tag string func structMarshaler(typ reflect.Type, marshalers []inFieldMarshaler) func([]reflect.Value) reflect.Value { return func(values []reflect.Value) reflect.Value { - structInst := reflect.New(typ) + structInst := reflect.Zero(typ) for i, m := range marshalers { val := m.inMarshaler(values[:m.n]) @@ -458,90 +504,108 @@ func (c *Container) Provide(constructor interface{}) error { } func (c *Container) ProvideWithScope(constructor interface{}, scope Scope) error { - p, sp, err := ConstructorToProvider(constructor, scope, c.securityContext) + p, err := ConstructorToProvider(constructor, scope, c.securityContext) if err != nil { return err } - if p != nil { - return c.RegisterProvider(p) - } - - if sp != nil { - return c.RegisterScopeProvider(sp) - } - - return fmt.Errorf("unexpected case") + return c.RegisterProvider(p) } -func ConstructorToProvider(constructor interface{}, scope Scope, securityContext func(scope Scope, tag string) error) (*Provider, *ScopeProvider, error) { +func ConstructorToProvider(constructor interface{}, scope Scope, securityContext func(scope Scope, tag string) error) (Provider, error) { ctrTyp := reflect.TypeOf(constructor) if ctrTyp.Kind() != reflect.Func { - return nil, nil, fmt.Errorf("expected function got %T", constructor) + return Provider{}, fmt.Errorf("expected function got %T", constructor) } numIn := ctrTyp.NumIn() - numOut := ctrTyp.NumIn() + numOut := ctrTyp.NumOut() var scopeProvider bool + i := 0 if numIn >= 1 { if in0 := ctrTyp.In(0); in0 == scopeTyp { scopeProvider = true + i = 1 } } - if !scopeProvider { - var inputs []Input - var inMarshalers []inFieldMarshaler - for i := 0; i < numIn; i++ { - in, inMarshaler, err := TypeToInput(ctrTyp.In(i)) - if err != nil { - return nil, nil, err - } - inputs = append(inputs, in...) - inMarshalers = append(inMarshalers, inFieldMarshaler{ - n: len(in), - inMarshaler: inMarshaler, - }) + var inputs []Input + var inMarshalers []inFieldMarshaler + for ; i < numIn; i++ { + in, inMarshaler, err := TypeToInput(ctrTyp.In(i)) + if err != nil { + return Provider{}, err } + inputs = append(inputs, in...) + inMarshalers = append(inMarshalers, inFieldMarshaler{ + n: len(in), + inMarshaler: inMarshaler, + }) + } - var outputs []SecureOutput - var outMarshalers []OutMarshaler - for i := 0; i < numOut; i++ { - out, outMarshaler, err := TypeToOutput(ctrTyp.Out(i), securityContext) - if err != nil { - return nil, nil, err - } - outputs = append(outputs, out...) - outMarshalers = append(outMarshalers, outMarshaler) + var outputs []Output + var outMarshalers []OutMarshaler + for i := 0; i < numOut; i++ { + out, outMarshaler, err := TypeToOutput(ctrTyp.Out(i), securityContext) + if err != nil { + return Provider{}, err } + outputs = append(outputs, out...) + outMarshalers = append(outMarshalers, outMarshaler) + } - ctrVal := reflect.ValueOf(constructor) - provideCtr := func(deps []reflect.Value) ([]reflect.Value, error) { - inVals := make([]reflect.Value, numIn) - for i := 0; i < numIn; i++ { - m := inMarshalers[i] - inVals[i] = m.inMarshaler(deps[m.n:]) - deps = deps[:m.n] - } + ctrVal := reflect.ValueOf(constructor) + provideCtr := func(deps []reflect.Value, scope Scope) ([]reflect.Value, error) { + var inVals []reflect.Value - outVals := ctrVal.Call(inVals) + if scopeProvider { + inVals = append(inVals, reflect.ValueOf(scope)) + } - var provides []reflect.Value - for i := 0; i < numOut; i++ { - provides = append(provides, outMarshalers[i](outVals[i])...) - } + nInMarshalers := len(inMarshalers) + for i = 0; i < nInMarshalers; i++ { + m := inMarshalers[i] + inVals = append(inVals, m.inMarshaler(deps[:m.n])) + deps = deps[m.n:] + } + + outVals := ctrVal.Call(inVals) - return outVals, nil + var provides []reflect.Value + for i := 0; i < numOut; i++ { + provides = append(provides, outMarshalers[i](outVals[i])...) } - return &Provider{ - Constructor: provideCtr, - Needs: inputs, - Provides: outputs, - Scope: scope, - }, nil, nil - } else { + return outVals, nil + } + + return Provider{ + Constructor: provideCtr, + Needs: inputs, + Provides: outputs, + Scope: scope, + IsScopeProvider: scopeProvider, + }, nil +} +func (c *Container) Invoke(fn interface{}) error { + fnTyp := reflect.TypeOf(fn) + if fnTyp.Kind() != reflect.Func { + return fmt.Errorf("expected function got %T", fn) } + + numIn := fnTyp.NumIn() + in := make([]reflect.Value, numIn) + for i := 0; i < numIn; i++ { + val, err := c.Resolve("", Key{Type: fnTyp.In(i)}) + if err != nil { + return err + } + in[i] = val + } + + _ = reflect.ValueOf(fn).Call(in) + + return nil } diff --git a/core/container/container_test.go b/core/container/container_test.go index 5300a759d74e..0fda7f763d14 100644 --- a/core/container/container_test.go +++ b/core/container/container_test.go @@ -1,126 +1,215 @@ package container import ( - "reflect" "testing" "github.com/stretchr/testify/require" ) -type storeKey struct { +type ssKey struct { name string + db db +} + +type scKey struct { + name string + db db +} + +type kvStoreKey struct { + ssKey + scKey } type keeperA struct { - key storeKey + key kvStoreKey } type keeperB struct { - key storeKey + key kvStoreKey a keeperA } +type db struct{} + +func dbProvider() db { + return db{} +} + +func ssKeyProvider(scope Scope, db db) ssKey { + return ssKey{db: db, name: string(scope)} +} + +func scKeyProvider(scope Scope, db db) scKey { + return scKey{db: db, name: string(scope)} +} + +type kvStoreKeyInput struct { + StructArgs + SSKey ssKey + SCKey scKey +} + +func kvStoreKeyProvider(scope Scope, input kvStoreKeyInput) kvStoreKey { + return kvStoreKey{input.SSKey, input.SCKey} +} + +func keeperAProvider(key kvStoreKey) keeperA { + return keeperA{key: key} +} + +func keeperBProvider(key kvStoreKey, a keeperA) keeperB { + return keeperB{key, a} +} + func TestContainer(t *testing.T) { c := NewContainer() - require.NoError(t, c.RegisterProvider(Provider{ - Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { - return []reflect.Value{reflect.ValueOf(keeperA{deps[0].Interface().(storeKey)})}, nil - }, - Needs: []Key{ - { - Type: reflect.TypeOf(storeKey{}), - }, - }, - Provides: []Key{ - { - Type: reflect.TypeOf((*keeperA)(nil)), - }, - }, - Scope: "a", - })) - require.NoError(t, c.RegisterProvider(Provider{ - Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { - return []reflect.Value{reflect.ValueOf(keeperB{ - key: deps[0].Interface().(storeKey), - a: deps[1].Interface().(keeperA), - })}, nil - }, - Needs: []Input{ - { - Key: Key{ - Type: reflect.TypeOf(storeKey{}), + require.NoError(t, c.Provide(dbProvider)) + require.NoError(t, c.Provide(ssKeyProvider)) + require.NoError(t, c.Provide(scKeyProvider)) + require.NoError(t, c.Provide(kvStoreKeyProvider)) + require.NoError(t, c.ProvideWithScope(keeperAProvider, "a")) + require.NoError(t, c.ProvideWithScope(keeperBProvider, "b")) + require.NoError(t, c.Invoke(func(b keeperB) { + require.Equal(t, keeperB{ + key: kvStoreKey{ + ssKey: ssKey{ + name: "b", + db: db{}, }, - }, - { - Key: Key{ - Type: reflect.TypeOf((*keeperA)(nil)), + scKey: scKey{ + name: "b", + db: db{}, }, }, - }, - Provides: []SecureOutput{ - { - Key: Key{ - Type: reflect.TypeOf((*keeperB)(nil)), + a: keeperA{ + key: kvStoreKey{ + ssKey: ssKey{ + name: "a", + db: db{}, + }, + scKey: scKey{ + name: "a", + db: db{}, + }, }, }, - }, - Scope: "b", + }, b) })) - require.NoError(t, c.RegisterScopeProvider( - ScopeProvider{ - Constructor: func(scope Scope, deps []reflect.Value) ([]reflect.Value, error) { - return []reflect.Value{reflect.ValueOf(storeKey{name: scope})}, nil - }, - Needs: nil, - Provides: []Key{ - { - Type: reflect.TypeOf(storeKey{}), - }, - }, - }, - )) - - res, err := c.Resolve("b", Key{Type: reflect.TypeOf((*keeperB)(nil))}) - require.NoError(t, err) - b := res.Interface().(keeperB) - t.Logf("%+v", b) - require.Equal(t, "b", b.key.name) - require.Equal(t, "a", b.a.key.name) } func TestCycle(t *testing.T) { c := NewContainer() - require.NoError(t, c.RegisterProvider(Provider{ - Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { - return nil, nil - }, - Needs: []Key{ - { - Type: reflect.TypeOf((*keeperB)(nil)), - }, - }, - Provides: []Key{ - { - Type: reflect.TypeOf((*keeperA)(nil)), - }, - }, + require.NoError(t, c.Provide(func(a keeperA) keeperB { + return keeperB{} })) - require.NoError(t, c.RegisterProvider(Provider{ - Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { - return nil, nil - }, - Needs: []Key{ - { - Type: reflect.TypeOf((*keeperA)(nil)), - }, - }, - Provides: []Key{ - { - Type: reflect.TypeOf((*keeperB)(nil)), - }, - }, + require.NoError(t, c.Provide(func(a keeperB) keeperA { + return keeperA{} })) - - _, err := c.Resolve("b", Key{Type: reflect.TypeOf((*keeperB)(nil))}) - require.EqualError(t, err, "fatal: cycle detected") + require.EqualError(t, c.Invoke(func(a keeperA) {}), "fatal: cycle detected") } + +//func TestContainer(t *testing.T) { +// c := NewContainer() +// require.NoError(t, c.RegisterProvider(Provider{ +// Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { +// return []reflect.Value{reflect.ValueOf(keeperA{deps[0].Interface().(storeKey)})}, nil +// }, +// Needs: []Key{ +// { +// Type: reflect.TypeOf(storeKey{}), +// }, +// }, +// Provides: []Key{ +// { +// Type: reflect.TypeOf((*keeperA)(nil)), +// }, +// }, +// Scope: "a", +// })) +// require.NoError(t, c.RegisterProvider(Provider{ +// Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { +// return []reflect.Value{reflect.ValueOf(keeperB{ +// key: deps[0].Interface().(storeKey), +// a: deps[1].Interface().(keeperA), +// })}, nil +// }, +// Needs: []Input{ +// { +// Key: Key{ +// Type: reflect.TypeOf(storeKey{}), +// }, +// }, +// { +// Key: Key{ +// Type: reflect.TypeOf((*keeperA)(nil)), +// }, +// }, +// }, +// Provides: []Output{ +// { +// Key: Key{ +// Type: reflect.TypeOf((*keeperB)(nil)), +// }, +// }, +// }, +// Scope: "b", +// })) +// require.NoError(t, c.RegisterScopeProvider( +// ScopeProvider{ +// Constructor: func(scope Scope, deps []reflect.Value) ([]reflect.Value, error) { +// return []reflect.Value{reflect.ValueOf(storeKey{name: scope})}, nil +// }, +// Needs: nil, +// Provides: []Key{ +// { +// Type: reflect.TypeOf(storeKey{}), +// }, +// }, +// }, +// )) +// +// res, err := c.Resolve("b", Key{Type: reflect.TypeOf((*keeperB)(nil))}) +// require.NoError(t, err) +// b := res.Interface().(keeperB) +// t.Logf("%+v", b) +// require.Equal(t, "b", b.key.name) +// require.Equal(t, "a", b.a.key.name) +//} +// +//func TestCycle(t *testing.T) { +// c := NewContainer() +// require.NoError(t, c.RegisterProvider(Provider{ +// Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { +// return nil, nil +// }, +// Needs: []Key{ +// { +// Type: reflect.TypeOf((*keeperB)(nil)), +// }, +// }, +// Provides: []Key{ +// { +// Type: reflect.TypeOf((*keeperA)(nil)), +// }, +// }, +// })) +// require.NoError(t, c.RegisterProvider(Provider{ +// Constructor: func(deps []reflect.Value) ([]reflect.Value, error) { +// return nil, nil +// }, +// Needs: []Key{ +// { +// Type: reflect.TypeOf((*keeperA)(nil)), +// }, +// }, +// Provides: []Key{ +// { +// Type: reflect.TypeOf((*keeperB)(nil)), +// }, +// }, +// })) +// +// _, err := c.Resolve("b", Key{Type: reflect.TypeOf((*keeperB)(nil))}) +// require.EqualError(t, err, "fatal: cycle detected") +//} diff --git a/core/store/kv/kv.go b/core/store/kv/kv.go new file mode 100644 index 000000000000..64d96d49e0a6 --- /dev/null +++ b/core/store/kv/kv.go @@ -0,0 +1,20 @@ +package kv + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/core/container" + "github.com/cosmos/cosmos-sdk/core/store" + "github.com/cosmos/cosmos-sdk/core/store/sc" + "github.com/cosmos/cosmos-sdk/core/store/ss" +) + +type StoreKey struct{} + +func StoreKeyProvider(scope container.Scope, ssKey ss.StoreKey, scKey sc.StoreKey) StoreKey { + panic("TODO") +} + +func (StoreKey) Open(context.Context) store.KVStore { + panic("TODO") +} diff --git a/core/store/sc/sc.go b/core/store/sc/sc.go new file mode 100644 index 000000000000..628367f65a1b --- /dev/null +++ b/core/store/sc/sc.go @@ -0,0 +1,18 @@ +package sc + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/core/container" + "github.com/cosmos/cosmos-sdk/core/store" +) + +type StoreKey struct{} + +func StoreKeyProvider(scope container.Scope) StoreKey { + panic("TODO") +} + +func (StoreKey) Open(context.Context) store.BasicKVStore { + panic("TODO") +} diff --git a/core/store/ss/ss.go b/core/store/ss/ss.go new file mode 100644 index 000000000000..278ebb7aa2c7 --- /dev/null +++ b/core/store/ss/ss.go @@ -0,0 +1,18 @@ +package ss + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/core/container" + "github.com/cosmos/cosmos-sdk/core/store" +) + +type StoreKey struct{} + +func StoreKeyProvider(scope container.Scope) StoreKey { + panic("TODO") +} + +func (StoreKey) Open(context.Context) store.KVStore { + panic("TODO") +} diff --git a/core/tx/module/module.go b/core/tx/module/module.go index 02481439ec3e..d54e64394767 100644 --- a/core/tx/module/module.go +++ b/core/tx/module/module.go @@ -8,17 +8,18 @@ import ( tx2 "github.com/cosmos/cosmos-sdk/types/tx" + abci "github.com/tendermint/tendermint/abci/types" + "google.golang.org/grpc" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/core/module/app" "github.com/cosmos/cosmos-sdk/core/tx" - abci "github.com/tendermint/tendermint/abci/types" - "google.golang.org/grpc" ) -func init() { - app.RegisterAppModule(appModule{}) -} +//func init() { +// app.RegisterAppModule(appModule{}) +//} type appModule struct { Config *tx.Module @@ -49,7 +50,7 @@ func (a appModule) RegisterQueryServices(registrar grpc.ServiceRegistrar) {} func (a appModule) TxHandler(params app_config.TxHandlerParams) app_config.TxHandler { return txHandler{ - Module: a.Module, + Module: a.Config, msgRouter: params.MsgRouter, } } @@ -64,10 +65,10 @@ type MiddlewareRegistrar interface { type MiddlewareFactory func(config interface{}) Middleware -type Middleware interface { - OnCheckTx(ctx context.Context, tx tx2.Tx, req abci.RequestCheckTx, next TxHandler) (abci.ResponseCheckTx, error) - OnDeliverTx(ctx context.Context, tx tx2.Tx, req abci.RequestDeliverTx, next TxHandler) (abci.ResponseDeliverTx, error) -} +//type Middleware interface { +// OnCheckTx(ctx context.Context, tx tx2.Tx, req abci.RequestCheckTx, next TxHandler) (abci.ResponseCheckTx, error) +// OnDeliverTx(ctx context.Context, tx tx2.Tx, req abci.RequestDeliverTx, next TxHandler) (abci.ResponseDeliverTx, error) +//} type TxHandler interface { CheckTx(ctx context.Context, tx tx2.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) @@ -86,3 +87,5 @@ func (t txHandler) CheckTx(ctx context.Context, req abci.RequestCheckTx) (abci.R func (t txHandler) DeliverTx(ctx context.Context, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { panic("implement me") } + +type Middleware func(TxHandler) TxHandler diff --git a/x/authn/app/middleware.go b/x/authn/app/middleware.go index f358ec69e884..9acedae8d2a7 100644 --- a/x/authn/app/middleware.go +++ b/x/authn/app/middleware.go @@ -3,48 +3,45 @@ package app import ( "context" - "github.com/cosmos/cosmos-sdk/core/app_config" - abci "github.com/tendermint/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/core/module/app" + "github.com/cosmos/cosmos-sdk/core/tx/module" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/authn" ) type validateMemoMiddlewareHandler struct { + module.TxHandler *authn.ValidateMemoMiddleware } -func (v validateMemoMiddlewareHandler) validate(tx tx.Tx) error { - memoLength := len(tx.Body.Memo) - if uint64(memoLength) > v.MaxMemoCharacters { - return sdkerrors.Wrapf(sdkerrors.ErrMemoTooLarge, - "maximum number of characters is %d but received %d characters", - v.MaxMemoCharacters, memoLength, - ) - } - - return nil -} - -func (v validateMemoMiddlewareHandler) OnCheckTx(ctx context.Context, tx tx.Tx, req abci.RequestCheckTx, next app_config.TxHandler) (abci.ResponseCheckTx, error) { +func (v validateMemoMiddlewareHandler) CheckTx(ctx context.Context, tx tx.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) { err := v.validate(tx) if err != nil { return abci.ResponseCheckTx{}, err } - return next.CheckTx(ctx, tx, req) + return v.TxHandler.CheckTx(ctx, tx, req) } -func (v validateMemoMiddlewareHandler) OnDeliverTx(ctx context.Context, tx tx.Tx, req abci.RequestDeliverTx, next app_config.TxHandler) (abci.ResponseDeliverTx, error) { +func (v validateMemoMiddlewareHandler) DeliverTx(ctx context.Context, tx tx.Tx, req abci.RequestDeliverTx) (abci.ResponseDeliverTx, error) { err := v.validate(tx) if err != nil { return abci.ResponseDeliverTx{}, err } - return next.DeliverTx(ctx, tx, req) + return v.TxHandler.DeliverTx(ctx, tx, req) } -var _ app.TxMiddleware = validateMemoMiddlewareHandler{} +func (v validateMemoMiddlewareHandler) validate(tx tx.Tx) error { + memoLength := len(tx.Body.Memo) + if uint64(memoLength) > v.MaxMemoCharacters { + return sdkerrors.Wrapf(sdkerrors.ErrMemoTooLarge, + "maximum number of characters is %d but received %d characters", + v.MaxMemoCharacters, memoLength, + ) + } + + return nil +} diff --git a/x/authn/module/module.go b/x/authn/module/module.go index f5ee367e0fc5..46343a74b874 100644 --- a/x/authn/module/module.go +++ b/x/authn/module/module.go @@ -1,19 +1,11 @@ package module -import ( - codec2 "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/core/codec" - "github.com/cosmos/cosmos-sdk/core/module/app" - "github.com/cosmos/cosmos-sdk/core/store" - "github.com/cosmos/cosmos-sdk/x/authn" -) - -var _ codec.TypeProvider = Module{} - -func (m Module) RegisterTypes(registry codec.TypeRegistry) { - authn.RegisterTypes(registry) -} - -func (m Module) NewAppHandler(cdc codec2.Codec, storeKey store.KVStoreKey) app.Handler { - -} +//var _ codec.TypeProvider = Module{} +// +//func (m Module) RegisterTypes(registry codec.TypeRegistry) { +// authn.RegisterTypes(registry) +//} +// +//func (m Module) NewAppHandler(cdc codec2.Codec, storeKey store.KVStoreKey) app.Handler { +// +//}