refactor channel selector

remove unused code
This commit is contained in:
Niko Storni 2019-08-15 19:31:43 +02:00
parent b477d18a16
commit 81616c1d96

View file

@ -271,40 +271,33 @@ func (s *Sync) ensureChannelOwnership() error {
} else if channels == nil { } else if channels == nil {
return errors.Err("no channel response") return errors.Err("no channel response")
} }
//special case for wallets we don't retain full control anymore
if len((*channels).Items) > 1 { var channelToUse *jsonrpc.Transaction
// This wallet is probably not under our control anymore but we still want to publish to it if len((*channels).Items) > 0 {
// here we shall check if within all the channels there is one that was created by ytsync
logUtils.SendInfoToSlack("we are dealing with a wallet that has multiple channels. This indicates that the wallet was probably transferred but we still want to sync their content. YoutubeID: %s", s.YoutubeChannelID)
if s.lbryChannelID == "" { if s.lbryChannelID == "" {
return errors.Err("this channel does not have a recorded claimID in the database. To prevent failures, updates are not supported until an entry is manually added in the database") return errors.Err("this channel does not have a recorded claimID in the database. To prevent failures, updates are not supported until an entry is manually added in the database")
} }
for _, c := range (*channels).Items { for _, c := range (*channels).Items {
log.Debugf("checking listed channel %s (%s)", c.ClaimID, c.Name)
if c.ClaimID != s.lbryChannelID { if c.ClaimID != s.lbryChannelID {
continue
}
if c.Name != s.LbryChannelName { if c.Name != s.LbryChannelName {
return errors.Err("the channel in the wallet is different than the channel in the database") return errors.Err("the channel in the wallet is different than the channel in the database")
} }
return nil // we have the ytsync channel and both the claimID and the channelName from the database are correct channelToUse = &c
} break
}
if channelToUse == nil {
return errors.Err("this wallet has channels but not a single one is ours! Expected claim_id: %s (%s)", s.lbryChannelID, s.LbryChannelName)
} }
} }
channelUsesOldMetadata := false channelUsesOldMetadata := false
if len((*channels).Items) == 1 { if channelToUse != nil {
channel := ((*channels).Items)[0] channelUsesOldMetadata = channelToUse.Value.GetThumbnail() == nil
if channel.Name == s.LbryChannelName {
channelUsesOldMetadata = channel.Value.GetThumbnail() == nil
//TODO: eventually get rid of this when the whole db is filled
if s.lbryChannelID == "" {
err = s.Manager.apiConfig.SetChannelClaimID(s.YoutubeChannelID, channel.ClaimID)
} else if channel.ClaimID != s.lbryChannelID {
return errors.Err("the channel in the wallet is different than the channel in the database")
}
s.lbryChannelID = channel.ClaimID
if !channelUsesOldMetadata { if !channelUsesOldMetadata {
return err return nil
}
} else {
return errors.Err("this channel does not belong to this wallet! Expected: %s, found: %s", s.LbryChannelName, channel.Name)
} }
} }
@ -404,24 +397,6 @@ func (s *Sync) ensureChannelOwnership() error {
return s.Manager.apiConfig.SetChannelClaimID(s.YoutubeChannelID, s.lbryChannelID) return s.Manager.apiConfig.SetChannelClaimID(s.YoutubeChannelID, s.lbryChannelID)
} }
func allUTXOsConfirmed(utxolist *jsonrpc.UTXOListResponse) bool {
if utxolist == nil {
return false
}
if len(*utxolist) < 1 {
return false
}
for _, utxo := range *utxolist {
if utxo.Confirmations <= 0 {
return false
}
}
return true
}
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 := logUtils.GetLbrycrdClient(s.LbrycrdString) lbrycrdd, err := logUtils.GetLbrycrdClient(s.LbrycrdString)