x/ibc: final gRPC migration (#7077)
* x/ibc: final gRPC migration * grpc test * query client consensus states * remove dup type * query constructors * CLI queries * missing cmd * latest consensus state * parser test * register query service * Update x/ibc/02-client/client/cli/query.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * Update x/ibc/module.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * few grpc tests * fix tests * final gRPC tests * rm comment * address @colin-axner comment Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
This commit is contained in:
parent
049731bb3c
commit
3368dae5f5
10
go.sum
10
go.sum
|
@ -107,8 +107,6 @@ github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc
|
|||
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU=
|
||||
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
|
||||
github.com/cosmos/iavl v0.15.0-rc1 h1:cYMPAxu5xpGPhGYvGlpeCmgmgH7oY+kebZm2oHfh2nE=
|
||||
github.com/cosmos/iavl v0.15.0-rc1/go.mod h1:qFTkoCC00sBKWCG3Ws8GAUaYR1jIOtwNZ9p8uFOu4Jo=
|
||||
github.com/cosmos/iavl v0.15.0-rc2 h1:4HI/LYLjWUnou8dehPD+NqEsDc8uamJOU2yHcqdTKv8=
|
||||
github.com/cosmos/iavl v0.15.0-rc2/go.mod h1:bXLXbwmww0kYtAYRCYNXR/k44lWaK8rIZJlCmqSK8lQ=
|
||||
github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4=
|
||||
|
@ -444,8 +442,6 @@ github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt2
|
|||
github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4=
|
||||
github.com/prometheus/common v0.10.0 h1:RyRA7RzGXQZiW+tGMr7sxa85G1z0yOpM1qq5c8lNawc=
|
||||
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
|
||||
github.com/prometheus/common v0.12.0 h1:mj4ewtVukAfkS37JU7IXPJPr7zwLEjwgWO6nZo8ROvk=
|
||||
github.com/prometheus/common v0.12.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
|
||||
github.com/prometheus/common v0.13.0 h1:vJlpe9wPgDRM1Z+7Wj3zUUjY1nr6/1jNKyl7llliccg=
|
||||
github.com/prometheus/common v0.13.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
|
@ -510,7 +506,6 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
|||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
|
||||
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
|
||||
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
|
||||
github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk=
|
||||
github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
|
||||
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
||||
|
@ -537,11 +532,8 @@ github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 h1:hqAk8riJvK4RM
|
|||
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15/go.mod h1:z4YtwM70uOnk8h0pjJYlj3zdYwi9l03By6iAIF5j/Pk=
|
||||
github.com/tendermint/go-amino v0.15.1 h1:D2uk35eT4iTsvJd9jWIetzthE5C0/k2QmMFkCN+4JgQ=
|
||||
github.com/tendermint/go-amino v0.15.1/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
|
||||
github.com/tendermint/tendermint v0.34.0-rc2/go.mod h1:+AG8ftE2PD4uMVzGSB7c0oH9xbTlIyMeoX0M9r89x3Y=
|
||||
github.com/tendermint/tendermint v0.34.0-rc3 h1:d7Fsd5rdbxq4GmJ0kRfx7l7LesQM7e70f0ytWLTQ/Go=
|
||||
github.com/tendermint/tendermint v0.34.0-rc3/go.mod h1:BoHcEpjfpBHc1Be7RQz3AHaXFNObcDG7SNHCev6Or4g=
|
||||
github.com/tendermint/tm-db v0.6.0 h1:Us30k7H1UDcdqoSPhmP8ztAW/SWV6c6OfsfeCiboTC4=
|
||||
github.com/tendermint/tm-db v0.6.0/go.mod h1:xj3AWJ08kBDlCHKijnhJ7mTcDMOikT1r8Poxy2pJn7Q=
|
||||
github.com/tendermint/tm-db v0.6.1 h1:w3X87itMPXopcRPlFiqspEKhw4FXihPk2rnFFkP0zGk=
|
||||
github.com/tendermint/tm-db v0.6.1/go.mod h1:m3x9kRP4UFd7JODJL0yBAZqE7wTw+S37uAE90cTx7OA=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
|
@ -753,7 +745,6 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ
|
|||
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60=
|
||||
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/grpc v1.31.0 h1:T7P4R73V3SSDPhH7WW7ATbfViLtmamH0DKrP3f9AuDI=
|
||||
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
|
@ -799,7 +790,6 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
|
|||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
|
|
|
@ -8,8 +8,16 @@ import "google/protobuf/any.proto";
|
|||
|
||||
// IdentifiedClientState defines a client state with additional client identifier field.
|
||||
message IdentifiedClientState {
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
// client identifier
|
||||
string id = 1 [(gogoproto.moretags) = "yaml:\"id\""];
|
||||
google.protobuf.Any client_state = 2;
|
||||
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
|
||||
// client state
|
||||
google.protobuf.Any client_state = 2 [(gogoproto.moretags) = "yaml:\"client_state\""];
|
||||
}
|
||||
|
||||
// ClientConsensusStates defines all the stored consensus states for a given client.
|
||||
message ClientConsensusStates {
|
||||
// client identifier
|
||||
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
|
||||
// consensus states associated with the client
|
||||
repeated google.protobuf.Any consensus_states = 2 [(gogoproto.moretags) = "yaml:\"consensus_states\""];
|
||||
}
|
||||
|
|
|
@ -3,36 +3,19 @@ package ibc.client;
|
|||
|
||||
option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types";
|
||||
|
||||
import "ibc/client/client.proto";
|
||||
import "gogoproto/gogo.proto";
|
||||
import "google/protobuf/any.proto";
|
||||
|
||||
// GenesisClientState defines an identified ClientState as protobuf Any format.
|
||||
message GenesisClientState {
|
||||
string client_id = 1 [
|
||||
(gogoproto.moretags) = "yaml:\"client_id\""
|
||||
];
|
||||
google.protobuf.Any client_state = 2 [(gogoproto.moretags) = "yaml:\"client_state\""];
|
||||
}
|
||||
|
||||
// ClientConsensusStates defines all the stored consensus states for a given client.
|
||||
message ClientConsensusStates {
|
||||
string client_id = 1;
|
||||
repeated google.protobuf.Any consensus_states = 2 [
|
||||
(gogoproto.moretags) = "yaml:\"consensus_states\""
|
||||
];
|
||||
}
|
||||
|
||||
// GenesisState defines the ibc client submodule's genesis state.
|
||||
message GenesisState {
|
||||
repeated GenesisClientState clients = 1 [
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
// client states with their corresponding identifiers
|
||||
repeated IdentifiedClientState clients = 1 [(gogoproto.nullable) = false];
|
||||
// consensus states from each client
|
||||
repeated ClientConsensusStates clients_consensus = 2 [
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.castrepeated) = "ClientsConsensusStates",
|
||||
(gogoproto.moretags) = "yaml:\"clients_consensus\""
|
||||
];
|
||||
bool create_localhost = 3 [
|
||||
(gogoproto.moretags) = "yaml:\"create_localhost\""
|
||||
(gogoproto.moretags) = "yaml:\"clients_consensus\""
|
||||
];
|
||||
// create localhost on initialization
|
||||
bool create_localhost = 3 [(gogoproto.moretags) = "yaml:\"create_localhost\""];
|
||||
}
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
syntax = "proto3";
|
||||
package ibc.client;
|
||||
|
||||
import "cosmos/base/query/v1beta1/pagination.proto";
|
||||
import "ibc/client/client.proto";
|
||||
import "google/protobuf/any.proto";
|
||||
import "google/api/annotations.proto";
|
||||
|
||||
option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types";
|
||||
|
||||
// Query provides defines the gRPC querier service
|
||||
service Query {
|
||||
// ClientState queries an IBC light client.
|
||||
rpc ClientState(QueryClientStateRequest) returns (QueryClientStateResponse) {
|
||||
option (google.api.http).get = "/ibc/client/v1beta1/client_states/{client_id}";
|
||||
}
|
||||
|
||||
// ClientStates queries all the IBC light clients of a chain.
|
||||
rpc ClientStates(QueryClientStatesRequest) returns (QueryClientStatesResponse) {
|
||||
option (google.api.http).get = "/ibc/client/v1beta1/client_states";
|
||||
}
|
||||
|
||||
// ConsensusState queries a consensus state associated with a client state at a given height.
|
||||
rpc ConsensusState(QueryConsensusStateRequest) returns (QueryConsensusStateResponse) {
|
||||
option (google.api.http).get = "/ibc/client/v1beta1/consensus_states/{client_id}/{height}";
|
||||
}
|
||||
|
||||
// ConsensusStates queries all the consensus state associated with a given client.
|
||||
rpc ConsensusStates(QueryConsensusStatesRequest) returns (QueryConsensusStatesResponse) {
|
||||
option (google.api.http).get = "/ibc/client/v1beta1/consensus_states/{client_id}";
|
||||
}
|
||||
}
|
||||
|
||||
// QueryClientStateRequest is the request type for the Query/ClientState RPC
|
||||
// method
|
||||
message QueryClientStateRequest {
|
||||
// client state unique identifier
|
||||
string client_id = 1;
|
||||
}
|
||||
|
||||
// QueryClientStateResponse is the response type for the Query/ClientState RPC
|
||||
// method. Besides the client state, it includes a proof and the height from
|
||||
// which the proof was retrieved.
|
||||
message QueryClientStateResponse {
|
||||
// client state associated with the request identifier
|
||||
google.protobuf.Any client_state = 1;
|
||||
// merkle proof of existence
|
||||
bytes proof = 2;
|
||||
// merkle proof path
|
||||
string proof_path = 3;
|
||||
// height at which the proof was retrieved
|
||||
uint64 proof_height = 4;
|
||||
}
|
||||
|
||||
// QueryClientStatesRequest is the request type for the Query/ClientStates RPC
|
||||
// method
|
||||
message QueryClientStatesRequest {
|
||||
// pagination request
|
||||
cosmos.base.query.v1beta1.PageRequest pagination = 1;
|
||||
}
|
||||
|
||||
// QueryClientStatesResponse is the response type for the Query/ClientStates RPC
|
||||
// method.
|
||||
message QueryClientStatesResponse {
|
||||
// list of stored ClientStates of the chain.
|
||||
repeated IdentifiedClientState client_states = 1;
|
||||
// pagination response
|
||||
cosmos.base.query.v1beta1.PageResponse pagination = 2;
|
||||
}
|
||||
|
||||
// QueryConsensusStateRequest is the request type for the Query/ConsensusState RPC method. Besides
|
||||
// the consensus state, it includes a proof and the height from which the proof was retrieved.
|
||||
message QueryConsensusStateRequest {
|
||||
// client identifier
|
||||
string client_id = 1;
|
||||
// consensus state height
|
||||
uint64 height = 2;
|
||||
// latest_height overrrides the height field and queries the latest stored ConsensusState
|
||||
bool latest_height = 3;
|
||||
}
|
||||
|
||||
// QueryConsensusStateResponse is the response type for the Query/ConsensusState RPC method
|
||||
message QueryConsensusStateResponse {
|
||||
// consensus state associated with the client identifier at the given height
|
||||
google.protobuf.Any consensus_state = 1;
|
||||
// merkle proof of existence
|
||||
bytes proof = 2;
|
||||
// merkle proof path
|
||||
string proof_path = 3;
|
||||
// height at which the proof was retrieved
|
||||
uint64 proof_height = 4;
|
||||
}
|
||||
|
||||
// QueryConsensusStatesRequest is the request type for the Query/ConsensusStates RPC method.
|
||||
message QueryConsensusStatesRequest {
|
||||
// client identifier
|
||||
string client_id = 1;
|
||||
// pagination request
|
||||
cosmos.base.query.v1beta1.PageRequest pagination = 2;
|
||||
}
|
||||
|
||||
// QueryConsensusStatesResponse is the response type for the Query/ConsensusStates RPC method
|
||||
message QueryConsensusStatesResponse {
|
||||
// consensus states associated with the identifier
|
||||
repeated google.protobuf.Any consensus_states = 1;
|
||||
// pagination response
|
||||
cosmos.base.query.v1beta1.PageResponse pagination = 2;
|
||||
}
|
|
@ -20,6 +20,7 @@ func GetQueryCmd() *cobra.Command {
|
|||
queryCmd.AddCommand(
|
||||
GetCmdQueryClientStates(),
|
||||
GetCmdQueryClientState(),
|
||||
GetCmdQueryConsensusStates(),
|
||||
GetCmdQueryConsensusState(),
|
||||
GetCmdQueryHeader(),
|
||||
GetCmdNodeConsensusState(),
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
|
@ -16,6 +16,8 @@ import (
|
|||
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
|
||||
)
|
||||
|
||||
const flagLatestHeight = "latest-height"
|
||||
|
||||
// GetCmdQueryClientStates defines the command to query all the light clients
|
||||
// that this chain mantains.
|
||||
func GetCmdQueryClientStates() *cobra.Command {
|
||||
|
@ -32,23 +34,27 @@ func GetCmdQueryClientStates() *cobra.Command {
|
|||
return err
|
||||
}
|
||||
|
||||
page, _ := cmd.Flags().GetInt(flags.FlagPage)
|
||||
limit, _ := cmd.Flags().GetInt(flags.FlagLimit)
|
||||
queryClient := types.NewQueryClient(clientCtx)
|
||||
|
||||
clientStates, height, err := utils.QueryAllClientStates(clientCtx, page, limit)
|
||||
pageReq, err := client.ReadPageRequest(cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clientCtx = clientCtx.WithHeight(height)
|
||||
req := &types.QueryClientStatesRequest{
|
||||
Pagination: pageReq,
|
||||
}
|
||||
|
||||
return clientCtx.PrintOutputLegacy(clientStates)
|
||||
res, err := queryClient.ClientStates(context.Background(), req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintOutput(res)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().Int(flags.FlagPage, 1, "pagination page of light clients to query for")
|
||||
cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of light clients to query for")
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
flags.AddPaginationFlagsToCmd(cmd, "client states")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
@ -70,10 +76,6 @@ func GetCmdQueryClientState() *cobra.Command {
|
|||
}
|
||||
|
||||
clientID := args[0]
|
||||
if strings.TrimSpace(clientID) == "" {
|
||||
return errors.New("client ID can't be blank")
|
||||
}
|
||||
|
||||
prove, _ := cmd.Flags().GetBool(flags.FlagProve)
|
||||
|
||||
clientStateRes, err := utils.QueryClientState(clientCtx, clientID, prove)
|
||||
|
@ -81,8 +83,7 @@ func GetCmdQueryClientState() *cobra.Command {
|
|||
return err
|
||||
}
|
||||
|
||||
clientCtx = clientCtx.WithHeight(int64(clientStateRes.ProofHeight))
|
||||
return clientCtx.PrintOutputLegacy(clientStateRes)
|
||||
return clientCtx.PrintOutput(clientStateRes)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -92,15 +93,15 @@ func GetCmdQueryClientState() *cobra.Command {
|
|||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryConsensusState defines the command to query the consensus state of
|
||||
// the chain as defined in https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#query
|
||||
func GetCmdQueryConsensusState() *cobra.Command {
|
||||
// GetCmdQueryConsensusStates defines the command to query all the consensus states from a given
|
||||
// client state.
|
||||
func GetCmdQueryConsensusStates() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "consensus-state [client-id] [height]",
|
||||
Short: "Query the consensus state of a client at a given height",
|
||||
Long: "Query the consensus state for a particular light client at a given height",
|
||||
Example: fmt.Sprintf("%s query %s %s consensus-state [client-id] [height]", version.AppName, host.ModuleName, types.SubModuleName),
|
||||
Args: cobra.ExactArgs(2),
|
||||
Use: "consensus-states [client-id]",
|
||||
Short: "Query all the consensus states of a client.",
|
||||
Long: "Query all the consensus states from a given client state.",
|
||||
Example: fmt.Sprintf("%s query %s %s consensus-states [client-id]", version.AppName, host.ModuleName, types.SubModuleName),
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
|
||||
|
@ -109,28 +110,80 @@ func GetCmdQueryConsensusState() *cobra.Command {
|
|||
}
|
||||
|
||||
clientID := args[0]
|
||||
if strings.TrimSpace(clientID) == "" {
|
||||
return errors.New("client ID can't be blank")
|
||||
}
|
||||
|
||||
height, err := strconv.ParseUint(args[1], 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("expected integer height, got: %s", args[1])
|
||||
}
|
||||
queryClient := types.NewQueryClient(clientCtx)
|
||||
|
||||
prove, _ := cmd.Flags().GetBool(flags.FlagProve)
|
||||
|
||||
csRes, err := utils.QueryConsensusState(clientCtx, clientID, height, prove)
|
||||
pageReq, err := client.ReadPageRequest(cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clientCtx = clientCtx.WithHeight(int64(csRes.ProofHeight))
|
||||
return clientCtx.PrintOutputLegacy(csRes)
|
||||
req := &types.QueryConsensusStatesRequest{
|
||||
ClientId: clientID,
|
||||
Pagination: pageReq,
|
||||
}
|
||||
|
||||
res, err := queryClient.ConsensusStates(context.Background(), req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintOutput(res)
|
||||
},
|
||||
}
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
flags.AddPaginationFlagsToCmd(cmd, "consensus states")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryConsensusState defines the command to query the consensus state of
|
||||
// the chain as defined in https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#query
|
||||
func GetCmdQueryConsensusState() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "consensus-state [client-id] [height]",
|
||||
Short: "Query the consensus state of a client at a given height",
|
||||
Long: `Query the consensus state for a particular light client at a given height.
|
||||
If the '--latest' flag is included, the query returns the latest consensus state, overriding the height argument.`,
|
||||
Example: fmt.Sprintf("%s query %s %s consensus-state [client-id] [height]", version.AppName, host.ModuleName, types.SubModuleName),
|
||||
Args: cobra.RangeArgs(1, 2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clientID := args[0]
|
||||
|
||||
queryLatestHeight, _ := cmd.Flags().GetBool(flagLatestHeight)
|
||||
|
||||
var height uint64
|
||||
|
||||
if !queryLatestHeight {
|
||||
if len(args) != 2 {
|
||||
return errors.New("must include a second 'height' argument when '--latest-height' flag is not provided")
|
||||
}
|
||||
|
||||
height, err = strconv.ParseUint(args[1], 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("expected integer height, got: %s", args[1])
|
||||
}
|
||||
}
|
||||
|
||||
prove, _ := cmd.Flags().GetBool(flags.FlagProve)
|
||||
|
||||
csRes, err := utils.QueryConsensusState(clientCtx, clientID, height, prove, queryLatestHeight)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintOutput(csRes)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results")
|
||||
cmd.Flags().Bool(flagLatestHeight, false, "return latest stored consensus state")
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
|
@ -143,6 +196,7 @@ func GetCmdQueryHeader() *cobra.Command {
|
|||
Short: "Query the latest header of the running chain",
|
||||
Long: "Query the latest Tendermint header of the running chain",
|
||||
Example: fmt.Sprintf("%s query %s %s header", version.AppName, host.ModuleName, types.SubModuleName),
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
|
||||
|
@ -173,7 +227,7 @@ func GetCmdNodeConsensusState() *cobra.Command {
|
|||
Short: "Query a node consensus state",
|
||||
Long: "Query a node consensus state. This result is feed to the client creation transaction.",
|
||||
Example: fmt.Sprintf("%s query %s %s node-state", version.AppName, host.ModuleName, types.SubModuleName),
|
||||
Args: cobra.ExactArgs(0),
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"context"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
@ -14,120 +14,83 @@ import (
|
|||
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
|
||||
)
|
||||
|
||||
// QueryAllClientStates returns all the light client states. It _does not_ return
|
||||
// any merkle proof.
|
||||
func QueryAllClientStates(clientCtx client.Context, page, limit int) ([]exported.ClientState, int64, error) {
|
||||
params := types.NewQueryAllClientsParams(page, limit)
|
||||
bz, err := clientCtx.JSONMarshaler.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("failed to marshal query params: %w", err)
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s/%s", "ibc", types.QuerierRoute, types.QueryAllClients)
|
||||
res, height, err := clientCtx.QueryWithData(route, bz)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
var clients []exported.ClientState
|
||||
err = clientCtx.JSONMarshaler.UnmarshalJSON(res, &clients)
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("failed to unmarshal light clients: %w", err)
|
||||
}
|
||||
return clients, height, nil
|
||||
}
|
||||
|
||||
// QueryClientState queries the store to get the light client state and a merkle
|
||||
// proof.
|
||||
// TODO: delete
|
||||
// QueryClientState returns a client state.
|
||||
// If prove is true, it performs an ABCI store query in order to retrieve the merkle proof. Otherwise,
|
||||
// it uses the gRPC query client.
|
||||
func QueryClientState(
|
||||
clientCtx client.Context, clientID string, prove bool,
|
||||
) (types.StateResponse, error) {
|
||||
) (*types.QueryClientStateResponse, error) {
|
||||
if prove {
|
||||
return QueryClientStateABCI(clientCtx, clientID)
|
||||
}
|
||||
|
||||
queryClient := types.NewQueryClient(clientCtx)
|
||||
req := &types.QueryClientStateRequest{
|
||||
ClientId: clientID,
|
||||
}
|
||||
|
||||
return queryClient.ClientState(context.Background(), req)
|
||||
}
|
||||
|
||||
// QueryClientStateABCI queries the store to get the light client state and a merkle proof.
|
||||
func QueryClientStateABCI(
|
||||
clientCtx client.Context, clientID string,
|
||||
) (*types.QueryClientStateResponse, error) {
|
||||
req := abci.RequestQuery{
|
||||
Path: "store/ibc/key",
|
||||
Data: host.FullKeyClientPath(clientID, host.KeyClientState()),
|
||||
Prove: prove,
|
||||
Prove: true,
|
||||
}
|
||||
|
||||
res, err := clientCtx.QueryABCI(req)
|
||||
if err != nil {
|
||||
return types.StateResponse{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var clientState exported.ClientState
|
||||
if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &clientState); err != nil {
|
||||
return types.StateResponse{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
clientStateRes := types.NewClientStateResponse(clientID, clientState, res.ProofOps, res.Height)
|
||||
anyClientState, err := types.PackClientState(clientState)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
clientStateRes := types.NewQueryClientStateResponse(clientID, anyClientState, proofBz, res.Height)
|
||||
return clientStateRes, nil
|
||||
}
|
||||
|
||||
// QueryClientState queries the store to get the light client state and a merkle
|
||||
// proof.
|
||||
func QueryClientStateABCI(
|
||||
clientCtx client.Context, clientID string,
|
||||
) (exported.ClientState, []byte, uint64, error) {
|
||||
req := abci.RequestQuery{
|
||||
Path: "store/ibc/key",
|
||||
Data: host.FullKeyClientPath(clientID, host.KeyClientState()),
|
||||
Prove: true,
|
||||
}
|
||||
|
||||
res, err := clientCtx.QueryABCI(req)
|
||||
if err != nil {
|
||||
return nil, nil, 0, err
|
||||
}
|
||||
|
||||
proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
|
||||
if err != nil {
|
||||
return nil, nil, 0, err
|
||||
}
|
||||
|
||||
var clientState exported.ClientState
|
||||
if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &clientState); err != nil {
|
||||
return nil, nil, 0, err
|
||||
}
|
||||
|
||||
// FIXME: height + 1 is returned as the proof height
|
||||
// Issue: https://github.com/cosmos/cosmos-sdk/issues/6567
|
||||
return clientState, proofBz, uint64(res.Height + 1), nil
|
||||
}
|
||||
|
||||
// QueryConsensusState queries the store to get the consensus state and a merkle
|
||||
// proof.
|
||||
// TODO: delete
|
||||
// QueryConsensusState returns a consensus state.
|
||||
// If prove is true, it performs an ABCI store query in order to retrieve the merkle proof. Otherwise,
|
||||
// it uses the gRPC query client.
|
||||
func QueryConsensusState(
|
||||
clientCtx client.Context, clientID string, height uint64, prove bool,
|
||||
) (types.ConsensusStateResponse, error) {
|
||||
var conStateRes types.ConsensusStateResponse
|
||||
|
||||
req := abci.RequestQuery{
|
||||
Path: "store/ibc/key",
|
||||
Data: host.FullKeyClientPath(clientID, host.KeyConsensusState(height)),
|
||||
Prove: prove,
|
||||
clientCtx client.Context, clientID string, height uint64, prove, latestHeight bool,
|
||||
) (*types.QueryConsensusStateResponse, error) {
|
||||
if prove {
|
||||
return QueryConsensusStateABCI(clientCtx, clientID, height)
|
||||
}
|
||||
|
||||
res, err := clientCtx.QueryABCI(req)
|
||||
if err != nil {
|
||||
return conStateRes, err
|
||||
queryClient := types.NewQueryClient(clientCtx)
|
||||
req := &types.QueryConsensusStateRequest{
|
||||
ClientId: clientID,
|
||||
Height: height,
|
||||
LatestHeight: latestHeight,
|
||||
}
|
||||
|
||||
var cs exported.ConsensusState
|
||||
if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &cs); err != nil {
|
||||
return conStateRes, err
|
||||
}
|
||||
|
||||
return types.NewConsensusStateResponse(clientID, cs, res.ProofOps, res.Height), nil
|
||||
return queryClient.ConsensusState(context.Background(), req)
|
||||
}
|
||||
|
||||
// QueryConsensusState queries the store to get the consensus state of a light
|
||||
// client and a merkle proof of its existence or non-existence.
|
||||
// QueryConsensusStateABCI queries the store to get the consensus state of a light client and a
|
||||
// merkle proof of its existence or non-existence.
|
||||
func QueryConsensusStateABCI(
|
||||
clientCtx client.Context, clientID string, height uint64,
|
||||
) (exported.ConsensusState, []byte, uint64, error) {
|
||||
|
||||
) (*types.QueryConsensusStateResponse, error) {
|
||||
req := abci.RequestQuery{
|
||||
Path: "store/ibc/key",
|
||||
Data: host.FullKeyClientPath(clientID, host.KeyConsensusState(height)),
|
||||
|
@ -136,22 +99,25 @@ func QueryConsensusStateABCI(
|
|||
|
||||
res, err := clientCtx.QueryABCI(req)
|
||||
if err != nil {
|
||||
return nil, nil, 0, err
|
||||
}
|
||||
|
||||
proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
|
||||
if err != nil {
|
||||
return nil, nil, 0, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var cs exported.ConsensusState
|
||||
if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &cs); err != nil {
|
||||
return nil, nil, 0, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// FIXME: height + 1 is returned as the proof height
|
||||
// Issue: https://github.com/cosmos/cosmos-sdk/issues/6567
|
||||
return cs, proofBz, uint64(res.Height + 1), nil
|
||||
anyConsensusState, err := types.PackConsensusState(cs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return types.NewQueryConsensusStateResponse(clientID, anyConsensusState, proofBz, res.Height), nil
|
||||
}
|
||||
|
||||
// QueryTendermintHeader takes a client context and returns the appropriate
|
||||
|
|
|
@ -5,12 +5,24 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
)
|
||||
|
||||
// UnmarshalClientState attempts to decode and return an ClientState object from
|
||||
// raw encoded bytes.
|
||||
func (k Keeper) UnmarshalClientState(bz []byte) (exported.ClientState, error) {
|
||||
return types.UnmarshalClientState(k.cdc, bz)
|
||||
}
|
||||
|
||||
// MustUnmarshalClientState attempts to decode and return an ClientState object from
|
||||
// raw encoded bytes. It panics on error.
|
||||
func (k Keeper) MustUnmarshalClientState(bz []byte) exported.ClientState {
|
||||
return types.MustUnmarshalClientState(k.cdc, bz)
|
||||
}
|
||||
|
||||
// UnmarshalConsensusState attempts to decode and return an ConsensusState object from
|
||||
// raw encoded bytes.
|
||||
func (k Keeper) UnmarshalConsensusState(bz []byte) (exported.ConsensusState, error) {
|
||||
return types.UnmarshalConsensusState(k.cdc, bz)
|
||||
}
|
||||
|
||||
// MustUnmarshalConsensusState attempts to decode and return an ConsensusState object from
|
||||
// raw encoded bytes. It panics on error.
|
||||
func (k Keeper) MustUnmarshalConsensusState(bz []byte) exported.ConsensusState {
|
||||
|
|
|
@ -0,0 +1,177 @@
|
|||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/types/query"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
|
||||
)
|
||||
|
||||
var _ types.QueryServer = Keeper{}
|
||||
|
||||
// ClientState implements the Query/ClientState gRPC method
|
||||
func (q Keeper) ClientState(c context.Context, req *types.QueryClientStateRequest) (*types.QueryClientStateResponse, error) {
|
||||
if req == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
if err := host.ClientIdentifierValidator(req.ClientId); err != nil {
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
clientState, found := q.GetClientState(ctx, req.ClientId)
|
||||
if !found {
|
||||
return nil, status.Error(
|
||||
codes.NotFound,
|
||||
sdkerrors.Wrap(types.ErrClientNotFound, req.ClientId).Error(),
|
||||
)
|
||||
}
|
||||
|
||||
any, err := types.PackClientState(clientState)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
return &types.QueryClientStateResponse{
|
||||
ClientState: any,
|
||||
ProofHeight: uint64(ctx.BlockHeight()),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ClientStates implements the Query/ClientStates gRPC method
|
||||
func (q Keeper) ClientStates(c context.Context, req *types.QueryClientStatesRequest) (*types.QueryClientStatesResponse, error) {
|
||||
if req == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
clientStates := []*types.IdentifiedClientState{}
|
||||
store := prefix.NewStore(ctx.KVStore(q.storeKey), host.KeyClientStorePrefix)
|
||||
|
||||
pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error {
|
||||
keySplit := strings.Split(string(key), "/")
|
||||
if keySplit[len(keySplit)-1] != "clientState" {
|
||||
return nil
|
||||
}
|
||||
|
||||
clientState, err := q.UnmarshalClientState(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clientID := keySplit[1]
|
||||
if err := host.ClientIdentifierValidator(clientID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
identifiedClient := types.NewIdentifiedClientState(clientID, clientState)
|
||||
clientStates = append(clientStates, &identifiedClient)
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.QueryClientStatesResponse{
|
||||
ClientStates: clientStates,
|
||||
Pagination: pageRes,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ConsensusState implements the Query/ConsensusState gRPC method
|
||||
func (q Keeper) ConsensusState(c context.Context, req *types.QueryConsensusStateRequest) (*types.QueryConsensusStateResponse, error) {
|
||||
if req == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
if err := host.ClientIdentifierValidator(req.ClientId); err != nil {
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
var (
|
||||
consensusState exported.ConsensusState
|
||||
found bool
|
||||
)
|
||||
|
||||
if req.LatestHeight {
|
||||
consensusState, found = q.GetLatestClientConsensusState(ctx, req.ClientId)
|
||||
} else {
|
||||
if req.Height == 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "consensus state height cannot be 0")
|
||||
}
|
||||
|
||||
consensusState, found = q.GetClientConsensusState(ctx, req.ClientId, req.Height)
|
||||
}
|
||||
|
||||
if !found {
|
||||
return nil, status.Error(
|
||||
codes.NotFound,
|
||||
sdkerrors.Wrapf(types.ErrConsensusStateNotFound, "client-id: %s, height: %d", req.ClientId, req.Height).Error(),
|
||||
)
|
||||
}
|
||||
|
||||
any, err := types.PackConsensusState(consensusState)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
return &types.QueryConsensusStateResponse{
|
||||
ConsensusState: any,
|
||||
ProofHeight: uint64(ctx.BlockHeight()),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ConsensusStates implements the Query/ConsensusStates gRPC method
|
||||
func (q Keeper) ConsensusStates(c context.Context, req *types.QueryConsensusStatesRequest) (*types.QueryConsensusStatesResponse, error) {
|
||||
if req == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
if err := host.ClientIdentifierValidator(req.ClientId); err != nil {
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
consensusStates := []*codectypes.Any{}
|
||||
store := prefix.NewStore(ctx.KVStore(q.storeKey), host.FullKeyClientPath(req.ClientId, []byte("consensusState/")))
|
||||
|
||||
pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error {
|
||||
consensusState, err := q.UnmarshalConsensusState(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
any, err := types.PackConsensusState(consensusState)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
consensusStates = append(consensusStates, any)
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.QueryConsensusStatesResponse{
|
||||
ConsensusStates: consensusStates,
|
||||
Pagination: pageRes,
|
||||
}, nil
|
||||
}
|
|
@ -0,0 +1,357 @@
|
|||
package keeper_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/types/query"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
|
||||
)
|
||||
|
||||
func (suite *KeeperTestSuite) TestQueryClientState() {
|
||||
var (
|
||||
req *types.QueryClientStateRequest
|
||||
expClientState *codectypes.Any
|
||||
)
|
||||
|
||||
testCases := []struct {
|
||||
msg string
|
||||
malleate func()
|
||||
expPass bool
|
||||
}{
|
||||
{"invalid clientID",
|
||||
func() {
|
||||
req = &types.QueryClientStateRequest{}
|
||||
},
|
||||
false,
|
||||
},
|
||||
{"client not found",
|
||||
func() {
|
||||
req = &types.QueryClientStateRequest{
|
||||
ClientId: testClientID,
|
||||
}
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"success",
|
||||
func() {
|
||||
clientState := ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, 0, commitmenttypes.GetSDKSpecs())
|
||||
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
|
||||
|
||||
var err error
|
||||
expClientState, err = types.PackClientState(clientState)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
req = &types.QueryClientStateRequest{
|
||||
ClientId: testClientID,
|
||||
}
|
||||
},
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
|
||||
suite.SetupTest() // reset
|
||||
|
||||
tc.malleate()
|
||||
ctx := sdk.WrapSDKContext(suite.ctx)
|
||||
res, err := suite.queryClient.ClientState(ctx, req)
|
||||
|
||||
if tc.expPass {
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(res)
|
||||
|
||||
expClientState.ClearCachedValue()
|
||||
suite.Require().Equal(expClientState, res.ClientState)
|
||||
} else {
|
||||
suite.Require().Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestQueryClientStates() {
|
||||
var (
|
||||
req *types.QueryClientStatesRequest
|
||||
expClientStates = []*types.IdentifiedClientState(nil)
|
||||
)
|
||||
|
||||
testCases := []struct {
|
||||
msg string
|
||||
malleate func()
|
||||
expPass bool
|
||||
}{
|
||||
{
|
||||
"empty pagination",
|
||||
func() {
|
||||
req = &types.QueryClientStatesRequest{}
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"success, no results",
|
||||
func() {
|
||||
req = &types.QueryClientStatesRequest{
|
||||
Pagination: &query.PageRequest{
|
||||
Limit: 3,
|
||||
CountTotal: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"success",
|
||||
func() {
|
||||
clientState := ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, 0, commitmenttypes.GetSDKSpecs())
|
||||
clientState2 := ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, 0, commitmenttypes.GetSDKSpecs())
|
||||
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
|
||||
suite.keeper.SetClientState(suite.ctx, testClientID2, clientState2)
|
||||
|
||||
idcs := types.NewIdentifiedClientState(testClientID, clientState)
|
||||
idcs2 := types.NewIdentifiedClientState(testClientID2, clientState2)
|
||||
|
||||
// order is swapped because the res is sorted by client id
|
||||
expClientStates = []*types.IdentifiedClientState{&idcs2, &idcs}
|
||||
req = &types.QueryClientStatesRequest{
|
||||
Pagination: &query.PageRequest{
|
||||
Limit: 3,
|
||||
CountTotal: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
|
||||
suite.SetupTest() // reset
|
||||
|
||||
tc.malleate()
|
||||
ctx := sdk.WrapSDKContext(suite.ctx)
|
||||
|
||||
res, err := suite.queryClient.ClientStates(ctx, req)
|
||||
|
||||
if tc.expPass {
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(res)
|
||||
suite.Require().Equal(len(expClientStates), len(res.ClientStates))
|
||||
for i := range expClientStates {
|
||||
suite.Require().Equal(expClientStates[i].ClientId, res.ClientStates[i].ClientId)
|
||||
suite.Require().NotNil(res.ClientStates[i].ClientState)
|
||||
expClientStates[i].ClientState.ClearCachedValue()
|
||||
suite.Require().Equal(expClientStates[i].ClientState, res.ClientStates[i].ClientState)
|
||||
}
|
||||
} else {
|
||||
suite.Require().Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestQueryConsensusState() {
|
||||
var (
|
||||
req *types.QueryConsensusStateRequest
|
||||
expConsensusState *codectypes.Any
|
||||
)
|
||||
|
||||
testCases := []struct {
|
||||
msg string
|
||||
malleate func()
|
||||
expPass bool
|
||||
}{
|
||||
{
|
||||
"invalid clientID",
|
||||
func() {
|
||||
req = &types.QueryConsensusStateRequest{}
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"invalid height",
|
||||
func() {
|
||||
req = &types.QueryConsensusStateRequest{
|
||||
ClientId: testClientID,
|
||||
Height: 0,
|
||||
LatestHeight: false,
|
||||
}
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"consensus state not found",
|
||||
func() {
|
||||
req = &types.QueryConsensusStateRequest{
|
||||
ClientId: testClientID,
|
||||
LatestHeight: true,
|
||||
}
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"success latest height",
|
||||
func() {
|
||||
clientState := ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs())
|
||||
cs := ibctmtypes.NewConsensusState(
|
||||
suite.consensusState.Timestamp, commitmenttypes.NewMerkleRoot([]byte("hash1")), suite.consensusState.GetHeight(), nil,
|
||||
)
|
||||
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
|
||||
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, suite.consensusState.GetHeight(), cs)
|
||||
|
||||
var err error
|
||||
expConsensusState, err = types.PackConsensusState(cs)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
req = &types.QueryConsensusStateRequest{
|
||||
ClientId: testClientID,
|
||||
LatestHeight: true,
|
||||
}
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"success with height",
|
||||
func() {
|
||||
cs := ibctmtypes.NewConsensusState(
|
||||
suite.consensusState.Timestamp, commitmenttypes.NewMerkleRoot([]byte("hash1")), suite.consensusState.GetHeight(), nil,
|
||||
)
|
||||
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight, cs)
|
||||
|
||||
var err error
|
||||
expConsensusState, err = types.PackConsensusState(cs)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
req = &types.QueryConsensusStateRequest{
|
||||
ClientId: testClientID,
|
||||
Height: testClientHeight,
|
||||
}
|
||||
},
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
|
||||
suite.SetupTest() // reset
|
||||
|
||||
tc.malleate()
|
||||
ctx := sdk.WrapSDKContext(suite.ctx)
|
||||
res, err := suite.queryClient.ConsensusState(ctx, req)
|
||||
|
||||
if tc.expPass {
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(res)
|
||||
|
||||
expConsensusState.ClearCachedValue()
|
||||
suite.Require().Equal(expConsensusState, res.ConsensusState)
|
||||
} else {
|
||||
suite.Require().Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestQueryConsensusStates() {
|
||||
var (
|
||||
req *types.QueryConsensusStatesRequest
|
||||
expConsensusStates = []*codectypes.Any(nil)
|
||||
)
|
||||
|
||||
testCases := []struct {
|
||||
msg string
|
||||
malleate func()
|
||||
expPass bool
|
||||
}{
|
||||
{
|
||||
"invalid client identifier",
|
||||
func() {
|
||||
req = &types.QueryConsensusStatesRequest{}
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"empty pagination",
|
||||
func() {
|
||||
req = &types.QueryConsensusStatesRequest{
|
||||
ClientId: testClientID,
|
||||
}
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"success, no results",
|
||||
func() {
|
||||
req = &types.QueryConsensusStatesRequest{
|
||||
ClientId: testClientID,
|
||||
Pagination: &query.PageRequest{
|
||||
Limit: 3,
|
||||
CountTotal: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"success",
|
||||
func() {
|
||||
cs := ibctmtypes.NewConsensusState(
|
||||
suite.consensusState.Timestamp, commitmenttypes.NewMerkleRoot([]byte("hash1")), suite.consensusState.GetHeight(), nil,
|
||||
)
|
||||
cs2 := ibctmtypes.NewConsensusState(
|
||||
suite.consensusState.Timestamp.Add(time.Second), commitmenttypes.NewMerkleRoot([]byte("hash2")), suite.consensusState.GetHeight(), nil,
|
||||
)
|
||||
|
||||
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight, cs)
|
||||
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight+1, cs2)
|
||||
|
||||
any, err := types.PackConsensusState(cs)
|
||||
suite.Require().NoError(err)
|
||||
any2, err := types.PackConsensusState(cs2)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// order is swapped because the res is sorted by client id
|
||||
expConsensusStates = []*codectypes.Any{any, any2}
|
||||
req = &types.QueryConsensusStatesRequest{
|
||||
ClientId: testClientID,
|
||||
Pagination: &query.PageRequest{
|
||||
Limit: 3,
|
||||
CountTotal: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
|
||||
suite.SetupTest() // reset
|
||||
|
||||
tc.malleate()
|
||||
ctx := sdk.WrapSDKContext(suite.ctx)
|
||||
|
||||
res, err := suite.queryClient.ConsensusStates(ctx, req)
|
||||
|
||||
if tc.expPass {
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().NotNil(res)
|
||||
suite.Require().Equal(len(expConsensusStates), len(res.ConsensusStates))
|
||||
for i := range expConsensusStates {
|
||||
suite.Require().NotNil(res.ConsensusStates[i])
|
||||
expConsensusStates[i].ClearCachedValue()
|
||||
suite.Require().Equal(expConsensusStates[i], res.ConsensusStates[i])
|
||||
}
|
||||
} else {
|
||||
suite.Require().Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -116,10 +116,10 @@ func (k Keeper) IterateConsensusStates(ctx sdk.Context, cb func(clientID string,
|
|||
}
|
||||
}
|
||||
|
||||
// GetAllGenesisClients returns all the clients in state with their client ids returned as GenesisClientState
|
||||
func (k Keeper) GetAllGenesisClients(ctx sdk.Context) (genClients []types.GenesisClientState) {
|
||||
// GetAllGenesisClients returns all the clients in state with their client ids returned as IdentifiedClientState
|
||||
func (k Keeper) GetAllGenesisClients(ctx sdk.Context) (genClients []types.IdentifiedClientState) {
|
||||
k.IterateClients(ctx, func(clientID string, cs exported.ClientState) bool {
|
||||
genClients = append(genClients, types.NewGenesisClientState(clientID, cs))
|
||||
genClients = append(genClients, types.NewIdentifiedClientState(clientID, cs))
|
||||
return false
|
||||
})
|
||||
return
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
@ -48,6 +49,8 @@ type KeeperTestSuite struct {
|
|||
privVal tmtypes.PrivValidator
|
||||
now time.Time
|
||||
past time.Time
|
||||
|
||||
queryClient types.QueryClient
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) SetupTest() {
|
||||
|
@ -83,6 +86,10 @@ func (suite *KeeperTestSuite) SetupTest() {
|
|||
|
||||
app.StakingKeeper.SetHistoricalInfo(suite.ctx, int64(i), stakingtypes.NewHistoricalInfo(suite.ctx.BlockHeader(), validators))
|
||||
}
|
||||
|
||||
queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, app.InterfaceRegistry())
|
||||
types.RegisterQueryServer(queryHelper, app.IBCKeeper.ClientKeeper)
|
||||
suite.queryClient = types.NewQueryClient(queryHelper)
|
||||
}
|
||||
|
||||
func TestKeeperTestSuite(t *testing.T) {
|
||||
|
@ -152,18 +159,18 @@ func (suite KeeperTestSuite) TestGetAllGenesisClients() {
|
|||
ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, 0, commitmenttypes.GetSDKSpecs()),
|
||||
}
|
||||
|
||||
expGenClients := make([]types.GenesisClientState, len(expClients))
|
||||
expGenClients := make([]types.IdentifiedClientState, len(expClients))
|
||||
|
||||
for i := range expClients {
|
||||
suite.keeper.SetClientState(suite.ctx, clientIDs[i], expClients[i])
|
||||
expGenClients[i] = types.NewGenesisClientState(clientIDs[i], expClients[i])
|
||||
expGenClients[i] = types.NewIdentifiedClientState(clientIDs[i], expClients[i])
|
||||
}
|
||||
|
||||
// add localhost client
|
||||
// TODO: uncomment after simapp is migrated to proto
|
||||
// localHostClient, found := suite.keeper.GetClientState(suite.ctx, exported.ClientTypeLocalHost)
|
||||
// suite.Require().True(found)
|
||||
// expGenClients = append(expGenClients, types.NewGenesisClientState(exported.ClientTypeLocalHost, localHostClient))
|
||||
// expGenClients = append(expGenClients, types.NewIdentifiedClientState(exported.ClientTypeLocalHost, localHostClient))
|
||||
|
||||
genClients := suite.keeper.GetAllGenesisClients(suite.ctx)
|
||||
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
package keeper
|
||||
|
||||
import (
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
)
|
||||
|
||||
// QuerierClients defines the sdk.Querier to query all the light client states.
|
||||
func QuerierClients(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc codec.JSONMarshaler) ([]byte, error) {
|
||||
var params types.QueryAllClientsParams
|
||||
|
||||
if err := legacyQuerierCdc.UnmarshalJSON(req.Data, ¶ms); err != nil {
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
|
||||
}
|
||||
|
||||
clients := k.GetAllClients(ctx)
|
||||
|
||||
start, end := client.Paginate(len(clients), params.Page, params.Limit, 100)
|
||||
if start < 0 || end < 0 {
|
||||
clients = []exported.ClientState{}
|
||||
} else {
|
||||
clients = clients[start:end]
|
||||
}
|
||||
|
||||
res, err := codec.MarshalJSONIndent(legacyQuerierCdc, clients)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/client/cli"
|
||||
|
@ -16,3 +17,8 @@ func Name() string {
|
|||
func GetQueryCmd() *cobra.Command {
|
||||
return cli.GetQueryCmd()
|
||||
}
|
||||
|
||||
// RegisterQueryService registers the gRPC query service for IBC client.
|
||||
func RegisterQueryService(server grpc.Server, queryServer types.QueryServer) {
|
||||
types.RegisterQueryServer(server, queryServer)
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ func NewIdentifiedClientState(clientID string, clientState exported.ClientState)
|
|||
}
|
||||
|
||||
return IdentifiedClientState{
|
||||
Id: clientID,
|
||||
ClientId: clientID,
|
||||
ClientState: anyClientState,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
|||
// IdentifiedClientState defines a client state with additional client identifier field.
|
||||
type IdentifiedClientState struct {
|
||||
// client identifier
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" yaml:"id"`
|
||||
ClientState *types.Any `protobuf:"bytes,2,opt,name=client_state,json=clientState,proto3" json:"client_state,omitempty"`
|
||||
ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty" yaml:"client_id"`
|
||||
// client state
|
||||
ClientState *types.Any `protobuf:"bytes,2,opt,name=client_state,json=clientState,proto3" json:"client_state,omitempty" yaml:"client_state"`
|
||||
}
|
||||
|
||||
func (m *IdentifiedClientState) Reset() { *m = IdentifiedClientState{} }
|
||||
|
@ -64,30 +65,104 @@ func (m *IdentifiedClientState) XXX_DiscardUnknown() {
|
|||
|
||||
var xxx_messageInfo_IdentifiedClientState proto.InternalMessageInfo
|
||||
|
||||
func (m *IdentifiedClientState) GetClientId() string {
|
||||
if m != nil {
|
||||
return m.ClientId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *IdentifiedClientState) GetClientState() *types.Any {
|
||||
if m != nil {
|
||||
return m.ClientState
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClientConsensusStates defines all the stored consensus states for a given client.
|
||||
type ClientConsensusStates struct {
|
||||
// client identifier
|
||||
ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty" yaml:"client_id"`
|
||||
// consensus states associated with the client
|
||||
ConsensusStates []*types.Any `protobuf:"bytes,2,rep,name=consensus_states,json=consensusStates,proto3" json:"consensus_states,omitempty" yaml:"consensus_states"`
|
||||
}
|
||||
|
||||
func (m *ClientConsensusStates) Reset() { *m = ClientConsensusStates{} }
|
||||
func (m *ClientConsensusStates) String() string { return proto.CompactTextString(m) }
|
||||
func (*ClientConsensusStates) ProtoMessage() {}
|
||||
func (*ClientConsensusStates) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_226f80e576f20abd, []int{1}
|
||||
}
|
||||
func (m *ClientConsensusStates) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *ClientConsensusStates) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_ClientConsensusStates.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 *ClientConsensusStates) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_ClientConsensusStates.Merge(m, src)
|
||||
}
|
||||
func (m *ClientConsensusStates) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *ClientConsensusStates) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_ClientConsensusStates.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_ClientConsensusStates proto.InternalMessageInfo
|
||||
|
||||
func (m *ClientConsensusStates) GetClientId() string {
|
||||
if m != nil {
|
||||
return m.ClientId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *ClientConsensusStates) GetConsensusStates() []*types.Any {
|
||||
if m != nil {
|
||||
return m.ConsensusStates
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*IdentifiedClientState)(nil), "ibc.client.IdentifiedClientState")
|
||||
proto.RegisterType((*ClientConsensusStates)(nil), "ibc.client.ClientConsensusStates")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("ibc/client/client.proto", fileDescriptor_226f80e576f20abd) }
|
||||
|
||||
var fileDescriptor_226f80e576f20abd = []byte{
|
||||
// 250 bytes of a gzipped FileDescriptorProto
|
||||
// 314 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcf, 0x4c, 0x4a, 0xd6,
|
||||
0x4f, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0x81, 0x52, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x5c,
|
||||
0x99, 0x49, 0xc9, 0x7a, 0x10, 0x11, 0x29, 0x91, 0xf4, 0xfc, 0xf4, 0x7c, 0xb0, 0xb0, 0x3e, 0x88,
|
||||
0x05, 0x51, 0x21, 0x25, 0x99, 0x9e, 0x9f, 0x9f, 0x9e, 0x93, 0xaa, 0x0f, 0xe6, 0x25, 0x95, 0xa6,
|
||||
0xe9, 0x27, 0xe6, 0x55, 0x42, 0xa4, 0x94, 0x4a, 0xb9, 0x44, 0x3d, 0x53, 0x52, 0xf3, 0x4a, 0x32,
|
||||
0xd3, 0x32, 0x53, 0x53, 0x9c, 0xc1, 0x86, 0x04, 0x97, 0x24, 0x96, 0xa4, 0x0a, 0xc9, 0x72, 0x31,
|
||||
0x65, 0xa6, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x3a, 0xf1, 0x7e, 0xba, 0x27, 0xcf, 0x59, 0x99,
|
||||
0x98, 0x9b, 0x63, 0xa5, 0x94, 0x99, 0xa2, 0x14, 0xc4, 0x94, 0x99, 0x22, 0x64, 0xce, 0xc5, 0x03,
|
||||
0xb1, 0x32, 0xbe, 0x18, 0xa4, 0x5c, 0x82, 0x49, 0x81, 0x51, 0x83, 0xdb, 0x48, 0x44, 0x0f, 0x62,
|
||||
0x93, 0x1e, 0xcc, 0x26, 0x3d, 0xc7, 0xbc, 0xca, 0x20, 0xee, 0x64, 0x84, 0xb9, 0x56, 0x2c, 0x1d,
|
||||
0x0b, 0xe4, 0x19, 0x9c, 0x7c, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23,
|
||||
0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca,
|
||||
0x28, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x3f, 0x39, 0xbf, 0x38, 0x37,
|
||||
0xbf, 0x18, 0x4a, 0xe9, 0x16, 0xa7, 0x64, 0xeb, 0x57, 0xe8, 0x83, 0x42, 0xc1, 0xc0, 0x48, 0x17,
|
||||
0x1a, 0x10, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0xeb, 0x8c, 0x01, 0x01, 0x00, 0x00,
|
||||
0xff, 0xff, 0x40, 0x46, 0x80, 0x22, 0x23, 0x01, 0x00, 0x00,
|
||||
0xe9, 0x27, 0xe6, 0x55, 0x42, 0xa4, 0x94, 0xe6, 0x30, 0x72, 0x89, 0x7a, 0xa6, 0xa4, 0xe6, 0x95,
|
||||
0x64, 0xa6, 0x65, 0xa6, 0xa6, 0x38, 0x83, 0x4d, 0x09, 0x2e, 0x49, 0x2c, 0x49, 0x15, 0x32, 0xe4,
|
||||
0xe2, 0x84, 0x18, 0x1a, 0x9f, 0x99, 0x22, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0xe9, 0x24, 0xf2, 0xe9,
|
||||
0x9e, 0xbc, 0x40, 0x65, 0x62, 0x6e, 0x8e, 0x95, 0x12, 0x5c, 0x4a, 0x29, 0x88, 0x03, 0xc2, 0xf6,
|
||||
0x4c, 0x11, 0x0a, 0xe0, 0xe2, 0x81, 0x8a, 0x17, 0x83, 0x8c, 0x90, 0x60, 0x52, 0x60, 0xd4, 0xe0,
|
||||
0x36, 0x12, 0xd1, 0x83, 0x58, 0xaf, 0x07, 0xb3, 0x5e, 0xcf, 0x31, 0xaf, 0xd2, 0x49, 0xfc, 0xd3,
|
||||
0x3d, 0x79, 0x61, 0x14, 0xb3, 0xc0, 0x7a, 0x94, 0x82, 0xb8, 0x93, 0x11, 0x8e, 0x50, 0x5a, 0xc1,
|
||||
0xc8, 0x25, 0x0a, 0x71, 0x94, 0x73, 0x7e, 0x5e, 0x71, 0x6a, 0x5e, 0x71, 0x69, 0x31, 0x58, 0xa2,
|
||||
0x98, 0x1c, 0xe7, 0xc5, 0x70, 0x09, 0x24, 0xc3, 0x4c, 0x81, 0xd8, 0x56, 0x2c, 0xc1, 0xa4, 0xc0,
|
||||
0x8c, 0xd3, 0x89, 0xd2, 0x9f, 0xee, 0xc9, 0x8b, 0x43, 0xcd, 0x43, 0xd3, 0xa7, 0x14, 0xc4, 0x9f,
|
||||
0x8c, 0xea, 0x20, 0x27, 0x9f, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48,
|
||||
0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x32,
|
||||
0x4a, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0xce, 0xcd,
|
||||
0x2f, 0x86, 0x52, 0xba, 0xc5, 0x29, 0xd9, 0xfa, 0x15, 0xfa, 0xa0, 0x88, 0x35, 0x30, 0xd2, 0x85,
|
||||
0xc6, 0x6d, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0x25, 0xc6, 0x80, 0x00, 0x00, 0x00,
|
||||
0xff, 0xff, 0x38, 0x45, 0x52, 0x5c, 0xf6, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *IdentifiedClientState) Marshal() (dAtA []byte, err error) {
|
||||
|
@ -122,10 +197,54 @@ func (m *IdentifiedClientState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
|||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
if len(m.Id) > 0 {
|
||||
i -= len(m.Id)
|
||||
copy(dAtA[i:], m.Id)
|
||||
i = encodeVarintClient(dAtA, i, uint64(len(m.Id)))
|
||||
if len(m.ClientId) > 0 {
|
||||
i -= len(m.ClientId)
|
||||
copy(dAtA[i:], m.ClientId)
|
||||
i = encodeVarintClient(dAtA, i, uint64(len(m.ClientId)))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *ClientConsensusStates) 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 *ClientConsensusStates) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *ClientConsensusStates) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.ConsensusStates) > 0 {
|
||||
for iNdEx := len(m.ConsensusStates) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size, err := m.ConsensusStates[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintClient(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
}
|
||||
if len(m.ClientId) > 0 {
|
||||
i -= len(m.ClientId)
|
||||
copy(dAtA[i:], m.ClientId)
|
||||
i = encodeVarintClient(dAtA, i, uint64(len(m.ClientId)))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
|
@ -149,7 +268,7 @@ func (m *IdentifiedClientState) Size() (n int) {
|
|||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.Id)
|
||||
l = len(m.ClientId)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovClient(uint64(l))
|
||||
}
|
||||
|
@ -160,6 +279,25 @@ func (m *IdentifiedClientState) Size() (n int) {
|
|||
return n
|
||||
}
|
||||
|
||||
func (m *ClientConsensusStates) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.ClientId)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovClient(uint64(l))
|
||||
}
|
||||
if len(m.ConsensusStates) > 0 {
|
||||
for _, e := range m.ConsensusStates {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovClient(uint64(l))
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovClient(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
}
|
||||
|
@ -197,7 +335,7 @@ func (m *IdentifiedClientState) Unmarshal(dAtA []byte) error {
|
|||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType)
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field ClientId", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
|
@ -225,7 +363,7 @@ func (m *IdentifiedClientState) Unmarshal(dAtA []byte) error {
|
|||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Id = string(dAtA[iNdEx:postIndex])
|
||||
m.ClientId = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
|
@ -287,6 +425,125 @@ func (m *IdentifiedClientState) Unmarshal(dAtA []byte) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
func (m *ClientConsensusStates) 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 ErrIntOverflowClient
|
||||
}
|
||||
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: ClientConsensusStates: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: ClientConsensusStates: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field ClientId", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowClient
|
||||
}
|
||||
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 ErrInvalidLengthClient
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthClient
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.ClientId = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field ConsensusStates", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowClient
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthClient
|
||||
}
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthClient
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.ConsensusStates = append(m.ConsensusStates, &types.Any{})
|
||||
if err := m.ConsensusStates[len(m.ConsensusStates)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipClient(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if skippy < 0 {
|
||||
return ErrInvalidLengthClient
|
||||
}
|
||||
if (iNdEx + skippy) < 0 {
|
||||
return ErrInvalidLengthClient
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipClient(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
|
|
|
@ -53,6 +53,34 @@ func init() {
|
|||
amino.Seal()
|
||||
}
|
||||
|
||||
// PackClientState constructs a new Any packed with the given client state value. It returns
|
||||
// an error if the client state can't be casted to a protobuf message or if the concrete
|
||||
// implemention is not registered to the protobuf codec.
|
||||
func PackClientState(clientState exported.ClientState) (*codectypes.Any, error) {
|
||||
msg, ok := clientState.(proto.Message)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot proto marshal %T", clientState)
|
||||
}
|
||||
|
||||
anyClientState, err := codectypes.NewAnyWithValue(msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return anyClientState, nil
|
||||
}
|
||||
|
||||
// UnpackClientState unpacks an Any into a ClientState. It returns an error if the
|
||||
// client state can't be unpacked into a ClientState.
|
||||
func UnpackClientState(any *codectypes.Any) (exported.ClientState, error) {
|
||||
clientState, ok := any.GetCachedValue().(exported.ClientState)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot unpack Any into ClientState %T", any)
|
||||
}
|
||||
|
||||
return clientState, nil
|
||||
}
|
||||
|
||||
// PackConsensusState constructs a new Any packed with the given consensus state value. It returns
|
||||
// an error if the consensus state can't be casted to a protobuf message or if the concrete
|
||||
// implemention is not registered to the protobuf codec.
|
||||
|
|
|
@ -4,48 +4,18 @@ import (
|
|||
"fmt"
|
||||
"sort"
|
||||
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
|
||||
)
|
||||
|
||||
var (
|
||||
_ codectypes.UnpackInterfacesMessage = GenesisClientState{}
|
||||
_ codectypes.UnpackInterfacesMessage = IdentifiedClientState{}
|
||||
_ codectypes.UnpackInterfacesMessage = ClientsConsensusStates{}
|
||||
_ codectypes.UnpackInterfacesMessage = ClientConsensusStates{}
|
||||
_ codectypes.UnpackInterfacesMessage = GenesisState{}
|
||||
)
|
||||
|
||||
// NewGenesisClientState creates a new GenesisClientState instance.
|
||||
func NewGenesisClientState(clientID string, clientState exported.ClientState) GenesisClientState {
|
||||
msg, ok := clientState.(proto.Message)
|
||||
if !ok {
|
||||
panic(fmt.Errorf("cannot proto marshal %T", clientState))
|
||||
}
|
||||
|
||||
anyClientState, err := codectypes.NewAnyWithValue(msg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return GenesisClientState{
|
||||
ClientId: clientID,
|
||||
ClientState: anyClientState,
|
||||
}
|
||||
}
|
||||
|
||||
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
|
||||
func (gs GenesisClientState) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
|
||||
var clientState exported.ClientState
|
||||
err := unpacker.UnpackAny(gs.ClientState, &clientState)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ sort.Interface = ClientsConsensusStates{}
|
||||
|
||||
// ClientsConsensusStates defines a slice of ClientConsensusStates that supports the sort interface
|
||||
|
@ -104,7 +74,7 @@ func (ccs ClientConsensusStates) UnpackInterfaces(unpacker codectypes.AnyUnpacke
|
|||
|
||||
// NewGenesisState creates a GenesisState instance.
|
||||
func NewGenesisState(
|
||||
clients []GenesisClientState, clientsConsensus ClientsConsensusStates, createLocalhost bool,
|
||||
clients []IdentifiedClientState, clientsConsensus ClientsConsensusStates, createLocalhost bool,
|
||||
) GenesisState {
|
||||
return GenesisState{
|
||||
Clients: clients,
|
||||
|
@ -116,7 +86,7 @@ func NewGenesisState(
|
|||
// DefaultGenesisState returns the ibc client submodule's default genesis state.
|
||||
func DefaultGenesisState() GenesisState {
|
||||
return GenesisState{
|
||||
Clients: []GenesisClientState{},
|
||||
Clients: []IdentifiedClientState{},
|
||||
ClientsConsensus: ClientsConsensusStates{},
|
||||
CreateLocalhost: false,
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ package types
|
|||
|
||||
import (
|
||||
fmt "fmt"
|
||||
types "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
_ "github.com/gogo/protobuf/gogoproto"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
io "io"
|
||||
|
@ -24,124 +23,21 @@ var _ = math.Inf
|
|||
// proto package needs to be updated.
|
||||
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
// GenesisClientState defines an identified ClientState as protobuf Any format.
|
||||
type GenesisClientState struct {
|
||||
ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty" yaml:"client_id"`
|
||||
ClientState *types.Any `protobuf:"bytes,2,opt,name=client_state,json=clientState,proto3" json:"client_state,omitempty" yaml:"client_state"`
|
||||
}
|
||||
|
||||
func (m *GenesisClientState) Reset() { *m = GenesisClientState{} }
|
||||
func (m *GenesisClientState) String() string { return proto.CompactTextString(m) }
|
||||
func (*GenesisClientState) ProtoMessage() {}
|
||||
func (*GenesisClientState) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2eb5d7ff040be5c2, []int{0}
|
||||
}
|
||||
func (m *GenesisClientState) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *GenesisClientState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_GenesisClientState.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 *GenesisClientState) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_GenesisClientState.Merge(m, src)
|
||||
}
|
||||
func (m *GenesisClientState) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *GenesisClientState) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_GenesisClientState.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_GenesisClientState proto.InternalMessageInfo
|
||||
|
||||
func (m *GenesisClientState) GetClientId() string {
|
||||
if m != nil {
|
||||
return m.ClientId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *GenesisClientState) GetClientState() *types.Any {
|
||||
if m != nil {
|
||||
return m.ClientState
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClientConsensusStates defines all the stored consensus states for a given client.
|
||||
type ClientConsensusStates struct {
|
||||
ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"`
|
||||
ConsensusStates []*types.Any `protobuf:"bytes,2,rep,name=consensus_states,json=consensusStates,proto3" json:"consensus_states,omitempty" yaml:"consensus_states"`
|
||||
}
|
||||
|
||||
func (m *ClientConsensusStates) Reset() { *m = ClientConsensusStates{} }
|
||||
func (m *ClientConsensusStates) String() string { return proto.CompactTextString(m) }
|
||||
func (*ClientConsensusStates) ProtoMessage() {}
|
||||
func (*ClientConsensusStates) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2eb5d7ff040be5c2, []int{1}
|
||||
}
|
||||
func (m *ClientConsensusStates) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *ClientConsensusStates) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_ClientConsensusStates.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 *ClientConsensusStates) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_ClientConsensusStates.Merge(m, src)
|
||||
}
|
||||
func (m *ClientConsensusStates) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *ClientConsensusStates) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_ClientConsensusStates.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_ClientConsensusStates proto.InternalMessageInfo
|
||||
|
||||
func (m *ClientConsensusStates) GetClientId() string {
|
||||
if m != nil {
|
||||
return m.ClientId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *ClientConsensusStates) GetConsensusStates() []*types.Any {
|
||||
if m != nil {
|
||||
return m.ConsensusStates
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GenesisState defines the ibc client submodule's genesis state.
|
||||
type GenesisState struct {
|
||||
Clients []GenesisClientState `protobuf:"bytes,1,rep,name=clients,proto3" json:"clients"`
|
||||
// client states with their corresponding identifiers
|
||||
Clients []IdentifiedClientState `protobuf:"bytes,1,rep,name=clients,proto3" json:"clients"`
|
||||
// consensus states from each client
|
||||
ClientsConsensus ClientsConsensusStates `protobuf:"bytes,2,rep,name=clients_consensus,json=clientsConsensus,proto3,castrepeated=ClientsConsensusStates" json:"clients_consensus" yaml:"clients_consensus"`
|
||||
CreateLocalhost bool `protobuf:"varint,3,opt,name=create_localhost,json=createLocalhost,proto3" json:"create_localhost,omitempty" yaml:"create_localhost"`
|
||||
// create localhost on initialization
|
||||
CreateLocalhost bool `protobuf:"varint,3,opt,name=create_localhost,json=createLocalhost,proto3" json:"create_localhost,omitempty" yaml:"create_localhost"`
|
||||
}
|
||||
|
||||
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_2eb5d7ff040be5c2, []int{2}
|
||||
return fileDescriptor_2eb5d7ff040be5c2, []int{0}
|
||||
}
|
||||
func (m *GenesisState) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
|
@ -170,7 +66,7 @@ func (m *GenesisState) XXX_DiscardUnknown() {
|
|||
|
||||
var xxx_messageInfo_GenesisState proto.InternalMessageInfo
|
||||
|
||||
func (m *GenesisState) GetClients() []GenesisClientState {
|
||||
func (m *GenesisState) GetClients() []IdentifiedClientState {
|
||||
if m != nil {
|
||||
return m.Clients
|
||||
}
|
||||
|
@ -192,128 +88,33 @@ func (m *GenesisState) GetCreateLocalhost() bool {
|
|||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*GenesisClientState)(nil), "ibc.client.GenesisClientState")
|
||||
proto.RegisterType((*ClientConsensusStates)(nil), "ibc.client.ClientConsensusStates")
|
||||
proto.RegisterType((*GenesisState)(nil), "ibc.client.GenesisState")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("ibc/client/genesis.proto", fileDescriptor_2eb5d7ff040be5c2) }
|
||||
|
||||
var fileDescriptor_2eb5d7ff040be5c2 = []byte{
|
||||
// 432 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x52, 0xbf, 0x8e, 0xd3, 0x30,
|
||||
0x1c, 0x8e, 0x7b, 0x08, 0xee, 0x7c, 0x27, 0x11, 0x42, 0xe1, 0xc2, 0x9d, 0x94, 0x04, 0x4f, 0x5d,
|
||||
0xce, 0x86, 0xb2, 0xdd, 0x80, 0x44, 0x4e, 0x02, 0x21, 0xdd, 0x80, 0xc2, 0x86, 0x90, 0xaa, 0xc4,
|
||||
0x35, 0xb9, 0x88, 0x34, 0xae, 0x6a, 0x57, 0x22, 0xaf, 0xc0, 0x84, 0xd8, 0x98, 0xd9, 0x78, 0x92,
|
||||
0x8e, 0x1d, 0x99, 0x02, 0x6a, 0xdf, 0x20, 0x4f, 0x80, 0x62, 0x27, 0x6d, 0x9a, 0x72, 0x53, 0x9c,
|
||||
0xef, 0xf7, 0xfb, 0xfe, 0xe8, 0xb3, 0xa1, 0x9d, 0x44, 0x94, 0xd0, 0x34, 0x61, 0x99, 0x24, 0x31,
|
||||
0xcb, 0x98, 0x48, 0x04, 0x9e, 0xce, 0xb8, 0xe4, 0x16, 0x4c, 0x22, 0x8a, 0xf5, 0xe4, 0xac, 0x1f,
|
||||
0xf3, 0x98, 0x2b, 0x98, 0x54, 0x27, 0xbd, 0x71, 0xf6, 0x24, 0xe6, 0x3c, 0x4e, 0x19, 0x51, 0x7f,
|
||||
0xd1, 0xfc, 0x13, 0x09, 0xb3, 0x5c, 0x8f, 0xd0, 0x0f, 0x00, 0xad, 0x37, 0x5a, 0xee, 0x4a, 0x49,
|
||||
0xbc, 0x97, 0xa1, 0x64, 0xd6, 0x73, 0x78, 0xa4, 0x15, 0x47, 0xc9, 0xd8, 0x06, 0x1e, 0x18, 0x1c,
|
||||
0xf9, 0xfd, 0xb2, 0x70, 0xcd, 0x3c, 0x9c, 0xa4, 0x97, 0x68, 0x33, 0x42, 0xc1, 0xa1, 0x3e, 0xbf,
|
||||
0x1d, 0x5b, 0xef, 0xe0, 0x49, 0x8d, 0x8b, 0x4a, 0xc2, 0xee, 0x79, 0x60, 0x70, 0x3c, 0xec, 0x63,
|
||||
0xed, 0x8d, 0x1b, 0x6f, 0xfc, 0x2a, 0xcb, 0xfd, 0xd3, 0xb2, 0x70, 0x1f, 0xee, 0x68, 0x29, 0x0e,
|
||||
0x0a, 0x8e, 0xe9, 0x36, 0x04, 0xfa, 0x0e, 0xe0, 0x23, 0x1d, 0xea, 0x8a, 0x67, 0x82, 0x65, 0x62,
|
||||
0x2e, 0xd4, 0x40, 0x58, 0xe7, 0x7b, 0xf1, 0x5a, 0x41, 0x3e, 0x42, 0x93, 0x36, 0xfb, 0x5a, 0x57,
|
||||
0xd8, 0x3d, 0xef, 0xe0, 0xd6, 0x30, 0xe7, 0x65, 0xe1, 0x9e, 0xd6, 0x61, 0x3a, 0x3c, 0x14, 0xdc,
|
||||
0xa7, 0xbb, 0xd6, 0xe8, 0x67, 0x0f, 0x9e, 0xd4, 0x85, 0xe9, 0xaa, 0x5e, 0xc2, 0x7b, 0xda, 0x5a,
|
||||
0xd8, 0x40, 0xb9, 0x38, 0x78, 0x7b, 0x21, 0x78, 0xbf, 0x5b, 0xff, 0xce, 0xa2, 0x70, 0x8d, 0xa0,
|
||||
0x21, 0x59, 0x5f, 0x01, 0x7c, 0x50, 0x9f, 0x47, 0x1b, 0xb3, 0x3a, 0xf0, 0xd3, 0xb6, 0xd4, 0x7f,
|
||||
0xab, 0xf0, 0x2f, 0x2b, 0xb5, 0xb2, 0x70, 0xed, 0x76, 0x9d, 0x2d, 0x25, 0xf4, 0xeb, 0x8f, 0xfb,
|
||||
0x58, 0x53, 0x45, 0x87, 0x1b, 0x98, 0xb4, 0x83, 0x5b, 0xaf, 0xa1, 0x49, 0x67, 0x2c, 0x94, 0x6c,
|
||||
0x94, 0x72, 0x1a, 0xa6, 0x37, 0x5c, 0x48, 0xfb, 0xc0, 0x03, 0x83, 0xc3, 0x9d, 0x96, 0x3a, 0x1b,
|
||||
0x55, 0x4b, 0x0a, 0xba, 0x6e, 0x10, 0xff, 0x7a, 0xb1, 0x72, 0xc0, 0x72, 0xe5, 0x80, 0xbf, 0x2b,
|
||||
0x07, 0x7c, 0x5b, 0x3b, 0xc6, 0x72, 0xed, 0x18, 0xbf, 0xd7, 0x8e, 0xf1, 0x61, 0x18, 0x27, 0xf2,
|
||||
0x66, 0x1e, 0x61, 0xca, 0x27, 0x84, 0x72, 0x31, 0xe1, 0xa2, 0xfe, 0x5c, 0x88, 0xf1, 0x67, 0xf2,
|
||||
0x85, 0x54, 0xcf, 0xfc, 0xd9, 0xf0, 0xa2, 0x7e, 0xe9, 0x32, 0x9f, 0x32, 0x11, 0xdd, 0x55, 0xf7,
|
||||
0xf5, 0xe2, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x63, 0xf9, 0x67, 0x68, 0x04, 0x03, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *GenesisClientState) 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 *GenesisClientState) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *GenesisClientState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if m.ClientState != nil {
|
||||
{
|
||||
size, err := m.ClientState.MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
if len(m.ClientId) > 0 {
|
||||
i -= len(m.ClientId)
|
||||
copy(dAtA[i:], m.ClientId)
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(len(m.ClientId)))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *ClientConsensusStates) 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 *ClientConsensusStates) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *ClientConsensusStates) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.ConsensusStates) > 0 {
|
||||
for iNdEx := len(m.ConsensusStates) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size, err := m.ConsensusStates[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
}
|
||||
if len(m.ClientId) > 0 {
|
||||
i -= len(m.ClientId)
|
||||
copy(dAtA[i:], m.ClientId)
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(len(m.ClientId)))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
// 313 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xc8, 0x4c, 0x4a, 0xd6,
|
||||
0x4f, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b,
|
||||
0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0xca, 0x4c, 0x4a, 0xd6, 0x83, 0xc8, 0x48, 0x89, 0x23, 0xa9,
|
||||
0x82, 0x50, 0x10, 0x45, 0x52, 0x22, 0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0xa6, 0x3e, 0x88, 0x05, 0x11,
|
||||
0x55, 0x5a, 0xc6, 0xc4, 0xc5, 0xe3, 0x0e, 0x31, 0x2c, 0xb8, 0x24, 0xb1, 0x24, 0x55, 0xc8, 0x91,
|
||||
0x8b, 0x1d, 0xa2, 0xad, 0x58, 0x82, 0x51, 0x81, 0x59, 0x83, 0xdb, 0x48, 0x51, 0x0f, 0x61, 0xba,
|
||||
0x9e, 0x67, 0x4a, 0x6a, 0x5e, 0x49, 0x66, 0x5a, 0x66, 0x6a, 0x8a, 0x33, 0x58, 0x00, 0xac, 0xc7,
|
||||
0x89, 0xe5, 0xc4, 0x3d, 0x79, 0x86, 0x20, 0x98, 0x3e, 0xa1, 0x2e, 0x46, 0x2e, 0x41, 0x28, 0x3b,
|
||||
0x3e, 0x39, 0x3f, 0xaf, 0x38, 0x35, 0xaf, 0xb8, 0xb4, 0x58, 0x82, 0x09, 0xd3, 0x34, 0x88, 0x19,
|
||||
0xce, 0x30, 0x25, 0x60, 0xc3, 0x8a, 0x9d, 0xac, 0x40, 0xa6, 0x7d, 0xba, 0x27, 0x2f, 0x51, 0x99,
|
||||
0x98, 0x9b, 0x63, 0xa5, 0x84, 0x61, 0x92, 0xd2, 0xaa, 0xfb, 0xf2, 0x62, 0x10, 0xad, 0xc5, 0x68,
|
||||
0x7a, 0x83, 0x04, 0x92, 0xd1, 0xc4, 0x85, 0xdc, 0xb8, 0x04, 0x92, 0x8b, 0x52, 0x13, 0x4b, 0x52,
|
||||
0xe3, 0x73, 0xf2, 0x93, 0x13, 0x73, 0x32, 0xf2, 0x8b, 0x4b, 0x24, 0x98, 0x15, 0x18, 0x35, 0x38,
|
||||
0x9c, 0xa4, 0x3f, 0xdd, 0x93, 0x17, 0x87, 0xda, 0x81, 0xa6, 0x42, 0x29, 0x88, 0x1f, 0x22, 0xe4,
|
||||
0x03, 0x13, 0x71, 0xf2, 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, 0xa3,
|
||||
0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xe4, 0xfc, 0xe2, 0xdc, 0xfc,
|
||||
0x62, 0x28, 0xa5, 0x5b, 0x9c, 0x92, 0xad, 0x5f, 0xa1, 0x0f, 0x8a, 0x10, 0x03, 0x23, 0x5d, 0x68,
|
||||
0x9c, 0x94, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x43, 0xdf, 0x18, 0x10, 0x00, 0x00, 0xff,
|
||||
0xff, 0xe0, 0x1c, 0x5d, 0xa3, 0xd4, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *GenesisState) Marshal() (dAtA []byte, err error) {
|
||||
|
@ -388,42 +189,6 @@ func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int {
|
|||
dAtA[offset] = uint8(v)
|
||||
return base
|
||||
}
|
||||
func (m *GenesisClientState) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.ClientId)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
if m.ClientState != nil {
|
||||
l = m.ClientState.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *ClientConsensusStates) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.ClientId)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
if len(m.ConsensusStates) > 0 {
|
||||
for _, e := range m.ConsensusStates {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *GenesisState) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
|
@ -454,246 +219,6 @@ func sovGenesis(x uint64) (n int) {
|
|||
func sozGenesis(x uint64) (n int) {
|
||||
return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||
}
|
||||
func (m *GenesisClientState) 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: GenesisClientState: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: GenesisClientState: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field ClientId", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
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 ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.ClientId = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field ClientState", 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
|
||||
}
|
||||
if m.ClientState == nil {
|
||||
m.ClientState = &types.Any{}
|
||||
}
|
||||
if err := m.ClientState.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 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if (iNdEx + skippy) < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *ClientConsensusStates) 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: ClientConsensusStates: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: ClientConsensusStates: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field ClientId", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
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 ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.ClientId = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field ConsensusStates", 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.ConsensusStates = append(m.ConsensusStates, &types.Any{})
|
||||
if err := m.ConsensusStates[len(m.ConsensusStates)-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 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if (iNdEx + skippy) < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *GenesisState) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
|
@ -752,7 +277,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error {
|
|||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Clients = append(m.Clients, GenesisClientState{})
|
||||
m.Clients = append(m.Clients, IdentifiedClientState{})
|
||||
if err := m.Clients[len(m.Clients)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -47,11 +47,11 @@ func TestValidateGenesis(t *testing.T) {
|
|||
{
|
||||
name: "valid genesis",
|
||||
genState: types.NewGenesisState(
|
||||
[]types.GenesisClientState{
|
||||
types.NewGenesisClientState(
|
||||
[]types.IdentifiedClientState{
|
||||
types.NewIdentifiedClientState(
|
||||
clientID, ibctmtypes.NewClientState(chainID, ibctesting.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
||||
),
|
||||
types.NewGenesisClientState(
|
||||
types.NewIdentifiedClientState(
|
||||
exported.ClientTypeLocalHost, localhosttypes.NewClientState("chainID", 10),
|
||||
),
|
||||
},
|
||||
|
@ -72,11 +72,11 @@ func TestValidateGenesis(t *testing.T) {
|
|||
{
|
||||
name: "invalid clientid",
|
||||
genState: types.NewGenesisState(
|
||||
[]types.GenesisClientState{
|
||||
types.NewGenesisClientState(
|
||||
[]types.IdentifiedClientState{
|
||||
types.NewIdentifiedClientState(
|
||||
"/~@$*", ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
||||
),
|
||||
types.NewGenesisClientState(
|
||||
types.NewIdentifiedClientState(
|
||||
exported.ClientTypeLocalHost, localhosttypes.NewClientState("chainID", 10),
|
||||
),
|
||||
},
|
||||
|
@ -97,11 +97,11 @@ func TestValidateGenesis(t *testing.T) {
|
|||
{
|
||||
name: "invalid client",
|
||||
genState: types.NewGenesisState(
|
||||
[]types.GenesisClientState{
|
||||
types.NewGenesisClientState(
|
||||
[]types.IdentifiedClientState{
|
||||
types.NewIdentifiedClientState(
|
||||
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
||||
),
|
||||
types.NewGenesisClientState(exported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 0)),
|
||||
types.NewIdentifiedClientState(exported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 0)),
|
||||
},
|
||||
nil,
|
||||
true,
|
||||
|
@ -111,11 +111,11 @@ func TestValidateGenesis(t *testing.T) {
|
|||
{
|
||||
name: "invalid consensus state",
|
||||
genState: types.NewGenesisState(
|
||||
[]types.GenesisClientState{
|
||||
types.NewGenesisClientState(
|
||||
[]types.IdentifiedClientState{
|
||||
types.NewIdentifiedClientState(
|
||||
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
||||
),
|
||||
types.NewGenesisClientState(
|
||||
types.NewIdentifiedClientState(
|
||||
exported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 10),
|
||||
),
|
||||
},
|
||||
|
@ -136,11 +136,11 @@ func TestValidateGenesis(t *testing.T) {
|
|||
{
|
||||
name: "invalid consensus state",
|
||||
genState: types.NewGenesisState(
|
||||
[]types.GenesisClientState{
|
||||
types.NewGenesisClientState(
|
||||
[]types.IdentifiedClientState{
|
||||
types.NewIdentifiedClientState(
|
||||
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
||||
),
|
||||
types.NewGenesisClientState(
|
||||
types.NewIdentifiedClientState(
|
||||
exported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 10),
|
||||
),
|
||||
},
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
tmcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
|
||||
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
|
||||
)
|
||||
|
||||
// query routes supported by the IBC client Querier
|
||||
const (
|
||||
QueryAllClients = "client_states"
|
||||
)
|
||||
|
||||
// QueryAllClientsParams defines the parameters necessary for querying for all
|
||||
// light client states.
|
||||
type QueryAllClientsParams struct {
|
||||
Page int `json:"page" yaml:"page"`
|
||||
Limit int `json:"limit" yaml:"limit"`
|
||||
}
|
||||
|
||||
// NewQueryAllClientsParams creates a new QueryAllClientsParams instance.
|
||||
func NewQueryAllClientsParams(page, limit int) QueryAllClientsParams {
|
||||
return QueryAllClientsParams{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
}
|
||||
}
|
||||
|
||||
// StateResponse defines the client response for a client state query.
|
||||
// It includes the commitment proof and the height of the proof.
|
||||
type StateResponse struct {
|
||||
ClientState exported.ClientState `json:"client_state" yaml:"client_state"`
|
||||
Proof commitmenttypes.MerkleProof `json:"proof,omitempty" yaml:"proof,omitempty"`
|
||||
ProofPath commitmenttypes.MerklePath `json:"proof_path,omitempty" yaml:"proof_path,omitempty"`
|
||||
ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"`
|
||||
}
|
||||
|
||||
// NewClientStateResponse creates a new StateResponse instance.
|
||||
func NewClientStateResponse(
|
||||
clientID string, clientState exported.ClientState, proof *tmcrypto.ProofOps, height int64,
|
||||
) StateResponse {
|
||||
return StateResponse{
|
||||
ClientState: clientState,
|
||||
Proof: commitmenttypes.MerkleProof{Proof: proof},
|
||||
ProofPath: commitmenttypes.NewMerklePath(append([]string{clientID}, strings.Split(host.ClientStatePath(), "/")...)),
|
||||
ProofHeight: uint64(height),
|
||||
}
|
||||
}
|
||||
|
||||
// ConsensusStateResponse defines the client response for a Consensus state query.
|
||||
// It includes the commitment proof and the height of the proof.
|
||||
type ConsensusStateResponse struct {
|
||||
ConsensusState exported.ConsensusState `json:"consensus_state" yaml:"consensus_state"`
|
||||
Proof commitmenttypes.MerkleProof `json:"proof,omitempty" yaml:"proof,omitempty"`
|
||||
ProofPath commitmenttypes.MerklePath `json:"proof_path,omitempty" yaml:"proof_path,omitempty"`
|
||||
ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"`
|
||||
}
|
||||
|
||||
// NewConsensusStateResponse creates a new ConsensusStateResponse instance.
|
||||
func NewConsensusStateResponse(
|
||||
clientID string, cs exported.ConsensusState, proof *tmcrypto.ProofOps, height int64,
|
||||
) ConsensusStateResponse {
|
||||
return ConsensusStateResponse{
|
||||
ConsensusState: cs,
|
||||
Proof: commitmenttypes.MerkleProof{Proof: proof},
|
||||
ProofPath: commitmenttypes.NewMerklePath(append([]string{clientID}, strings.Split(host.ClientStatePath(), "/")...)),
|
||||
ProofHeight: uint64(height),
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
|
||||
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
|
||||
)
|
||||
|
||||
// NewQueryClientStateResponse creates a new QueryClientStateResponse instance.
|
||||
func NewQueryClientStateResponse(
|
||||
clientID string, clientStateAny *codectypes.Any, proof []byte, height int64,
|
||||
) *QueryClientStateResponse {
|
||||
path := commitmenttypes.NewMerklePath(append([]string{clientID}, strings.Split(host.ClientStatePath(), "/")...))
|
||||
return &QueryClientStateResponse{
|
||||
ClientState: clientStateAny,
|
||||
Proof: proof,
|
||||
ProofPath: path.Pretty(),
|
||||
ProofHeight: uint64(height),
|
||||
}
|
||||
}
|
||||
|
||||
// NewQueryConsensusStateResponse creates a new QueryConsensusStateResponse instance.
|
||||
func NewQueryConsensusStateResponse(
|
||||
clientID string, consensusStateAny *codectypes.Any, proof []byte, height int64,
|
||||
) *QueryConsensusStateResponse {
|
||||
path := commitmenttypes.NewMerklePath(strings.Split(host.FullClientPath(clientID, host.ConsensusStatePath(uint64(height))), "/"))
|
||||
return &QueryConsensusStateResponse{
|
||||
ConsensusState: consensusStateAny,
|
||||
Proof: proof,
|
||||
ProofPath: path.Pretty(),
|
||||
ProofHeight: uint64(height),
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,518 @@
|
|||
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
|
||||
// source: ibc/client/query.proto
|
||||
|
||||
/*
|
||||
Package types is a reverse proxy.
|
||||
|
||||
It translates gRPC into RESTful JSON APIs.
|
||||
*/
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
"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"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
"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_ClientState_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryClientStateRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["client_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "client_id")
|
||||
}
|
||||
|
||||
protoReq.ClientId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "client_id", err)
|
||||
}
|
||||
|
||||
msg, err := client.ClientState(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_ClientState_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryClientStateRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["client_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "client_id")
|
||||
}
|
||||
|
||||
protoReq.ClientId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "client_id", err)
|
||||
}
|
||||
|
||||
msg, err := server.ClientState(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_Query_ClientStates_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
|
||||
func request_Query_ClientStates_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryClientStatesRequest
|
||||
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_ClientStates_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.ClientStates(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_ClientStates_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryClientStatesRequest
|
||||
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_ClientStates_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.ClientStates(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_Query_ConsensusState_0 = &utilities.DoubleArray{Encoding: map[string]int{"client_id": 0, "height": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}}
|
||||
)
|
||||
|
||||
func request_Query_ConsensusState_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryConsensusStateRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["client_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "client_id")
|
||||
}
|
||||
|
||||
protoReq.ClientId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "client_id", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["height"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "height")
|
||||
}
|
||||
|
||||
protoReq.Height, err = runtime.Uint64(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "height", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ConsensusState_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.ConsensusState(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_ConsensusState_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryConsensusStateRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["client_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "client_id")
|
||||
}
|
||||
|
||||
protoReq.ClientId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "client_id", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["height"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "height")
|
||||
}
|
||||
|
||||
protoReq.Height, err = runtime.Uint64(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "height", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ConsensusState_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.ConsensusState(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_Query_ConsensusStates_0 = &utilities.DoubleArray{Encoding: map[string]int{"client_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
|
||||
)
|
||||
|
||||
func request_Query_ConsensusStates_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryConsensusStatesRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["client_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "client_id")
|
||||
}
|
||||
|
||||
protoReq.ClientId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "client_id", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ConsensusStates_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.ConsensusStates(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_ConsensusStates_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryConsensusStatesRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["client_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "client_id")
|
||||
}
|
||||
|
||||
protoReq.ClientId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "client_id", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ConsensusStates_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.ConsensusStates(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_ClientState_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_ClientState_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_ClientState_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_ClientStates_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_ClientStates_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_ClientStates_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_ConsensusState_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_ConsensusState_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_ConsensusState_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_ConsensusStates_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_ConsensusStates_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_ConsensusStates_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) {
|
||||
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_ClientState_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_ClientState_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_ClientState_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_ClientStates_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_ClientStates_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_ClientStates_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_ConsensusState_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_ConsensusState_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_ConsensusState_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_ConsensusStates_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_ConsensusStates_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_ConsensusStates_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
pattern_Query_ClientState_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"ibc", "client", "v1beta1", "client_states", "client_id"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_Query_ClientStates_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"ibc", "client", "v1beta1", "client_states"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_Query_ConsensusState_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"ibc", "client", "v1beta1", "consensus_states", "client_id", "height"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_Query_ConsensusStates_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"ibc", "client", "v1beta1", "consensus_states", "client_id"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
)
|
||||
|
||||
var (
|
||||
forward_Query_ClientState_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_ClientStates_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_ConsensusState_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_ConsensusStates_0 = runtime.ForwardResponseMessage
|
||||
)
|
|
@ -122,14 +122,18 @@ func QueryConnectionClientState(
|
|||
}
|
||||
|
||||
if prove {
|
||||
clientState, proof, proofHeight, err := clientutils.QueryClientStateABCI(clientCtx, res.IdentifiedClientState.Id)
|
||||
clientStateRes, err := clientutils.QueryClientStateABCI(clientCtx, res.IdentifiedClientState.ClientId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// use client state returned from ABCI query in case query height differs
|
||||
identifiedClientState := clienttypes.NewIdentifiedClientState(res.IdentifiedClientState.Id, clientState)
|
||||
res = types.NewQueryConnectionClientStateResponse(identifiedClientState, proof, int64(proofHeight))
|
||||
identifiedClientState := clienttypes.IdentifiedClientState{
|
||||
ClientId: res.IdentifiedClientState.ClientId,
|
||||
ClientState: clientStateRes.ClientState,
|
||||
}
|
||||
|
||||
res = types.NewQueryConnectionClientStateResponse(identifiedClientState, clientStateRes.Proof, int64(clientStateRes.ProofHeight))
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
@ -159,18 +163,12 @@ func QueryConnectionConsensusState(
|
|||
}
|
||||
|
||||
if prove {
|
||||
consensusState, proof, proofHeight, err := clientutils.QueryConsensusStateABCI(clientCtx, res.ClientId, consensusState.GetHeight())
|
||||
consensusStateRes, err := clientutils.QueryConsensusStateABCI(clientCtx, res.ClientId, consensusState.GetHeight())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// use consensus state returned from ABCI query in case query height differs
|
||||
anyConsensusState, err := clienttypes.PackConsensusState(consensusState)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = types.NewQueryConnectionConsensusStateResponse(res.ClientId, anyConsensusState, consensusState.GetHeight(), proof, int64(proofHeight))
|
||||
res = types.NewQueryConnectionConsensusStateResponse(res.ClientId, consensusStateRes.ConsensusState, consensusState.GetHeight(), consensusStateRes.Proof, int64(consensusStateRes.ProofHeight))
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
|
|
@ -44,7 +44,7 @@ func NewQueryClientConnectionsRequest(clientID string) *QueryClientConnectionsRe
|
|||
|
||||
// NewQueryConnectionClientStateResponse creates a newQueryConnectionClientStateResponse instance
|
||||
func NewQueryConnectionClientStateResponse(identifiedClientState clienttypes.IdentifiedClientState, proof []byte, height int64) *QueryConnectionClientStateResponse {
|
||||
path := commitmenttypes.NewMerklePath(strings.Split(host.FullClientPath(identifiedClientState.Id, host.ClientStatePath()), "/"))
|
||||
path := commitmenttypes.NewMerklePath(strings.Split(host.FullClientPath(identifiedClientState.ClientId, host.ClientStatePath()), "/"))
|
||||
return &QueryConnectionClientStateResponse{
|
||||
IdentifiedClientState: &identifiedClientState,
|
||||
Proof: proof,
|
||||
|
|
|
@ -122,14 +122,17 @@ func QueryChannelClientState(
|
|||
}
|
||||
|
||||
if prove {
|
||||
clientState, proof, proofHeight, err := clientutils.QueryClientStateABCI(clientCtx, res.IdentifiedClientState.Id)
|
||||
clientStateRes, err := clientutils.QueryClientStateABCI(clientCtx, res.IdentifiedClientState.ClientId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// use client state returned from ABCI query in case query height differs
|
||||
identifiedClientState := clienttypes.NewIdentifiedClientState(res.IdentifiedClientState.Id, clientState)
|
||||
res = types.NewQueryChannelClientStateResponse(identifiedClientState, proof, int64(proofHeight))
|
||||
identifiedClientState := clienttypes.IdentifiedClientState{
|
||||
ClientId: res.IdentifiedClientState.ClientId,
|
||||
ClientState: clientStateRes.ClientState,
|
||||
}
|
||||
res = types.NewQueryChannelClientStateResponse(identifiedClientState, clientStateRes.Proof, int64(clientStateRes.ProofHeight))
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
@ -160,18 +163,12 @@ func QueryChannelConsensusState(
|
|||
}
|
||||
|
||||
if prove {
|
||||
consensusState, proof, proofHeight, err := clientutils.QueryConsensusStateABCI(clientCtx, res.ClientId, consensusState.GetHeight())
|
||||
consensusStateRes, err := clientutils.QueryConsensusStateABCI(clientCtx, res.ClientId, consensusState.GetHeight())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// use consensus state returned from ABCI query in case query height differs
|
||||
anyConsensusState, err := clienttypes.PackConsensusState(consensusState)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = types.NewQueryChannelConsensusStateResponse(res.ClientId, anyConsensusState, consensusState.GetHeight(), proof, int64(proofHeight))
|
||||
res = types.NewQueryChannelConsensusStateResponse(res.ClientId, consensusStateRes.ConsensusState, consensusState.GetHeight(), consensusStateRes.Proof, int64(consensusStateRes.ProofHeight))
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
|
|
@ -22,7 +22,7 @@ func NewQueryChannelResponse(portID, channelID string, channel Channel, proof []
|
|||
|
||||
// NewQueryChannelClientStateResponse creates a newQueryChannelClientStateResponse instance
|
||||
func NewQueryChannelClientStateResponse(identifiedClientState clienttypes.IdentifiedClientState, proof []byte, height int64) *QueryChannelClientStateResponse {
|
||||
path := commitmenttypes.NewMerklePath(strings.Split(host.FullClientPath(identifiedClientState.Id, host.ClientStatePath()), "/"))
|
||||
path := commitmenttypes.NewMerklePath(strings.Split(host.FullClientPath(identifiedClientState.ClientId, host.ClientStatePath()), "/"))
|
||||
return &QueryChannelClientStateResponse{
|
||||
IdentifiedClientState: &identifiedClientState,
|
||||
Proof: proof,
|
||||
|
|
|
@ -17,7 +17,7 @@ func RemovePath(paths []string, path string) ([]string, bool) {
|
|||
}
|
||||
|
||||
// ParseConnectionPath returns the connection ID from a full path. It returns
|
||||
// an error if the provided path is invalid,
|
||||
// an error if the provided path is invalid.
|
||||
func ParseConnectionPath(path string) (string, error) {
|
||||
split := strings.Split(path, "/")
|
||||
if len(split) != 2 {
|
||||
|
@ -28,7 +28,7 @@ func ParseConnectionPath(path string) (string, error) {
|
|||
}
|
||||
|
||||
// ParseChannelPath returns the port and channel ID from a full path. It returns
|
||||
// an error if the provided path is invalid,
|
||||
// an error if the provided path is invalid.
|
||||
func ParseChannelPath(path string) (string, string, error) {
|
||||
split := strings.Split(path, "/")
|
||||
if len(split) < 5 {
|
||||
|
@ -43,7 +43,7 @@ func ParseChannelPath(path string) (string, string, error) {
|
|||
}
|
||||
|
||||
// MustParseConnectionPath returns the connection ID from a full path. Panics
|
||||
// if the provided path is invalid
|
||||
// if the provided path is invalid.
|
||||
func MustParseConnectionPath(path string) string {
|
||||
connectionID, err := ParseConnectionPath(path)
|
||||
if err != nil {
|
||||
|
@ -53,7 +53,7 @@ func MustParseConnectionPath(path string) string {
|
|||
}
|
||||
|
||||
// MustParseChannelPath returns the port and channel ID from a full path. Panics
|
||||
// if the provided path is invalid
|
||||
// if the provided path is invalid.
|
||||
func MustParseChannelPath(path string) (string, string) {
|
||||
portID, channelID, err := ParseChannelPath(path)
|
||||
if err != nil {
|
||||
|
|
|
@ -35,11 +35,11 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
|
|||
name: "valid genesis",
|
||||
genState: &types.GenesisState{
|
||||
ClientGenesis: clienttypes.NewGenesisState(
|
||||
[]clienttypes.GenesisClientState{
|
||||
clienttypes.NewGenesisClientState(
|
||||
[]clienttypes.IdentifiedClientState{
|
||||
clienttypes.NewIdentifiedClientState(
|
||||
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
||||
),
|
||||
clienttypes.NewGenesisClientState(
|
||||
clienttypes.NewIdentifiedClientState(
|
||||
clientexported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 10),
|
||||
),
|
||||
},
|
||||
|
@ -95,11 +95,11 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
|
|||
name: "invalid client genesis",
|
||||
genState: &types.GenesisState{
|
||||
ClientGenesis: clienttypes.NewGenesisState(
|
||||
[]clienttypes.GenesisClientState{
|
||||
clienttypes.NewGenesisClientState(
|
||||
[]clienttypes.IdentifiedClientState{
|
||||
clienttypes.NewIdentifiedClientState(
|
||||
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
||||
),
|
||||
clienttypes.NewGenesisClientState(
|
||||
clienttypes.NewIdentifiedClientState(
|
||||
clientexported.ClientTypeLocalHost, localhosttypes.NewClientState("(chaindID)", 0),
|
||||
),
|
||||
},
|
||||
|
@ -164,11 +164,11 @@ func (suite *IBCTestSuite) TestInitGenesis() {
|
|||
name: "valid genesis",
|
||||
genState: &types.GenesisState{
|
||||
ClientGenesis: clienttypes.NewGenesisState(
|
||||
[]clienttypes.GenesisClientState{
|
||||
clienttypes.NewGenesisClientState(
|
||||
[]clienttypes.IdentifiedClientState{
|
||||
clienttypes.NewIdentifiedClientState(
|
||||
clientID, ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs()),
|
||||
),
|
||||
clienttypes.NewGenesisClientState(
|
||||
clienttypes.NewIdentifiedClientState(
|
||||
clientexported.ClientTypeLocalHost, localhosttypes.NewClientState("chaindID", 10),
|
||||
),
|
||||
},
|
||||
|
|
|
@ -3,10 +3,31 @@ package keeper
|
|||
import (
|
||||
"context"
|
||||
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
|
||||
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
|
||||
)
|
||||
|
||||
// ClientState implements the IBC QueryServer interface
|
||||
func (q Keeper) ClientState(c context.Context, req *clienttypes.QueryClientStateRequest) (*clienttypes.QueryClientStateResponse, error) {
|
||||
return q.ClientKeeper.ClientState(c, req)
|
||||
}
|
||||
|
||||
// ClientStates implements the IBC QueryServer interface
|
||||
func (q Keeper) ClientStates(c context.Context, req *clienttypes.QueryClientStatesRequest) (*clienttypes.QueryClientStatesResponse, error) {
|
||||
return q.ClientKeeper.ClientStates(c, req)
|
||||
}
|
||||
|
||||
// ConsensusState implements the IBC QueryServer interface
|
||||
func (q Keeper) ConsensusState(c context.Context, req *clienttypes.QueryConsensusStateRequest) (*clienttypes.QueryConsensusStateResponse, error) {
|
||||
return q.ClientKeeper.ConsensusState(c, req)
|
||||
}
|
||||
|
||||
// ConsensusStates implements the IBC QueryServer interface
|
||||
func (q Keeper) ConsensusStates(c context.Context, req *clienttypes.QueryConsensusStatesRequest) (*clienttypes.QueryConsensusStatesResponse, error) {
|
||||
return q.ClientKeeper.ConsensusStates(c, req)
|
||||
}
|
||||
|
||||
// Connection implements the IBC QueryServer interface
|
||||
func (q Keeper) Connection(c context.Context, req *connectiontypes.QueryConnectionRequest) (*connectiontypes.QueryConnectionResponse, error) {
|
||||
return q.ConnectionKeeper.Connection(c, req)
|
||||
|
|
|
@ -15,21 +15,18 @@ import (
|
|||
type KeeperTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
cdc *codec.LegacyAmino
|
||||
ctx sdk.Context
|
||||
keeper *keeper.Keeper
|
||||
querier sdk.Querier
|
||||
cdc *codec.LegacyAmino
|
||||
ctx sdk.Context
|
||||
keeper *keeper.Keeper
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) SetupTest() {
|
||||
isCheckTx := false
|
||||
app := simapp.Setup(isCheckTx)
|
||||
legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino())
|
||||
|
||||
suite.cdc = app.LegacyAmino()
|
||||
suite.ctx = app.BaseApp.NewContext(isCheckTx, tmproto.Header{})
|
||||
suite.keeper = app.IBCKeeper
|
||||
suite.querier = keeper.NewQuerier(*app.IBCKeeper, legacyQuerierCdc)
|
||||
}
|
||||
|
||||
func TestKeeperTestSuite(t *testing.T) {
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
package keeper
|
||||
|
||||
import (
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
clientkeeper "github.com/cosmos/cosmos-sdk/x/ibc/02-client/keeper"
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
|
||||
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
|
||||
)
|
||||
|
||||
// NewQuerier creates a querier for the IBC module
|
||||
func NewQuerier(k Keeper, legacyQuerierCdc codec.JSONMarshaler) sdk.Querier {
|
||||
return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) {
|
||||
var (
|
||||
res []byte
|
||||
err error
|
||||
)
|
||||
|
||||
switch path[0] {
|
||||
case clienttypes.SubModuleName:
|
||||
switch path[1] {
|
||||
case clienttypes.QueryAllClients:
|
||||
res, err = clientkeeper.QuerierClients(ctx, req, k.ClientKeeper, legacyQuerierCdc)
|
||||
default:
|
||||
err = sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown IBC %s query endpoint", clienttypes.SubModuleName)
|
||||
}
|
||||
case connectiontypes.SubModuleName:
|
||||
err = sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown IBC %s query endpoint", connectiontypes.SubModuleName)
|
||||
case channeltypes.SubModuleName:
|
||||
err = sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown IBC %s query endpoint", channeltypes.SubModuleName)
|
||||
default:
|
||||
err = sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown IBC query endpoint")
|
||||
}
|
||||
|
||||
return res, err
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package keeper_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
|
||||
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
// TestNewQuerier tests that the querier paths are correct.
|
||||
// NOTE: the actuall testing functionality are located on each ICS querier test.
|
||||
func (suite *KeeperTestSuite) TestNewQuerier() {
|
||||
query := abci.RequestQuery{
|
||||
Path: "",
|
||||
Data: []byte{},
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
path []string
|
||||
expectsDefaultErr bool
|
||||
errMsg string
|
||||
}{
|
||||
{"client - QuerierClients",
|
||||
[]string{clienttypes.SubModuleName, clienttypes.QueryAllClients},
|
||||
false,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"client - invalid query",
|
||||
[]string{clienttypes.SubModuleName, "foo"},
|
||||
true,
|
||||
fmt.Sprintf("unknown IBC %s query endpoint", clienttypes.SubModuleName),
|
||||
},
|
||||
{
|
||||
"connection - invalid query",
|
||||
[]string{connectiontypes.SubModuleName, "foo"},
|
||||
true,
|
||||
fmt.Sprintf("unknown IBC %s query endpoint", connectiontypes.SubModuleName),
|
||||
},
|
||||
{
|
||||
"channel - invalid query",
|
||||
[]string{channeltypes.SubModuleName, "foo"},
|
||||
true,
|
||||
fmt.Sprintf("unknown IBC %s query endpoint", channeltypes.SubModuleName),
|
||||
},
|
||||
{
|
||||
"invalid query",
|
||||
[]string{"foo"},
|
||||
true,
|
||||
"unknown IBC query endpoint",
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
i, tc := i, tc
|
||||
suite.Run(tc.name, func() {
|
||||
_, err := suite.querier(suite.ctx, tc.path, query)
|
||||
if tc.expectsDefaultErr {
|
||||
require.Contains(suite.T(), err.Error(), tc.errMsg, "test case #%d", i)
|
||||
} else {
|
||||
suite.Error(err, "test case #%d", i)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -117,9 +117,9 @@ func (AppModule) QuerierRoute() string {
|
|||
return host.QuerierRoute
|
||||
}
|
||||
|
||||
// LegacyQuerierHandler returns the ibc module sdk.Querier.
|
||||
// LegacyQuerierHandler returns nil. IBC does not support the legacy querier.
|
||||
func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc codec.JSONMarshaler) sdk.Querier {
|
||||
return keeper.NewQuerier(*am.keeper, legacyQuerierCdc)
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterQueryService registers the gRPC query service for the ibc module.
|
||||
|
|
|
@ -3,6 +3,8 @@ package types
|
|||
import (
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
|
||||
client "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
|
||||
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
|
||||
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
|
||||
|
@ -11,12 +13,14 @@ import (
|
|||
|
||||
// QueryServer defines the IBC interfaces that the gRPC query server must implement
|
||||
type QueryServer interface {
|
||||
clienttypes.QueryServer
|
||||
connectiontypes.QueryServer
|
||||
channeltypes.QueryServer
|
||||
}
|
||||
|
||||
// RegisterQueryService registers each individual IBC submodule query service
|
||||
func RegisterQueryService(server grpc.Server, queryService QueryServer) {
|
||||
client.RegisterQueryService(server, queryService)
|
||||
connection.RegisterQueryService(server, queryService)
|
||||
channel.RegisterQueryService(server, queryService)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue