forked from TrueCloudLab/neoneo-go
19a430b262
* Adds basic RPC supporting files * Adds interrupt handling and error chan * Add getblock RPC method * Update request structure * Update names of nodes * Allow bad addresses to be registered in discovery externally * Small tidy up * Few tweaks * Check if error is close error in tcp transport * Fix tests * Fix priv port * Small tweak to param name * Comment fix * Remove version from server * Moves submitblock to TODO block * Remove old field * Bumps version and fix hex issues
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package transaction
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"io"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
)
|
|
|
|
// Witness contains 2 scripts.
|
|
type Witness struct {
|
|
InvocationScript []byte `json:"stack"`
|
|
VerificationScript []byte `json:"redeem"`
|
|
}
|
|
|
|
// DecodeBinary implements the payload interface.
|
|
func (wit *Witness) DecodeBinary(r io.Reader) error {
|
|
lenb := util.ReadVarUint(r)
|
|
wit.InvocationScript = make([]byte, lenb)
|
|
if err := binary.Read(r, binary.LittleEndian, wit.InvocationScript); err != nil {
|
|
return err
|
|
}
|
|
lenb = util.ReadVarUint(r)
|
|
wit.VerificationScript = make([]byte, lenb)
|
|
return binary.Read(r, binary.LittleEndian, wit.VerificationScript)
|
|
}
|
|
|
|
// EncodeBinary implements the payload interface.
|
|
func (wit *Witness) EncodeBinary(w io.Writer) error {
|
|
if err := util.WriteVarUint(w, uint64(len(wit.InvocationScript))); err != nil {
|
|
return err
|
|
}
|
|
if err := binary.Write(w, binary.LittleEndian, wit.InvocationScript); err != nil {
|
|
return err
|
|
}
|
|
if err := util.WriteVarUint(w, uint64(len(wit.VerificationScript))); err != nil {
|
|
return err
|
|
}
|
|
return binary.Write(w, binary.LittleEndian, wit.VerificationScript)
|
|
}
|