Skip to content

Commit

Permalink
feat(chain-examples) remove usage of deprecated data in SimulateResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoragrega committed Jun 1, 2023
1 parent 7bc9e31 commit a0aa02f
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 17 deletions.
8 changes: 6 additions & 2 deletions examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func main() {

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

clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
Expand All @@ -56,6 +57,7 @@ func main() {

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

defaultSubaccountID := chainClient.DefaultSubaccount(senderAddress)
Expand All @@ -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)
Expand All @@ -96,6 +99,7 @@ func main() {

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

time.Sleep(time.Second * 5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func main() {

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

clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
Expand All @@ -57,6 +58,7 @@ func main() {

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

defaultSubaccountID := chainClient.DefaultSubaccount(senderAddress)
Expand Down Expand Up @@ -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)
Expand All @@ -101,6 +104,7 @@ func main() {

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

time.Sleep(time.Second * 5)
Expand Down
7 changes: 5 additions & 2 deletions examples/chain/17_MsgBatchUpdateOrders/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func main() {

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

clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
Expand All @@ -57,6 +58,7 @@ func main() {

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

defaultSubaccountID := chainClient.DefaultSubaccount(senderAddress)
Expand Down Expand Up @@ -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)

Expand All @@ -117,6 +119,7 @@ func main() {

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

time.Sleep(time.Second * 5)
Expand Down
9 changes: 7 additions & 2 deletions examples/chain/38_MsgLiquidate/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func main() {

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

senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
Expand All @@ -44,6 +45,7 @@ func main() {

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

clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmRPC)
Expand All @@ -57,6 +59,7 @@ func main() {

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

defaultSubaccountID := chainClient.DefaultSubaccount(senderAddress)
Expand All @@ -74,21 +77,23 @@ 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
err = chainClient.QueueBroadcastMsg(&liqMsg)

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

time.Sleep(time.Second * 5)
Expand Down
10 changes: 7 additions & 3 deletions examples/chain/3_MsgCreateSpotLimitOrder/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func main() {
)
if err != nil {
fmt.Println(err)
return
}
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -96,6 +99,7 @@ func main() {

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

time.Sleep(time.Second * 5)
Expand Down
8 changes: 6 additions & 2 deletions examples/chain/4_MsgCreateSpotMarketOrder/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func main() {

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

defaultSubaccountID := chainClient.DefaultSubaccount(senderAddress)
Expand All @@ -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)
Expand All @@ -95,6 +98,7 @@ func main() {

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

time.Sleep(time.Second * 5)
Expand Down
3 changes: 1 addition & 2 deletions examples/chain/6_MsgCreateDerivativeLimitOrder/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions examples/chain/7_MsgCreateDerivativeMarketOrder/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func main() {

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

clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
Expand All @@ -57,6 +58,7 @@ func main() {

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

defaultSubaccountID := chainClient.DefaultSubaccount(senderAddress)
Expand Down Expand Up @@ -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)
Expand All @@ -101,6 +104,7 @@ func main() {

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

time.Sleep(time.Second * 5)
Expand Down

0 comments on commit a0aa02f

Please sign in to comment.