Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI #12

Merged
merged 5 commits into from
Sep 18, 2017
Merged

CLI #12

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}