Skip to content

Commit

Permalink
fixing more bugs! Added verbose logging for single address lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacwhyte committed Sep 18, 2018
1 parent 56fdf23 commit 5335893
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
29 changes: 28 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ var gfx = map[string]string{
// Lastcall is used as a timestamp for the last api call (for rate limiting)
var lastcall = time.Now()

// Save lists of addresses for verbose logging if in single address mode
var addlists = make(map[string][]Address)

func main() {

var phrases []string
Expand Down Expand Up @@ -126,7 +129,7 @@ func main() {
bal = firstrun[v].Balance
} else {
var err error
bal, err = p.LookupBTCBal(v)
bal, addlists[v], err = p.LookupBTCBal(v)
if err != nil {
fmt.Println("full bal lookup error: ", err)
return
Expand Down Expand Up @@ -162,6 +165,12 @@ func main() {
// End
fmt.Println(gfx["end"])
fmt.Println()

if len(os.Args) > 1 {
// Show some verbose balance logging if only looking up a single phrase
listAddBals(addlists)
}

fmt.Println(centerText("You're welcome!", 76))
fmt.Println()
}
Expand Down Expand Up @@ -191,3 +200,21 @@ func rightBalance(amount float64, width int) string {

return strings.Repeat(" ", width-len(v)) + v
}

func listAddBals(adds map[string][]Address) {
order := []string{"btc", "tbt", "bch"}

for _, cur := range order {

var line string
for i, v := range adds[cur] {
if v.Balance > 0 {
line += fmt.Sprintf("Child %d (%s) balance: %f\n", i, v.Address, v.Balance)
}
}

if line != "" {
fmt.Printf("\n %s:\n%s\n", strings.ToUpper(cur), line)
}
}
}
6 changes: 4 additions & 2 deletions phrase.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (p Phrase) LookupBCH(chain uint32, child uint32, count int) (addresses []Ad
for _, d := range BTCcom.Data {
if d.Address == v.Address {
addresses[i].TxCount = d.TxCount
addresses[i].Balance = float64(d.Balance / 100000000)
addresses[i].Balance = float64(float64(d.Balance) / 100000000)
break
}
}
Expand Down Expand Up @@ -392,7 +392,7 @@ func (p Phrase) LookupETH(isTestnet bool) (addresses []Address, err error) {
}

// LookupBTCBal follows the entire btc/bch chain and finds out the remaining balance for the entire wallet.
func (p Phrase) LookupBTCBal(coin string) (balance float64, err error) {
func (p Phrase) LookupBTCBal(coin string) (balance float64, addresses []Address, err error) {

batch := 50 // How many addresses to fetch at one time
skips := 0 // How many empty addresses in a row we've found
Expand All @@ -413,6 +413,8 @@ func (p Phrase) LookupBTCBal(coin string) (balance float64, err error) {
addr, err = p.LookupBCH(chain, child, batch)
}

addresses = append(addresses, addr...)

for _, v := range addr {
balance += v.Balance
if v.TxCount > 0 {
Expand Down

0 comments on commit 5335893

Please sign in to comment.