ytsync/sources/shared.go

32 lines
813 B
Go
Raw Normal View History

2018-02-13 18:47:05 +01:00
package sources
import (
"strings"
"sync"
"github.com/lbryio/lbry.go/v2/extras/jsonrpc"
2020-06-11 18:45:56 +02:00
"github.com/lbryio/ytsync/v5/namer"
2018-02-13 18:47:05 +01:00
)
type SyncSummary struct {
ClaimID string
ClaimName string
}
func publishAndRetryExistingNames(daemon *jsonrpc.Client, title, filename string, amount float64, options jsonrpc.StreamCreateOptions, namer *namer.Namer, walletLock *sync.RWMutex) (*SyncSummary, error) {
walletLock.RLock()
defer walletLock.RUnlock()
2018-02-13 18:47:05 +01:00
for {
2018-09-18 21:20:34 +02:00
name := namer.GetNextName(title)
response, err := daemon.StreamCreate(name, filename, amount, options)
2018-09-18 21:20:34 +02:00
if err != nil {
if strings.Contains(err.Error(), "failed: Multiple claims (") {
2018-02-13 18:47:05 +01:00
continue
}
return nil, err
2018-02-13 18:47:05 +01:00
}
PublishedClaim := response.Outputs[0]
return &SyncSummary{ClaimID: PublishedClaim.ClaimID, ClaimName: name}, nil
2018-02-13 18:47:05 +01:00
}
}