From 53358939ad1ca82072eb2585ec3b354c3cac5f5b Mon Sep 17 00:00:00 2001 From: jmacwhyte Date: Tue, 18 Sep 2018 15:58:11 -0700 Subject: [PATCH] fixing more bugs! Added verbose logging for single address lookup --- main.go | 29 ++++++++++++++++++++++++++++- phrase.go | 6 ++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index e1d8134..cde4d88 100644 --- a/main.go +++ b/main.go @@ -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 @@ -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 @@ -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() } @@ -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) + } + } +} diff --git a/phrase.go b/phrase.go index 943ff23..a6fec69 100644 --- a/phrase.go +++ b/phrase.go @@ -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 } } @@ -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 @@ -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 {