forked from TrueCloudLab/neoneo-go
transaction: attribute type is now type, not usage
This commit is contained in:
parent
fb70c82157
commit
acc2265169
3 changed files with 24 additions and 24 deletions
|
@ -1,10 +0,0 @@
|
||||||
package transaction
|
|
||||||
|
|
||||||
//go:generate stringer -type=AttrUsage
|
|
||||||
|
|
||||||
// AttrUsage represents the purpose of the attribute.
|
|
||||||
type AttrUsage uint8
|
|
||||||
|
|
||||||
// List of valid attribute usages (none for preview3).
|
|
||||||
//const (
|
|
||||||
//)
|
|
|
@ -10,26 +10,26 @@ import (
|
||||||
|
|
||||||
// Attribute represents a Transaction attribute.
|
// Attribute represents a Transaction attribute.
|
||||||
type Attribute struct {
|
type Attribute struct {
|
||||||
Usage AttrUsage
|
Type AttrType
|
||||||
Data []byte
|
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 {
|
||||||
Usage string `json:"usage"`
|
Type string `json:"type"`
|
||||||
Data string `json:"data"`
|
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.Usage = AttrUsage(br.ReadB())
|
attr.Type = AttrType(br.ReadB())
|
||||||
|
|
||||||
var datasize uint64
|
var datasize uint64
|
||||||
/**
|
/**
|
||||||
|
|
||||||
switch attr.Usage {
|
switch attr.Type {
|
||||||
default:
|
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
|
return
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -39,18 +39,18 @@ func (attr *Attribute) DecodeBinary(br *io.BinReader) {
|
||||||
|
|
||||||
// EncodeBinary implements Serializable interface.
|
// EncodeBinary implements Serializable interface.
|
||||||
func (attr *Attribute) EncodeBinary(bw *io.BinWriter) {
|
func (attr *Attribute) EncodeBinary(bw *io.BinWriter) {
|
||||||
bw.WriteB(byte(attr.Usage))
|
bw.WriteB(byte(attr.Type))
|
||||||
switch attr.Usage {
|
switch attr.Type {
|
||||||
default:
|
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.
|
// MarshalJSON implements the json Marshaller interface.
|
||||||
func (attr *Attribute) MarshalJSON() ([]byte, error) {
|
func (attr *Attribute) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(attrJSON{
|
return json.Marshal(attrJSON{
|
||||||
Usage: "", // attr.Usage.String() when we're to have some real attributes
|
Type: "", // attr.Type.String() when we're to have some real attributes
|
||||||
Data: base64.StdEncoding.EncodeToString(attr.Data),
|
Data: base64.StdEncoding.EncodeToString(attr.Data),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,9 +66,9 @@ func (attr *Attribute) UnmarshalJSON(data []byte) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
switch aj.Usage {
|
switch aj.Type {
|
||||||
default:
|
default:
|
||||||
return errors.New("wrong Usage")
|
return errors.New("wrong Type")
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
10
pkg/core/transaction/attrtype.go
Normal file
10
pkg/core/transaction/attrtype.go
Normal file
|
@ -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 (
|
||||||
|
//)
|
Loading…
Reference in a new issue