Skip to content

Commit

Permalink
Merge pull request #124 from InjectiveLabs/f/add-get-chain-tx
Browse files Browse the repository at this point in the history
feat: add get tx
  • Loading branch information
achilleas-kal committed May 2, 2023
2 parents 31c98b1 + 27cb844 commit a1240bb
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
8 changes: 8 additions & 0 deletions client/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ type ChainClient interface {
StreamEventOrderFail(sender string, failEventCh chan map[string]uint)
StreamOrderbookUpdateEvents(orderbookType OrderbookType, marketIds []string, orderbookCh chan exchangetypes.Orderbook)

// get tx from chain node
GetTx(ctx context.Context, txHash string) (*txtypes.GetTxResponse, error)
Close()
}

Expand Down Expand Up @@ -1278,6 +1280,12 @@ func (c *chainClient) StreamOrderbookUpdateEvents(orderbookType OrderbookType, m
}
}

func (c *chainClient) GetTx(ctx context.Context, txHash string) (*txtypes.GetTxResponse, error) {
return c.txClient.GetTx(ctx, &txtypes.GetTxRequest{
Hash: txHash,
})
}

type DerivativeOrderData struct {
OrderType exchangetypes.OrderType
Price cosmtypes.Dec
Expand Down
File renamed without changes.
70 changes: 70 additions & 0 deletions examples/chain/39_GetTx/example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package main

import (
"context"
"fmt"
"os"
"time"

"github.com/InjectiveLabs/sdk-go/client/common"

chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
)

func main() {
// network := common.LoadNetwork("mainnet", "k8s")
network := common.LoadNetwork("mainnet", "k8s")
tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket")

if err != nil {
fmt.Println(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 {
fmt.Println(err)
}

clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmRPC)

chainClient, err := chainclient.NewChainClient(
clientCtx,
network.ChainGrpcEndpoint,
common.OptionTLSCert(network.ChainTlsCert),
common.OptionGasPrices("500000000inj"),
)

if err != nil {
fmt.Println(err)
}

timeOutCtx, cancelFn := context.WithTimeout(context.Background(), 30*time.Second)
defer cancelFn()

resp, err := chainClient.GetTx(timeOutCtx, "A2B2B971C690AE7977451D24D6F450AECE6BCCB271E91E32C2563342DDA5254B")
if err != nil {
panic(err)
}

fmt.Println(resp.TxResponse)
}

0 comments on commit a1240bb

Please sign in to comment.