2018-03-04 13:56:49 +00:00
|
|
|
package transaction
|
2018-01-31 08:27:08 +00:00
|
|
|
|
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
|
|
|
|
2018-03-04 13:56:49 +00:00
|
|
|
// Witness contains 2 scripts.
|
2018-01-31 08:27:08 +00:00
|
|
|
type Witness struct {
|
2018-03-23 20:36:59 +00:00
|
|
|
InvocationScript []byte `json:"stack"`
|
|
|
|
VerificationScript []byte `json:"redeem"`
|
2018-01-31 08:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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-03-04 13:56:49 +00:00
|
|
|
if err := binary.Read(r, binary.LittleEndian, wit.InvocationScript); err != nil {
|
|
|
|
return err
|
2018-02-04 19:54:51 +00:00
|
|
|
}
|
|
|
|
lenb = util.ReadVarUint(r)
|
2018-01-31 10:47:54 +00:00
|
|
|
wit.VerificationScript = make([]byte, lenb)
|
2018-03-04 13:56:49 +00:00
|
|
|
return binary.Read(r, binary.LittleEndian, wit.VerificationScript)
|
2018-01-31 08:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeBinary implements the payload interface.
|
|
|
|
func (wit *Witness) EncodeBinary(w io.Writer) error {
|
2018-03-17 11:53:21 +00:00
|
|
|
if err := util.WriteVarUint(w, uint64(len(wit.InvocationScript))); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-02-07 14:16:50 +00:00
|
|
|
if err := binary.Write(w, binary.LittleEndian, wit.InvocationScript); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-03-17 11:53:21 +00:00
|
|
|
if err := util.WriteVarUint(w, uint64(len(wit.VerificationScript))); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-02-07 14:16:50 +00:00
|
|
|
return binary.Write(w, binary.LittleEndian, wit.VerificationScript)
|
2018-01-31 08:27:08 +00:00
|
|
|
}
|