lbry.go/cmd/test.go

71 lines
1.4 KiB
Go
Raw Normal View History

2017-10-03 17:26:44 +02:00
package cmd
import (
"fmt"
"sync"
"github.com/lbryio/lbry.go/jsonrpc"
"github.com/davecgh/go-spew/spew"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func init() {
var testCmd = &cobra.Command{
Use: "test",
Short: "For testing stuff",
Run: test,
}
RootCmd.AddCommand(testCmd)
}
2017-10-11 04:02:16 +02:00
func strPtr(s string) *string { return &s }
2017-10-03 17:26:44 +02:00
func test(cmd *cobra.Command, args []string) {
2017-10-11 04:02:16 +02:00
daemon := jsonrpc.NewClient("")
2017-10-03 17:26:44 +02:00
addresses, err := daemon.WalletList()
if err != nil {
panic(err)
} else if addresses == nil || len(*addresses) == 0 {
panic(fmt.Errorf("could not find an address in wallet"))
}
2017-10-11 04:02:16 +02:00
claimAddress := (*addresses)[0]
2017-10-03 17:26:44 +02:00
if claimAddress == "" {
panic(fmt.Errorf("found blank claim address"))
}
var wg sync.WaitGroup
publishes := []jsonrpc.PublishOptions{
{
Title: strPtr("a"),
Language: strPtr("en"),
ClaimAddress: &claimAddress,
ChannelName: strPtr("@x"),
},
{
Title: strPtr("b"),
Language: strPtr("en"),
ClaimAddress: &claimAddress,
ChannelName: strPtr("@x"),
},
}
for _, o := range publishes {
wg.Add(1)
go func(o jsonrpc.PublishOptions) {
defer wg.Done()
log.Println("Publishing " + *o.Title)
response, err := daemon.Publish(*o.Title, "/home/grin/Desktop/cake.jpg", 0.01, o)
if err != nil {
spew.Dump([]interface{}{o, err})
}
spew.Dump(response)
}(o)
}
wg.Wait()
}