cli: add command getPubKeyHash
This commit is contained in:
parent
2974ee8571
commit
5f4f2f518d
17
cli.go
17
cli.go
|
@ -25,6 +25,7 @@ func (cli *CLI) printUsage() {
|
||||||
fmt.Println("Exploring cmds:")
|
fmt.Println("Exploring cmds:")
|
||||||
fmt.Println(" generateKey - generate KeyPair for exploring")
|
fmt.Println(" generateKey - generate KeyPair for exploring")
|
||||||
fmt.Println(" getAddress -pubKey PUBKEY - convert pubKey to address")
|
fmt.Println(" getAddress -pubKey PUBKEY - convert pubKey to address")
|
||||||
|
fmt.Println(" getPubKeyHash -address Address - get pubKeyHash of an address")
|
||||||
fmt.Println(" validateAddress -addr Address - validate an address")
|
fmt.Println(" validateAddress -addr Address - validate an address")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ func (cli *CLI) Run() {
|
||||||
startNodeCmd := flag.NewFlagSet("startnode", flag.ExitOnError)
|
startNodeCmd := flag.NewFlagSet("startnode", flag.ExitOnError)
|
||||||
generateKeyCmd := flag.NewFlagSet("generateKey", flag.ExitOnError)
|
generateKeyCmd := flag.NewFlagSet("generateKey", flag.ExitOnError)
|
||||||
getAddressCmd := flag.NewFlagSet("getAddress", flag.ExitOnError)
|
getAddressCmd := flag.NewFlagSet("getAddress", flag.ExitOnError)
|
||||||
|
getPubKeyHashCmd := flag.NewFlagSet("getPubKeyHash", flag.ExitOnError)
|
||||||
validateAddrCmd := flag.NewFlagSet("validateAddress", flag.ExitOnError)
|
validateAddrCmd := flag.NewFlagSet("validateAddress", flag.ExitOnError)
|
||||||
|
|
||||||
getBalanceAddress := getBalanceCmd.String("address", "", "The address to get balance for")
|
getBalanceAddress := getBalanceCmd.String("address", "", "The address to get balance for")
|
||||||
|
@ -65,6 +67,7 @@ func (cli *CLI) Run() {
|
||||||
sendMine := sendCmd.Bool("mine", false, "Mine immediately on the same node")
|
sendMine := sendCmd.Bool("mine", false, "Mine immediately on the same node")
|
||||||
startNodeMiner := startNodeCmd.String("miner", "", "Enable mining mode and send reward to ADDRESS")
|
startNodeMiner := startNodeCmd.String("miner", "", "Enable mining mode and send reward to ADDRESS")
|
||||||
pubKey := getAddressCmd.String("pubKey", "", "the key where address generated")
|
pubKey := getAddressCmd.String("pubKey", "", "the key where address generated")
|
||||||
|
pubKeyAddress := getPubKeyHashCmd.String("address", "", "the pub address")
|
||||||
address := validateAddrCmd.String("addr", "", "the public address")
|
address := validateAddrCmd.String("addr", "", "the public address")
|
||||||
|
|
||||||
switch os.Args[1] {
|
switch os.Args[1] {
|
||||||
|
@ -118,6 +121,11 @@ func (cli *CLI) Run() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
|
case "getPubKeyHash":
|
||||||
|
err := getPubKeyHashCmd.Parse(os.Args[2:])
|
||||||
|
if err != nil {
|
||||||
|
log.Panic(err)
|
||||||
|
}
|
||||||
case "getAddress":
|
case "getAddress":
|
||||||
err := getAddressCmd.Parse(os.Args[2:])
|
err := getAddressCmd.Parse(os.Args[2:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -191,6 +199,15 @@ func (cli *CLI) Run() {
|
||||||
cli.getAddress(*pubKey)
|
cli.getAddress(*pubKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if getPubKeyHashCmd.Parsed() {
|
||||||
|
if *pubKeyAddress == "" {
|
||||||
|
getPubKeyHashCmd.Usage()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
cli.getPubKeyHash(*pubKeyAddress)
|
||||||
|
}
|
||||||
|
|
||||||
if validateAddrCmd.Parsed() {
|
if validateAddrCmd.Parsed() {
|
||||||
if *address == "" {
|
if *address == "" {
|
||||||
validateAddrCmd.Usage()
|
validateAddrCmd.Usage()
|
||||||
|
|
|
@ -27,6 +27,11 @@ func (cli *CLI) getAddress(pubKey string) {
|
||||||
fmt.Printf("Address : %s\n", address)
|
fmt.Printf("Address : %s\n", address)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cli *CLI) getPubKeyHash(address string) {
|
||||||
|
pubKeyHash := Base58Decode([]byte(address))
|
||||||
|
fmt.Printf("%x\n", pubKeyHash[1:len(pubKeyHash)-4])
|
||||||
|
}
|
||||||
|
|
||||||
func (cli *CLI) validateAddr(address string) {
|
func (cli *CLI) validateAddr(address string) {
|
||||||
fmt.Printf("Address: %s\n", address)
|
fmt.Printf("Address: %s\n", address)
|
||||||
if !ValidateAddress(address) {
|
if !ValidateAddress(address) {
|
||||||
|
|
Loading…
Reference in New Issue