/
query.go
65 lines (52 loc) · 1.77 KB
/
query.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
59
60
61
62
63
64
65
package cli
import (
"fmt"
"strconv"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/sun-blockchain/harmony-cosmos-cross/x/ethbridge/types"
)
// GetCmdGetEthBridgeProphecy queries information about a specific prophecy
func GetCmdGetEthBridgeProphecy(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: `prophecy [bridge-registry-contract] [nonce] [symbol] [ethereum-sender]
--ethereum-chain-id [ethereum-chain-id] --token-contract-address [token-contract-address]`,
Short: "Query prophecy",
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
ethereumChainIDString := viper.GetString(types.FlagEthereumChainID)
ethereumChainID, err := strconv.Atoi(ethereumChainIDString)
if err != nil {
return err
}
tokenContractString := viper.GetString(types.FlagTokenContractAddr)
tokenContract := types.NewEthereumAddress(tokenContractString)
bridgeContract := types.NewEthereumAddress(args[0])
nonce, err := strconv.Atoi(args[1])
if err != nil {
return err
}
symbol := args[2]
ethereumSender := types.NewEthereumAddress(args[3])
bz, err := cdc.MarshalJSON(types.NewQueryEthProphecyParams(
ethereumChainID, bridgeContract, nonce, symbol, tokenContract, ethereumSender))
if err != nil {
return err
}
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryEthProphecy)
res, _, err := cliCtx.QueryWithData(route, bz)
if err != nil {
return err
}
var out types.QueryEthProphecyResponse
err = cdc.UnmarshalJSON(res, &out)
if err != nil {
return err
}
return cliCtx.PrintOutput(out)
},
}
}