use channelIDs instead of channel names

add support for custom lbrycrd instance
This commit is contained in:
Niko Storni 2018-08-08 17:59:59 -04:00
parent 41551c8e01
commit dafce6ae84
3 changed files with 26 additions and 7 deletions

View file

@ -39,6 +39,7 @@ type SyncManager struct {
BlobsDir string BlobsDir string
VideosLimit int VideosLimit int
MaxVideoSize int MaxVideoSize int
LbrycrdString string
} }
const ( const (
@ -212,6 +213,7 @@ func (s SyncManager) Start() error {
TakeOverExistingChannel: s.TakeOverExistingChannel, TakeOverExistingChannel: s.TakeOverExistingChannel,
Refill: s.Refill, Refill: s.Refill,
Manager: &s, Manager: &s,
LbrycrdString: s.LbrycrdString,
} }
shouldInterruptLoop = true shouldInterruptLoop = true
} else { } else {
@ -242,6 +244,7 @@ func (s SyncManager) Start() error {
TakeOverExistingChannel: s.TakeOverExistingChannel, TakeOverExistingChannel: s.TakeOverExistingChannel,
Refill: s.Refill, Refill: s.Refill,
Manager: &s, Manager: &s,
LbrycrdString: s.LbrycrdString,
}) })
} }
} }

View file

@ -104,6 +104,7 @@ func (s *Sync) ensureEnoughUTXOs() error {
} }
target := 40 target := 40
slack := target - int(float32(0.05)*float32(target))
count := 0 count := 0
for _, utxo := range *utxolist { for _, utxo := range *utxolist {
@ -112,7 +113,7 @@ func (s *Sync) ensureEnoughUTXOs() error {
} }
} }
if count < target { if count < target-slack {
newAddresses := target - count newAddresses := target - count
balance, err := s.daemon.WalletBalance() balance, err := s.daemon.WalletBalance()
@ -257,9 +258,18 @@ func allUTXOsConfirmed(utxolist *jsonrpc.UTXOListResponse) bool {
func (s *Sync) addCredits(amountToAdd float64) error { func (s *Sync) addCredits(amountToAdd float64) error {
log.Printf("Adding %f credits", amountToAdd) log.Printf("Adding %f credits", amountToAdd)
lbrycrdd, err := lbrycrd.NewWithDefaultURL() var lbrycrdd *lbrycrd.Client
if err != nil { var err error
return err 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() addressResp, err := s.daemon.WalletUnusedAddress()
@ -280,6 +290,4 @@ func (s *Sync) addCredits(amountToAdd float64) error {
time.Sleep(wait) time.Sleep(wait)
return nil return nil
//log.Println("Waiting for transaction to be confirmed")
//return s.waitUntilUTXOsConfirmed()
} }

View file

@ -60,6 +60,7 @@ type Sync struct {
TakeOverExistingChannel bool TakeOverExistingChannel bool
Refill int Refill int
Manager *SyncManager Manager *SyncManager
LbrycrdString string
daemon *jsonrpc.Client daemon *jsonrpc.Client
claimAddress string claimAddress string
@ -169,6 +170,7 @@ func (s *Sync) FullCycle() (e error) {
defaultWalletDir = os.Getenv("HOME") + "/.lbryum_regtest/wallets/default_wallet" defaultWalletDir = os.Getenv("HOME") + "/.lbryum_regtest/wallets/default_wallet"
} }
walletBackupDir := os.Getenv("HOME") + "/wallets/" + strings.Replace(s.LbryChannelName, "@", "", 1) 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) { if _, err := os.Stat(defaultWalletDir); !os.IsNotExist(err) {
return errors.Err("default_wallet already exists") return errors.Err("default_wallet already exists")
@ -180,6 +182,12 @@ func (s *Sync) FullCycle() (e error) {
return errors.Wrap(err, 0) return errors.Wrap(err, 0)
} }
log.Println("Continuing previous upload") 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() { defer func() {
@ -195,7 +203,7 @@ func (s *Sync) FullCycle() (e error) {
if processDeathError != nil { if processDeathError != nil {
logShutdownError(processDeathError) logShutdownError(processDeathError)
} else { } else {
walletErr := os.Rename(defaultWalletDir, walletBackupDir) walletErr := os.Rename(defaultWalletDir, newWalletBackupDir)
if walletErr != nil { if walletErr != nil {
log.Errorf("error moving wallet to backup dir: %v", walletErr) log.Errorf("error moving wallet to backup dir: %v", walletErr)
} }