add DecodeClaimJSON
This commit is contained in:
parent
d89334f9eb
commit
f53da5c3e5
1 changed files with 12 additions and 2 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"../pb"
|
"../pb"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/golang/protobuf/jsonpb"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,10 +17,10 @@ func (c *ClaimHelper) ValidateAddresses(blockchainName string) error {
|
||||||
// check the validity of a fee address
|
// check the validity of a fee address
|
||||||
if c.GetClaimType() == pb.Claim_streamType {
|
if c.GetClaimType() == pb.Claim_streamType {
|
||||||
fee := c.GetStream().GetMetadata().GetFee()
|
fee := c.GetStream().GetMetadata().GetFee()
|
||||||
if fee.String() != "" {
|
if fee != nil {
|
||||||
tmp_addr := fee.GetAddress()
|
tmp_addr := fee.GetAddress()
|
||||||
if len(tmp_addr) != 25 {
|
if len(tmp_addr) != 25 {
|
||||||
return errors.New("invalid address length")
|
return errors.New("invalid address length: " + string(len(tmp_addr)) + "!")
|
||||||
}
|
}
|
||||||
addr := [25]byte{}
|
addr := [25]byte{}
|
||||||
for i := range addr {
|
for i := range addr {
|
||||||
|
@ -101,6 +102,15 @@ func DecodeClaimHex(serialized string, blockchainName string) (*ClaimHelper, err
|
||||||
return DecodeClaimBytes(claim_bytes, blockchainName)
|
return DecodeClaimBytes(claim_bytes, blockchainName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DecodeClaimJSON(claimJSON string, blockchainName string) (*ClaimHelper, error) {
|
||||||
|
c := &pb.Claim{}
|
||||||
|
err := jsonpb.UnmarshalString(claimJSON, c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &ClaimHelper{c}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *ClaimHelper) GetStream() *pb.Stream {
|
func (c *ClaimHelper) GetStream() *pb.Stream {
|
||||||
if c != nil {
|
if c != nil {
|
||||||
return c.Stream
|
return c.Stream
|
||||||
|
|
Loading…
Reference in a new issue