From 01e7ce114fb731856132390963cb3fdf1a99f39c Mon Sep 17 00:00:00 2001 From: abel Date: Thu, 25 Apr 2024 12:13:56 -0300 Subject: [PATCH] (feat) Added support for IBC Core Connection module. Included example scripts --- client/chain/chain.go | 122 ++++++++++++++---- client/chain/chain_test_support.go | 44 +++++-- .../connection/query/1_Connection/example.go | 71 ++++++++++ .../connection/query/2_Connections/example.go | 73 +++++++++++ .../query/3_ClientConnections/example.go | 71 ++++++++++ .../query/4_ConnectionClientState/example.go | 69 ++++++++++ .../5_ConnectionConsensusState/example.go | 72 +++++++++++ .../query/6_ConnectionParams/example.go | 70 ++++++++++ 8 files changed, 552 insertions(+), 40 deletions(-) create mode 100644 examples/chain/ibc/connection/query/1_Connection/example.go create mode 100644 examples/chain/ibc/connection/query/2_Connections/example.go create mode 100644 examples/chain/ibc/connection/query/3_ClientConnections/example.go create mode 100644 examples/chain/ibc/connection/query/4_ConnectionClientState/example.go create mode 100644 examples/chain/ibc/connection/query/5_ConnectionConsensusState/example.go create mode 100644 examples/chain/ibc/connection/query/6_ConnectionParams/example.go diff --git a/client/chain/chain.go b/client/chain/chain.go index 5cb9bf9f..3e33f06a 100644 --- a/client/chain/chain.go +++ b/client/chain/chain.go @@ -39,6 +39,7 @@ import ( "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" + ibcconnectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" eth "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" @@ -279,6 +280,14 @@ type ChainClient interface { FetchIBCUpgradedClientState(ctx context.Context) (*ibcclienttypes.QueryUpgradedClientStateResponse, error) FetchIBCUpgradedConsensusState(ctx context.Context) (*ibcclienttypes.QueryUpgradedConsensusStateResponse, error) + // IBC Core Connection module + FetchIBCConnection(ctx context.Context, connectionId string) (*ibcconnectiontypes.QueryConnectionResponse, error) + FetchIBCConnections(ctx context.Context, pagination *query.PageRequest) (*ibcconnectiontypes.QueryConnectionsResponse, error) + FetchIBCClientConnections(ctx context.Context, clientId string) (*ibcconnectiontypes.QueryClientConnectionsResponse, error) + FetchIBCConnectionClientState(ctx context.Context, connectionId string) (*ibcconnectiontypes.QueryConnectionClientStateResponse, error) + FetchIBCConnectionConsensusState(ctx context.Context, connectionId string, revisionNumber uint64, revisionHeight uint64) (*ibcconnectiontypes.QueryConnectionConsensusStateResponse, error) + FetchIBCConnectionParams(ctx context.Context) (*ibcconnectiontypes.QueryConnectionParamsResponse, error) + Close() } @@ -305,20 +314,21 @@ type chainClient struct { sessionEnabled bool - authQueryClient authtypes.QueryClient - authzQueryClient authztypes.QueryClient - bankQueryClient banktypes.QueryClient - chainStreamClient chainstreamtypes.StreamClient - distributionQueryClient distributiontypes.QueryClient - exchangeQueryClient exchangetypes.QueryClient - ibcChannelQueryClient ibcchanneltypes.QueryClient - ibcClientQueryClient ibcclienttypes.QueryClient - ibcTransferQueryClient ibctransfertypes.QueryClient - tendermintQueryClient tmservice.ServiceClient - tokenfactoryQueryClient tokenfactorytypes.QueryClient - txClient txtypes.ServiceClient - wasmQueryClient wasmtypes.QueryClient - subaccountToNonce map[ethcommon.Hash]uint32 + authQueryClient authtypes.QueryClient + authzQueryClient authztypes.QueryClient + bankQueryClient banktypes.QueryClient + chainStreamClient chainstreamtypes.StreamClient + distributionQueryClient distributiontypes.QueryClient + exchangeQueryClient exchangetypes.QueryClient + ibcChannelQueryClient ibcchanneltypes.QueryClient + ibcClientQueryClient ibcclienttypes.QueryClient + ibcConnectionQueryClient ibcconnectiontypes.QueryClient + ibcTransferQueryClient ibctransfertypes.QueryClient + tendermintQueryClient tmservice.ServiceClient + tokenfactoryQueryClient tokenfactorytypes.QueryClient + txClient txtypes.ServiceClient + wasmQueryClient wasmtypes.QueryClient + subaccountToNonce map[ethcommon.Hash]uint32 closed int64 canSign bool @@ -404,20 +414,21 @@ func NewChainClient( sessionEnabled: stickySessionEnabled, - authQueryClient: authtypes.NewQueryClient(conn), - authzQueryClient: authztypes.NewQueryClient(conn), - bankQueryClient: banktypes.NewQueryClient(conn), - chainStreamClient: chainstreamtypes.NewStreamClient(chainStreamConn), - 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), - txClient: txtypes.NewServiceClient(conn), - wasmQueryClient: wasmtypes.NewQueryClient(conn), - subaccountToNonce: make(map[ethcommon.Hash]uint32), + authQueryClient: authtypes.NewQueryClient(conn), + authzQueryClient: authztypes.NewQueryClient(conn), + bankQueryClient: banktypes.NewQueryClient(conn), + chainStreamClient: chainstreamtypes.NewStreamClient(chainStreamConn), + distributionQueryClient: distributiontypes.NewQueryClient(conn), + exchangeQueryClient: exchangetypes.NewQueryClient(conn), + ibcChannelQueryClient: ibcchanneltypes.NewQueryClient(conn), + ibcClientQueryClient: ibcclienttypes.NewQueryClient(conn), + ibcConnectionQueryClient: ibcconnectiontypes.NewQueryClient(conn), + ibcTransferQueryClient: ibctransfertypes.NewQueryClient(conn), + tendermintQueryClient: tmservice.NewServiceClient(conn), + tokenfactoryQueryClient: tokenfactorytypes.NewQueryClient(conn), + txClient: txtypes.NewServiceClient(conn), + wasmQueryClient: wasmtypes.NewQueryClient(conn), + subaccountToNonce: make(map[ethcommon.Hash]uint32), } if cc.canSign { @@ -2565,3 +2576,58 @@ func (c *chainClient) FetchIBCUpgradedConsensusState(ctx context.Context) (*ibcc return res, err } + +// IBC Core Connection module +func (c *chainClient) FetchIBCConnection(ctx context.Context, connectionId string) (*ibcconnectiontypes.QueryConnectionResponse, error) { + req := &ibcconnectiontypes.QueryConnectionRequest{ + ConnectionId: connectionId, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcConnectionQueryClient.Connection, req) + + return res, err +} + +func (c *chainClient) FetchIBCConnections(ctx context.Context, pagination *query.PageRequest) (*ibcconnectiontypes.QueryConnectionsResponse, error) { + req := &ibcconnectiontypes.QueryConnectionsRequest{ + Pagination: pagination, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcConnectionQueryClient.Connections, req) + + return res, err +} + +func (c *chainClient) FetchIBCClientConnections(ctx context.Context, clientId string) (*ibcconnectiontypes.QueryClientConnectionsResponse, error) { + req := &ibcconnectiontypes.QueryClientConnectionsRequest{ + ClientId: clientId, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcConnectionQueryClient.ClientConnections, req) + + return res, err +} + +func (c *chainClient) FetchIBCConnectionClientState(ctx context.Context, connectionId string) (*ibcconnectiontypes.QueryConnectionClientStateResponse, error) { + req := &ibcconnectiontypes.QueryConnectionClientStateRequest{ + ConnectionId: connectionId, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcConnectionQueryClient.ConnectionClientState, req) + + return res, err +} + +func (c *chainClient) FetchIBCConnectionConsensusState(ctx context.Context, connectionId string, revisionNumber uint64, revisionHeight uint64) (*ibcconnectiontypes.QueryConnectionConsensusStateResponse, error) { + req := &ibcconnectiontypes.QueryConnectionConsensusStateRequest{ + ConnectionId: connectionId, + RevisionNumber: revisionNumber, + RevisionHeight: revisionHeight, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcConnectionQueryClient.ConnectionConsensusState, req) + + return res, err +} + +func (c *chainClient) FetchIBCConnectionParams(ctx context.Context) (*ibcconnectiontypes.QueryConnectionParamsResponse, error) { + req := &ibcconnectiontypes.QueryConnectionParamsRequest{} + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcConnectionQueryClient.ConnectionParams, req) + + return res, err +} diff --git a/client/chain/chain_test_support.go b/client/chain/chain_test_support.go index b8b01b14..4139697c 100644 --- a/client/chain/chain_test_support.go +++ b/client/chain/chain_test_support.go @@ -5,22 +5,13 @@ import ( "errors" "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" - "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" - - distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - - tokenfactorytypes "github.com/InjectiveLabs/sdk-go/chain/tokenfactory/types" + "google.golang.org/grpc" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainstreamtypes "github.com/InjectiveLabs/sdk-go/chain/stream/types" + tokenfactorytypes "github.com/InjectiveLabs/sdk-go/chain/tokenfactory/types" "github.com/InjectiveLabs/sdk-go/client/common" rpchttp "github.com/cometbft/cometbft/rpc/client/http" "github.com/cosmos/cosmos-sdk/client" @@ -30,8 +21,12 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authztypes "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + ibcconnectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" eth "github.com/ethereum/go-ethereum/common" - "google.golang.org/grpc" ) type MockChainClient struct { @@ -695,3 +690,28 @@ func (c *MockChainClient) FetchIBCUpgradedClientState(ctx context.Context) (*ibc func (c *MockChainClient) FetchIBCUpgradedConsensusState(ctx context.Context) (*ibcclienttypes.QueryUpgradedConsensusStateResponse, error) { return &ibcclienttypes.QueryUpgradedConsensusStateResponse{}, nil } + +// IBC Core Connection module +func (c *MockChainClient) FetchIBCConnection(ctx context.Context, connectionId string) (*ibcconnectiontypes.QueryConnectionResponse, error) { + return &ibcconnectiontypes.QueryConnectionResponse{}, nil +} + +func (c *MockChainClient) FetchIBCConnections(ctx context.Context, pagination *query.PageRequest) (*ibcconnectiontypes.QueryConnectionsResponse, error) { + return &ibcconnectiontypes.QueryConnectionsResponse{}, nil +} + +func (c *MockChainClient) FetchIBCClientConnections(ctx context.Context, clientId string) (*ibcconnectiontypes.QueryClientConnectionsResponse, error) { + return &ibcconnectiontypes.QueryClientConnectionsResponse{}, nil +} + +func (c *MockChainClient) FetchIBCConnectionClientState(ctx context.Context, connectionId string) (*ibcconnectiontypes.QueryConnectionClientStateResponse, error) { + return &ibcconnectiontypes.QueryConnectionClientStateResponse{}, nil +} + +func (c *MockChainClient) FetchIBCConnectionConsensusState(ctx context.Context, connectionId string, revisionNumber uint64, revisionHeight uint64) (*ibcconnectiontypes.QueryConnectionConsensusStateResponse, error) { + return &ibcconnectiontypes.QueryConnectionConsensusStateResponse{}, nil +} + +func (c *MockChainClient) FetchIBCConnectionParams(ctx context.Context) (*ibcconnectiontypes.QueryConnectionParamsResponse, error) { + return &ibcconnectiontypes.QueryConnectionParamsResponse{}, nil +} diff --git a/examples/chain/ibc/connection/query/1_Connection/example.go b/examples/chain/ibc/connection/query/1_Connection/example.go new file mode 100644 index 00000000..f0e88c63 --- /dev/null +++ b/examples/chain/ibc/connection/query/1_Connection/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) + } + + connectionId := "connection-0" + ctx := context.Background() + + res, err := chainClient.FetchIBCConnection(ctx, connectionId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/ibc/connection/query/2_Connections/example.go b/examples/chain/ibc/connection/query/2_Connections/example.go new file mode 100644 index 00000000..42c23719 --- /dev/null +++ b/examples/chain/ibc/connection/query/2_Connections/example.go @@ -0,0 +1,73 @@ +package main + +import ( + "context" + "encoding/json" + "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.FetchIBCConnections(ctx, &pagination) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/ibc/connection/query/3_ClientConnections/example.go b/examples/chain/ibc/connection/query/3_ClientConnections/example.go new file mode 100644 index 00000000..a1fd5599 --- /dev/null +++ b/examples/chain/ibc/connection/query/3_ClientConnections/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.FetchIBCClientConnections(ctx, clientId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/ibc/connection/query/4_ConnectionClientState/example.go b/examples/chain/ibc/connection/query/4_ConnectionClientState/example.go new file mode 100644 index 00000000..30488c64 --- /dev/null +++ b/examples/chain/ibc/connection/query/4_ConnectionClientState/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) + } + + connectionId := "connection-0" + ctx := context.Background() + + res, err := chainClient.FetchIBCConnectionClientState(ctx, connectionId) + if err != nil { + fmt.Println(err) + } + + fmt.Print(res) + +} diff --git a/examples/chain/ibc/connection/query/5_ConnectionConsensusState/example.go b/examples/chain/ibc/connection/query/5_ConnectionConsensusState/example.go new file mode 100644 index 00000000..c2cf7d8a --- /dev/null +++ b/examples/chain/ibc/connection/query/5_ConnectionConsensusState/example.go @@ -0,0 +1,72 @@ +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) + } + + connectionId := "connection-0" + revisionNumber := uint64(0) + revisionHeight := uint64(7379538) + + ctx := context.Background() + + res, err := chainClient.FetchIBCConnectionConsensusState(ctx, connectionId, revisionNumber, revisionHeight) + if err != nil { + fmt.Println(err) + } + + fmt.Print(res) + +} diff --git a/examples/chain/ibc/connection/query/6_ConnectionParams/example.go b/examples/chain/ibc/connection/query/6_ConnectionParams/example.go new file mode 100644 index 00000000..dd0cf9ea --- /dev/null +++ b/examples/chain/ibc/connection/query/6_ConnectionParams/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.FetchIBCConnectionParams(ctx) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +}