mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 13:38:35 +00:00
6ccb518ab0
* Optimizations + some improvements - optimized pkg/core/storage.HeaderHashes - optimized pkg/rpc.performRequest (used json.Encoder) - fixes for pkg/util.ReadVarUint and pkg/util.WriteVarUint - optimized and fix fixed8 (Fixed8DecodeString / MarshalJSON) + tests - optimized and fix uint160 (Bytes / Uint160DecodeString / Equal / MarshalJSON) + tests - optimized and fix uint256 (Bytes / Equal / MarshalJSON) + tests - preallocate for pkg/vm.buildStackOutput - add go.mod / go.sum * update version
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package transaction
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
"io"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
)
|
|
|
|
// Witness contains 2 scripts.
|
|
type Witness struct {
|
|
InvocationScript []byte
|
|
VerificationScript []byte
|
|
}
|
|
|
|
// DecodeBinary implements the payload interface.
|
|
func (w *Witness) DecodeBinary(r io.Reader) error {
|
|
lenb := util.ReadVarUint(r)
|
|
w.InvocationScript = make([]byte, lenb)
|
|
if err := binary.Read(r, binary.LittleEndian, w.InvocationScript); err != nil {
|
|
return err
|
|
}
|
|
lenb = util.ReadVarUint(r)
|
|
w.VerificationScript = make([]byte, lenb)
|
|
return binary.Read(r, binary.LittleEndian, w.VerificationScript)
|
|
}
|
|
|
|
// EncodeBinary implements the payload interface.
|
|
func (w *Witness) EncodeBinary(writer io.Writer) error {
|
|
if err := util.WriteVarUint(writer, uint64(len(w.InvocationScript))); err != nil {
|
|
return err
|
|
}
|
|
if err := binary.Write(writer, binary.LittleEndian, w.InvocationScript); err != nil {
|
|
return err
|
|
}
|
|
if err := util.WriteVarUint(writer, uint64(len(w.VerificationScript))); err != nil {
|
|
return err
|
|
}
|
|
return binary.Write(writer, binary.LittleEndian, w.VerificationScript)
|
|
}
|
|
|
|
// MarshalJSON implements the json marshaller interface.
|
|
func (w *Witness) MarshalJSON() ([]byte, error) {
|
|
data := map[string]string{
|
|
"invocation": hex.EncodeToString(w.InvocationScript),
|
|
"verification": hex.EncodeToString(w.VerificationScript),
|
|
}
|
|
|
|
return json.Marshal(data)
|
|
}
|