add channel takeover flag

This commit is contained in:
Alex Grintsvayg 2017-11-06 16:42:52 -05:00
parent 27c5db03fb
commit 750313f00b

View file

@ -35,12 +35,13 @@ const (
// Sync stores the options that control how syncing happens // Sync stores the options that control how syncing happens
type Sync struct { type Sync struct {
YoutubeAPIKey string YoutubeAPIKey string
YoutubeChannelID string YoutubeChannelID string
LbryChannelName string LbryChannelName string
StopOnError bool StopOnError bool
MaxTries int MaxTries int
ConcurrentVideos int ConcurrentVideos int
TakeOverExistingChannel bool
daemon *jsonrpc.Client daemon *jsonrpc.Client
claimAddress string claimAddress string
@ -397,13 +398,19 @@ func (s *Sync) ensureChannelOwnership() error {
return err return err
} }
channelNotFound := (*resolveResp)[s.LbryChannelName].Error != nil && strings.Contains(*((*resolveResp)[s.LbryChannelName].Error), "cannot be resolved") channel := (*resolveResp)[s.LbryChannelName]
channelBidAmount := channelClaimAmount
channelNotFound := channel.Error != nil && strings.Contains(*(channel.Error), "cannot be resolved")
if !channelNotFound { if !channelNotFound {
return errors.New("Channel exists and we don't own it. Pick another channel.") if !s.TakeOverExistingChannel {
return errors.New("Channel exists and we don't own it. Pick another channel.")
}
log.Println("Channel exists and we don't own it. Outbidding existing claim.")
channelBidAmount, _ = channel.Certificate.Amount.Add(decimal.NewFromFloat(channelClaimAmount)).Float64()
} }
_, err = s.daemon.ChannelNew(s.LbryChannelName, channelClaimAmount) _, err = s.daemon.ChannelNew(s.LbryChannelName, channelBidAmount)
if err != nil { if err != nil {
return err return err
} }