mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-05 13:06:20 +00:00
Smartcontract (#39)
* deleted transfer_output added asset type and transaction result to core * removed writing 0x00 when buffer length is 0 * Refactored emit into VM package + moved tx to own package. * implemented transaction along with claimTransaction. * refactored naming of transaction + added decode address for uint160 types * removed unnecessary folder and files. * transaction/smartcontract logic * bumped version 0.24.0
This commit is contained in:
parent
42195b1af4
commit
1a1a19da7d
36 changed files with 1066 additions and 170 deletions
79
pkg/core/transaction/attribute.go
Normal file
79
pkg/core/transaction/attribute.go
Normal file
|
@ -0,0 +1,79 @@
|
|||
package transaction
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/util"
|
||||
)
|
||||
|
||||
// Attribute represents a Transaction attribute.
|
||||
type Attribute struct {
|
||||
Usage AttrUsage
|
||||
Data []byte
|
||||
}
|
||||
|
||||
// DecodeBinary implements the Payloader interface.
|
||||
func (attr *Attribute) DecodeBinary(r io.Reader) error {
|
||||
if err := binary.Read(r, binary.LittleEndian, &attr.Usage); err != nil {
|
||||
return err
|
||||
}
|
||||
if attr.Usage == ContractHash ||
|
||||
attr.Usage == Vote ||
|
||||
(attr.Usage >= Hash1 && attr.Usage <= Hash15) {
|
||||
attr.Data = make([]byte, 32)
|
||||
return binary.Read(r, binary.LittleEndian, attr.Data)
|
||||
}
|
||||
if attr.Usage == ECDH02 || attr.Usage == ECDH03 {
|
||||
attr.Data = make([]byte, 33)
|
||||
attr.Data[0] = byte(attr.Usage)
|
||||
return binary.Read(r, binary.LittleEndian, attr.Data[1:])
|
||||
}
|
||||
if attr.Usage == Script {
|
||||
attr.Data = make([]byte, 20)
|
||||
return binary.Read(r, binary.LittleEndian, attr.Data)
|
||||
}
|
||||
if attr.Usage == DescriptionUrl {
|
||||
attr.Data = make([]byte, 1)
|
||||
return binary.Read(r, binary.LittleEndian, attr.Data)
|
||||
}
|
||||
if attr.Usage == Description || attr.Usage >= Remark {
|
||||
lenData := util.ReadVarUint(r)
|
||||
attr.Data = make([]byte, lenData)
|
||||
return binary.Read(r, binary.LittleEndian, attr.Data)
|
||||
}
|
||||
return errors.New("format error in decoding transaction attribute")
|
||||
}
|
||||
|
||||
// EncodeBinary implements the Payload interface.
|
||||
func (attr *Attribute) EncodeBinary(w io.Writer) error {
|
||||
if err := binary.Write(w, binary.LittleEndian, &attr.Usage); err != nil {
|
||||
return err
|
||||
}
|
||||
if attr.Usage == ContractHash ||
|
||||
attr.Usage == Vote ||
|
||||
(attr.Usage >= Hash1 && attr.Usage <= Hash15) {
|
||||
return binary.Write(w, binary.LittleEndian, attr.Data)
|
||||
}
|
||||
if attr.Usage == ECDH02 || attr.Usage == ECDH03 {
|
||||
attr.Data[0] = byte(attr.Usage)
|
||||
return binary.Write(w, binary.LittleEndian, attr.Data[1:33])
|
||||
}
|
||||
if attr.Usage == Script {
|
||||
return binary.Write(w, binary.LittleEndian, attr.Data)
|
||||
}
|
||||
if attr.Usage == DescriptionUrl {
|
||||
if err := util.WriteVarUint(w, uint64(len(attr.Data))); err != nil {
|
||||
return err
|
||||
}
|
||||
return binary.Write(w, binary.LittleEndian, attr.Data)
|
||||
}
|
||||
if attr.Usage == Description || attr.Usage >= Remark {
|
||||
if err := util.WriteVarUint(w, uint64(len(attr.Data))); err != nil {
|
||||
return err
|
||||
}
|
||||
return binary.Write(w, binary.LittleEndian, attr.Data)
|
||||
}
|
||||
return errors.New("format error in encoding transaction attribute")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue