Skip to content

Commit

Permalink
xpubs command now displays first address for every entry
Browse files Browse the repository at this point in the history
  • Loading branch information
solipsis committed Oct 23, 2019
1 parent f631ed6 commit 3023568
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions cmd/xpubs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"encoding/hex"
"fmt"
"os"
"text/tabwriter"
Expand All @@ -18,18 +19,19 @@ func init() {
type coin struct {
name string
slip44 string
extra string
}

// TODO: ask device for coin table instead making another damn coin table
var coins = []coin{
coin{"Bitcoin", "44'/0'"},
coin{"Testnet", "44'/1'"},
coin{"Litecoin", "44'/2'"},
coin{"Dogecoin", "44'/3'"},
coin{"Dash", "44'/5'"},
coin{"Ethereum", "44'/60'"},
coin{"Bitcoin (segwit)", "49'/0'"},
coin{"EOS", "44'/194'"},
coin{"Bitcoin", "44'/0'", ""},
coin{"Testnet", "44'/1'", ""},
coin{"Litecoin", "44'/2'", ""},
coin{"Dogecoin", "44'/3'", ""},
coin{"Dash", "44'/5'", ""},
coin{"Ethereum", "44'/60'", ""},
coin{"Bitcoin", "49'/0'", " (Segwit)"},
coin{"EOS", "44'/194'", ""},
}

var numAccounts uint32
Expand All @@ -44,8 +46,8 @@ var xpubsCmd = &cobra.Command{
w.Init(os.Stdout, 0, 8, 2, '\t', 0)

magenta := color.New(color.FgBlue).FprintfFunc()
magenta(w, "| coin |\t| path |\t| xpub |\n")
fmt.Fprintf(w, "__________\t__________\t__________\n")
magenta(w, "| coin |\t| path |\t| xpub |\t| address (m/x'/y'/z'/0/0) |\n")
fmt.Fprintf(w, "__________\t__________\t_______________________________________________________________________________________________________________\t__________________________________\n")

for _, c := range coins {
for x := 0; x < int(numAccounts); x++ {
Expand All @@ -58,7 +60,22 @@ var xpubsCmd = &cobra.Command{
os.Exit(1)
}

fmt.Fprintf(w, "%s\t%s/%d'\t%s\n", c.name, c.slip44, x, xpub)
addrPath := append(path, []uint32{0, 0}...)

var addr string
if c.name == "Ethereum" {
var buf []byte
buf, err = kk.EthereumGetAddress(addrPath, false)
addr = "0x" + hex.EncodeToString(buf)
} else {
addr, err = kk.GetAddress(addrPath, c.name, false)
}
if err != nil {
fmt.Println(err)
os.Exit(1)
}

fmt.Fprintf(w, "%s%s\t%s/%d'\t%s\t%s\n", c.name, c.extra, c.slip44, x, xpub, addr)
}
}
w.Flush()
Expand Down

0 comments on commit 3023568

Please sign in to comment.