2019-08-14 06:44:27 +02:00
|
|
|
package lbrycrd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
|
2021-10-06 20:00:59 +02:00
|
|
|
c "github.com/lbryio/lbry.go/v3/schema/stake"
|
2019-08-14 06:44:27 +02:00
|
|
|
pb "github.com/lbryio/types/v2/go"
|
|
|
|
|
2021-10-06 20:00:59 +02:00
|
|
|
"github.com/cockroachdb/errors"
|
|
|
|
"github.com/lbryio/lbcd/btcec"
|
|
|
|
"github.com/lbryio/lbcd/wire"
|
2019-08-14 06:44:27 +02:00
|
|
|
)
|
|
|
|
|
2021-10-06 20:00:59 +02:00
|
|
|
func NewImageStreamClaim() (*c.Helper, error) {
|
2019-08-14 06:44:27 +02:00
|
|
|
streamClaim := new(pb.Claim_Stream)
|
|
|
|
stream := new(pb.Stream)
|
|
|
|
image := new(pb.Stream_Image)
|
|
|
|
image.Image = new(pb.Image)
|
|
|
|
stream.Type = image
|
|
|
|
|
|
|
|
streamClaim.Stream = stream
|
|
|
|
|
|
|
|
pbClaim := new(pb.Claim)
|
|
|
|
pbClaim.Type = streamClaim
|
|
|
|
|
2021-10-06 20:00:59 +02:00
|
|
|
helper := c.Helper{Claim: pbClaim}
|
2019-08-14 06:44:27 +02:00
|
|
|
|
|
|
|
return &helper, nil
|
|
|
|
}
|
|
|
|
|
2021-10-06 20:00:59 +02:00
|
|
|
func NewVideoStreamClaim() (*c.Helper, error) {
|
2019-08-14 06:44:27 +02:00
|
|
|
streamClaim := new(pb.Claim_Stream)
|
|
|
|
stream := new(pb.Stream)
|
|
|
|
video := new(pb.Stream_Video)
|
|
|
|
video.Video = new(pb.Video)
|
|
|
|
stream.Type = video
|
|
|
|
streamClaim.Stream = stream
|
|
|
|
|
|
|
|
pbClaim := new(pb.Claim)
|
|
|
|
pbClaim.Type = streamClaim
|
|
|
|
|
2021-10-06 20:00:59 +02:00
|
|
|
helper := c.Helper{Claim: pbClaim}
|
2019-08-14 06:44:27 +02:00
|
|
|
|
|
|
|
return &helper, nil
|
|
|
|
}
|
|
|
|
|
2021-10-06 20:00:59 +02:00
|
|
|
func NewStreamClaim(title, description string) (*c.Helper, error) {
|
2019-08-14 06:44:27 +02:00
|
|
|
streamClaim := new(pb.Claim_Stream)
|
|
|
|
stream := new(pb.Stream)
|
|
|
|
streamClaim.Stream = stream
|
|
|
|
|
|
|
|
pbClaim := new(pb.Claim)
|
|
|
|
pbClaim.Type = streamClaim
|
|
|
|
|
2021-10-06 20:00:59 +02:00
|
|
|
helper := c.Helper{Claim: pbClaim}
|
2020-10-28 06:36:49 +01:00
|
|
|
helper.Claim.Title = title
|
|
|
|
helper.Claim.Description = description
|
2019-08-14 06:44:27 +02:00
|
|
|
|
|
|
|
return &helper, nil
|
|
|
|
}
|
|
|
|
|
2021-10-06 20:00:59 +02:00
|
|
|
func SignClaim(rawTx *wire.MsgTx, privKey btcec.PrivateKey, claim, channel *c.Helper, channelClaimID string) error {
|
2019-08-14 06:44:27 +02:00
|
|
|
claimIDHexBytes, err := hex.DecodeString(channelClaimID)
|
|
|
|
if err != nil {
|
2021-10-06 20:00:59 +02:00
|
|
|
return errors.WithStack(err)
|
2019-08-14 06:44:27 +02:00
|
|
|
}
|
|
|
|
claim.Version = c.WithSig
|
|
|
|
claim.ClaimID = rev(claimIDHexBytes)
|
|
|
|
hash, err := c.GetOutpointHash(rawTx.TxIn[0].PreviousOutPoint.Hash.String(), rawTx.TxIn[0].PreviousOutPoint.Index)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
sig, err := c.Sign(privKey, *channel, *claim, hash)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
lbrySig, err := sig.LBRYSDKEncode()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
claim.Signature = lbrySig
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|