Skip to content

Commit

Permalink
transaction: attribute type is now type, not usage
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov committed Aug 11, 2020
1 parent 7e075f5 commit 5a68565
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
10 changes: 0 additions & 10 deletions pkg/core/transaction/attr_usage.go

This file was deleted.

28 changes: 14 additions & 14 deletions pkg/core/transaction/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ import (

// Attribute represents a Transaction attribute.
type Attribute struct {
Usage AttrUsage
Data []byte
Type AttrType
Data []byte
}

// attrJSON is used for JSON I/O of Attribute.
type attrJSON struct {
Usage string `json:"usage"`
Data string `json:"data"`
Type string `json:"type"`
Data string `json:"data"`
}

// DecodeBinary implements Serializable interface.
func (attr *Attribute) DecodeBinary(br *io.BinReader) {
attr.Usage = AttrUsage(br.ReadB())
attr.Type = AttrType(br.ReadB())

var datasize uint64
switch attr.Usage {
switch attr.Type {
default:
br.Err = fmt.Errorf("failed decoding TX attribute usage: 0x%2x", int(attr.Usage))
br.Err = fmt.Errorf("failed decoding TX attribute usage: 0x%2x", int(attr.Type))
return
}
attr.Data = make([]byte, datasize)
Expand All @@ -37,18 +37,18 @@ func (attr *Attribute) DecodeBinary(br *io.BinReader) {

// EncodeBinary implements Serializable interface.
func (attr *Attribute) EncodeBinary(bw *io.BinWriter) {
bw.WriteB(byte(attr.Usage))
switch attr.Usage {
bw.WriteB(byte(attr.Type))
switch attr.Type {
default:
bw.Err = fmt.Errorf("failed encoding TX attribute usage: 0x%2x", attr.Usage)
bw.Err = fmt.Errorf("failed encoding TX attribute usage: 0x%2x", attr.Type)
}
}

// MarshalJSON implements the json Marshaller interface.
func (attr *Attribute) MarshalJSON() ([]byte, error) {
return json.Marshal(attrJSON{
Usage: "", // attr.Usage.String() when we're to have some real attributes
Data: base64.StdEncoding.EncodeToString(attr.Data),
Type: "", // attr.Type.String() when we're to have some real attributes
Data: base64.StdEncoding.EncodeToString(attr.Data),
})
}

Expand All @@ -63,9 +63,9 @@ func (attr *Attribute) UnmarshalJSON(data []byte) error {
if err != nil {
return err
}
switch aj.Usage {
switch aj.Type {
default:
return errors.New("wrong Usage")
return errors.New("wrong Type")

}
attr.Data = binData
Expand Down
10 changes: 10 additions & 0 deletions pkg/core/transaction/attrtype.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package transaction

//go:generate stringer -type=AttrType

// AttrType represents the purpose of the attribute.
type AttrType uint8

// List of valid attribute types (none for preview3).
//const (
//)

0 comments on commit 5a68565

Please sign in to comment.