7 "github.com/spf13/cobra"
8 jww "github.com/spf13/jwalterweatherman"
10 "github.com/bytom/blockchain"
11 "github.com/bytom/env"
15 home = blockchain.HomeDirFromEnvironment()
16 coreURL = env.String("BYTOM_URL", "http://localhost:9888")
19 var blockHashCmd = &cobra.Command{
21 Short: "Get the hash of most recent block",
23 Run: func(cmd *cobra.Command, args []string) {
24 data, exitCode := clientCall("block-hash")
25 if exitCode != Success {
32 var blockHeightCmd = &cobra.Command{
34 Short: "Get the number of most recent block",
36 Run: func(cmd *cobra.Command, args []string) {
37 data, exitCode := clientCall("/block-height")
38 if exitCode != Success {
45 var getBlockByHashCmd = &cobra.Command{
46 Use: "get-block-by-hash <hash>",
47 Short: "Get a whole block matching the given hash",
48 Args: cobra.ExactArgs(1),
49 Run: func(cmd *cobra.Command, args []string) {
50 data, exitCode := clientCall("/get-block-by-hash", args[0])
51 if exitCode != Success {
58 var getBlockHeaderByHashCmd = &cobra.Command{
59 Use: "get-block-header-by-hash",
60 Short: "Get the header of a block matching the given hash",
61 Args: cobra.ExactArgs(1),
62 Run: func(cmd *cobra.Command, args []string) {
63 data, exitCode := clientCall("/get-block-header-by-hash", args[0])
64 if exitCode != Success {
71 var getBlockTransactionsCountByHashCmd = &cobra.Command{
72 Use: "get-block-transactions-count-by-hash",
73 Short: "Get the transactions count of a block matching the given hash",
74 Args: cobra.ExactArgs(1),
75 Run: func(cmd *cobra.Command, args []string) {
76 data, exitCode := clientCall("/get-block-transactions-count-by-hash", args[0])
77 if exitCode != Success {
84 var getBlockByHeightCmd = &cobra.Command{
85 Use: "get-block-by-height <height>",
86 Short: "Get a whole block matching the given height",
87 Args: cobra.ExactArgs(1),
88 Run: func(cmd *cobra.Command, args []string) {
89 height, err := strconv.ParseUint(args[0], 10, 64)
91 jww.ERROR.Printf("Invalid height value")
95 data, exitCode := clientCall("/get-block-by-height", height)
96 if exitCode != Success {
104 var getBlockTransactionsCountByHeightCmd = &cobra.Command{
105 Use: "get-block-transactions-count-by-height",
106 Short: "Get the transactions count of a block matching the given height",
107 Args: cobra.ExactArgs(1),
108 Run: func(cmd *cobra.Command, args []string) {
109 ui64, err := strconv.ParseUint(args[0], 10, 64)
111 jww.ERROR.Printf("Invalid height value")
115 data, exitCode := clientCall("/get-block-transactions-count-by-height", ui64)
116 if exitCode != Success {