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
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,
})
}
}

View file

@ -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,10 +258,19 @@ func allUTXOsConfirmed(utxolist *jsonrpc.UTXOListResponse) bool {
func (s *Sync) addCredits(amountToAdd float64) error {
log.Printf("Adding %f credits", amountToAdd)
lbrycrdd, err := lbrycrd.NewWithDefaultURL()
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()
if err != nil {
@ -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()
}

View file

@ -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)
}