From eb2f6273e405b6a4cb08ad0a8e991b97f7a70d84 Mon Sep 17 00:00:00 2001 From: Mark Beamer Jr Date: Tue, 20 Aug 2019 23:38:36 -0400 Subject: [PATCH] Add transfer of channel after all video's have been transferred Add channel status call to notify external db that the channel has been transferred. --- manager/manager.go | 7 +++++++ manager/transfer.go | 34 +++++++++++++++++++++++++++++++--- sdk/api.go | 3 ++- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/manager/manager.go b/manager/manager.go index 0ad6c38..aa956e1 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -100,6 +100,13 @@ const ( VideoStatusTranferFailed = "transferfailed" ) +const ( + TransferStateNotTouched = iota + TransferStatePending + TransferStateComplete + TransferStateFailed = -1 +) + func (s *SyncManager) Start() error { if logUtils.ShouldCleanOnStartup() { diff --git a/manager/transfer.go b/manager/transfer.go index 9c51234..8d9c4a9 100644 --- a/manager/transfer.go +++ b/manager/transfer.go @@ -8,7 +8,7 @@ import ( ) func TransferChannel(channel *Sync) error { - //Transfer channel + transferStatus := TransferStateComplete for _, video := range channel.syncedVideos { //Todo - Wait for prior sync to see that the publish is confirmed in lbrycrd? c, err := channel.daemon.ClaimSearch(nil, &video.ClaimID, nil, nil) @@ -39,6 +39,7 @@ func TransferChannel(channel *Sync) error { _, err = channel.daemon.StreamUpdate(video.ClaimID, streamUpdateOptions) if err != nil { + transferStatus = TransferStateFailed videoStatus.FailureReason = err.Error() videoStatus.Status = VideoStatusTranferFailed videoStatus.IsTransferred = util.PtrToBool(false) @@ -51,8 +52,35 @@ func TransferChannel(channel *Sync) error { return errors.Err(err) } } - // Todo - Transfer Channel as last step and post back to remote db that channel is transferred. + //Transfer channel + if transferStatus < 0 { + return errors.Err("A video has failed to transfer for the channel...skipping channel transfer") + } + failureReason := "" + channelClaim, err := channel.daemon.ClaimSearch(nil, &channel.lbryChannelID, nil, nil) + if err != nil { + return errors.Err(err) + } + if channelClaim == nil { + return errors.Err("There is no channel claim for channel %s", channel.LbryChannelName) + } + updateOptions := jsonrpc.ChannelUpdateOptions{ + ChannelCreateOptions: jsonrpc.ChannelCreateOptions{ + ClaimCreateOptions: jsonrpc.ClaimCreateOptions{ + ClaimAddress: &channel.publishAddress, + }, + }, + } + _, err = channel.daemon.ChannelUpdate(channel.lbryChannelID, updateOptions) + if err != nil { + transferStatus = TransferStateFailed + failureReason = err.Error() + } - return nil + _, _, channelStatusErr := channel.APIConfig.SetChannelStatus(channel.lbryChannelID, VideoStatusPublished, failureReason, transferStatus) + if channelStatusErr != nil { + return errors.Err(err) + } + return errors.Err(err) } diff --git a/sdk/api.go b/sdk/api.go index d3b8559..837083e 100644 --- a/sdk/api.go +++ b/sdk/api.go @@ -133,7 +133,7 @@ func (a *APIConfig) SetChannelCert(certHex string, channelID string) error { } -func (a *APIConfig) SetChannelStatus(channelID string, status string, failureReason string) (map[string]SyncedVideo, map[string]bool, error) { +func (a *APIConfig) SetChannelStatus(channelID string, status string, failureReason string, transferState int) (map[string]SyncedVideo, map[string]bool, error) { type apiChannelStatusResponse struct { Success bool `json:"success"` Error null.String `json:"error"` @@ -148,6 +148,7 @@ func (a *APIConfig) SetChannelStatus(channelID string, status string, failureRea "auth_token": {a.ApiToken}, "sync_status": {status}, "failure_reason": {failureReason}, + "transferred": {strconv.Itoa(transferState)}, }) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body)