2019-09-11 20:35:25 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2019-10-03 22:13:08 +02:00
|
|
|
"encoding/hex"
|
|
|
|
"fmt"
|
|
|
|
|
2021-04-02 20:30:36 +02:00
|
|
|
"github.com/lbryio/lbry.go/v2/schema/stake"
|
2019-09-11 20:35:25 +02:00
|
|
|
|
|
|
|
"github.com/davecgh/go-spew/spew"
|
2019-10-03 22:13:08 +02:00
|
|
|
"github.com/golang/protobuf/jsonpb"
|
2019-09-11 20:35:25 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
var cmd = &cobra.Command{
|
|
|
|
Use: "decode VALUE",
|
|
|
|
Short: "Decode a claim value",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
Run: decodeCmd,
|
|
|
|
}
|
|
|
|
rootCmd.AddCommand(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeCmd(cmd *cobra.Command, args []string) {
|
2021-04-02 20:30:36 +02:00
|
|
|
c, err := stake.DecodeClaimHex(args[0], "")
|
2019-09-11 20:35:25 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-10-03 22:13:08 +02:00
|
|
|
m := jsonpb.Marshaler{Indent: " "}
|
|
|
|
|
2019-09-11 20:35:25 +02:00
|
|
|
if stream := c.Claim.GetStream(); stream != nil {
|
2019-10-03 22:13:08 +02:00
|
|
|
json, err := m.MarshalToString(stream)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
fmt.Println(json)
|
|
|
|
fmt.Printf("SD hash as hex: %s\n", hex.EncodeToString(stream.GetSource().GetSdHash()))
|
2019-09-11 20:35:25 +02:00
|
|
|
} else if channel := c.Claim.GetChannel(); channel != nil {
|
2019-10-03 22:13:08 +02:00
|
|
|
json, err := m.MarshalToString(channel)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
fmt.Println(json)
|
|
|
|
} else if repost := c.Claim.GetRepost(); repost != nil {
|
|
|
|
json, err := m.MarshalToString(repost)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
fmt.Println(json)
|
2019-09-11 20:35:25 +02:00
|
|
|
} else {
|
|
|
|
spew.Dump(c)
|
|
|
|
}
|
|
|
|
}
|