diff --git a/manager.go b/manager.go index 9e72d90..825ddb5 100644 --- a/manager.go +++ b/manager.go @@ -39,6 +39,7 @@ type SyncManager struct { BlobsDir string VideosLimit int MaxVideoSize int + LbrycrdString string } const ( @@ -212,6 +213,7 @@ func (s SyncManager) Start() error { TakeOverExistingChannel: s.TakeOverExistingChannel, Refill: s.Refill, Manager: &s, + LbrycrdString: s.LbrycrdString, } shouldInterruptLoop = true } else { @@ -242,6 +244,7 @@ func (s SyncManager) Start() error { TakeOverExistingChannel: s.TakeOverExistingChannel, Refill: s.Refill, Manager: &s, + LbrycrdString: s.LbrycrdString, }) } } diff --git a/setup.go b/setup.go index 7a40ccd..e154f16 100644 --- a/setup.go +++ b/setup.go @@ -104,6 +104,7 @@ func (s *Sync) ensureEnoughUTXOs() error { } target := 40 + slack := target - int(float32(0.05)*float32(target)) count := 0 for _, utxo := range *utxolist { @@ -112,7 +113,7 @@ func (s *Sync) ensureEnoughUTXOs() error { } } - if count < target { + if count < target-slack { newAddresses := target - count balance, err := s.daemon.WalletBalance() @@ -257,9 +258,18 @@ func allUTXOsConfirmed(utxolist *jsonrpc.UTXOListResponse) bool { func (s *Sync) addCredits(amountToAdd float64) error { log.Printf("Adding %f credits", amountToAdd) - lbrycrdd, err := lbrycrd.NewWithDefaultURL() - if err != nil { - return err + var lbrycrdd *lbrycrd.Client + var err error + if s.LbrycrdString == "" { + lbrycrdd, err = lbrycrd.NewWithDefaultURL() + if err != nil { + return err + } + } else { + lbrycrdd, err = lbrycrd.New(s.LbrycrdString) + if err != nil { + return err + } } addressResp, err := s.daemon.WalletUnusedAddress() @@ -280,6 +290,4 @@ func (s *Sync) addCredits(amountToAdd float64) error { time.Sleep(wait) return nil - //log.Println("Waiting for transaction to be confirmed") - //return s.waitUntilUTXOsConfirmed() } diff --git a/ytsync.go b/ytsync.go index c44d9c6..70dee4e 100644 --- a/ytsync.go +++ b/ytsync.go @@ -60,6 +60,7 @@ type Sync struct { TakeOverExistingChannel bool Refill int Manager *SyncManager + LbrycrdString string daemon *jsonrpc.Client claimAddress string @@ -169,6 +170,7 @@ func (s *Sync) FullCycle() (e error) { defaultWalletDir = os.Getenv("HOME") + "/.lbryum_regtest/wallets/default_wallet" } walletBackupDir := os.Getenv("HOME") + "/wallets/" + strings.Replace(s.LbryChannelName, "@", "", 1) + newWalletBackupDir := os.Getenv("HOME") + "/renamed_wallets/" + s.YoutubeChannelID if _, err := os.Stat(defaultWalletDir); !os.IsNotExist(err) { return errors.Err("default_wallet already exists") @@ -180,6 +182,12 @@ func (s *Sync) FullCycle() (e error) { return errors.Wrap(err, 0) } log.Println("Continuing previous upload") + } else if _, err = os.Stat(newWalletBackupDir); !os.IsNotExist(err) { + err = os.Rename(newWalletBackupDir, defaultWalletDir) + if err != nil { + return errors.Wrap(err, 0) + } + log.Println("Continuing previous upload") } defer func() { @@ -195,7 +203,7 @@ func (s *Sync) FullCycle() (e error) { if processDeathError != nil { logShutdownError(processDeathError) } else { - walletErr := os.Rename(defaultWalletDir, walletBackupDir) + walletErr := os.Rename(defaultWalletDir, newWalletBackupDir) if walletErr != nil { log.Errorf("error moving wallet to backup dir: %v", walletErr) }