2018-01-31 08:27:08 +00:00
|
|
|
package core
|
|
|
|
|
2018-01-31 10:47:54 +00:00
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"io"
|
2018-02-04 19:54:51 +00:00
|
|
|
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
2018-01-31 10:47:54 +00:00
|
|
|
)
|
2018-01-31 08:27:08 +00:00
|
|
|
|
|
|
|
// Witness ...
|
|
|
|
type Witness struct {
|
|
|
|
InvocationScript []byte
|
|
|
|
VerificationScript []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeBinary implements the payload interface.
|
|
|
|
func (wit *Witness) DecodeBinary(r io.Reader) error {
|
2018-02-04 19:54:51 +00:00
|
|
|
lenb := util.ReadVarUint(r)
|
2018-01-31 10:47:54 +00:00
|
|
|
wit.InvocationScript = make([]byte, lenb)
|
2018-02-04 19:54:51 +00:00
|
|
|
if err := binary.Read(r, binary.LittleEndian, &wit.InvocationScript); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
lenb = util.ReadVarUint(r)
|
2018-01-31 10:47:54 +00:00
|
|
|
wit.VerificationScript = make([]byte, lenb)
|
2018-02-04 19:54:51 +00:00
|
|
|
if err := binary.Read(r, binary.LittleEndian, &wit.VerificationScript); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2018-01-31 10:47:54 +00:00
|
|
|
|
2018-02-04 19:54:51 +00:00
|
|
|
return nil
|
2018-01-31 08:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeBinary implements the payload interface.
|
|
|
|
func (wit *Witness) EncodeBinary(w io.Writer) error {
|
2018-02-07 14:16:50 +00:00
|
|
|
util.WriteVarUint(w, uint64(len(wit.InvocationScript)))
|
|
|
|
if err := binary.Write(w, binary.LittleEndian, wit.InvocationScript); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
util.WriteVarUint(w, uint64(len(wit.VerificationScript)))
|
|
|
|
return binary.Write(w, binary.LittleEndian, wit.VerificationScript)
|
2018-01-31 08:27:08 +00:00
|
|
|
}
|