add support for transferred channels

fix bugs
update dependencies
This commit is contained in:
Niko Storni 2019-01-03 17:01:00 +01:00
parent 730bcae128
commit 1b07cadcbf
No known key found for this signature in database
GPG key ID: F37FE63398800368
4 changed files with 56 additions and 37 deletions

10
Gopkg.lock generated
View file

@ -95,13 +95,13 @@
branch = "master"
name = "github.com/lbryio/lbry.go"
packages = ["errors","jsonrpc","lbrycrd","null","stop","util"]
revision = "7a6eb5728093ff8da4bc6d9691308acf10fb9a53"
revision = "f986bd3066b9044ae1a44534908bdf4b381bbd1b"
[[projects]]
branch = "master"
name = "github.com/lbryio/lbryschema.go"
packages = ["pb"]
revision = "185433f2fd0c732547654749b98b37e56223dd22"
name = "github.com/lbryio/types"
packages = ["go"]
revision = "594241d24e0025d769d2cb58168536b6963d51cf"
[[projects]]
branch = "master"
@ -131,7 +131,7 @@
branch = "master"
name = "github.com/rylio/ytdl"
packages = ["."]
revision = "0227c2bacb82a434f2332d7d8c64093615c08a40"
revision = "44fe64bba886b85c00fc7045e092d796484d6f90"
[[projects]]
branch = "master"

View file

@ -135,7 +135,7 @@ func (a *APIConfig) SetChannelClaimID(channelID string, channelClaimID string) e
var response apiChannelStatusResponse
err := json.Unmarshal(body, &response)
if err != nil {
return err
return errors.Err(err)
}
if !response.Error.IsNull() {
return errors.Err(response.Error.String)

View file

@ -186,9 +186,25 @@ func (s *Sync) ensureChannelOwnership() error {
} else if channels == nil {
return errors.Err("no channel response")
}
isChannelMine := false
for _, channel := range *channels {
//special case for wallets we don't retain full control anymore
if len(*channels) > 1 {
// This wallet is probably not under our control anymore but we still want to publish to it
// here we shall check if within all the channels there is one that was created by ytsync
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 == "" {
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 {
if c.ClaimID != s.lbryChannelID {
if c.Name != s.LbryChannelName {
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
}
}
}
if len(*channels) == 1 {
channel := (*channels)[0]
if channel.Name == s.LbryChannelName {
//TODO: eventually get rid of this when the whole db is filled
if s.lbryChannelID == "" {
@ -196,18 +212,12 @@ func (s *Sync) ensureChannelOwnership() error {
} else if channel.ClaimID != s.lbryChannelID {
return errors.Err("the channel in the wallet is different than the channel in the database")
}
if channel.Name != s.LbryChannelName {
return errors.Err("the channel in the wallet is different than the channel in the database")
}
s.lbryChannelID = channel.ClaimID
isChannelMine = true
return err
} else {
return errors.Err("this wallet has multiple channels. maybe something went wrong during setup?")
return errors.Err("this channel does not belong to this wallet! Expected: %s, found: %s", s.LbryChannelName, channel.Name)
}
}
if isChannelMine {
return err
}
channelBidAmount := channelClaimAmount

View file

@ -102,23 +102,29 @@ func (s *Sync) AppendSyncedVideo(videoID string, published bool, failureReason s
}
// SendErrorToSlack Sends an error message to the default channel and to the process log.
func SendErrorToSlack(format string, a ...interface{}) error {
func SendErrorToSlack(format string, a ...interface{}) {
message := format
if len(a) > 0 {
message = fmt.Sprintf(format, a...)
}
log.Errorln(message)
return util.SendToSlack(":sos: " + message)
err := util.SendToSlack(":sos: " + message)
if err != nil {
log.Errorln(err)
}
}
// SendInfoToSlack Sends an info message to the default channel and to the process log.
func SendInfoToSlack(format string, a ...interface{}) error {
func SendInfoToSlack(format string, a ...interface{}) {
message := format
if len(a) > 0 {
message = fmt.Sprintf(format, a...)
}
log.Infoln(message)
return util.SendToSlack(":information_source: " + message)
err := util.SendToSlack(":information_source: " + message)
if err != nil {
log.Errorln(err)
}
}
// IsInterrupted can be queried to discover if the sync process was interrupted manually
@ -371,22 +377,28 @@ func logShutdownError(shutdownErr error) {
SendErrorToSlack("WALLET HAS NOT BEEN MOVED TO THE WALLET BACKUP DIR")
}
func isYtsyncClaim(c jsonrpc.Claim) bool {
if !util.InSlice(c.Category, []string{"claim", "update"}) || c.Value.Stream == nil {
return false
}
if c.Value.Stream.Metadata == nil || c.Value.Stream.Metadata.Thumbnail == nil {
//most likely a claim created outside of ytsync, ignore!
return false
}
//we're dealing with something that wasn't published by us!
return !strings.Contains(*c.Value.Stream.Metadata.Thumbnail, "https://berk.ninja/thumbnails/")
}
// fixDupes abandons duplicate claims
func (s *Sync) fixDupes(claims []jsonrpc.Claim) (bool, error) {
abandonedClaims := false
videoIDs := make(map[string]jsonrpc.Claim)
for _, c := range claims {
if !util.InSlice(c.Category, []string{"claim", "update"}) || c.Value.Stream == nil {
if !isYtsyncClaim(c) {
continue
}
if c.Value.Stream.Metadata == nil || c.Value.Stream.Metadata.Thumbnail == nil {
return false, errors.Err("something is wrong with this claim: %s", c.ClaimID)
}
tn := *c.Value.Stream.Metadata.Thumbnail
if !strings.Contains(tn, "https://berk.ninja/thumbnails/") {
//we're dealing with something that wasn't published by us!
continue
}
videoID := tn[strings.LastIndex(tn, "/")+1:]
log.Infof("claimid: %s, claimName: %s, videoID: %s", c.ClaimID, c.Name, videoID)
@ -402,11 +414,11 @@ func (s *Sync) fixDupes(claims []jsonrpc.Claim) (bool, error) {
claimToAbandon = cl
videoIDs[videoID] = c
}
log.Debugf("abandoning %+v", claimToAbandon)
_, err := s.daemon.ClaimAbandon(claimToAbandon.Txid, claimToAbandon.Nout)
if err != nil {
return true, err
}
log.Debugf("abandoning %+v", claimToAbandon)
abandonedClaims = true
//return true, nil
}
@ -417,12 +429,10 @@ func (s *Sync) fixDupes(claims []jsonrpc.Claim) (bool, error) {
func (s *Sync) updateRemoteDB(claims []jsonrpc.Claim) (total int, fixed int, err error) {
count := 0
for _, c := range claims {
if !util.InSlice(c.Category, []string{"claim", "update"}) || c.Value.Stream == nil {
if !isYtsyncClaim(c) {
continue
}
if c.Value.Stream.Metadata == nil || c.Value.Stream.Metadata.Thumbnail == nil {
return count, fixed, errors.Err("something is wrong with the this claim: %s", c.ClaimID)
}
count++
//check if claimID is in remote db
tn := *c.Value.Stream.Metadata.Thumbnail
videoID := tn[strings.LastIndex(tn, "/")+1:]
@ -431,12 +441,11 @@ func (s *Sync) updateRemoteDB(claims []jsonrpc.Claim) (total int, fixed int, err
fixed++
err = s.Manager.apiConfig.MarkVideoStatus(s.YoutubeChannelID, videoID, VideoStatusPublished, c.ClaimID, c.Name, "", nil)
if err != nil {
return total, fixed, err
return count, fixed, err
}
}
total++
}
return total, fixed, nil
return count, fixed, nil
}
func (s *Sync) doSync() error {