Skip to content

Commit

Permalink
CLI (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie Revett authored Sep 18, 2017
1 parent 4f24886 commit 01f9cae
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@

# Added by Authors
vendor/
go-tcw.*
go-tcw.*
neo-go-sdk
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
BRANCH = "master"
VERSION = $(shell cat ./VERSION)

build-cli:
@go build .

check-version:
@echo "=> Checking if VERSION exists as Git tag..."
(! git rev-list ${VERSION})
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,5 @@ See [GoDoc](https://godoc.org/github.com/CityOfZion/neo-go-sdk/neo) for full doc
## License

- Open-source [MIT](https://github.com/CityOfZion/neo-go-sdk/blob/master/LICENSE).
- Main author is [@revett](https://github.com/revett).
- Main author is [@revett](https://github.com/revett).
- This project adheres to the [Contributor Covenant Code of Conduct](https://github.com/goreleaser/goreleaser/blob/master/CODE_OF_CONDUCT.md).
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.0
1.3.0
54 changes: 54 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package main

import (
"fmt"
"os"

"github.com/CityOfZion/neo-go-sdk/neo"
)

func main() {
if len(os.Args) != 3 || os.Args[1] != "--wif" {
outputUsage()
}

wif := os.Args[2]

if len(wif) != 52 {
outputError("WIF entered is not 52 characters long.")
}

privateKey, err := neo.NewPrivateKeyFromWIF(wif)
if err != nil {
outputError("Unable to convert WIF to private key.")
}

publicAddress, err := privateKey.PublicAddress()
if err != nil {
outputError("Error when deriving public address from private key.")
}

fmt.Println("Details:")
fmt.Printf(" - Private key: \t\t%s\n", privateKey.Output())
fmt.Printf(" - Private key (base64): \t%s\n", privateKey.OutputBase64())
fmt.Printf(" - Public address (compressed): %s\n", publicAddress)
fmt.Printf(" - WIF (compressed): \t\t%s\n", wif)
}

func outputError(message string) {
fmt.Printf("[ERROR] %s\n", message)
fmt.Println("Try: neo-go-sdk --help")
os.Exit(1)
}

func outputUsage() {
fmt.Println("Tool to help debug a NEO public and private key pair.")
fmt.Println("")
fmt.Println("Usage:")
fmt.Println("\tneo-go-sdk --wif <WIF>")
fmt.Println("")
fmt.Println("Options:")
fmt.Println("\t--wif\tWIF (wallet import format) for NEO private key.")
fmt.Println("\t--help\tPrint usage.")
os.Exit(1)
}

0 comments on commit 01f9cae

Please sign in to comment.