2018-02-13 12:47:05 -05:00
|
|
|
package sources
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2019-06-12 03:17:59 +02:00
|
|
|
"sync"
|
2018-06-04 10:35:35 -04:00
|
|
|
|
2019-10-10 16:50:33 +02:00
|
|
|
"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 12:47:05 -05:00
|
|
|
)
|
|
|
|
|
2018-07-20 19:56:36 -04:00
|
|
|
type SyncSummary struct {
|
|
|
|
ClaimID string
|
|
|
|
ClaimName string
|
|
|
|
}
|
|
|
|
|
2019-06-12 03:17:59 +02:00
|
|
|
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 12:47:05 -05:00
|
|
|
for {
|
2018-09-18 15:20:34 -04:00
|
|
|
name := namer.GetNextName(title)
|
2019-04-18 21:22:51 -04:00
|
|
|
response, err := daemon.StreamCreate(name, filename, amount, options)
|
2018-09-18 15:20:34 -04:00
|
|
|
if err != nil {
|
|
|
|
if strings.Contains(err.Error(), "failed: Multiple claims (") {
|
2018-02-13 12:47:05 -05:00
|
|
|
continue
|
|
|
|
}
|
2018-07-20 19:56:36 -04:00
|
|
|
return nil, err
|
2018-02-13 12:47:05 -05:00
|
|
|
}
|
2019-04-18 21:22:51 -04:00
|
|
|
PublishedClaim := response.Outputs[0]
|
|
|
|
return &SyncSummary{ClaimID: PublishedClaim.ClaimID, ClaimName: name}, nil
|
2018-02-13 12:47:05 -05:00
|
|
|
}
|
|
|
|
}
|