transaction: remove Attribute.Data field

This commit is contained in:
Evgenii Stratonikov 2020-09-16 13:39:53 +03:00
parent bfe3b3d05d
commit 06b29e409c
2 changed files with 1 additions and 13 deletions

View file

@ -1,7 +1,6 @@
package transaction package transaction
import ( import (
"encoding/base64"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -12,28 +11,23 @@ import (
// Attribute represents a Transaction attribute. // Attribute represents a Transaction attribute.
type Attribute struct { type Attribute struct {
Type AttrType Type AttrType
Data []byte
} }
// attrJSON is used for JSON I/O of Attribute. // attrJSON is used for JSON I/O of Attribute.
type attrJSON struct { type attrJSON struct {
Type string `json:"type"` Type string `json:"type"`
Data string `json:"data"`
} }
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (attr *Attribute) DecodeBinary(br *io.BinReader) { func (attr *Attribute) DecodeBinary(br *io.BinReader) {
attr.Type = AttrType(br.ReadB()) attr.Type = AttrType(br.ReadB())
var datasize uint64
switch attr.Type { switch attr.Type {
case HighPriority: case HighPriority:
default: default:
br.Err = fmt.Errorf("failed decoding TX attribute usage: 0x%2x", int(attr.Type)) br.Err = fmt.Errorf("failed decoding TX attribute usage: 0x%2x", int(attr.Type))
return return
} }
attr.Data = make([]byte, datasize)
br.ReadBytes(attr.Data)
} }
// EncodeBinary implements Serializable interface. // EncodeBinary implements Serializable interface.
@ -50,7 +44,6 @@ func (attr *Attribute) EncodeBinary(bw *io.BinWriter) {
func (attr *Attribute) MarshalJSON() ([]byte, error) { func (attr *Attribute) MarshalJSON() ([]byte, error) {
return json.Marshal(attrJSON{ return json.Marshal(attrJSON{
Type: attr.Type.String(), Type: attr.Type.String(),
Data: base64.StdEncoding.EncodeToString(attr.Data),
}) })
} }
@ -61,10 +54,6 @@ func (attr *Attribute) UnmarshalJSON(data []byte) error {
if err != nil { if err != nil {
return err return err
} }
binData, err := base64.StdEncoding.DecodeString(aj.Data)
if err != nil {
return err
}
switch aj.Type { switch aj.Type {
case "HighPriority": case "HighPriority":
attr.Type = HighPriority attr.Type = HighPriority
@ -72,6 +61,5 @@ func (attr *Attribute) UnmarshalJSON(data []byte) error {
return errors.New("wrong Type") return errors.New("wrong Type")
} }
attr.Data = binData
return nil return nil
} }

View file

@ -115,7 +115,7 @@ func TestMarshalUnmarshalJSONInvocationTX(t *testing.T) {
Version: 0, Version: 0,
Signers: []Signer{{Account: util.Uint160{1, 2, 3}}}, Signers: []Signer{{Account: util.Uint160{1, 2, 3}}},
Script: []byte{1, 2, 3, 4}, Script: []byte{1, 2, 3, 4},
Attributes: []Attribute{{Type: HighPriority, Data: []byte{}}}, Attributes: []Attribute{{Type: HighPriority}},
Scripts: []Witness{}, Scripts: []Witness{},
Trimmed: false, Trimmed: false,
} }