From 3353d92ac5a15cbdf17978b765aaa1d660384cda Mon Sep 17 00:00:00 2001 From: Achilleas Kalantzis Date: Fri, 13 May 2022 14:21:55 +0100 Subject: [PATCH 1/4] feat: add INJ gas logs --- client/chain/chain.go | 17 +++++++++++++++ examples/chain/0_LocalOrderHash/example.go | 21 ++++++++++++++++--- .../example.go | 10 ++++++--- .../example.go | 14 +++++++++++-- .../example.go | 16 +++++++++++--- .../13_MsgIncreasePositionMargin/example.go | 10 ++++++--- examples/chain/15_MsgWithdraw/example.go | 10 ++++++--- .../chain/16_MsgSubaccountTransfer/example.go | 10 ++++++--- .../chain/17_MsgBatchUpdateOrders/example.go | 13 +++++++++--- examples/chain/18_MsgBid/example.go | 10 ++++++--- examples/chain/19_MsgGrant/example.go | 14 +++++++++++-- examples/chain/1_MsgSend/example.go | 14 ++++++++++--- examples/chain/20_MsgExec/example.go | 19 ++++++++++++----- examples/chain/21_MsgRevoke/example.go | 10 ++++++--- examples/chain/22_MsgSendToEth/example.go | 10 ++++++--- .../23_MsgRelayPriceFeedPrice/example.go | 10 ++++++--- examples/chain/24_MsgRegisterAsDMM/example.go | 18 +++++++++------- examples/chain/25_MsgDelegate/example.go | 10 +++++++-- .../26_MsgWithdrawDelegatorReward/example.go | 10 +++++++-- examples/chain/2_MsgDeposit/example.go | 7 ++++++- .../3_MsgCreateSpotLimitOrder/example.go | 15 ++++++++++--- .../4_MsgCreateSpotMarketOrder/example.go | 10 ++++++++- .../chain/5_MsgCancelSpotOrder/example.go | 8 +++++-- .../example.go | 16 +++++++++++--- .../example.go | 16 +++++++++++--- .../8_MsgCancelDerivativeOrder/example.go | 8 +++++-- .../9_MsgBatchCancelSpotOrders/example.go | 10 ++++++--- 27 files changed, 262 insertions(+), 74 deletions(-) diff --git a/client/chain/chain.go b/client/chain/chain.go index 94927266..6a1eb5d7 100644 --- a/client/chain/chain.go +++ b/client/chain/chain.go @@ -23,6 +23,7 @@ import ( log "github.com/xlab/suplog" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "math" "math/big" "net/http" "os" @@ -86,6 +87,8 @@ type ChainClient interface { DerivativeOrder(defaultSubaccountID eth.Hash, network common.Network, d *DerivativeOrderData) *exchangetypes.DerivativeOrder OrderCancel(defaultSubaccountID eth.Hash, d *OrderCancelData) *exchangetypes.OrderData + GetGasFee() (string, error) + Close() } @@ -104,6 +107,7 @@ type chainClient struct { accNum uint64 accSeq uint64 gasWanted uint64 + gasFee string sessionCookie string sessionEnabled bool @@ -656,6 +660,19 @@ func (c *chainClient) runBatchBroadcast() { } } +func (c *chainClient) GetGasFee() (string, error) { + gasPrices := strings.Trim(c.opts.GasPrices, "inj") + + gas, _ := strconv.ParseFloat(gasPrices, 18) + + gasFeeAdjusted := gas * float64(c.gasWanted) / math.Pow(10, 18) + gasFeeFormatted := strconv.FormatFloat(gasFeeAdjusted, 'f', -1, 64) + c.gasFee = gasFeeFormatted + log.Debugln("gas fee: ", c.gasFee+" "+"INJ") + + return c.gasFee, nil +} + func (c *chainClient) DefaultSubaccount(acc cosmtypes.AccAddress) eth.Hash { return eth.BytesToHash(eth.RightPadBytes(acc.Bytes(), 32)) } diff --git a/examples/chain/0_LocalOrderHash/example.go b/examples/chain/0_LocalOrderHash/example.go index dcaf9257..a4a1b7a0 100644 --- a/examples/chain/0_LocalOrderHash/example.go +++ b/examples/chain/0_LocalOrderHash/example.go @@ -16,6 +16,7 @@ func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -29,31 +30,37 @@ func main() { "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided false, ) + if err != nil { panic(err) } + // initialize grpc client + 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) } - // build orders + // prepare tx msg defaultSubaccountID := chainClient.DefaultSubaccount(senderAddress) spotOrder := chainClient.SpotOrder(defaultSubaccountID, network, &chainclient.SpotOrderData{ @@ -81,16 +88,24 @@ func main() { msg1.Sender = senderAddress.String() msg1.Orders = []exchangetypes.DerivativeOrder{*derivativeOrder, *derivativeOrder} + // compute local order hashes orderHashes, err := chainClient.ComputeOrderHashes(msg.Orders, msg1.Orders) + if err != nil { fmt.Println(err) } - fmt.Println("computed spot order hashes", orderHashes.Spot) - fmt.Println("computed derivative order hashes", orderHashes.Derivative) + fmt.Println("computed spot order hashes: ", orderHashes.Spot) + fmt.Println("computed derivative order hashes: ", orderHashes.Derivative) + + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg, msg1) + if err != nil { fmt.Println(err) } + time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/10_MsgBatchCancelDerivativeOrders/example.go b/examples/chain/10_MsgBatchCancelDerivativeOrders/example.go index 041ae47d..919f906d 100644 --- a/examples/chain/10_MsgBatchCancelDerivativeOrders/example.go +++ b/examples/chain/10_MsgBatchCancelDerivativeOrders/example.go @@ -5,18 +5,19 @@ import ( "os" "time" - cosmtypes "github.com/cosmos/cosmos-sdk/types" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" + "github.com/InjectiveLabs/sdk-go/client/common" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + cosmtypes "github.com/cosmos/cosmos-sdk/types" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -73,6 +74,7 @@ func main() { msg.Data = []exchangetypes.OrderData{*order} CosMsgs := []cosmtypes.Msg{msg} + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(CosMsgs...) if err != nil { @@ -80,4 +82,6 @@ func main() { } time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go b/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go index f8cdd3b0..3476b5e8 100644 --- a/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go +++ b/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go @@ -5,18 +5,19 @@ import ( "os" "time" + "github.com/InjectiveLabs/sdk-go/client/common" "github.com/shopspring/decimal" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -76,20 +77,29 @@ func main() { msg.Orders = []exchangetypes.SpotOrder{*order} simRes, err := chainClient.SimulateMsg(clientCtx, msg) + if err != nil { fmt.Println(err) } + simResMsgs := common.MsgResponse(simRes.Result.Data) msgBatchCreateSpotLimitOrdersResponse := exchangetypes.MsgBatchCreateSpotLimitOrdersResponse{} msgBatchCreateSpotLimitOrdersResponse.Unmarshal(simResMsgs[0].Data) + if err != nil { fmt.Println(err) } + fmt.Println("simulated order hashes", msgBatchCreateSpotLimitOrdersResponse.OrderHashes) + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) + if err != nil { fmt.Println(err) } + time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go b/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go index e4f434b2..d6fe9ae1 100644 --- a/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go +++ b/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go @@ -5,19 +5,20 @@ import ( "os" "time" - cosmtypes "github.com/cosmos/cosmos-sdk/types" + "github.com/InjectiveLabs/sdk-go/client/common" "github.com/shopspring/decimal" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + cosmtypes "github.com/cosmos/cosmos-sdk/types" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -81,20 +82,29 @@ func main() { msg.Orders = []exchangetypes.DerivativeOrder{*order} simRes, err := chainClient.SimulateMsg(clientCtx, msg) + if err != nil { fmt.Println(err) } + simResMsgs := common.MsgResponse(simRes.Result.Data) msgBatchCreateDerivativeLimitOrdersResponse := exchangetypes.MsgBatchCreateDerivativeLimitOrdersResponse{} msgBatchCreateDerivativeLimitOrdersResponse.Unmarshal(simResMsgs[0].Data) + if err != nil { fmt.Println(err) } + fmt.Println("simulated order hashes", msgBatchCreateDerivativeLimitOrdersResponse.OrderHashes) + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) + if err != nil { fmt.Println(err) } + time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/13_MsgIncreasePositionMargin/example.go b/examples/chain/13_MsgIncreasePositionMargin/example.go index 658b03d9..977124de 100644 --- a/examples/chain/13_MsgIncreasePositionMargin/example.go +++ b/examples/chain/13_MsgIncreasePositionMargin/example.go @@ -5,18 +5,19 @@ import ( "os" "time" - cosmtypes "github.com/cosmos/cosmos-sdk/types" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" + "github.com/InjectiveLabs/sdk-go/client/common" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + cosmtypes "github.com/cosmos/cosmos-sdk/types" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -66,6 +67,7 @@ func main() { fmt.Println(err) } + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -73,4 +75,6 @@ func main() { } time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/15_MsgWithdraw/example.go b/examples/chain/15_MsgWithdraw/example.go index 5acb8119..49e19f63 100644 --- a/examples/chain/15_MsgWithdraw/example.go +++ b/examples/chain/15_MsgWithdraw/example.go @@ -5,18 +5,19 @@ import ( "os" "time" - sdktypes "github.com/cosmos/cosmos-sdk/types" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" + "github.com/InjectiveLabs/sdk-go/client/common" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + sdktypes "github.com/cosmos/cosmos-sdk/types" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -66,6 +67,7 @@ func main() { fmt.Println(err) } + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -73,4 +75,6 @@ func main() { } time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/16_MsgSubaccountTransfer/example.go b/examples/chain/16_MsgSubaccountTransfer/example.go index 1e1c267f..d68f03f0 100644 --- a/examples/chain/16_MsgSubaccountTransfer/example.go +++ b/examples/chain/16_MsgSubaccountTransfer/example.go @@ -5,18 +5,19 @@ import ( "os" "time" - sdktypes "github.com/cosmos/cosmos-sdk/types" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" + "github.com/InjectiveLabs/sdk-go/client/common" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + sdktypes "github.com/cosmos/cosmos-sdk/types" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -67,6 +68,7 @@ func main() { fmt.Println(err) } + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -74,4 +76,6 @@ func main() { } time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/17_MsgBatchUpdateOrders/example.go b/examples/chain/17_MsgBatchUpdateOrders/example.go index 1578efad..1e17fb62 100644 --- a/examples/chain/17_MsgBatchUpdateOrders/example.go +++ b/examples/chain/17_MsgBatchUpdateOrders/example.go @@ -5,19 +5,20 @@ import ( "os" "time" - cosmtypes "github.com/cosmos/cosmos-sdk/types" + "github.com/InjectiveLabs/sdk-go/client/common" "github.com/shopspring/decimal" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + cosmtypes "github.com/cosmos/cosmos-sdk/types" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -99,6 +100,7 @@ func main() { msg.DerivativeMarketIdsToCancelAll = dmarketIds simRes, err := chainClient.SimulateMsg(clientCtx, msg) + if err != nil { fmt.Println(err) } @@ -111,9 +113,14 @@ func main() { fmt.Println("simulated derivative order hashes", MsgBatchUpdateOrdersResponse.DerivativeOrderHashes) + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) + if err != nil { fmt.Println(err) } + time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/18_MsgBid/example.go b/examples/chain/18_MsgBid/example.go index d485557f..c0bf4da2 100644 --- a/examples/chain/18_MsgBid/example.go +++ b/examples/chain/18_MsgBid/example.go @@ -5,18 +5,19 @@ import ( "os" "time" - sdktypes "github.com/cosmos/cosmos-sdk/types" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" + "github.com/InjectiveLabs/sdk-go/client/common" auctiontypes "github.com/InjectiveLabs/sdk-go/chain/auction/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + sdktypes "github.com/cosmos/cosmos-sdk/types" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -69,6 +70,7 @@ func main() { fmt.Println(err) } + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -76,4 +78,6 @@ func main() { } time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/19_MsgGrant/example.go b/examples/chain/19_MsgGrant/example.go index 49a3572b..2c319db7 100644 --- a/examples/chain/19_MsgGrant/example.go +++ b/examples/chain/19_MsgGrant/example.go @@ -5,16 +5,17 @@ import ( "os" "time" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" + "github.com/InjectiveLabs/sdk-go/client/common" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -28,6 +29,7 @@ func main() { "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided false, ) + if err != nil { panic(err) } @@ -37,9 +39,11 @@ func main() { senderAddress.String(), cosmosKeyring, ) + if err != nil { fmt.Println(err) } + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmRPC) chainClient, err := chainclient.NewChainClient( @@ -48,6 +52,7 @@ func main() { common.OptionTLSCert(network.ChainTlsCert), common.OptionGasPrices("500000000inj"), ) + if err != nil { fmt.Println(err) } @@ -70,9 +75,14 @@ func main() { expireIn, ) + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) + if err != nil { fmt.Println(err) } + time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/1_MsgSend/example.go b/examples/chain/1_MsgSend/example.go index 5ee9c719..c650dff5 100644 --- a/examples/chain/1_MsgSend/example.go +++ b/examples/chain/1_MsgSend/example.go @@ -5,18 +5,19 @@ import ( "os" "time" + "github.com/InjectiveLabs/sdk-go/client/common" + + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" sdktypes "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" rpchttp "github.com/tendermint/tendermint/rpc/client/http" - - chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -35,6 +36,8 @@ func main() { panic(err) } + // initialize grpc client + clientCtx, err := chainclient.NewClientContext( network.ChainId, senderAddress.String(), @@ -47,6 +50,8 @@ func main() { clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmRPC) + // prepare tx msg + msg := &banktypes.MsgSend{ FromAddress: senderAddress.String(), ToAddress: "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r", @@ -66,6 +71,7 @@ func main() { fmt.Println(err) } + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -73,4 +79,6 @@ func main() { } time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/20_MsgExec/example.go b/examples/chain/20_MsgExec/example.go index 92866673..42961994 100644 --- a/examples/chain/20_MsgExec/example.go +++ b/examples/chain/20_MsgExec/example.go @@ -5,21 +5,22 @@ import ( "os" "time" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - authztypes "github.com/cosmos/cosmos-sdk/x/authz" + "github.com/InjectiveLabs/sdk-go/client/common" "github.com/shopspring/decimal" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + authztypes "github.com/cosmos/cosmos-sdk/x/authz" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -33,6 +34,7 @@ func main() { "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided false, ) + if err != nil { panic(err) } @@ -46,6 +48,7 @@ func main() { "f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3", // keyring will be used if pk not provided false, ) + if err != nil { panic(err) } @@ -69,6 +72,7 @@ func main() { common.OptionTLSCert(network.ChainTlsCert), common.OptionGasPrices("500000000inj"), ) + if err != nil { fmt.Println(err) } @@ -105,9 +109,14 @@ func main() { Msgs: []*codectypes.Any{msg0Any}, } + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) + if err != nil { fmt.Println(err) } + time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/21_MsgRevoke/example.go b/examples/chain/21_MsgRevoke/example.go index b0858ad5..e199e190 100644 --- a/examples/chain/21_MsgRevoke/example.go +++ b/examples/chain/21_MsgRevoke/example.go @@ -5,17 +5,18 @@ import ( "os" "time" - authztypes "github.com/cosmos/cosmos-sdk/x/authz" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" + "github.com/InjectiveLabs/sdk-go/client/common" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + authztypes "github.com/cosmos/cosmos-sdk/x/authz" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -66,6 +67,7 @@ func main() { fmt.Println(err) } + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -73,4 +75,6 @@ func main() { } time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/22_MsgSendToEth/example.go b/examples/chain/22_MsgSendToEth/example.go index 198e908e..724225f3 100644 --- a/examples/chain/22_MsgSendToEth/example.go +++ b/examples/chain/22_MsgSendToEth/example.go @@ -5,18 +5,19 @@ import ( "os" "time" - sdktypes "github.com/cosmos/cosmos-sdk/types" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" + "github.com/InjectiveLabs/sdk-go/client/common" peggytypes "github.com/InjectiveLabs/sdk-go/chain/peggy/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + sdktypes "github.com/cosmos/cosmos-sdk/types" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -74,6 +75,7 @@ func main() { fmt.Println(err) } + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -81,4 +83,6 @@ func main() { } time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/23_MsgRelayPriceFeedPrice/example.go b/examples/chain/23_MsgRelayPriceFeedPrice/example.go index bfc25406..d7b813c6 100644 --- a/examples/chain/23_MsgRelayPriceFeedPrice/example.go +++ b/examples/chain/23_MsgRelayPriceFeedPrice/example.go @@ -5,18 +5,19 @@ import ( "os" "time" - cosmtypes "github.com/cosmos/cosmos-sdk/types" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" + "github.com/InjectiveLabs/sdk-go/client/common" oracletypes "github.com/InjectiveLabs/sdk-go/chain/oracle/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + cosmtypes "github.com/cosmos/cosmos-sdk/types" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -69,6 +70,7 @@ func main() { fmt.Println(err) } + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -76,4 +78,6 @@ func main() { } time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/24_MsgRegisterAsDMM/example.go b/examples/chain/24_MsgRegisterAsDMM/example.go index bd3f6ab0..5acf944d 100644 --- a/examples/chain/24_MsgRegisterAsDMM/example.go +++ b/examples/chain/24_MsgRegisterAsDMM/example.go @@ -5,17 +5,18 @@ import ( "os" "time" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" + "github.com/InjectiveLabs/sdk-go/client/common" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -62,11 +63,14 @@ func main() { fmt.Println(err) } - for i := 0; i < 1; i++ { - err := chainClient.QueueBroadcastMsg(msg) - if err != nil { - fmt.Println(err) - } + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + err = chainClient.QueueBroadcastMsg(msg) + + if err != nil { + fmt.Println(err) } + time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/25_MsgDelegate/example.go b/examples/chain/25_MsgDelegate/example.go index b7cf16e9..846abb57 100644 --- a/examples/chain/25_MsgDelegate/example.go +++ b/examples/chain/25_MsgDelegate/example.go @@ -5,18 +5,19 @@ import ( "os" "time" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" + "github.com/InjectiveLabs/sdk-go/client/common" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" sdktypes "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -65,9 +66,14 @@ func main() { Denom: "inj", Amount: sdktypes.NewInt(1000000000000000000), // 1 INJ } + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) + if err != nil { fmt.Println(err) } + time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/26_MsgWithdrawDelegatorReward/example.go b/examples/chain/26_MsgWithdrawDelegatorReward/example.go index 25bb4d1b..7d0e3ea9 100644 --- a/examples/chain/26_MsgWithdrawDelegatorReward/example.go +++ b/examples/chain/26_MsgWithdrawDelegatorReward/example.go @@ -5,17 +5,18 @@ import ( "os" "time" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" + "github.com/InjectiveLabs/sdk-go/client/common" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -61,9 +62,14 @@ func main() { msg.DelegatorAddress = senderAddress.String() msg.ValidatorAddress = "injvaloper14gy4acwjm96wd20awm9ar6j54lev5p7espy9ug" + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) + if err != nil { fmt.Println(err) } + time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/2_MsgDeposit/example.go b/examples/chain/2_MsgDeposit/example.go index ad560973..52cc7ffb 100644 --- a/examples/chain/2_MsgDeposit/example.go +++ b/examples/chain/2_MsgDeposit/example.go @@ -5,18 +5,20 @@ import ( "os" "time" + "github.com/InjectiveLabs/sdk-go/client/common" + sdktypes "github.com/cosmos/cosmos-sdk/types" rpchttp "github.com/tendermint/tendermint/rpc/client/http" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -66,6 +68,7 @@ func main() { fmt.Println(err) } + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -73,4 +76,6 @@ func main() { } time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/3_MsgCreateSpotLimitOrder/example.go b/examples/chain/3_MsgCreateSpotLimitOrder/example.go index c69729f3..8a21150c 100644 --- a/examples/chain/3_MsgCreateSpotLimitOrder/example.go +++ b/examples/chain/3_MsgCreateSpotLimitOrder/example.go @@ -5,18 +5,19 @@ import ( "os" "time" + "github.com/InjectiveLabs/sdk-go/client/common" "github.com/shopspring/decimal" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -78,20 +79,28 @@ func main() { msg.Order = exchangetypes.SpotOrder(*order) simRes, err := chainClient.SimulateMsg(clientCtx, msg) + if err != nil { fmt.Println(err) } + simResMsgs := common.MsgResponse(simRes.Result.Data) msgCreateSpotLimitOrderResponse := exchangetypes.MsgCreateSpotLimitOrderResponse{} msgCreateSpotLimitOrderResponse.Unmarshal(simResMsgs[0].Data) + if err != nil { fmt.Println(err) } - fmt.Println("simulated order hash", msgCreateSpotLimitOrderResponse.OrderHash) + fmt.Println("simulated order hash: ", msgCreateSpotLimitOrderResponse.OrderHash) + + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { fmt.Println(err) } + time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/4_MsgCreateSpotMarketOrder/example.go b/examples/chain/4_MsgCreateSpotMarketOrder/example.go index 6e384041..46b27b0f 100644 --- a/examples/chain/4_MsgCreateSpotMarketOrder/example.go +++ b/examples/chain/4_MsgCreateSpotMarketOrder/example.go @@ -5,18 +5,20 @@ import ( "os" "time" + "github.com/InjectiveLabs/sdk-go/client/common" "github.com/shopspring/decimal" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -84,14 +86,20 @@ func main() { simResMsgs := common.MsgResponse(simRes.Result.Data) msgCreateSpotMarketOrderResponse := exchangetypes.MsgCreateSpotMarketOrderResponse{} msgCreateSpotMarketOrderResponse.Unmarshal(simResMsgs[0].Data) + if err != nil { fmt.Println(err) } + fmt.Println("simulated order hash", msgCreateSpotMarketOrderResponse.OrderHash) + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) + if err != nil { fmt.Println(err) } time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/5_MsgCancelSpotOrder/example.go b/examples/chain/5_MsgCancelSpotOrder/example.go index 8990eae2..ad0881b0 100644 --- a/examples/chain/5_MsgCancelSpotOrder/example.go +++ b/examples/chain/5_MsgCancelSpotOrder/example.go @@ -5,17 +5,18 @@ import ( "os" "time" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" + "github.com/InjectiveLabs/sdk-go/client/common" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -64,6 +65,7 @@ func main() { fmt.Println(err) } + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -71,4 +73,6 @@ func main() { } time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go b/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go index 51d204f3..9df5d9d8 100644 --- a/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go +++ b/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go @@ -5,19 +5,20 @@ import ( "os" "time" - cosmtypes "github.com/cosmos/cosmos-sdk/types" + "github.com/InjectiveLabs/sdk-go/client/common" "github.com/shopspring/decimal" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + cosmtypes "github.com/cosmos/cosmos-sdk/types" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -81,20 +82,29 @@ func main() { msg.Order = exchangetypes.DerivativeOrder(*order) simRes, err := chainClient.SimulateMsg(clientCtx, msg) + if err != nil { fmt.Println(err) } + simResMsgs := common.MsgResponse(simRes.Result.Data) msgCreateDerivativeLimitOrderResponse := exchangetypes.MsgCreateDerivativeLimitOrderResponse{} msgCreateDerivativeLimitOrderResponse.Unmarshal(simResMsgs[0].Data) + if err != nil { fmt.Println(err) } + fmt.Println("simulated order hash", msgCreateDerivativeLimitOrderResponse.OrderHash) + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) + if err != nil { fmt.Println(err) } + time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go b/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go index 4e9c911f..0d338b81 100644 --- a/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go +++ b/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go @@ -5,19 +5,20 @@ import ( "os" "time" - cosmtypes "github.com/cosmos/cosmos-sdk/types" + "github.com/InjectiveLabs/sdk-go/client/common" "github.com/shopspring/decimal" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + cosmtypes "github.com/cosmos/cosmos-sdk/types" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -81,20 +82,29 @@ func main() { msg.Order = exchangetypes.DerivativeOrder(*order) simRes, err := chainClient.SimulateMsg(clientCtx, msg) + if err != nil { fmt.Println(err) } + simResMsgs := common.MsgResponse(simRes.Result.Data) msgCreateDerivativeMarketOrderResponse := exchangetypes.MsgCreateDerivativeMarketOrderResponse{} msgCreateDerivativeMarketOrderResponse.Unmarshal(simResMsgs[0].Data) + if err != nil { fmt.Println(err) } + fmt.Println("simulated order hash", msgCreateDerivativeMarketOrderResponse.OrderHash) + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) + if err != nil { fmt.Println(err) } + time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/8_MsgCancelDerivativeOrder/example.go b/examples/chain/8_MsgCancelDerivativeOrder/example.go index ca587144..33f1b169 100644 --- a/examples/chain/8_MsgCancelDerivativeOrder/example.go +++ b/examples/chain/8_MsgCancelDerivativeOrder/example.go @@ -5,17 +5,18 @@ import ( "os" "time" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" + "github.com/InjectiveLabs/sdk-go/client/common" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -64,6 +65,7 @@ func main() { fmt.Println(err) } + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -71,4 +73,6 @@ func main() { } time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } diff --git a/examples/chain/9_MsgBatchCancelSpotOrders/example.go b/examples/chain/9_MsgBatchCancelSpotOrders/example.go index 3632555b..38ccfee5 100644 --- a/examples/chain/9_MsgBatchCancelSpotOrders/example.go +++ b/examples/chain/9_MsgBatchCancelSpotOrders/example.go @@ -5,18 +5,19 @@ import ( "os" "time" - cosmtypes "github.com/cosmos/cosmos-sdk/types" - rpchttp "github.com/tendermint/tendermint/rpc/client/http" + "github.com/InjectiveLabs/sdk-go/client/common" exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" - "github.com/InjectiveLabs/sdk-go/client/common" + cosmtypes "github.com/cosmos/cosmos-sdk/types" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" ) func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { fmt.Println(err) } @@ -73,6 +74,7 @@ func main() { msg.Data = []exchangetypes.OrderData{*order} CosMsgs := []cosmtypes.Msg{msg} + // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(CosMsgs...) if err != nil { @@ -80,4 +82,6 @@ func main() { } time.Sleep(time.Second * 5) + + chainClient.GetGasFee() } From e8c27543022e7964a59955401175df7baf226c61 Mon Sep 17 00:00:00 2001 From: Achilleas Kalantzis Date: Fri, 13 May 2022 14:33:48 +0100 Subject: [PATCH 2/4] chore: remove nil in GetGasFee --- client/chain/chain.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/client/chain/chain.go b/client/chain/chain.go index 6a1eb5d7..cd73c71a 100644 --- a/client/chain/chain.go +++ b/client/chain/chain.go @@ -87,8 +87,7 @@ type ChainClient interface { DerivativeOrder(defaultSubaccountID eth.Hash, network common.Network, d *DerivativeOrderData) *exchangetypes.DerivativeOrder OrderCancel(defaultSubaccountID eth.Hash, d *OrderCancelData) *exchangetypes.OrderData - GetGasFee() (string, error) - + GetGasFee() string Close() } @@ -660,7 +659,7 @@ func (c *chainClient) runBatchBroadcast() { } } -func (c *chainClient) GetGasFee() (string, error) { +func (c *chainClient) GetGasFee() string { gasPrices := strings.Trim(c.opts.GasPrices, "inj") gas, _ := strconv.ParseFloat(gasPrices, 18) @@ -670,7 +669,7 @@ func (c *chainClient) GetGasFee() (string, error) { c.gasFee = gasFeeFormatted log.Debugln("gas fee: ", c.gasFee+" "+"INJ") - return c.gasFee, nil + return c.gasFee } func (c *chainClient) DefaultSubaccount(acc cosmtypes.AccAddress) eth.Hash { From 38858c9b856e679fbae8a5b834582e7d63e61403 Mon Sep 17 00:00:00 2001 From: Achilleas Kalantzis Date: Fri, 13 May 2022 15:07:10 +0100 Subject: [PATCH 3/4] chore: add err logs for GetGasFee --- client/chain/chain.go | 13 ++++++++----- examples/chain/0_LocalOrderHash/example.go | 9 ++++++++- .../10_MsgBatchCancelDerivativeOrders/example.go | 9 ++++++++- .../11_MsgBatchCreateSpotLimitOrders/example.go | 13 ++++++++++--- .../example.go | 13 ++++++++++--- .../chain/13_MsgIncreasePositionMargin/example.go | 11 +++++++++-- examples/chain/15_MsgWithdraw/example.go | 11 +++++++++-- examples/chain/16_MsgSubaccountTransfer/example.go | 11 +++++++++-- examples/chain/17_MsgBatchUpdateOrders/example.go | 13 ++++++++++--- examples/chain/18_MsgBid/example.go | 11 +++++++++-- examples/chain/19_MsgGrant/example.go | 13 ++++++++++--- examples/chain/1_MsgSend/example.go | 11 +++++++++-- examples/chain/20_MsgExec/example.go | 13 ++++++++++--- examples/chain/21_MsgRevoke/example.go | 11 +++++++++-- examples/chain/22_MsgSendToEth/example.go | 11 +++++++++-- .../chain/23_MsgRelayPriceFeedPrice/example.go | 11 +++++++++-- examples/chain/24_MsgRegisterAsDMM/example.go | 11 +++++++++-- examples/chain/25_MsgDelegate/example.go | 13 ++++++++++--- .../chain/26_MsgWithdrawDelegatorReward/example.go | 13 ++++++++++--- examples/chain/2_MsgDeposit/example.go | 12 +++++++++--- .../chain/3_MsgCreateSpotLimitOrder/example.go | 12 ++++++++++-- .../chain/4_MsgCreateSpotMarketOrder/example.go | 14 +++++++++++--- examples/chain/5_MsgCancelSpotOrder/example.go | 11 +++++++++-- .../6_MsgCreateDerivativeLimitOrder/example.go | 13 ++++++++++--- .../7_MsgCreateDerivativeMarketOrder/example.go | 13 ++++++++++--- .../chain/8_MsgCancelDerivativeOrder/example.go | 11 +++++++++-- .../chain/9_MsgBatchCancelSpotOrders/example.go | 9 ++++++++- 27 files changed, 251 insertions(+), 65 deletions(-) diff --git a/client/chain/chain.go b/client/chain/chain.go index cd73c71a..eecc5b9f 100644 --- a/client/chain/chain.go +++ b/client/chain/chain.go @@ -87,7 +87,7 @@ type ChainClient interface { DerivativeOrder(defaultSubaccountID eth.Hash, network common.Network, d *DerivativeOrderData) *exchangetypes.DerivativeOrder OrderCancel(defaultSubaccountID eth.Hash, d *OrderCancelData) *exchangetypes.OrderData - GetGasFee() string + GetGasFee() (string, error) Close() } @@ -659,17 +659,20 @@ func (c *chainClient) runBatchBroadcast() { } } -func (c *chainClient) GetGasFee() string { +func (c *chainClient) GetGasFee() (string, error) { gasPrices := strings.Trim(c.opts.GasPrices, "inj") - gas, _ := strconv.ParseFloat(gasPrices, 18) + gas, err := strconv.ParseFloat(gasPrices, 64) + + if err != nil { + return "", err + } gasFeeAdjusted := gas * float64(c.gasWanted) / math.Pow(10, 18) gasFeeFormatted := strconv.FormatFloat(gasFeeAdjusted, 'f', -1, 64) c.gasFee = gasFeeFormatted - log.Debugln("gas fee: ", c.gasFee+" "+"INJ") - return c.gasFee + return c.gasFee, err } func (c *chainClient) DefaultSubaccount(acc cosmtypes.AccAddress) eth.Hash { diff --git a/examples/chain/0_LocalOrderHash/example.go b/examples/chain/0_LocalOrderHash/example.go index a4a1b7a0..5c33265d 100644 --- a/examples/chain/0_LocalOrderHash/example.go +++ b/examples/chain/0_LocalOrderHash/example.go @@ -107,5 +107,12 @@ func main() { time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/10_MsgBatchCancelDerivativeOrders/example.go b/examples/chain/10_MsgBatchCancelDerivativeOrders/example.go index 919f906d..9286d060 100644 --- a/examples/chain/10_MsgBatchCancelDerivativeOrders/example.go +++ b/examples/chain/10_MsgBatchCancelDerivativeOrders/example.go @@ -83,5 +83,12 @@ func main() { time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go b/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go index 3476b5e8..706e412f 100644 --- a/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go +++ b/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go @@ -92,14 +92,21 @@ func main() { fmt.Println("simulated order hashes", msgBatchCreateSpotLimitOrdersResponse.OrderHashes) - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { fmt.Println(err) } - + time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go b/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go index d6fe9ae1..7b06bf6a 100644 --- a/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go +++ b/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go @@ -97,14 +97,21 @@ func main() { fmt.Println("simulated order hashes", msgBatchCreateDerivativeLimitOrdersResponse.OrderHashes) - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { fmt.Println(err) } - + time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/13_MsgIncreasePositionMargin/example.go b/examples/chain/13_MsgIncreasePositionMargin/example.go index 977124de..0746e757 100644 --- a/examples/chain/13_MsgIncreasePositionMargin/example.go +++ b/examples/chain/13_MsgIncreasePositionMargin/example.go @@ -67,7 +67,7 @@ func main() { fmt.Println(err) } - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -76,5 +76,12 @@ func main() { time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/15_MsgWithdraw/example.go b/examples/chain/15_MsgWithdraw/example.go index 49e19f63..09513d52 100644 --- a/examples/chain/15_MsgWithdraw/example.go +++ b/examples/chain/15_MsgWithdraw/example.go @@ -67,7 +67,7 @@ func main() { fmt.Println(err) } - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -76,5 +76,12 @@ func main() { time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/16_MsgSubaccountTransfer/example.go b/examples/chain/16_MsgSubaccountTransfer/example.go index d68f03f0..96f41d8d 100644 --- a/examples/chain/16_MsgSubaccountTransfer/example.go +++ b/examples/chain/16_MsgSubaccountTransfer/example.go @@ -68,7 +68,7 @@ func main() { fmt.Println(err) } - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -77,5 +77,12 @@ func main() { time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/17_MsgBatchUpdateOrders/example.go b/examples/chain/17_MsgBatchUpdateOrders/example.go index 1e17fb62..4f296d6e 100644 --- a/examples/chain/17_MsgBatchUpdateOrders/example.go +++ b/examples/chain/17_MsgBatchUpdateOrders/example.go @@ -113,14 +113,21 @@ func main() { fmt.Println("simulated derivative order hashes", MsgBatchUpdateOrdersResponse.DerivativeOrderHashes) - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { fmt.Println(err) } - + time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/18_MsgBid/example.go b/examples/chain/18_MsgBid/example.go index c0bf4da2..2ce266c5 100644 --- a/examples/chain/18_MsgBid/example.go +++ b/examples/chain/18_MsgBid/example.go @@ -70,7 +70,7 @@ func main() { fmt.Println(err) } - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -79,5 +79,12 @@ func main() { time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/19_MsgGrant/example.go b/examples/chain/19_MsgGrant/example.go index 2c319db7..54d2f112 100644 --- a/examples/chain/19_MsgGrant/example.go +++ b/examples/chain/19_MsgGrant/example.go @@ -75,14 +75,21 @@ func main() { expireIn, ) - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { fmt.Println(err) } - + time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/1_MsgSend/example.go b/examples/chain/1_MsgSend/example.go index c650dff5..c80040e8 100644 --- a/examples/chain/1_MsgSend/example.go +++ b/examples/chain/1_MsgSend/example.go @@ -71,7 +71,7 @@ func main() { fmt.Println(err) } - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -80,5 +80,12 @@ func main() { time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/20_MsgExec/example.go b/examples/chain/20_MsgExec/example.go index 42961994..67cb2e20 100644 --- a/examples/chain/20_MsgExec/example.go +++ b/examples/chain/20_MsgExec/example.go @@ -109,14 +109,21 @@ func main() { Msgs: []*codectypes.Any{msg0Any}, } - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { fmt.Println(err) } - + time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/21_MsgRevoke/example.go b/examples/chain/21_MsgRevoke/example.go index e199e190..49c9ce78 100644 --- a/examples/chain/21_MsgRevoke/example.go +++ b/examples/chain/21_MsgRevoke/example.go @@ -67,7 +67,7 @@ func main() { fmt.Println(err) } - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -76,5 +76,12 @@ func main() { time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/22_MsgSendToEth/example.go b/examples/chain/22_MsgSendToEth/example.go index 724225f3..eda469fd 100644 --- a/examples/chain/22_MsgSendToEth/example.go +++ b/examples/chain/22_MsgSendToEth/example.go @@ -75,7 +75,7 @@ func main() { fmt.Println(err) } - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -84,5 +84,12 @@ func main() { time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/23_MsgRelayPriceFeedPrice/example.go b/examples/chain/23_MsgRelayPriceFeedPrice/example.go index d7b813c6..4bf1846b 100644 --- a/examples/chain/23_MsgRelayPriceFeedPrice/example.go +++ b/examples/chain/23_MsgRelayPriceFeedPrice/example.go @@ -70,7 +70,7 @@ func main() { fmt.Println(err) } - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -79,5 +79,12 @@ func main() { time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/24_MsgRegisterAsDMM/example.go b/examples/chain/24_MsgRegisterAsDMM/example.go index 5acf944d..a6706ae7 100644 --- a/examples/chain/24_MsgRegisterAsDMM/example.go +++ b/examples/chain/24_MsgRegisterAsDMM/example.go @@ -63,7 +63,7 @@ func main() { fmt.Println(err) } - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -72,5 +72,12 @@ func main() { time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/25_MsgDelegate/example.go b/examples/chain/25_MsgDelegate/example.go index 846abb57..10c3662c 100644 --- a/examples/chain/25_MsgDelegate/example.go +++ b/examples/chain/25_MsgDelegate/example.go @@ -66,14 +66,21 @@ func main() { Denom: "inj", Amount: sdktypes.NewInt(1000000000000000000), // 1 INJ } - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) - + if err != nil { fmt.Println(err) } time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/26_MsgWithdrawDelegatorReward/example.go b/examples/chain/26_MsgWithdrawDelegatorReward/example.go index 7d0e3ea9..a314b315 100644 --- a/examples/chain/26_MsgWithdrawDelegatorReward/example.go +++ b/examples/chain/26_MsgWithdrawDelegatorReward/example.go @@ -16,7 +16,7 @@ func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") - + if err != nil { fmt.Println(err) } @@ -62,7 +62,7 @@ func main() { msg.DelegatorAddress = senderAddress.String() msg.ValidatorAddress = "injvaloper14gy4acwjm96wd20awm9ar6j54lev5p7espy9ug" - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -71,5 +71,12 @@ func main() { time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/2_MsgDeposit/example.go b/examples/chain/2_MsgDeposit/example.go index 52cc7ffb..1c7c40a3 100644 --- a/examples/chain/2_MsgDeposit/example.go +++ b/examples/chain/2_MsgDeposit/example.go @@ -18,7 +18,6 @@ func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") - if err != nil { fmt.Println(err) } @@ -68,7 +67,7 @@ func main() { fmt.Println(err) } - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -77,5 +76,12 @@ func main() { time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/3_MsgCreateSpotLimitOrder/example.go b/examples/chain/3_MsgCreateSpotLimitOrder/example.go index 8a21150c..c6eafa24 100644 --- a/examples/chain/3_MsgCreateSpotLimitOrder/example.go +++ b/examples/chain/3_MsgCreateSpotLimitOrder/example.go @@ -94,13 +94,21 @@ func main() { fmt.Println("simulated order hash: ", msgCreateSpotLimitOrderResponse.OrderHash) - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) + if err != nil { fmt.Println(err) } time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/4_MsgCreateSpotMarketOrder/example.go b/examples/chain/4_MsgCreateSpotMarketOrder/example.go index 46b27b0f..75c5fcaf 100644 --- a/examples/chain/4_MsgCreateSpotMarketOrder/example.go +++ b/examples/chain/4_MsgCreateSpotMarketOrder/example.go @@ -18,7 +18,7 @@ func main() { // network := common.LoadNetwork("mainnet", "k8s") network := common.LoadNetwork("testnet", "k8s") tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") - + if err != nil { fmt.Println(err) } @@ -93,13 +93,21 @@ func main() { fmt.Println("simulated order hash", msgCreateSpotMarketOrderResponse.OrderHash) - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { fmt.Println(err) } + time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/5_MsgCancelSpotOrder/example.go b/examples/chain/5_MsgCancelSpotOrder/example.go index ad0881b0..b16c3c1a 100644 --- a/examples/chain/5_MsgCancelSpotOrder/example.go +++ b/examples/chain/5_MsgCancelSpotOrder/example.go @@ -65,7 +65,7 @@ func main() { fmt.Println(err) } - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -74,5 +74,12 @@ func main() { time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go b/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go index 9df5d9d8..016ff6bc 100644 --- a/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go +++ b/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go @@ -97,14 +97,21 @@ func main() { fmt.Println("simulated order hash", msgCreateDerivativeLimitOrderResponse.OrderHash) - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { fmt.Println(err) } - + time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go b/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go index 0d338b81..950561b3 100644 --- a/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go +++ b/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go @@ -97,14 +97,21 @@ func main() { fmt.Println("simulated order hash", msgCreateDerivativeMarketOrderResponse.OrderHash) - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { fmt.Println(err) } - + time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/8_MsgCancelDerivativeOrder/example.go b/examples/chain/8_MsgCancelDerivativeOrder/example.go index 33f1b169..2b4c1668 100644 --- a/examples/chain/8_MsgCancelDerivativeOrder/example.go +++ b/examples/chain/8_MsgCancelDerivativeOrder/example.go @@ -65,7 +65,7 @@ func main() { fmt.Println(err) } - // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg err = chainClient.QueueBroadcastMsg(msg) if err != nil { @@ -74,5 +74,12 @@ func main() { time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } diff --git a/examples/chain/9_MsgBatchCancelSpotOrders/example.go b/examples/chain/9_MsgBatchCancelSpotOrders/example.go index 38ccfee5..7e601a72 100644 --- a/examples/chain/9_MsgBatchCancelSpotOrders/example.go +++ b/examples/chain/9_MsgBatchCancelSpotOrders/example.go @@ -83,5 +83,12 @@ func main() { time.Sleep(time.Second * 5) - chainClient.GetGasFee() + gasFee, err := chainClient.GetGasFee() + + if err != nil { + fmt.Println(err) + return + } + + fmt.Println("gas fee: ", gasFee+" "+"INJ") } From dabec288d1106f2cc2572a60f031d14e12b7f97b Mon Sep 17 00:00:00 2001 From: Achilleas Kalantzis Date: Fri, 13 May 2022 15:27:16 +0100 Subject: [PATCH 4/4] fix: gas fee logs --- examples/chain/0_LocalOrderHash/example.go | 2 +- examples/chain/10_MsgBatchCancelDerivativeOrders/example.go | 2 +- examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go | 2 +- .../chain/12_MsgBatchCreateDerivativeLimitOrders/example.go | 2 +- examples/chain/13_MsgIncreasePositionMargin/example.go | 2 +- examples/chain/15_MsgWithdraw/example.go | 2 +- examples/chain/16_MsgSubaccountTransfer/example.go | 2 +- examples/chain/17_MsgBatchUpdateOrders/example.go | 2 +- examples/chain/18_MsgBid/example.go | 2 +- examples/chain/19_MsgGrant/example.go | 2 +- examples/chain/1_MsgSend/example.go | 2 +- examples/chain/20_MsgExec/example.go | 2 +- examples/chain/21_MsgRevoke/example.go | 2 +- examples/chain/22_MsgSendToEth/example.go | 2 +- examples/chain/23_MsgRelayPriceFeedPrice/example.go | 2 +- examples/chain/24_MsgRegisterAsDMM/example.go | 2 +- examples/chain/25_MsgDelegate/example.go | 2 +- examples/chain/26_MsgWithdrawDelegatorReward/example.go | 2 +- examples/chain/2_MsgDeposit/example.go | 2 +- examples/chain/3_MsgCreateSpotLimitOrder/example.go | 2 +- examples/chain/4_MsgCreateSpotMarketOrder/example.go | 2 +- examples/chain/5_MsgCancelSpotOrder/example.go | 2 +- examples/chain/6_MsgCreateDerivativeLimitOrder/example.go | 2 +- examples/chain/7_MsgCreateDerivativeMarketOrder/example.go | 2 +- examples/chain/8_MsgCancelDerivativeOrder/example.go | 2 +- examples/chain/9_MsgBatchCancelSpotOrders/example.go | 2 +- 26 files changed, 26 insertions(+), 26 deletions(-) diff --git a/examples/chain/0_LocalOrderHash/example.go b/examples/chain/0_LocalOrderHash/example.go index 5c33265d..762f1357 100644 --- a/examples/chain/0_LocalOrderHash/example.go +++ b/examples/chain/0_LocalOrderHash/example.go @@ -114,5 +114,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/10_MsgBatchCancelDerivativeOrders/example.go b/examples/chain/10_MsgBatchCancelDerivativeOrders/example.go index 9286d060..a4b2d12f 100644 --- a/examples/chain/10_MsgBatchCancelDerivativeOrders/example.go +++ b/examples/chain/10_MsgBatchCancelDerivativeOrders/example.go @@ -90,5 +90,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go b/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go index 706e412f..bac648cd 100644 --- a/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go +++ b/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go @@ -108,5 +108,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go b/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go index 7b06bf6a..2e12dfac 100644 --- a/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go +++ b/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go @@ -113,5 +113,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/13_MsgIncreasePositionMargin/example.go b/examples/chain/13_MsgIncreasePositionMargin/example.go index 0746e757..c4c8ca45 100644 --- a/examples/chain/13_MsgIncreasePositionMargin/example.go +++ b/examples/chain/13_MsgIncreasePositionMargin/example.go @@ -83,5 +83,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/15_MsgWithdraw/example.go b/examples/chain/15_MsgWithdraw/example.go index 09513d52..a5c5fafd 100644 --- a/examples/chain/15_MsgWithdraw/example.go +++ b/examples/chain/15_MsgWithdraw/example.go @@ -83,5 +83,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/16_MsgSubaccountTransfer/example.go b/examples/chain/16_MsgSubaccountTransfer/example.go index 96f41d8d..925443fa 100644 --- a/examples/chain/16_MsgSubaccountTransfer/example.go +++ b/examples/chain/16_MsgSubaccountTransfer/example.go @@ -84,5 +84,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/17_MsgBatchUpdateOrders/example.go b/examples/chain/17_MsgBatchUpdateOrders/example.go index 4f296d6e..2c1ef9d0 100644 --- a/examples/chain/17_MsgBatchUpdateOrders/example.go +++ b/examples/chain/17_MsgBatchUpdateOrders/example.go @@ -129,5 +129,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/18_MsgBid/example.go b/examples/chain/18_MsgBid/example.go index 2ce266c5..92772db8 100644 --- a/examples/chain/18_MsgBid/example.go +++ b/examples/chain/18_MsgBid/example.go @@ -86,5 +86,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/19_MsgGrant/example.go b/examples/chain/19_MsgGrant/example.go index 54d2f112..5726be10 100644 --- a/examples/chain/19_MsgGrant/example.go +++ b/examples/chain/19_MsgGrant/example.go @@ -91,5 +91,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/1_MsgSend/example.go b/examples/chain/1_MsgSend/example.go index c80040e8..8e217d97 100644 --- a/examples/chain/1_MsgSend/example.go +++ b/examples/chain/1_MsgSend/example.go @@ -87,5 +87,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/20_MsgExec/example.go b/examples/chain/20_MsgExec/example.go index 67cb2e20..1ec6b24d 100644 --- a/examples/chain/20_MsgExec/example.go +++ b/examples/chain/20_MsgExec/example.go @@ -125,5 +125,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/21_MsgRevoke/example.go b/examples/chain/21_MsgRevoke/example.go index 49c9ce78..1b4a9f45 100644 --- a/examples/chain/21_MsgRevoke/example.go +++ b/examples/chain/21_MsgRevoke/example.go @@ -83,5 +83,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/22_MsgSendToEth/example.go b/examples/chain/22_MsgSendToEth/example.go index eda469fd..731be7c1 100644 --- a/examples/chain/22_MsgSendToEth/example.go +++ b/examples/chain/22_MsgSendToEth/example.go @@ -91,5 +91,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/23_MsgRelayPriceFeedPrice/example.go b/examples/chain/23_MsgRelayPriceFeedPrice/example.go index 4bf1846b..cc0ce7ab 100644 --- a/examples/chain/23_MsgRelayPriceFeedPrice/example.go +++ b/examples/chain/23_MsgRelayPriceFeedPrice/example.go @@ -86,5 +86,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/24_MsgRegisterAsDMM/example.go b/examples/chain/24_MsgRegisterAsDMM/example.go index a6706ae7..a5698dd0 100644 --- a/examples/chain/24_MsgRegisterAsDMM/example.go +++ b/examples/chain/24_MsgRegisterAsDMM/example.go @@ -79,5 +79,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/25_MsgDelegate/example.go b/examples/chain/25_MsgDelegate/example.go index 10c3662c..10920449 100644 --- a/examples/chain/25_MsgDelegate/example.go +++ b/examples/chain/25_MsgDelegate/example.go @@ -82,5 +82,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/26_MsgWithdrawDelegatorReward/example.go b/examples/chain/26_MsgWithdrawDelegatorReward/example.go index a314b315..ae8a918b 100644 --- a/examples/chain/26_MsgWithdrawDelegatorReward/example.go +++ b/examples/chain/26_MsgWithdrawDelegatorReward/example.go @@ -78,5 +78,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/2_MsgDeposit/example.go b/examples/chain/2_MsgDeposit/example.go index 1c7c40a3..3fd3b77b 100644 --- a/examples/chain/2_MsgDeposit/example.go +++ b/examples/chain/2_MsgDeposit/example.go @@ -83,5 +83,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/3_MsgCreateSpotLimitOrder/example.go b/examples/chain/3_MsgCreateSpotLimitOrder/example.go index c6eafa24..bff0c420 100644 --- a/examples/chain/3_MsgCreateSpotLimitOrder/example.go +++ b/examples/chain/3_MsgCreateSpotLimitOrder/example.go @@ -110,5 +110,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/4_MsgCreateSpotMarketOrder/example.go b/examples/chain/4_MsgCreateSpotMarketOrder/example.go index 75c5fcaf..66fcc7ec 100644 --- a/examples/chain/4_MsgCreateSpotMarketOrder/example.go +++ b/examples/chain/4_MsgCreateSpotMarketOrder/example.go @@ -109,5 +109,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/5_MsgCancelSpotOrder/example.go b/examples/chain/5_MsgCancelSpotOrder/example.go index b16c3c1a..29586ff2 100644 --- a/examples/chain/5_MsgCancelSpotOrder/example.go +++ b/examples/chain/5_MsgCancelSpotOrder/example.go @@ -81,5 +81,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go b/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go index 016ff6bc..83efe047 100644 --- a/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go +++ b/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go @@ -113,5 +113,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go b/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go index 950561b3..0c7f6263 100644 --- a/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go +++ b/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go @@ -113,5 +113,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/8_MsgCancelDerivativeOrder/example.go b/examples/chain/8_MsgCancelDerivativeOrder/example.go index 2b4c1668..999e9006 100644 --- a/examples/chain/8_MsgCancelDerivativeOrder/example.go +++ b/examples/chain/8_MsgCancelDerivativeOrder/example.go @@ -81,5 +81,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") } diff --git a/examples/chain/9_MsgBatchCancelSpotOrders/example.go b/examples/chain/9_MsgBatchCancelSpotOrders/example.go index 7e601a72..e97eff31 100644 --- a/examples/chain/9_MsgBatchCancelSpotOrders/example.go +++ b/examples/chain/9_MsgBatchCancelSpotOrders/example.go @@ -90,5 +90,5 @@ func main() { return } - fmt.Println("gas fee: ", gasFee+" "+"INJ") + fmt.Println("gas fee:", gasFee, "INJ") }