From 12d627bd35cc2b4e379bd13e15e335729099c827 Mon Sep 17 00:00:00 2001
From: Niko Storni <niko@lbry.io>
Date: Tue, 12 Jan 2021 16:49:54 +0100
Subject: [PATCH] fix stupid error

---
 manager/setup.go | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/manager/setup.go b/manager/setup.go
index bd57757..6f53cae 100644
--- a/manager/setup.go
+++ b/manager/setup.go
@@ -225,6 +225,15 @@ func (s *Sync) ensureEnoughUTXOs() error {
 		if err != nil {
 			return errors.Err(err)
 		}
+		//this is dumb but sometimes the balance is negative and it breaks everything, so let's check again
+		if balanceAmount < 0 {
+			log.Infof("negative balance of %.2f found. Waiting to retry...", balanceAmount)
+			time.Sleep(10 * time.Second)
+			balanceAmount, err = strconv.ParseFloat(balance.Available.String(), 64)
+			if err != nil {
+				return errors.Err(err)
+			}
+		}
 		maxUTXOs := uint64(500)
 		desiredUTXOCount := uint64(math.Floor((balanceAmount) / 0.1))
 		if desiredUTXOCount > maxUTXOs {