2017-09-12 18:02:30 +02:00
|
|
|
package claim
|
|
|
|
|
|
|
|
import (
|
2017-11-27 16:22:04 +01:00
|
|
|
"encoding/hex"
|
2017-09-12 18:02:30 +02:00
|
|
|
"errors"
|
2018-11-09 23:04:05 +01:00
|
|
|
|
2017-09-12 18:02:30 +02:00
|
|
|
"github.com/golang/protobuf/proto"
|
2018-11-09 23:04:05 +01:00
|
|
|
"github.com/lbryio/types/go"
|
2017-09-12 18:02:30 +02:00
|
|
|
)
|
|
|
|
|
2017-11-27 16:22:04 +01:00
|
|
|
func (c *ClaimHelper) Serialized() ([]byte, error) {
|
|
|
|
serialized := c.String()
|
2017-09-12 18:02:30 +02:00
|
|
|
if serialized == "" {
|
|
|
|
return nil, errors.New("not initialized")
|
|
|
|
}
|
2017-11-27 16:22:04 +01:00
|
|
|
v := c.GetVersion()
|
|
|
|
t := c.GetClaimType()
|
2017-11-08 03:39:08 +01:00
|
|
|
|
|
|
|
return proto.Marshal(
|
|
|
|
&pb.Claim{
|
2017-11-27 16:22:04 +01:00
|
|
|
Version: &v,
|
|
|
|
ClaimType: &t,
|
|
|
|
Stream: c.GetStream(),
|
|
|
|
Certificate: c.GetCertificate(),
|
|
|
|
PublisherSignature: c.GetPublisherSignature()})
|
2017-11-08 03:39:08 +01:00
|
|
|
}
|
|
|
|
|
2017-11-27 16:22:04 +01:00
|
|
|
func (c *ClaimHelper) GetProtobuf() *pb.Claim {
|
|
|
|
v := c.GetVersion()
|
|
|
|
t := c.GetClaimType()
|
2017-11-08 03:39:08 +01:00
|
|
|
|
|
|
|
return &pb.Claim{
|
2017-11-27 16:22:04 +01:00
|
|
|
Version: &v,
|
|
|
|
ClaimType: &t,
|
|
|
|
Stream: c.GetStream(),
|
|
|
|
Certificate: c.GetCertificate(),
|
|
|
|
PublisherSignature: c.GetPublisherSignature()}
|
2017-09-12 18:02:30 +02:00
|
|
|
}
|
|
|
|
|
2017-11-27 16:22:04 +01:00
|
|
|
func (c *ClaimHelper) SerializedHexString() (string, error) {
|
|
|
|
serialized, err := c.Serialized()
|
2017-09-12 18:02:30 +02:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
serialized_hex := hex.EncodeToString(serialized)
|
|
|
|
return serialized_hex, nil
|
|
|
|
}
|
|
|
|
|
2017-11-27 16:22:04 +01:00
|
|
|
func (c *ClaimHelper) SerializedNoSignature() ([]byte, error) {
|
|
|
|
if c.String() == "" {
|
2017-09-12 18:02:30 +02:00
|
|
|
return nil, errors.New("not initialized")
|
|
|
|
}
|
2017-11-27 16:22:04 +01:00
|
|
|
if c.GetPublisherSignature() == nil {
|
|
|
|
serialized, err := c.Serialized()
|
2017-09-12 18:02:30 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return serialized, nil
|
|
|
|
} else {
|
|
|
|
clone := &pb.Claim{}
|
2017-11-27 16:22:04 +01:00
|
|
|
proto.Merge(clone, c.GetProtobuf())
|
2017-09-12 18:02:30 +02:00
|
|
|
proto.ClearAllExtensions(clone.PublisherSignature)
|
|
|
|
clone.PublisherSignature = nil
|
|
|
|
return proto.Marshal(clone)
|
|
|
|
}
|
|
|
|
}
|