-
Notifications
You must be signed in to change notification settings - Fork 1
/
query_get_price.go
58 lines (47 loc) · 1.51 KB
/
query_get_price.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package query
import (
"strconv"
"strings"
"github.com/Timwood0x10/sei-chain/x/dex/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
)
var _ = strconv.Itoa(0)
func CmdGetPrice() *cobra.Command {
cmd := &cobra.Command{
Use: "get-price [contract-address] [timestamp] [price-denom] [asset-denom]",
Short: "Query getPrice",
Long: strings.TrimSpace(`
Get the price for a pair from a dex specified by the contract-address. The price and asset denom are used to specify the dex pair for which to return the latest price. The timestamp is used to query the price for that specific timestamp. For the latest price use get-latest-price instead or for all prices use get-prices.
`),
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) (err error) {
reqContractAddr := args[0]
reqTimestamp, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
return err
}
reqPriceDenom := args[2]
reqAssetDenom := args[3]
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
params := &types.QueryGetPriceRequest{
ContractAddr: reqContractAddr,
PriceDenom: reqPriceDenom,
AssetDenom: reqAssetDenom,
Timestamp: reqTimestamp,
}
res, err := queryClient.GetPrice(cmd.Context(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}