improve getDefaultAccount

use default account on more calls
improve API logging
fix memory leak
This commit is contained in:
Niko Storni 2019-10-16 19:38:45 +02:00
parent 682117a030
commit 291a105269
3 changed files with 43 additions and 32 deletions

View file

@ -141,7 +141,9 @@ func (s *Sync) walletSetup() error {
return nil
}
func (s *Sync) getDefaultAccount() (string, error) {
if s.defaultAccountID == "" {
accounts, err := s.daemon.AccountList()
if err != nil {
return "", errors.Err(err)
@ -150,17 +152,17 @@ func (s *Sync) getDefaultAccount() (string, error) {
if logUtils.IsRegTest() {
accountsNet = (*accounts).LBCRegtest
}
defaultAccount := ""
for _, account := range accountsNet {
if account.IsDefault {
defaultAccount = account.ID
s.defaultAccountID = account.ID
break
}
}
if defaultAccount == "" {
if s.defaultAccountID == "" {
return "", errors.Err("No default account found")
}
return defaultAccount, nil
}
return s.defaultAccountID, nil
}
func (s *Sync) ensureEnoughUTXOs() error {

View file

@ -89,6 +89,7 @@ type Sync struct {
transferState int
clientPublishAddress string
publicKey string
defaultAccountID string
}
func (s *Sync) AppendSyncedVideo(videoID string, published bool, failureReason string, claimName string, claimID string, metadataVersion int8, size int64) {
@ -342,7 +343,10 @@ func (s *Sync) processTransfers() (e error) {
if err != nil {
return err
}
defaultAccount, err := s.getDefaultAccount()
if err != nil {
return err
}
reallocateSupports := supportAmount > 0.01
if reallocateSupports {
err = waitConfirmations(s)
@ -350,7 +354,7 @@ func (s *Sync) processTransfers() (e error) {
return err
}
isTip := true
summary, err := s.daemon.SupportCreate(s.lbryChannelID, fmt.Sprintf("%.6f", supportAmount), &isTip, nil, nil)
summary, err := s.daemon.SupportCreate(s.lbryChannelID, fmt.Sprintf("%.6f", supportAmount), &isTip, nil, []string{defaultAccount})
if err != nil {
return errors.Err(err)
}

View file

@ -82,13 +82,14 @@ func (a *APIConfig) FetchChannels(status string, cp *SyncProperties) ([]YoutubeC
if err != nil {
return nil, errors.Err(err)
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
if res.StatusCode != http.StatusOK {
util.SendErrorToSlack("Error %d while trying to call %s. Waiting to retry", res.StatusCode, endpoint)
log.Debugln(body)
time.Sleep(30 * time.Second)
return a.FetchChannels(status, cp)
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
var response apiJobsResponse
err = json.Unmarshal(body, &response)
if err != nil {
@ -139,14 +140,14 @@ func (a *APIConfig) SetChannelCert(certHex string, channelID string) error {
if err != nil {
return errors.Err(err)
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
if res.StatusCode != http.StatusOK {
util.SendErrorToSlack("Error %d while trying to call %s. Waiting to retry", res.StatusCode, endpoint)
log.Debugln(body)
time.Sleep(30 * time.Second)
return a.SetChannelCert(certHex, channelID)
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
var response apiSetChannelCertResponse
err = json.Unmarshal(body, &response)
if err != nil {
@ -182,13 +183,14 @@ func (a *APIConfig) SetChannelStatus(channelID string, status string, failureRea
if err != nil {
return nil, nil, errors.Err(err)
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
if res.StatusCode != http.StatusOK {
util.SendErrorToSlack("Error %d while trying to call %s. Waiting to retry", res.StatusCode, endpoint)
log.Debugln(body)
time.Sleep(30 * time.Second)
return a.SetChannelStatus(channelID, status, failureReason, transferState)
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
var response apiChannelStatusResponse
err = json.Unmarshal(body, &response)
if err != nil {
@ -226,13 +228,14 @@ func (a *APIConfig) SetChannelClaimID(channelID string, channelClaimID string) e
if err != nil {
return errors.Err(err)
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
if res.StatusCode != http.StatusOK {
util.SendErrorToSlack("Error %d while trying to call %s. Waiting to retry", res.StatusCode, endpoint)
log.Debugln(body)
time.Sleep(30 * time.Second)
return a.SetChannelClaimID(channelID, channelClaimID)
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
var response apiChannelStatusResponse
err = json.Unmarshal(body, &response)
if err != nil {
@ -264,13 +267,14 @@ func (a *APIConfig) DeleteVideos(videos []string) error {
if err != nil {
return errors.Err(err)
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
if res.StatusCode != http.StatusOK {
util.SendErrorToSlack("Error %d while trying to call %s. Waiting to retry", res.StatusCode, endpoint)
log.Debugln(body)
time.Sleep(30 * time.Second)
return a.DeleteVideos(videos)
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
var response struct {
Success bool `json:"success"`
Error null.String `json:"error"`
@ -336,13 +340,14 @@ func (a *APIConfig) MarkVideoStatus(status VideoStatus) error {
if err != nil {
return errors.Err(err)
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
if res.StatusCode != http.StatusOK {
util.SendErrorToSlack("Error %d while trying to call %s. Waiting to retry", res.StatusCode, endpoint)
log.Debugln(body)
time.Sleep(30 * time.Second)
return a.MarkVideoStatus(status)
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
var response struct {
Success bool `json:"success"`
Error null.String `json:"error"`