diff --git a/client/chain/chain.go b/client/chain/chain.go index bcd5443d..a827c014 100644 --- a/client/chain/chain.go +++ b/client/chain/chain.go @@ -13,8 +13,6 @@ import ( "sync/atomic" "time" - 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" @@ -39,6 +37,8 @@ import ( authztypes "github.com/cosmos/cosmos-sdk/x/authz" 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" + ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" eth "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" "github.com/shopspring/decimal" @@ -252,6 +252,21 @@ type ChainClient interface { FetchEscrowAddress(ctx context.Context, portId string, channelId string) (*ibctransfertypes.QueryEscrowAddressResponse, error) FetchTotalEscrowForDenom(ctx context.Context, denom string) (*ibctransfertypes.QueryTotalEscrowForDenomResponse, error) + // IBC Core Channel module + FetchIBCChannel(ctx context.Context, portId string, channelId string) (*ibcchanneltypes.QueryChannelResponse, error) + FetchIBCChannels(ctx context.Context, pagination *query.PageRequest) (*ibcchanneltypes.QueryChannelsResponse, error) + FetchIBCConnectionChannels(ctx context.Context, connection string, pagination *query.PageRequest) (*ibcchanneltypes.QueryConnectionChannelsResponse, error) + FetchIBCChannelClientState(ctx context.Context, portId string, channelId string) (*ibcchanneltypes.QueryChannelClientStateResponse, error) + FetchIBCChannelConsensusState(ctx context.Context, portId string, channelId string, revisionNumber uint64, revisionHeight uint64) (*ibcchanneltypes.QueryChannelConsensusStateResponse, error) + FetchIBCPacketCommitment(ctx context.Context, portId string, channelId string, sequence uint64) (*ibcchanneltypes.QueryPacketCommitmentResponse, error) + FetchIBCPacketCommitments(ctx context.Context, portId string, channelId string, pagination *query.PageRequest) (*ibcchanneltypes.QueryPacketCommitmentsResponse, error) + FetchIBCPacketReceipt(ctx context.Context, portId string, channelId string, sequence uint64) (*ibcchanneltypes.QueryPacketReceiptResponse, error) + FetchIBCPacketAcknowledgement(ctx context.Context, portId string, channelId string, sequence uint64) (*ibcchanneltypes.QueryPacketAcknowledgementResponse, error) + FetchIBCPacketAcknowledgements(ctx context.Context, portId string, channelId string, packetCommitmentSequences []uint64, pagination *query.PageRequest) (*ibcchanneltypes.QueryPacketAcknowledgementsResponse, error) + FetchIBCUnreceivedPackets(ctx context.Context, portId string, channelId string, packetCommitmentSequences []uint64) (*ibcchanneltypes.QueryUnreceivedPacketsResponse, error) + FetchIBCUnreceivedAcks(ctx context.Context, portId string, channelId string, packetAckSequences []uint64) (*ibcchanneltypes.QueryUnreceivedAcksResponse, error) + FetchIBCNextSequenceReceive(ctx context.Context, portId string, channelId string) (*ibcchanneltypes.QueryNextSequenceReceiveResponse, error) + Close() } @@ -284,6 +299,7 @@ type chainClient struct { chainStreamClient chainstreamtypes.StreamClient distributionQueryClient distributiontypes.QueryClient exchangeQueryClient exchangetypes.QueryClient + ibcChannelQueryClient ibcchanneltypes.QueryClient ibcTransferQueryClient ibctransfertypes.QueryClient tendermintQueryClient tmservice.ServiceClient tokenfactoryQueryClient tokenfactorytypes.QueryClient @@ -381,6 +397,7 @@ func NewChainClient( chainStreamClient: chainstreamtypes.NewStreamClient(chainStreamConn), distributionQueryClient: distributiontypes.NewQueryClient(conn), exchangeQueryClient: exchangetypes.NewQueryClient(conn), + ibcChannelQueryClient: ibcchanneltypes.NewQueryClient(conn), ibcTransferQueryClient: ibctransfertypes.NewQueryClient(conn), tendermintQueryClient: tmservice.NewServiceClient(conn), tokenfactoryQueryClient: tokenfactorytypes.NewQueryClient(conn), @@ -2313,3 +2330,143 @@ func (c *chainClient) FetchTotalEscrowForDenom(ctx context.Context, denom string return res, err } + +// IBC Core Channel module +func (c *chainClient) FetchIBCChannel(ctx context.Context, portId string, channelId string) (*ibcchanneltypes.QueryChannelResponse, error) { + req := &ibcchanneltypes.QueryChannelRequest{ + PortId: portId, + ChannelId: channelId, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcChannelQueryClient.Channel, req) + + return res, err +} + +func (c *chainClient) FetchIBCChannels(ctx context.Context, pagination *query.PageRequest) (*ibcchanneltypes.QueryChannelsResponse, error) { + req := &ibcchanneltypes.QueryChannelsRequest{ + Pagination: pagination, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcChannelQueryClient.Channels, req) + + return res, err +} + +func (c *chainClient) FetchIBCConnectionChannels(ctx context.Context, connection string, pagination *query.PageRequest) (*ibcchanneltypes.QueryConnectionChannelsResponse, error) { + req := &ibcchanneltypes.QueryConnectionChannelsRequest{ + Connection: connection, + Pagination: pagination, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcChannelQueryClient.ConnectionChannels, req) + + return res, err +} + +func (c *chainClient) FetchIBCChannelClientState(ctx context.Context, portId string, channelId string) (*ibcchanneltypes.QueryChannelClientStateResponse, error) { + req := &ibcchanneltypes.QueryChannelClientStateRequest{ + PortId: portId, + ChannelId: channelId, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcChannelQueryClient.ChannelClientState, req) + + return res, err +} + +func (c *chainClient) FetchIBCChannelConsensusState(ctx context.Context, portId string, channelId string, revisionNumber uint64, revisionHeight uint64) (*ibcchanneltypes.QueryChannelConsensusStateResponse, error) { + req := &ibcchanneltypes.QueryChannelConsensusStateRequest{ + PortId: portId, + ChannelId: channelId, + RevisionNumber: revisionNumber, + RevisionHeight: revisionHeight, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcChannelQueryClient.ChannelConsensusState, req) + + return res, err +} + +func (c *chainClient) FetchIBCPacketCommitment(ctx context.Context, portId string, channelId string, sequence uint64) (*ibcchanneltypes.QueryPacketCommitmentResponse, error) { + req := &ibcchanneltypes.QueryPacketCommitmentRequest{ + PortId: portId, + ChannelId: channelId, + Sequence: sequence, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcChannelQueryClient.PacketCommitment, req) + + return res, err +} + +func (c *chainClient) FetchIBCPacketCommitments(ctx context.Context, portId string, channelId string, pagination *query.PageRequest) (*ibcchanneltypes.QueryPacketCommitmentsResponse, error) { + req := &ibcchanneltypes.QueryPacketCommitmentsRequest{ + PortId: portId, + ChannelId: channelId, + Pagination: pagination, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcChannelQueryClient.PacketCommitments, req) + + return res, err +} + +func (c *chainClient) FetchIBCPacketReceipt(ctx context.Context, portId string, channelId string, sequence uint64) (*ibcchanneltypes.QueryPacketReceiptResponse, error) { + req := &ibcchanneltypes.QueryPacketReceiptRequest{ + PortId: portId, + ChannelId: channelId, + Sequence: sequence, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcChannelQueryClient.PacketReceipt, req) + + return res, err +} + +func (c *chainClient) FetchIBCPacketAcknowledgement(ctx context.Context, portId string, channelId string, sequence uint64) (*ibcchanneltypes.QueryPacketAcknowledgementResponse, error) { + req := &ibcchanneltypes.QueryPacketAcknowledgementRequest{ + PortId: portId, + ChannelId: channelId, + Sequence: sequence, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcChannelQueryClient.PacketAcknowledgement, req) + + return res, err +} + +func (c *chainClient) FetchIBCPacketAcknowledgements(ctx context.Context, portId string, channelId string, packetCommitmentSequences []uint64, pagination *query.PageRequest) (*ibcchanneltypes.QueryPacketAcknowledgementsResponse, error) { + req := &ibcchanneltypes.QueryPacketAcknowledgementsRequest{ + PortId: portId, + ChannelId: channelId, + Pagination: pagination, + PacketCommitmentSequences: packetCommitmentSequences, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcChannelQueryClient.PacketAcknowledgements, req) + + return res, err +} + +func (c *chainClient) FetchIBCUnreceivedPackets(ctx context.Context, portId string, channelId string, packetCommitmentSequences []uint64) (*ibcchanneltypes.QueryUnreceivedPacketsResponse, error) { + req := &ibcchanneltypes.QueryUnreceivedPacketsRequest{ + PortId: portId, + ChannelId: channelId, + PacketCommitmentSequences: packetCommitmentSequences, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcChannelQueryClient.UnreceivedPackets, req) + + return res, err +} + +func (c *chainClient) FetchIBCUnreceivedAcks(ctx context.Context, portId string, channelId string, packetAckSequences []uint64) (*ibcchanneltypes.QueryUnreceivedAcksResponse, error) { + req := &ibcchanneltypes.QueryUnreceivedAcksRequest{ + PortId: portId, + ChannelId: channelId, + PacketAckSequences: packetAckSequences, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcChannelQueryClient.UnreceivedAcks, req) + + return res, err +} + +func (c *chainClient) FetchIBCNextSequenceReceive(ctx context.Context, portId string, channelId string) (*ibcchanneltypes.QueryNextSequenceReceiveResponse, error) { + req := &ibcchanneltypes.QueryNextSequenceReceiveRequest{ + PortId: portId, + ChannelId: channelId, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.ibcChannelQueryClient.NextSequenceReceive, req) + + return res, err +} diff --git a/client/chain/chain_test_support.go b/client/chain/chain_test_support.go index cc643ecc..9414d73a 100644 --- a/client/chain/chain_test_support.go +++ b/client/chain/chain_test_support.go @@ -5,6 +5,8 @@ import ( "errors" "time" + 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" @@ -601,3 +603,56 @@ func (c *MockChainClient) FetchEscrowAddress(ctx context.Context, portId string, func (c *MockChainClient) FetchTotalEscrowForDenom(ctx context.Context, denom string) (*ibctransfertypes.QueryTotalEscrowForDenomResponse, error) { return &ibctransfertypes.QueryTotalEscrowForDenomResponse{}, nil } + +// IBC Core Channel module +func (c *MockChainClient) FetchIBCChannel(ctx context.Context, portId string, channelId string) (*ibcchanneltypes.QueryChannelResponse, error) { + return &ibcchanneltypes.QueryChannelResponse{}, nil +} + +func (c *MockChainClient) FetchIBCChannels(ctx context.Context, pagination *query.PageRequest) (*ibcchanneltypes.QueryChannelsResponse, error) { + return &ibcchanneltypes.QueryChannelsResponse{}, nil +} + +func (c *MockChainClient) FetchIBCConnectionChannels(ctx context.Context, connection string, pagination *query.PageRequest) (*ibcchanneltypes.QueryConnectionChannelsResponse, error) { + return &ibcchanneltypes.QueryConnectionChannelsResponse{}, nil +} + +func (c *MockChainClient) FetchIBCChannelClientState(ctx context.Context, portId string, channelId string) (*ibcchanneltypes.QueryChannelClientStateResponse, error) { + return &ibcchanneltypes.QueryChannelClientStateResponse{}, nil +} + +func (c *MockChainClient) FetchIBCChannelConsensusState(ctx context.Context, portId string, channelId string, revisionNumber uint64, revisionHeight uint64) (*ibcchanneltypes.QueryChannelConsensusStateResponse, error) { + return &ibcchanneltypes.QueryChannelConsensusStateResponse{}, nil +} + +func (c *MockChainClient) FetchIBCPacketCommitment(ctx context.Context, portId string, channelId string, sequence uint64) (*ibcchanneltypes.QueryPacketCommitmentResponse, error) { + return &ibcchanneltypes.QueryPacketCommitmentResponse{}, nil +} + +func (c *MockChainClient) FetchIBCPacketCommitments(ctx context.Context, portId string, channelId string, pagination *query.PageRequest) (*ibcchanneltypes.QueryPacketCommitmentsResponse, error) { + return &ibcchanneltypes.QueryPacketCommitmentsResponse{}, nil +} + +func (c *MockChainClient) FetchIBCPacketReceipt(ctx context.Context, portId string, channelId string, sequence uint64) (*ibcchanneltypes.QueryPacketReceiptResponse, error) { + return &ibcchanneltypes.QueryPacketReceiptResponse{}, nil +} + +func (c *MockChainClient) FetchIBCPacketAcknowledgement(ctx context.Context, portId string, channelId string, sequence uint64) (*ibcchanneltypes.QueryPacketAcknowledgementResponse, error) { + return &ibcchanneltypes.QueryPacketAcknowledgementResponse{}, nil +} + +func (c *MockChainClient) FetchIBCPacketAcknowledgements(ctx context.Context, portId string, channelId string, packetCommitmentSequences []uint64, pagination *query.PageRequest) (*ibcchanneltypes.QueryPacketAcknowledgementsResponse, error) { + return &ibcchanneltypes.QueryPacketAcknowledgementsResponse{}, nil +} + +func (c *MockChainClient) FetchIBCUnreceivedPackets(ctx context.Context, portId string, channelId string, packetCommitmentSequences []uint64) (*ibcchanneltypes.QueryUnreceivedPacketsResponse, error) { + return &ibcchanneltypes.QueryUnreceivedPacketsResponse{}, nil +} + +func (c *MockChainClient) FetchIBCUnreceivedAcks(ctx context.Context, portId string, channelId string, packetAckSequences []uint64) (*ibcchanneltypes.QueryUnreceivedAcksResponse, error) { + return &ibcchanneltypes.QueryUnreceivedAcksResponse{}, nil +} + +func (c *MockChainClient) FetchIBCNextSequenceReceive(ctx context.Context, portId string, channelId string) (*ibcchanneltypes.QueryNextSequenceReceiveResponse, error) { + return &ibcchanneltypes.QueryNextSequenceReceiveResponse{}, nil +} diff --git a/examples/chain/ibc/channel/query/10_PacketAcknowledgements/example.go b/examples/chain/ibc/channel/query/10_PacketAcknowledgements/example.go new file mode 100644 index 00000000..57a3d8c6 --- /dev/null +++ b/examples/chain/ibc/channel/query/10_PacketAcknowledgements/example.go @@ -0,0 +1,76 @@ +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) + } + + portId := "transfer" + channelId := "channel-126" + sequences := []uint64{1, 2} + pagination := query.PageRequest{Offset: 2, Limit: 4} + ctx := context.Background() + + res, err := chainClient.FetchIBCPacketAcknowledgements(ctx, portId, channelId, sequences, &pagination) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/ibc/channel/query/11_UnreceivedPackets/example.go b/examples/chain/ibc/channel/query/11_UnreceivedPackets/example.go new file mode 100644 index 00000000..59d77766 --- /dev/null +++ b/examples/chain/ibc/channel/query/11_UnreceivedPackets/example.go @@ -0,0 +1,73 @@ +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) + } + + portId := "transfer" + channelId := "channel-126" + sequences := []uint64{1, 2} + ctx := context.Background() + + res, err := chainClient.FetchIBCUnreceivedPackets(ctx, portId, channelId, sequences) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/ibc/channel/query/12_UnreceivedAcks/example.go b/examples/chain/ibc/channel/query/12_UnreceivedAcks/example.go new file mode 100644 index 00000000..ad1025ca --- /dev/null +++ b/examples/chain/ibc/channel/query/12_UnreceivedAcks/example.go @@ -0,0 +1,73 @@ +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) + } + + portId := "transfer" + channelId := "channel-126" + sequences := []uint64{1, 2} + ctx := context.Background() + + res, err := chainClient.FetchIBCUnreceivedAcks(ctx, portId, channelId, sequences) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/ibc/channel/query/13_NextSequenceReceive/example.go b/examples/chain/ibc/channel/query/13_NextSequenceReceive/example.go new file mode 100644 index 00000000..86171598 --- /dev/null +++ b/examples/chain/ibc/channel/query/13_NextSequenceReceive/example.go @@ -0,0 +1,72 @@ +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) + } + + portId := "transfer" + channelId := "channel-126" + ctx := context.Background() + + res, err := chainClient.FetchIBCNextSequenceReceive(ctx, portId, channelId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/ibc/channel/query/1_Channel/example.go b/examples/chain/ibc/channel/query/1_Channel/example.go new file mode 100644 index 00000000..73bab3cc --- /dev/null +++ b/examples/chain/ibc/channel/query/1_Channel/example.go @@ -0,0 +1,72 @@ +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) + } + + portId := "transfer" + channelId := "channel-126" + ctx := context.Background() + + res, err := chainClient.FetchIBCChannel(ctx, portId, channelId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/ibc/channel/query/2_Channels/example.go b/examples/chain/ibc/channel/query/2_Channels/example.go new file mode 100644 index 00000000..688bd8c7 --- /dev/null +++ b/examples/chain/ibc/channel/query/2_Channels/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.FetchIBCChannels(ctx, &pagination) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/ibc/channel/query/3_ConnectionChannels/example.go b/examples/chain/ibc/channel/query/3_ConnectionChannels/example.go new file mode 100644 index 00000000..525aaa85 --- /dev/null +++ b/examples/chain/ibc/channel/query/3_ConnectionChannels/example.go @@ -0,0 +1,74 @@ +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) + } + + connection := "connection-182" + pagination := query.PageRequest{Offset: 2, Limit: 4} + ctx := context.Background() + + res, err := chainClient.FetchIBCConnectionChannels(ctx, connection, &pagination) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/ibc/channel/query/4_ChannelClientState/example.go b/examples/chain/ibc/channel/query/4_ChannelClientState/example.go new file mode 100644 index 00000000..34579a77 --- /dev/null +++ b/examples/chain/ibc/channel/query/4_ChannelClientState/example.go @@ -0,0 +1,70 @@ +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) + } + + portId := "transfer" + channelId := "channel-126" + ctx := context.Background() + + res, err := chainClient.FetchIBCChannelClientState(ctx, portId, channelId) + if err != nil { + fmt.Println(err) + } + + fmt.Print(res) + +} diff --git a/examples/chain/ibc/channel/query/5_ChannelConsensusState/example.go b/examples/chain/ibc/channel/query/5_ChannelConsensusState/example.go new file mode 100644 index 00000000..1346834c --- /dev/null +++ b/examples/chain/ibc/channel/query/5_ChannelConsensusState/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) + } + + portId := "transfer" + channelId := "channel-126" + revisionNumber := uint64(1) + revisionHeight := uint64(7990906) + ctx := context.Background() + + res, err := chainClient.FetchIBCChannelConsensusState(ctx, portId, channelId, revisionNumber, revisionHeight) + if err != nil { + fmt.Println(err) + } + + fmt.Print(res) + +} diff --git a/examples/chain/ibc/channel/query/6_PacketCommitment/example.go b/examples/chain/ibc/channel/query/6_PacketCommitment/example.go new file mode 100644 index 00000000..2a5fec05 --- /dev/null +++ b/examples/chain/ibc/channel/query/6_PacketCommitment/example.go @@ -0,0 +1,73 @@ +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) + } + + portId := "transfer" + channelId := "channel-126" + sequence := uint64(1) + ctx := context.Background() + + res, err := chainClient.FetchIBCPacketCommitment(ctx, portId, channelId, sequence) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/ibc/channel/query/7_PacketCommitments/example.go b/examples/chain/ibc/channel/query/7_PacketCommitments/example.go new file mode 100644 index 00000000..e5af45c2 --- /dev/null +++ b/examples/chain/ibc/channel/query/7_PacketCommitments/example.go @@ -0,0 +1,75 @@ +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) + } + + portId := "transfer" + channelId := "channel-126" + pagination := query.PageRequest{Offset: 2, Limit: 4} + ctx := context.Background() + + res, err := chainClient.FetchIBCPacketCommitments(ctx, portId, channelId, &pagination) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/ibc/channel/query/8_PacketReceipt/example.go b/examples/chain/ibc/channel/query/8_PacketReceipt/example.go new file mode 100644 index 00000000..5b429ef3 --- /dev/null +++ b/examples/chain/ibc/channel/query/8_PacketReceipt/example.go @@ -0,0 +1,73 @@ +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) + } + + portId := "transfer" + channelId := "channel-126" + sequence := uint64(1) + ctx := context.Background() + + res, err := chainClient.FetchIBCPacketReceipt(ctx, portId, channelId, sequence) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/ibc/channel/query/9_PacketAcknowledgement/example.go b/examples/chain/ibc/channel/query/9_PacketAcknowledgement/example.go new file mode 100644 index 00000000..0737e5da --- /dev/null +++ b/examples/chain/ibc/channel/query/9_PacketAcknowledgement/example.go @@ -0,0 +1,73 @@ +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) + } + + portId := "transfer" + channelId := "channel-126" + sequence := uint64(1) + ctx := context.Background() + + res, err := chainClient.FetchIBCPacketAcknowledgement(ctx, portId, channelId, sequence) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +}