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

Improve address-gen cmd app #2713

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Add `GET /api/v2/transactions` API to get transactions with pagination.
- Add `-max-incoming-connection` flag to control the maximum allowed incoming connections.
- Add `qr_uri_prefix` field to `/api/v1/health` endpoint.
- Add `-key-pairs` flag to `address-gen` cmd app.

### Fixed

Expand Down
30 changes: 29 additions & 1 deletion cmd/address_gen/address_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func main() {
seed := flag.String("seed", "", "Seed for deterministic key generation. Will use bip39 as the seed if not provided")
secKeysList := flag.Bool("sec-keys-list", false, "only print a list of secret keys")
addrsList := flag.Bool("addrs-list", false, "only print a list of addresses")
keyPairs := flag.Bool("key-pairs", false, "only print pairs of public and private keys")
flag.Parse()

var coinType wallet.CoinType
Expand All @@ -55,7 +56,7 @@ func main() {
}
}

w, err := wallet.NewWallet("a.wlt", "", *seed, wallet.Options{
w, err := wallet.NewWallet("a.wlt", "address_gen", *seed, wallet.Options{
Type: deterministic.WalletType,
Coin: coinType,
GenerateN: uint64(*genCount),
Expand All @@ -80,6 +81,21 @@ func main() {
os.Exit(1)
}

if *keyPairs && *secKeysList {
fmt.Println("-key-pairs and -sec-keys-list can't be combined")
os.Exit(1)
}

if *keyPairs && *addrsList {
fmt.Println("-key-pairs and -addrs-list can't be combined")
os.Exit(1)
}

if *keyPairs && *hideSecrets {
fmt.Println("-key-pairs and -hide-secrets can't be combined")
os.Exit(1)
}

if *addrsList {
addrs, err := w.GetAddresses()
if err != nil {
Expand All @@ -99,6 +115,18 @@ func main() {
for _, e := range es {
fmt.Println(e.Secret.Hex())
}
} else if *keyPairs {
es, err := w.GetEntries()
if err != nil {
fmt.Println(err)
os.Exit(1)
}

for _, e := range es {
fmt.Println("SK:", e.Secret.Hex())
fmt.Println("PK:", e.Public.Hex())
fmt.Print("\n")
}
} else {
if *hideSecrets {
w.Erase()
Expand Down
Loading