do not update bitcoin balance if getting address balance fails
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Steven Polley 2024-11-08 13:17:01 -07:00
parent 6ed332d8b6
commit c4a79b0f4c

View File

@ -2,7 +2,6 @@ package bitcoin
import ( import (
"fmt" "fmt"
"log"
"os" "os"
"sync" "sync"
) )
@ -48,20 +47,21 @@ func (p *Provider) GetBalances() ([]int, []string, error) {
ynabAccountIDs := make([]string, 0) ynabAccountIDs := make([]string, 0)
var satoshiBalance int var satoshiBalance int
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
var goErr *error
for _, bitcoinAddress := range p.bitcoinAddresses { for _, bitcoinAddress := range p.bitcoinAddresses {
wg.Add(1) wg.Add(1)
go func() { go func(goErr *error) {
defer wg.Done() defer wg.Done()
addressResponse, err := p.client.getAddress(bitcoinAddress) addressResponse, err := p.client.getAddress(bitcoinAddress)
if err != nil { 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 return
} }
satoshiBalance += addressResponse.ChainStats.FundedTxoSum - addressResponse.ChainStats.SpentTxoSum satoshiBalance += addressResponse.ChainStats.FundedTxoSum - addressResponse.ChainStats.SpentTxoSum
}() }(goErr)
} }
wg.Wait() wg.Wait()
fiatBalance, err := p.client.convertBTCToCAD(satoshiBalance) fiatBalance, err := p.client.convertBTCToCAD(satoshiBalance)