parent
a865f18e6d
commit
92b1117cab
@ -0,0 +1,73 @@ |
||||
package cmd |
||||
|
||||
import ( |
||||
"fmt" |
||||
"strings" |
||||
|
||||
// homedir "github.com/mitchellh/go-homedir"
|
||||
"github.com/spf13/cobra" |
||||
) |
||||
|
||||
func init() { |
||||
cmdKeys := &cobra.Command{ |
||||
Use: "keys", |
||||
Short: "Add or view local private keys", |
||||
Long: ` |
||||
Manage your local keys |
||||
`, |
||||
Run: func(cmd *cobra.Command, args []string) { |
||||
fmt.Println("Print: " + strings.Join(args, " ")) |
||||
}, |
||||
} |
||||
|
||||
cmdMnemonic := &cobra.Command{ |
||||
Use: "mnemonic", |
||||
Short: "Compute the bip39 mnemonic for some input entropy", |
||||
Run: func(cmd *cobra.Command, args []string) { |
||||
fmt.Println(cmd) |
||||
}, |
||||
} |
||||
|
||||
cmdAdd := &cobra.Command{ |
||||
Use: "add", |
||||
Short: "Create a new key, or import from seed", |
||||
Run: func(cmd *cobra.Command, args []string) { |
||||
fmt.Println(cmd) |
||||
}, |
||||
} |
||||
|
||||
cmdList := &cobra.Command{ |
||||
Use: "list", |
||||
Short: "List all keys", |
||||
Run: func(cmd *cobra.Command, args []string) { |
||||
fmt.Println(cmd) |
||||
}, |
||||
} |
||||
|
||||
cmdShow := &cobra.Command{ |
||||
Use: "show", |
||||
Short: "Show key info for the given name", |
||||
Run: func(cmd *cobra.Command, args []string) { |
||||
fmt.Println(cmd) |
||||
}, |
||||
} |
||||
|
||||
cmdDelete := &cobra.Command{ |
||||
Use: "delete", |
||||
Short: "Delete the given key", |
||||
Run: func(cmd *cobra.Command, args []string) { |
||||
fmt.Println(cmd) |
||||
}, |
||||
} |
||||
|
||||
cmdUpdate := &cobra.Command{ |
||||
Use: "update", |
||||
Short: "Change the password used to protect private key", |
||||
Run: func(cmd *cobra.Command, args []string) { |
||||
fmt.Println(cmd) |
||||
}, |
||||
} |
||||
|
||||
cmdKeys.AddCommand(cmdMnemonic, cmdAdd, cmdList, cmdShow, cmdDelete, cmdUpdate) |
||||
rootCmd.AddCommand(cmdKeys) |
||||
} |
@ -0,0 +1,55 @@ |
||||
package cmd |
||||
|
||||
import ( |
||||
"bytes" |
||||
"encoding/json" |
||||
"fmt" |
||||
"io/ioutil" |
||||
"net/http" |
||||
"strconv" |
||||
|
||||
"github.com/spf13/cobra" |
||||
) |
||||
|
||||
// u, err := url.ParseRequestURI("http://google.com/")
|
||||
|
||||
var ( |
||||
node string |
||||
queryID = 0 |
||||
cmdQuery = &cobra.Command{ |
||||
Use: "account", |
||||
Short: "Query account balance", |
||||
Long: `Query account balances`, |
||||
Run: func(cmd *cobra.Command, args []string) { |
||||
requestBody, _ := json.Marshal(map[string]interface{}{ |
||||
"jsonrpc": JSON_RPC_VERSION, |
||||
"id": strconv.Itoa(queryID), |
||||
"method": "hmy_getBalance", |
||||
"params": [...]string{"0xD7Ff41CA29306122185A07d04293DdB35F24Cf2d", "latest"}, |
||||
}) |
||||
|
||||
resp, err := http.Post(node, "application/json", bytes.NewBuffer(requestBody)) |
||||
if err != nil { |
||||
fmt.Println(err) |
||||
} |
||||
|
||||
defer resp.Body.Close() |
||||
body, err := ioutil.ReadAll(resp.Body) |
||||
if err != nil { |
||||
fmt.Println("error") |
||||
} |
||||
fmt.Println(string(body)) |
||||
}, |
||||
} |
||||
) |
||||
|
||||
func init() { |
||||
cmdQuery.Flags().StringVarP( |
||||
&node, |
||||
"node", |
||||
"", |
||||
"http://localhost:9500", |
||||
"<host>:<port>", |
||||
) |
||||
rootCmd.AddCommand(cmdQuery) |
||||
} |
@ -0,0 +1,5 @@ |
||||
package cmd |
||||
|
||||
const ( |
||||
JSON_RPC_VERSION = "2.0" |
||||
) |
@ -0,0 +1,45 @@ |
||||
package cmd |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
|
||||
"github.com/spf13/cobra" |
||||
) |
||||
|
||||
var rootCmd = &cobra.Command{ |
||||
Use: "hmy_cli", |
||||
Short: "Harmony blockchain", |
||||
Long: ` |
||||
CLI interface to the Harmony blockchain |
||||
`, |
||||
Run: func(cmd *cobra.Command, args []string) { |
||||
cmd.Help() |
||||
}, |
||||
} |
||||
|
||||
var ( |
||||
prettyPrintJSONOutput bool |
||||
) |
||||
|
||||
func init() { |
||||
rootCmd.PersistentFlags().BoolVarP(&prettyPrintJSONOutput, "pretty", "p", false, "pretty print JSON outputs") |
||||
|
||||
cmdVersion := &cobra.Command{ |
||||
Use: "version", |
||||
Short: "Show version", |
||||
Run: func(cmd *cobra.Command, args []string) { |
||||
|
||||
os.Exit(0) |
||||
}, |
||||
} |
||||
|
||||
rootCmd.AddCommand(cmdVersion) |
||||
} |
||||
|
||||
func Execute() { |
||||
if err := rootCmd.Execute(); err != nil { |
||||
fmt.Println(err) |
||||
os.Exit(1) |
||||
} |
||||
} |
Loading…
Reference in new issue