mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-25 03:56:34 +00:00
095653af23
* Added new config attributes: 'SecondsPerBlock','LowPriorityThreshold' * Added new files: * Added new method: CompareTo * Fixed empty Slice case * Added new methods: LessThan, GreaterThan, Equal, CompareTo * Added new method: InputIntersection * Added MaxTransactionSize, GroupOutputByAssetID * Added ned method: ScriptHash * Added new method: IsDoubleSpend * Refactor blockchainer, Added Feer interface, Verify and GetMemPool method * 1) Added MemPool 2) Added new methods to satisfy the blockchainer interface: IsLowPriority, Verify, GetMemPool * Added new methods: RelayTxn, RelayDirectly * Fixed tests * Implemented RPC server method sendrawtransaction * Refactor getrawtransaction, sendrawtransaction in separate methods * Moved 'secondsPerBlock' to config file * Implemented Kim suggestions: 1) Fixed data race issues 2) refactor Verify method 3) Get rid of unused InputIntersection method due to refactoring Verify method 4) Fixed bug in https://github.com/CityOfZion/neo-go/pull/174#discussion_r264108135 5) minor simplications of the code * Fixed minor issues related to 1) space 2) getter methods do not need pointer on the receiver 3) error message 4) refactoring CompareTo method in uint256.go * Fixed small issues * Use sync.RWMutex instead of sync.Mutex * Refined (R)Lock/(R)Unlock * return error instead of bool in Verify methods
62 lines
1.7 KiB
Go
62 lines
1.7 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)
|
|
}
|
|
|
|
// Size returns the size in bytes of the Witness.
|
|
func (w *Witness) Size() int {
|
|
return util.GetVarSize(w.InvocationScript) + util.GetVarSize(w.VerificationScript)
|
|
}
|
|
|
|
// ScriptHash returns the hash of the VerificationScript.
|
|
func (w Witness) ScriptHash() (util.Uint160, error) {
|
|
return util.Uint160FromScript(w.VerificationScript)
|
|
}
|