pass errors up rather than logging directly
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-09-30 23:02:07 -06:00
parent 5f11b45dd4
commit e9466bebc5
2 changed files with 12 additions and 28 deletions

View File

@@ -3,8 +3,6 @@ package bitcoinElectrum
import (
"fmt"
"os"
"sync"
"sync/atomic"
"github.com/btcsuite/btcd/btcutil/hdkeychain"
)
@@ -27,7 +25,7 @@ func (p *Provider) Configure() error {
p.ynabAccountID = os.Getenv("bitcoin_ynab_account")
p.spvServer = os.Getenv("bitcoin_spv_server")
p.coinGeckoApiKey = os.Getenv("bitcoin_coingecko_api_key")
p.gapLimit = 20
p.gapLimit = 10
if zpub == "" || p.ynabAccountID == "" || p.spvServer == "" || p.coinGeckoApiKey == "" {
return fmt.Errorf("this account provider is not configured")
}
@@ -43,21 +41,17 @@ func (p *Provider) Configure() error {
// Returns slices of account balances and mapped YNAB account IDs, along with an error
func (p *Provider) GetBalances() ([]int, []string, error) {
var totalSats int64
var wg sync.WaitGroup
// branch 0 = regular
// branch 1 = change addresses
for _, branch := range []uint32{0, 1} {
wg.Add(1)
go func(branch uint32) {
defer wg.Done()
branchSats := scanBranch(p.masterKey, branch, p.gapLimit, p.spvServer)
atomic.AddInt64(&branchSats, totalSats)
}(branch)
branchSats, err := scanBranch(p.masterKey, branch, p.gapLimit, p.spvServer)
if err != nil {
return nil, nil, fmt.Errorf("failed to scan branch '%v': %v", branch, err)
}
totalSats += branchSats
}
wg.Wait()
cad, err := convertBTCToCAD(totalSats, p.coinGeckoApiKey)
if err != nil {
return nil, nil, fmt.Errorf("failed to convert sats to CAD: %v", err)