MCPcopy Create free account
hub / github.com/CPChain/chain / main

Function main

tools/smartcontract/testtool/testtool.go:35–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

33)
34
35func main() {
36 app := cli.NewApp()
37 app.Usage = "executable command tool for easy test"
38 app.Flags = []cli.Flag{
39 cli.StringFlag{
40 Name: ENDPOINT + ",ep",
41 Value: "http://127.0.0.1:8521",
42 Usage: "endpoint like http://127.0.0.1:8521",
43 },
44 }
45
46 app.Commands = []cli.Command{
47 {
48 Name: "get_block_number",
49 Aliases: []string{"bn"},
50 Usage: "get block number",
51 Action: func(c *cli.Context) error {
52 endpoint := c.GlobalString(ENDPOINT)
53 client, err := cpclient.Dial(endpoint)
54 if err != nil {
55 log.Fatal(err.Error())
56 }
57 blockNumber := client.GetBlockNumber()
58 fmt.Println(blockNumber)
59 return nil
60 },
61 },
62 {
63 Name: "balance",
64 Aliases: []string{"bal"},
65 Usage: "get balance by address. \n\t\texample: ./testtool bal ${addr}",
66 Action: func(c *cli.Context) error {
67 endpoint := c.GlobalString(ENDPOINT)
68 client, err := cpclient.Dial(endpoint)
69 if err != nil {
70 log.Fatal(err.Error())
71 }
72 balance, _ := client.BalanceAt(context.Background(), common.HexToAddress(c.Args().First()), nil)
73 fmt.Println(balance)
74 return nil
75 },
76 },
77 }
78
79 sort.Sort(cli.FlagsByName(app.Flags))
80 sort.Sort(cli.CommandsByName(app.Commands))
81
82 err := app.Run(os.Args)
83 if err != nil {
84 log.Fatal(err)
85 }
86}

Callers

nothing calls this directly

Calls 6

SortMethod · 0.80
FatalMethod · 0.65
ErrorMethod · 0.65
BalanceAtMethod · 0.65
RunMethod · 0.65
GetBlockNumberMethod · 0.45

Tested by

no test coverage detected