blockchain_go/cli_explore.go

45 lines
1.1 KiB
Go
Raw Normal View History

package main
import (
"encoding/hex"
"fmt"
)
func (cli *CLI) generateKey() {
2017-10-19 19:44:58 -05:00
private, public := newKeyPair()
fmt.Println("Public Key:")
fmt.Println(hex.EncodeToString(public))
2017-10-19 19:44:58 -05:00
priKey := append(private.PublicKey.X.Bytes(), private.PublicKey.Y.Bytes()...)
priKey = append(priKey, private.D.Bytes()...)
fmt.Println("Private Key:")
fmt.Printf("%d%s\n", private.Curve, hex.EncodeToString(priKey))
}
func (cli *CLI) getAddress(pubKey string) {
public, _ := hex.DecodeString(pubKey)
pubKeyHash := HashPubKey(public)
versionedPayload := append([]byte{version}, pubKeyHash...)
fullPayload := append(versionedPayload, checksum(versionedPayload)...)
fmt.Println()
2017-10-18 02:28:36 -05:00
fmt.Printf("PubKey : %s\n", pubKey)
fmt.Printf("PubKeyHash : %x\n", pubKeyHash)
fmt.Printf("Address : %s\n", Base58Encode(fullPayload))
}
2017-10-18 02:29:19 -05:00
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) {
fmt.Printf("Address: %s\n", address)
if !ValidateAddress(address) {
fmt.Println("Not valid!")
} else {
fmt.Println("Valid!")
}
}