Skip to content

Commit

Permalink
don't wait for btc peers if it takes too long
Browse files Browse the repository at this point in the history
Signed-off-by: Philemon Ukane <[email protected]>
  • Loading branch information
ukane-philemon committed Jan 18, 2024
1 parent 44e8262 commit 7f0493c
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions libwallet/assets/btc/dex-wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,27 @@ func (dw *DEXWallet) Birthday() time.Time {
}

func (dw *DEXWallet) Peers() ([]*asset.WalletPeer, error) {
peers := dw.spvService.CS.Peers()
var walletPeers []*asset.WalletPeer
for i := range peers {
p := peers[i]
walletPeers = append(walletPeers, &asset.WalletPeer{
Addr: p.Addr(),
Connected: p.Connected(),
Source: asset.WalletDefault,
})
peerChan := make(chan []*asset.WalletPeer)
go func() {
peers := dw.spvService.CS.Peers()
var walletPeers []*asset.WalletPeer
for i := range peers {
p := peers[i]
walletPeers = append(walletPeers, &asset.WalletPeer{
Addr: p.Addr(),
Connected: p.Connected(),
Source: asset.WalletDefault,
})
}
peerChan <- walletPeers
}()

select {
case <-time.After(1 * time.Second):
return nil, nil // okay.
case peers := <-peerChan:
return peers, nil
}
return walletPeers, nil
}

func (dw *DEXWallet) AddPeer(_ string) error {
Expand Down

0 comments on commit 7f0493c

Please sign in to comment.