do not update bitcoin balance if getting address balance fails
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
6ed332d8b6
commit
c4a79b0f4c
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user