From f53da5c3e5c357dbdb89b319984580acf0a4d21b Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Mon, 27 Nov 2017 10:23:24 -0500 Subject: [PATCH] add DecodeClaimJSON --- claim/claim.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/claim/claim.go b/claim/claim.go index 37caaa5..cc041a8 100644 --- a/claim/claim.go +++ b/claim/claim.go @@ -5,6 +5,7 @@ import ( "../pb" "encoding/hex" "errors" + "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" ) @@ -16,10 +17,10 @@ func (c *ClaimHelper) ValidateAddresses(blockchainName string) error { // check the validity of a fee address if c.GetClaimType() == pb.Claim_streamType { fee := c.GetStream().GetMetadata().GetFee() - if fee.String() != "" { + if fee != nil { tmp_addr := fee.GetAddress() if len(tmp_addr) != 25 { - return errors.New("invalid address length") + return errors.New("invalid address length: " + string(len(tmp_addr)) + "!") } addr := [25]byte{} for i := range addr { @@ -101,6 +102,15 @@ func DecodeClaimHex(serialized string, blockchainName string) (*ClaimHelper, err 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 { if c != nil { return c.Stream