/
interchain.go
78 lines (65 loc) · 1.48 KB
/
interchain.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
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"fmt"
"github.com/meshplus/bitxhub-kit/types"
"github.com/meshplus/bitxhub-model/constant"
rpcx "github.com/meshplus/go-bitxhub-client"
"github.com/meshplus/pier/internal/repo"
"github.com/urfave/cli"
)
var interchainCMD = cli.Command{
Name: "interchain",
Usage: "Query interchain info",
Flags: []cli.Flag{
cli.StringFlag{
Name: "key",
Usage: "Specify key.json path",
Required: true,
},
},
Subcommands: []cli.Command{
{
Name: "ibtp",
Usage: "Query ibtp by id",
Flags: []cli.Flag{
cli.StringFlag{
Name: "id",
Usage: "Specific ibtp id",
Required: true,
},
},
Action: getIBTP,
},
},
}
func getIBTP(ctx *cli.Context) error {
id := ctx.String("id")
repoRoot, err := repo.PathRootWithDefault(ctx.GlobalString("repo"))
if err != nil {
return err
}
config, err := repo.UnmarshalConfig(repoRoot)
if err != nil {
return fmt.Errorf("init config error: %s", err)
}
client, err := loadClient(repo.KeyPath(repoRoot), config.Mode.Relay.Addrs, ctx)
if err != nil {
return fmt.Errorf("load client: %w", err)
}
receipt, err := client.InvokeBVMContract(
constant.InterchainContractAddr.Address(),
"GetIBTPByID", nil,
rpcx.String(id), rpcx.Bool(true),
)
if err != nil {
return err
}
hash := types.NewHash(receipt.Ret)
fmt.Printf("Tx hash: %s\n", hash.String())
response, err := client.GetTransaction(hash.String())
if err != nil {
return err
}
fmt.Println(response)
return nil
}