From c4a79b0f4c58b92d335879ee1a421a67889fd92d Mon Sep 17 00:00:00 2001 From: Steven Polley Date: Fri, 8 Nov 2024 13:17:01 -0700 Subject: [PATCH] do not update bitcoin balance if getting address balance fails --- providers/bitcoin/providerImpl.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/providers/bitcoin/providerImpl.go b/providers/bitcoin/providerImpl.go index 1b02bdc..9e3eca2 100644 --- a/providers/bitcoin/providerImpl.go +++ b/providers/bitcoin/providerImpl.go @@ -2,7 +2,6 @@ package bitcoin import ( "fmt" - "log" "os" "sync" ) @@ -48,20 +47,21 @@ func (p *Provider) GetBalances() ([]int, []string, error) { ynabAccountIDs := make([]string, 0) var satoshiBalance int wg := sync.WaitGroup{} + var goErr *error for _, bitcoinAddress := range p.bitcoinAddresses { wg.Add(1) - go func() { + go func(goErr *error) { defer wg.Done() addressResponse, err := p.client.getAddress(bitcoinAddress) if err != nil { - log.Printf("failed to get bitcoin address '%s': %v", bitcoinAddress, err) + err := fmt.Errorf("failed to get bitcoin address '%s': %v", bitcoinAddress, err) + goErr = &err return } satoshiBalance += addressResponse.ChainStats.FundedTxoSum - addressResponse.ChainStats.SpentTxoSum - }() + }(goErr) } - wg.Wait() fiatBalance, err := p.client.convertBTCToCAD(satoshiBalance)