From 3878473aeca4b865cf4f0c2e3031e5a2072015ba Mon Sep 17 00:00:00 2001 From: abel Date: Tue, 23 Apr 2024 09:42:10 -0300 Subject: [PATCH 1/2] (feat) Added script examples for the IBC Core Client module queries --- client/chain/chain.go | 95 +++++++++++++++++++ client/chain/chain_test_support.go | 38 ++++++++ .../ibc/client/query/1_ClientState/example.go | 69 ++++++++++++++ .../client/query/2_ClientStates/example.go | 71 ++++++++++++++ .../client/query/3_ConsensusState/example.go | 73 ++++++++++++++ .../client/query/4_ConsensusStates/example.go | 72 ++++++++++++++ .../query/5_ConsensusStateHeight/example.go | 72 ++++++++++++++ .../client/query/6_ClientStatus/example.go | 71 ++++++++++++++ .../client/query/7_ClientParams/example.go | 70 ++++++++++++++ .../query/8_UpgradedClientState/example.go | 70 ++++++++++++++ .../query/9_UpgradedConsensusState/example.go | 70 ++++++++++++++ 11 files changed, 771 insertions(+) create mode 100644 examples/chain/ibc/client/query/1_ClientState/example.go create mode 100644 examples/chain/ibc/client/query/2_ClientStates/example.go create mode 100644 examples/chain/ibc/client/query/3_ConsensusState/example.go create mode 100644 examples/chain/ibc/client/query/4_ConsensusStates/example.go create mode 100644 examples/chain/ibc/client/query/5_ConsensusStateHeight/example.go create mode 100644 examples/chain/ibc/client/query/6_ClientStatus/example.go create mode 100644 examples/chain/ibc/client/query/7_ClientParams/example.go create mode 100644 examples/chain/ibc/client/query/8_UpgradedClientState/example.go create mode 100644 examples/chain/ibc/client/query/9_UpgradedConsensusState/example.go diff --git a/client/chain/chain.go b/client/chain/chain.go index a827c014..5cb9bf9f 100644 --- a/client/chain/chain.go +++ b/client/chain/chain.go @@ -38,6 +38,7 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/gogoproto/proto" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" eth "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" @@ -267,6 +268,17 @@ type ChainClient interface { FetchIBCUnreceivedAcks(ctx context.Context, portId string, channelId string, packetAckSequences []uint64) (*ibcchanneltypes.QueryUnreceivedAcksResponse, error) FetchIBCNextSequenceReceive(ctx context.Context, portId string, channelId string) (*ibcchanneltypes.QueryNextSequenceReceiveResponse, error) + // IBC Core Chain module + FetchIBCClientState(ctx context.Context, clientId string) (*ibcclienttypes.QueryClientStateResponse, error) + FetchIBCClientStates(ctx context.Context, pagination *query.PageRequest) (*ibcclienttypes.QueryClientStatesResponse, error) + FetchIBCConsensusState(ctx context.Context, clientId string, revisionNumber uint64, revisionHeight uint64, latestHeight bool) (*ibcclienttypes.QueryConsensusStateResponse, error) + FetchIBCConsensusStates(ctx context.Context, clientId string, pagination *query.PageRequest) (*ibcclienttypes.QueryConsensusStatesResponse, error) + FetchIBCConsensusStateHeights(ctx context.Context, clientId string, pagination *query.PageRequest) (*ibcclienttypes.QueryConsensusStateHeightsResponse, error) + FetchIBCClientStatus(ctx context.Context, clientId string) (*ibcclienttypes.QueryClientStatusResponse, error) + FetchIBCClientParams(ctx context.Context) (*ibcclienttypes.QueryClientParamsResponse, error) + FetchIBCUpgradedClientState(ctx context.Context) (*ibcclienttypes.QueryUpgradedClientStateResponse, error) + FetchIBCUpgradedConsensusState(ctx context.Context) (*ibcclienttypes.QueryUpgradedConsensusStateResponse, error) + Close() } @@ -300,6 +312,7 @@ type chainClient struct { distributionQueryClient distributiontypes.QueryClient exchangeQueryClient exchangetypes.QueryClient ibcChannelQueryClient ibcchanneltypes.QueryClient + ibcClientQueryClient ibcclienttypes.QueryClient ibcTransferQueryClient ibctransfertypes.QueryClient tendermintQueryClient tmservice.ServiceClient tokenfactoryQueryClient tokenfactorytypes.QueryClient @@ -398,6 +411,7 @@ func NewChainClient( distributionQueryClient: distributiontypes.NewQueryClient(conn), exchangeQueryClient: exchangetypes.NewQueryClient(conn), ibcChannelQueryClient: ibcchanneltypes.NewQueryClient(conn), + ibcClientQueryClient: ibcclienttypes.NewQueryClient(conn), ibcTransferQueryClient: ibctransfertypes.NewQueryClient(conn), tendermintQueryClient: tmservice.NewServiceClient(conn), tokenfactoryQueryClient: tokenfactorytypes.NewQueryClient(conn), @@ -2470,3 +2484,84 @@ func (c *chainClient) FetchIBCNextSequenceReceive(ctx context.Context, portId st return res, err } + +// IBC Core Chain module +func (c *chainClient) FetchIBCClientState(ctx context.Context, clientId string) (*ibcclienttypes.QueryClientStateResponse, error) { + req := &ibcclienttypes.QueryClientStateRequest{ + ClientId: clientId, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcClientQueryClient.ClientState, req) + + return res, err +} + +func (c *chainClient) FetchIBCClientStates(ctx context.Context, pagination *query.PageRequest) (*ibcclienttypes.QueryClientStatesResponse, error) { + req := &ibcclienttypes.QueryClientStatesRequest{ + Pagination: pagination, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcClientQueryClient.ClientStates, req) + + return res, err +} + +func (c *chainClient) FetchIBCConsensusState(ctx context.Context, clientId string, revisionNumber uint64, revisionHeight uint64, latestHeight bool) (*ibcclienttypes.QueryConsensusStateResponse, error) { + req := &ibcclienttypes.QueryConsensusStateRequest{ + ClientId: clientId, + RevisionNumber: revisionNumber, + RevisionHeight: revisionHeight, + LatestHeight: latestHeight, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcClientQueryClient.ConsensusState, req) + + return res, err +} + +func (c *chainClient) FetchIBCConsensusStates(ctx context.Context, clientId string, pagination *query.PageRequest) (*ibcclienttypes.QueryConsensusStatesResponse, error) { + req := &ibcclienttypes.QueryConsensusStatesRequest{ + ClientId: clientId, + Pagination: pagination, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcClientQueryClient.ConsensusStates, req) + + return res, err +} + +func (c *chainClient) FetchIBCConsensusStateHeights(ctx context.Context, clientId string, pagination *query.PageRequest) (*ibcclienttypes.QueryConsensusStateHeightsResponse, error) { + req := &ibcclienttypes.QueryConsensusStateHeightsRequest{ + ClientId: clientId, + Pagination: pagination, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcClientQueryClient.ConsensusStateHeights, req) + + return res, err +} + +func (c *chainClient) FetchIBCClientStatus(ctx context.Context, clientId string) (*ibcclienttypes.QueryClientStatusResponse, error) { + req := &ibcclienttypes.QueryClientStatusRequest{ + ClientId: clientId, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcClientQueryClient.ClientStatus, req) + + return res, err +} + +func (c *chainClient) FetchIBCClientParams(ctx context.Context) (*ibcclienttypes.QueryClientParamsResponse, error) { + req := &ibcclienttypes.QueryClientParamsRequest{} + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcClientQueryClient.ClientParams, req) + + return res, err +} + +func (c *chainClient) FetchIBCUpgradedClientState(ctx context.Context) (*ibcclienttypes.QueryUpgradedClientStateResponse, error) { + req := &ibcclienttypes.QueryUpgradedClientStateRequest{} + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcClientQueryClient.UpgradedClientState, req) + + return res, err +} + +func (c *chainClient) FetchIBCUpgradedConsensusState(ctx context.Context) (*ibcclienttypes.QueryUpgradedConsensusStateResponse, error) { + req := &ibcclienttypes.QueryUpgradedConsensusStateRequest{} + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcClientQueryClient.UpgradedConsensusState, req) + + return res, err +} diff --git a/client/chain/chain_test_support.go b/client/chain/chain_test_support.go index 9414d73a..f106cb36 100644 --- a/client/chain/chain_test_support.go +++ b/client/chain/chain_test_support.go @@ -3,6 +3,7 @@ package chain import ( "context" "errors" + ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "time" ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -656,3 +657,40 @@ func (c *MockChainClient) FetchIBCUnreceivedAcks(ctx context.Context, portId str func (c *MockChainClient) FetchIBCNextSequenceReceive(ctx context.Context, portId string, channelId string) (*ibcchanneltypes.QueryNextSequenceReceiveResponse, error) { return &ibcchanneltypes.QueryNextSequenceReceiveResponse{}, nil } + +// IBC Core Chain module +func (c *MockChainClient) FetchIBCClientState(ctx context.Context, clientId string) (*ibcclienttypes.QueryClientStateResponse, error) { + return &ibcclienttypes.QueryClientStateResponse{}, nil +} + +func (c *MockChainClient) FetchIBCClientStates(ctx context.Context, pagination *query.PageRequest) (*ibcclienttypes.QueryClientStatesResponse, error) { + return &ibcclienttypes.QueryClientStatesResponse{}, nil +} + +func (c *MockChainClient) FetchIBCConsensusState(ctx context.Context, clientId string, revisionNumber uint64, revisionHeight uint64, latestHeight bool) (*ibcclienttypes.QueryConsensusStateResponse, error) { + return &ibcclienttypes.QueryConsensusStateResponse{}, nil +} + +func (c *MockChainClient) FetchIBCConsensusStates(ctx context.Context, clientId string, pagination *query.PageRequest) (*ibcclienttypes.QueryConsensusStatesResponse, error) { + return &ibcclienttypes.QueryConsensusStatesResponse{}, nil +} + +func (c *MockChainClient) FetchIBCConsensusStateHeights(ctx context.Context, clientId string, pagination *query.PageRequest) (*ibcclienttypes.QueryConsensusStateHeightsResponse, error) { + return &ibcclienttypes.QueryConsensusStateHeightsResponse{}, nil +} + +func (c *MockChainClient) FetchIBCClientStatus(ctx context.Context, clientId string) (*ibcclienttypes.QueryClientStatusResponse, error) { + return &ibcclienttypes.QueryClientStatusResponse{}, nil +} + +func (c *MockChainClient) FetchIBCClientParams(ctx context.Context) (*ibcclienttypes.QueryClientParamsResponse, error) { + return &ibcclienttypes.QueryClientParamsResponse{}, nil +} + +func (c *MockChainClient) FetchIBCUpgradedClientState(ctx context.Context) (*ibcclienttypes.QueryUpgradedClientStateResponse, error) { + return &ibcclienttypes.QueryUpgradedClientStateResponse{}, nil +} + +func (c *MockChainClient) FetchIBCUpgradedConsensusState(ctx context.Context) (*ibcclienttypes.QueryUpgradedConsensusStateResponse, error) { + return &ibcclienttypes.QueryUpgradedConsensusStateResponse{}, nil +} diff --git a/examples/chain/ibc/client/query/1_ClientState/example.go b/examples/chain/ibc/client/query/1_ClientState/example.go new file mode 100644 index 00000000..ccc893dc --- /dev/null +++ b/examples/chain/ibc/client/query/1_ClientState/example.go @@ -0,0 +1,69 @@ +package main + +import ( + "context" + "fmt" + + "github.com/InjectiveLabs/sdk-go/client" + + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" + + "os" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + clientId := "07-tendermint-0" + ctx := context.Background() + + res, err := chainClient.FetchIBCClientState(ctx, clientId) + if err != nil { + fmt.Println(err) + } + + fmt.Print(res) + +} diff --git a/examples/chain/ibc/client/query/2_ClientStates/example.go b/examples/chain/ibc/client/query/2_ClientStates/example.go new file mode 100644 index 00000000..25d20383 --- /dev/null +++ b/examples/chain/ibc/client/query/2_ClientStates/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "fmt" + + "github.com/cosmos/cosmos-sdk/types/query" + + "github.com/InjectiveLabs/sdk-go/client" + + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" + + "os" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + pagination := query.PageRequest{Offset: 2, Limit: 4} + ctx := context.Background() + + res, err := chainClient.FetchIBCClientStates(ctx, &pagination) + if err != nil { + fmt.Println(err) + } + + fmt.Print(res) + +} diff --git a/examples/chain/ibc/client/query/3_ConsensusState/example.go b/examples/chain/ibc/client/query/3_ConsensusState/example.go new file mode 100644 index 00000000..4ec33765 --- /dev/null +++ b/examples/chain/ibc/client/query/3_ConsensusState/example.go @@ -0,0 +1,73 @@ +package main + +import ( + "context" + "fmt" + + "github.com/InjectiveLabs/sdk-go/client" + + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" + + "os" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + clientId := "07-tendermint-0" + revisionNumber := uint64(0) + revisionHeight := uint64(7379538) + latestHeight := false + + ctx := context.Background() + + res, err := chainClient.FetchIBCConsensusState(ctx, clientId, revisionNumber, revisionHeight, latestHeight) + if err != nil { + fmt.Println(err) + } + + fmt.Print(res) + +} diff --git a/examples/chain/ibc/client/query/4_ConsensusStates/example.go b/examples/chain/ibc/client/query/4_ConsensusStates/example.go new file mode 100644 index 00000000..81062887 --- /dev/null +++ b/examples/chain/ibc/client/query/4_ConsensusStates/example.go @@ -0,0 +1,72 @@ +package main + +import ( + "context" + "fmt" + + "github.com/cosmos/cosmos-sdk/types/query" + + "github.com/InjectiveLabs/sdk-go/client" + + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" + + "os" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + clientId := "07-tendermint-0" + pagination := query.PageRequest{Offset: 2, Limit: 4} + ctx := context.Background() + + res, err := chainClient.FetchIBCConsensusStates(ctx, clientId, &pagination) + if err != nil { + fmt.Println(err) + } + + fmt.Print(res) + +} diff --git a/examples/chain/ibc/client/query/5_ConsensusStateHeight/example.go b/examples/chain/ibc/client/query/5_ConsensusStateHeight/example.go new file mode 100644 index 00000000..450bdafb --- /dev/null +++ b/examples/chain/ibc/client/query/5_ConsensusStateHeight/example.go @@ -0,0 +1,72 @@ +package main + +import ( + "context" + "fmt" + + "github.com/cosmos/cosmos-sdk/types/query" + + "github.com/InjectiveLabs/sdk-go/client" + + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" + + "os" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + clientId := "07-tendermint-0" + pagination := query.PageRequest{Offset: 2, Limit: 4} + ctx := context.Background() + + res, err := chainClient.FetchIBCConsensusStateHeights(ctx, clientId, &pagination) + if err != nil { + fmt.Println(err) + } + + fmt.Print(res) + +} diff --git a/examples/chain/ibc/client/query/6_ClientStatus/example.go b/examples/chain/ibc/client/query/6_ClientStatus/example.go new file mode 100644 index 00000000..19d17442 --- /dev/null +++ b/examples/chain/ibc/client/query/6_ClientStatus/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/InjectiveLabs/sdk-go/client" + + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" + + "os" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + clientId := "07-tendermint-0" + ctx := context.Background() + + res, err := chainClient.FetchIBCClientStatus(ctx, clientId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/ibc/client/query/7_ClientParams/example.go b/examples/chain/ibc/client/query/7_ClientParams/example.go new file mode 100644 index 00000000..f0d4af1c --- /dev/null +++ b/examples/chain/ibc/client/query/7_ClientParams/example.go @@ -0,0 +1,70 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/InjectiveLabs/sdk-go/client" + + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" + + "os" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + res, err := chainClient.FetchIBCClientParams(ctx) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/ibc/client/query/8_UpgradedClientState/example.go b/examples/chain/ibc/client/query/8_UpgradedClientState/example.go new file mode 100644 index 00000000..9e792113 --- /dev/null +++ b/examples/chain/ibc/client/query/8_UpgradedClientState/example.go @@ -0,0 +1,70 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/InjectiveLabs/sdk-go/client" + + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" + + "os" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + res, err := chainClient.FetchIBCUpgradedClientState(ctx) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/ibc/client/query/9_UpgradedConsensusState/example.go b/examples/chain/ibc/client/query/9_UpgradedConsensusState/example.go new file mode 100644 index 00000000..1a69a9a8 --- /dev/null +++ b/examples/chain/ibc/client/query/9_UpgradedConsensusState/example.go @@ -0,0 +1,70 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/InjectiveLabs/sdk-go/client" + + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" + + "os" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + res, err := chainClient.FetchIBCUpgradedConsensusState(ctx) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} From 13eff7c4bb68b5b85ae8dea076835f4c75fd2bbf Mon Sep 17 00:00:00 2001 From: abel Date: Tue, 23 Apr 2024 09:46:47 -0300 Subject: [PATCH 2/2] (fix) Fixed pre-commit errors --- client/chain/chain_test_support.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/chain/chain_test_support.go b/client/chain/chain_test_support.go index f106cb36..b8b01b14 100644 --- a/client/chain/chain_test_support.go +++ b/client/chain/chain_test_support.go @@ -3,9 +3,10 @@ package chain import ( "context" "errors" - ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "time" + ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"