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

@ -41,6 +41,7 @@ type Sync struct {
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 {
if !s.TakeOverExistingChannel {
return errors.New("Channel exists and we don't own it. Pick another channel.") 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
} }