Skip to content

Commit

Permalink
added single-currency mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacwhyte committed Aug 30, 2019
1 parent 21b084e commit bb343b1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 21 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Either build the project with Go or download the binary, then...

**Multiple phrases:** List up multiple phrases, one per line, in a file titled `phrase.txt`. In the same directory as this file, run the binary with no arguments: `./phrase-scan`

**Single currency:** By default this tool will search for BTC, BCH, and ETH. If you want to search for just one of these, use the `-coin` flag followed by the currency you want to search for. For example, `./scan-phrase -coin=btc` will only look for bitcoin. This will work with either single- or multi-phrase mode, but in the case of single-phrase mode, the flag must always come before the phrase (e.g. `./scan-phrase -coin=btc [12 word phrase]`).

### Block explorers

This tool uses the following block explorers:
Expand Down
78 changes: 57 additions & 21 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"fmt"
"io/ioutil"
"os"
Expand All @@ -11,6 +12,9 @@ import (
)

var showTestnet = false
var showBTC = false
var showBCH = false
var showETH = false

var gfx = map[string]string{
"start": "╒═════════════════════════════════════╕\n",
Expand All @@ -28,20 +32,31 @@ var lastcall = time.Now()

func main() {

// Check our command line flags
cflag := flag.String("coin", "all", "which coins to search for (btc, bch, eth, all)")
flag.Parse()

switch strings.ToLower(*cflag) {
case "btc":
showBTC = true
case "bch":
showBCH = true
case "eth":
showETH = true
case "all":
showBTC = true
showBCH = true
showETH = true
default:
fmt.Println("Invalid -coin flag.")
return
}

var phrases []string

// If a phrase is provided, load that in as the only one. Otherwise, load up the "phrases.txt" file.
// All phrases will later be validated by the phrase library
if len(os.Args) == 13 {
var phrase string
for i, v := range os.Args[1:] {
phrase += v
if i < 11 {
phrase += " "
}
}
phrases = []string{phrase}
} else {
if len(flag.Args()) == 0 {
if _, e := os.Stat("phrases.txt"); os.IsNotExist(e) {
fmt.Println("Please create a phrases.txt file or call this command followed by a valid 12-word phrase.")
return
Expand All @@ -59,6 +74,19 @@ func main() {
phrases = append(phrases, v)
}
}

} else if len(flag.Args()) == 12 {
var phrase string
for i, v := range flag.Args() {
phrase += v
if i < 11 {
phrase += " "
}
}
phrases = []string{phrase}
} else {
fmt.Println("Please create a phrases.txt file or call this command followed by a valid 12-word phrase.")
return
}

fmt.Println()
Expand All @@ -83,27 +111,35 @@ func main() {
fmt.Printf(gfx["phrase3"])

// Print each currency
p.printBTCBalances("BTC", []BTCFormat{BTCFormat{Coin: "btc32", Type: "BIP32"}, BTCFormat{Coin: "btc44", Type: "BIP44"}})
if showTestnet {
p.printBTCBalances("TBT", []BTCFormat{BTCFormat{Coin: "tbt32", Type: "BIP32"}, BTCFormat{Coin: "tbt44", Type: "BIP44"}})
if showBTC {
p.printBTCBalances("BTC", []BTCFormat{BTCFormat{Coin: "btc32", Type: "BIP32"}, BTCFormat{Coin: "btc44", Type: "BIP44"}})
if showTestnet {
p.printBTCBalances("TBT", []BTCFormat{BTCFormat{Coin: "tbt32", Type: "BIP32"}, BTCFormat{Coin: "tbt44", Type: "BIP44"}})
}
}
p.printBTCBalances("BCH", []BTCFormat{
BTCFormat{Coin: "bch32", Type: "BIP32"},
BTCFormat{Coin: "bch440", Type: "BIP44-coin0"},
BTCFormat{Coin: "bch44145", Type: "BIP44-coin145"},
})
p.printETHBalances("ETH", false)
if showTestnet {
p.printETHBalances("TET", true)

if showBCH {
p.printBTCBalances("BCH", []BTCFormat{
BTCFormat{Coin: "bch32", Type: "BIP32"},
BTCFormat{Coin: "bch440", Type: "BIP44-coin0"},
BTCFormat{Coin: "bch44145", Type: "BIP44-coin145"},
})
}

if showETH {
p.printETHBalances("ETH", false)
if showTestnet {
p.printETHBalances("TET", true)
}
}
}

// End
fmt.Printf(gfx["end"])
fmt.Println()
}

// BTCFormat defines the specific flavor of bitcoin
type BTCFormat struct {
Coin string
Type string
Expand Down

0 comments on commit bb343b1

Please sign in to comment.