add support for channel claimid

This commit is contained in:
Niko Storni 2018-12-24 19:23:40 -05:00
parent f23e24c029
commit e560b590f5
No known key found for this signature in database
GPG key ID: F37FE63398800368
3 changed files with 41 additions and 3 deletions

View file

@ -110,6 +110,7 @@ func (s *SyncManager) Start() error {
APIConfig: s.apiConfig,
YoutubeChannelID: s.syncProperties.YoutubeChannelID,
LbryChannelName: lbryChannelName,
lbryChannelID: channels[0].ChannelClaimID,
StopOnError: s.stopOnError,
MaxTries: s.maxTries,
ConcurrentVideos: s.concurrentVideos,
@ -143,6 +144,7 @@ func (s *SyncManager) Start() error {
APIConfig: s.apiConfig,
YoutubeChannelID: c.ChannelId,
LbryChannelName: c.DesiredChannelName,
lbryChannelID: c.ChannelClaimID,
StopOnError: s.stopOnError,
MaxTries: s.maxTries,
ConcurrentVideos: s.concurrentVideos,

View file

@ -39,6 +39,7 @@ type YoutubeChannel struct {
Address string `json:"address"`
Currency string `json:"currency"`
} `json:"fee"`
ChannelClaimID string `json:"channel_claim_id"`
}
func (a *APIConfig) FetchChannels(status string, cp *SyncProperties) ([]YoutubeChannel, error) {
@ -117,6 +118,34 @@ func (a *APIConfig) SetChannelStatus(channelID string, status string, failureRea
return nil, nil, errors.Err("invalid API response. Status code: %d", res.StatusCode)
}
func (a *APIConfig) SetChannelClaimID(channelID string, channelClaimID string) error {
type apiChannelStatusResponse struct {
Success bool `json:"success"`
Error null.String `json:"error"`
Data string `json:"data"`
}
endpoint := a.ApiURL + "/yt/set_channel_claim_id"
res, _ := http.PostForm(endpoint, url.Values{
"channel_id": {channelID},
"auth_token": {a.ApiToken},
"channel_claim_id": {channelClaimID},
})
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
var response apiChannelStatusResponse
err := json.Unmarshal(body, &response)
if err != nil {
return err
}
if !response.Error.IsNull() {
return errors.Err(response.Error.String)
}
if response.Data != "ok" {
return errors.Err("Unexpected API response")
}
return nil
}
const (
VideoStatusPublished = "published"
VideoStatusFailed = "failed"

View file

@ -190,6 +190,10 @@ func (s *Sync) ensureChannelOwnership() error {
isChannelMine := false
for _, channel := range *channels {
if channel.Name == s.LbryChannelName {
//TODO: eventually get rid of this when the whole db is filled
if s.lbryChannelID == "" {
err = s.Manager.apiConfig.SetChannelClaimID(s.YoutubeChannelID, s.lbryChannelID)
}
s.lbryChannelID = channel.ClaimID
isChannelMine = true
} else {
@ -197,7 +201,7 @@ func (s *Sync) ensureChannelOwnership() error {
}
}
if isChannelMine {
return nil
return err
}
channelBidAmount := channelClaimAmount
@ -211,7 +215,10 @@ func (s *Sync) ensureChannelOwnership() error {
balance := decimal.Decimal(*balanceResp)
if balance.LessThan(decimal.NewFromFloat(channelBidAmount)) {
s.addCredits(channelBidAmount + 0.1)
err = s.addCredits(channelBidAmount + 0.1)
if err != nil {
return err
}
}
c, err := s.daemon.ChannelNew(s.LbryChannelName, channelBidAmount)
@ -219,7 +226,7 @@ func (s *Sync) ensureChannelOwnership() error {
return err
}
s.lbryChannelID = c.ClaimID
return nil
return s.Manager.apiConfig.SetChannelClaimID(s.YoutubeChannelID, s.lbryChannelID)
}
func allUTXOsConfirmed(utxolist *jsonrpc.UTXOListResponse) bool {