lbrynet/lbrycrd wallet management #34
4 changed files with 31 additions and 7 deletions
|
@ -94,6 +94,7 @@ func ytSync(cmd *cobra.Command, args []string) {
|
||||||
apiToken := os.Getenv("LBRY_API_TOKEN")
|
apiToken := os.Getenv("LBRY_API_TOKEN")
|
||||||
youtubeAPIKey := os.Getenv("YOUTUBE_API_KEY")
|
youtubeAPIKey := os.Getenv("YOUTUBE_API_KEY")
|
||||||
blobsDir := os.Getenv("BLOBS_DIRECTORY")
|
blobsDir := os.Getenv("BLOBS_DIRECTORY")
|
||||||
|
lbrycrdString := os.Getenv("LBRYCRD_STRING")
|
||||||
if apiURL == "" {
|
if apiURL == "" {
|
||||||
log.Errorln("An API URL was not defined. Please set the environment variable LBRY_API")
|
log.Errorln("An API URL was not defined. Please set the environment variable LBRY_API")
|
||||||
return
|
return
|
||||||
|
@ -106,6 +107,9 @@ func ytSync(cmd *cobra.Command, args []string) {
|
||||||
log.Errorln("A Youtube API key was not defined. Please set the environment variable YOUTUBE_API_KEY")
|
log.Errorln("A Youtube API key was not defined. Please set the environment variable YOUTUBE_API_KEY")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if lbrycrdString == "" {
|
||||||
|
log.Infoln("Using default (local) lbrycrd instance. Set LBRYCRD_STRING if you want to use something else")
|
||||||
|
}
|
||||||
if blobsDir == "" {
|
if blobsDir == "" {
|
||||||
usr, err := user.Current()
|
usr, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -136,6 +140,7 @@ func ytSync(cmd *cobra.Command, args []string) {
|
||||||
BlobsDir: blobsDir,
|
BlobsDir: blobsDir,
|
||||||
VideosLimit: videosLimit,
|
VideosLimit: videosLimit,
|
||||||
MaxVideoSize: maxVideoSize,
|
MaxVideoSize: maxVideoSize,
|
||||||
|
LbrycrdString: lbrycrdString,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := sm.Start()
|
err := sm.Start()
|
||||||
|
|
|
@ -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,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue