From a0aa02fbb998fb1cf947935360106b34fa0b9544 Mon Sep 17 00:00:00 2001 From: Hilari Moragrega Date: Thu, 1 Jun 2023 21:41:51 +0200 Subject: [PATCH] feat(chain-examples) remove usage of deprecated data in SimulateResponse --- .../chain/11_MsgBatchCreateSpotLimitOrders/example.go | 8 ++++++-- .../12_MsgBatchCreateDerivativeLimitOrders/example.go | 8 ++++++-- examples/chain/17_MsgBatchUpdateOrders/example.go | 7 +++++-- examples/chain/38_MsgLiquidate/example.go | 9 +++++++-- examples/chain/3_MsgCreateSpotLimitOrder/example.go | 10 +++++++--- examples/chain/4_MsgCreateSpotMarketOrder/example.go | 8 ++++++-- .../chain/6_MsgCreateDerivativeLimitOrder/example.go | 3 +-- .../chain/7_MsgCreateDerivativeMarketOrder/example.go | 8 ++++++-- 8 files changed, 44 insertions(+), 17 deletions(-) diff --git a/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go b/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go index 2ec68045..53f55a91 100644 --- a/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go +++ b/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go @@ -43,6 +43,7 @@ func main() { if err != nil { fmt.Println(err) + return } clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) @@ -56,6 +57,7 @@ func main() { if err != nil { fmt.Println(err) + return } defaultSubaccountID := chainClient.DefaultSubaccount(senderAddress) @@ -79,14 +81,15 @@ func main() { if err != nil { fmt.Println(err) + return } - simResMsgs := common.MsgResponse(simRes.Result.Data) msgBatchCreateSpotLimitOrdersResponse := exchangetypes.MsgBatchCreateSpotLimitOrdersResponse{} - msgBatchCreateSpotLimitOrdersResponse.Unmarshal(simResMsgs[0].Data) + err = msgBatchCreateSpotLimitOrdersResponse.Unmarshal(simRes.Result.MsgResponses[0].Value) if err != nil { fmt.Println(err) + return } fmt.Println("simulated order hashes", msgBatchCreateSpotLimitOrdersResponse.OrderHashes) @@ -96,6 +99,7 @@ func main() { if err != nil { fmt.Println(err) + return } time.Sleep(time.Second * 5) diff --git a/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go b/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go index 4c5ccbb4..3e372d16 100644 --- a/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go +++ b/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go @@ -44,6 +44,7 @@ func main() { if err != nil { fmt.Println(err) + return } clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) @@ -57,6 +58,7 @@ func main() { if err != nil { fmt.Println(err) + return } defaultSubaccountID := chainClient.DefaultSubaccount(senderAddress) @@ -84,14 +86,15 @@ func main() { if err != nil { fmt.Println(err) + return } - simResMsgs := common.MsgResponse(simRes.Result.Data) msgBatchCreateDerivativeLimitOrdersResponse := exchangetypes.MsgBatchCreateDerivativeLimitOrdersResponse{} - msgBatchCreateDerivativeLimitOrdersResponse.Unmarshal(simResMsgs[0].Data) + err = msgBatchCreateDerivativeLimitOrdersResponse.Unmarshal(simRes.Result.MsgResponses[0].Value) if err != nil { fmt.Println(err) + return } fmt.Println("simulated order hashes", msgBatchCreateDerivativeLimitOrdersResponse.OrderHashes) @@ -101,6 +104,7 @@ func main() { if err != nil { fmt.Println(err) + return } time.Sleep(time.Second * 5) diff --git a/examples/chain/17_MsgBatchUpdateOrders/example.go b/examples/chain/17_MsgBatchUpdateOrders/example.go index 8abd3406..bb354206 100644 --- a/examples/chain/17_MsgBatchUpdateOrders/example.go +++ b/examples/chain/17_MsgBatchUpdateOrders/example.go @@ -44,6 +44,7 @@ func main() { if err != nil { fmt.Println(err) + return } clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) @@ -57,6 +58,7 @@ func main() { if err != nil { fmt.Println(err) + return } defaultSubaccountID := chainClient.DefaultSubaccount(senderAddress) @@ -102,11 +104,11 @@ func main() { if err != nil { fmt.Println(err) + return } - simResMsgs := common.MsgResponse(simRes.Result.Data) MsgBatchUpdateOrdersResponse := exchangetypes.MsgBatchUpdateOrdersResponse{} - MsgBatchUpdateOrdersResponse.Unmarshal(simResMsgs[0].Data) + MsgBatchUpdateOrdersResponse.Unmarshal(simRes.Result.MsgResponses[0].Value) fmt.Println("simulated spot order hashes", MsgBatchUpdateOrdersResponse.SpotOrderHashes) @@ -117,6 +119,7 @@ func main() { if err != nil { fmt.Println(err) + return } time.Sleep(time.Second * 5) diff --git a/examples/chain/38_MsgLiquidate/example.go b/examples/chain/38_MsgLiquidate/example.go index be75396b..e3f2209e 100644 --- a/examples/chain/38_MsgLiquidate/example.go +++ b/examples/chain/38_MsgLiquidate/example.go @@ -20,6 +20,7 @@ func main() { if err != nil { fmt.Println(err) + return } senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( @@ -44,6 +45,7 @@ func main() { if err != nil { fmt.Println(err) + return } clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmRPC) @@ -57,6 +59,7 @@ func main() { if err != nil { fmt.Println(err) + return } defaultSubaccountID := chainClient.DefaultSubaccount(senderAddress) @@ -74,14 +77,15 @@ func main() { if err != nil { fmt.Println(err) + return } - simResMsgs := common.MsgResponse(simRes.Result.Data) msgLiquidatePositionResponse := exchangetypes.MsgLiquidatePositionResponse{} - msgLiquidatePositionResponse.Unmarshal(simResMsgs[0].Data) + msgLiquidatePositionResponse.Unmarshal(simRes.Result.MsgResponses[0].Value) if err != nil { fmt.Println(err) + return } //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg @@ -89,6 +93,7 @@ func main() { if err != nil { fmt.Println(err) + return } time.Sleep(time.Second * 5) diff --git a/examples/chain/3_MsgCreateSpotLimitOrder/example.go b/examples/chain/3_MsgCreateSpotLimitOrder/example.go index 934a431e..1bea2311 100644 --- a/examples/chain/3_MsgCreateSpotLimitOrder/example.go +++ b/examples/chain/3_MsgCreateSpotLimitOrder/example.go @@ -42,6 +42,7 @@ func main() { ) if err != nil { fmt.Println(err) + return } clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) @@ -54,11 +55,12 @@ func main() { if err != nil { fmt.Println(err) + return } defaultSubaccountID := chainClient.DefaultSubaccount(senderAddress) - marketId := "0x0511ddc4e6586f3bfe1acb2dd905f8b8a82c97e1edaef654b12ca7e6031ca0fa" + marketId := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" amount := decimal.NewFromFloat(2) price := decimal.NewFromFloat(22.55) @@ -79,14 +81,15 @@ func main() { if err != nil { fmt.Println(err) + return } - simResMsgs := common.MsgResponse(simRes.Result.Data) msgCreateSpotLimitOrderResponse := exchangetypes.MsgCreateSpotLimitOrderResponse{} - msgCreateSpotLimitOrderResponse.Unmarshal(simResMsgs[0].Data) + err = msgCreateSpotLimitOrderResponse.Unmarshal(simRes.Result.MsgResponses[0].Value) if err != nil { fmt.Println(err) + return } fmt.Println("simulated order hash: ", msgCreateSpotLimitOrderResponse.OrderHash) @@ -96,6 +99,7 @@ func main() { if err != nil { fmt.Println(err) + return } time.Sleep(time.Second * 5) diff --git a/examples/chain/4_MsgCreateSpotMarketOrder/example.go b/examples/chain/4_MsgCreateSpotMarketOrder/example.go index 651d9110..34c60eb4 100644 --- a/examples/chain/4_MsgCreateSpotMarketOrder/example.go +++ b/examples/chain/4_MsgCreateSpotMarketOrder/example.go @@ -56,6 +56,7 @@ func main() { if err != nil { fmt.Println(err) + return } defaultSubaccountID := chainClient.DefaultSubaccount(senderAddress) @@ -79,13 +80,15 @@ func main() { simRes, err := chainClient.SimulateMsg(clientCtx, msg) if err != nil { fmt.Println(err) + return } - simResMsgs := common.MsgResponse(simRes.Result.Data) + msgCreateSpotMarketOrderResponse := exchangetypes.MsgCreateSpotMarketOrderResponse{} - msgCreateSpotMarketOrderResponse.Unmarshal(simResMsgs[0].Data) + err = msgCreateSpotMarketOrderResponse.Unmarshal(simRes.Result.MsgResponses[0].Value) if err != nil { fmt.Println(err) + return } fmt.Println("simulated order hash", msgCreateSpotMarketOrderResponse.OrderHash) @@ -95,6 +98,7 @@ func main() { if err != nil { fmt.Println(err) + return } time.Sleep(time.Second * 5) diff --git a/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go b/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go index 40ed6cea..69d572b4 100644 --- a/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go +++ b/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go @@ -86,9 +86,8 @@ func main() { fmt.Println(err) } - simResMsgs := common.MsgResponse(simRes.Result.Data) msgCreateDerivativeLimitOrderResponse := exchangetypes.MsgCreateDerivativeLimitOrderResponse{} - msgCreateDerivativeLimitOrderResponse.Unmarshal(simResMsgs[0].Data) + err = msgCreateDerivativeLimitOrderResponse.Unmarshal(simRes.Result.MsgResponses[0].Value) if err != nil { fmt.Println(err) diff --git a/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go b/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go index 560d1b49..6474ffce 100644 --- a/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go +++ b/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go @@ -44,6 +44,7 @@ func main() { if err != nil { fmt.Println(err) + return } clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) @@ -57,6 +58,7 @@ func main() { if err != nil { fmt.Println(err) + return } defaultSubaccountID := chainClient.DefaultSubaccount(senderAddress) @@ -84,14 +86,15 @@ func main() { if err != nil { fmt.Println(err) + return } - simResMsgs := common.MsgResponse(simRes.Result.Data) msgCreateDerivativeMarketOrderResponse := exchangetypes.MsgCreateDerivativeMarketOrderResponse{} - msgCreateDerivativeMarketOrderResponse.Unmarshal(simResMsgs[0].Data) + err = msgCreateDerivativeMarketOrderResponse.Unmarshal(simRes.Result.MsgResponses[0].Value) if err != nil { fmt.Println(err) + return } fmt.Println("simulated order hash", msgCreateDerivativeMarketOrderResponse.OrderHash) @@ -101,6 +104,7 @@ func main() { if err != nil { fmt.Println(err) + return } time.Sleep(time.Second * 5)