2019-02-25 22:44:14 +00:00
|
|
|
package transaction
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/wire/util"
|
|
|
|
)
|
|
|
|
|
2019-03-17 18:26:35 +00:00
|
|
|
//Witness represents a Witness object in a neo transaction
|
2019-02-25 22:44:14 +00:00
|
|
|
type Witness struct {
|
|
|
|
InvocationScript []byte
|
|
|
|
VerificationScript []byte
|
|
|
|
}
|
|
|
|
|
2019-03-17 18:26:35 +00:00
|
|
|
// Encode encodes a Witness into a binary writer
|
2019-02-25 22:44:14 +00:00
|
|
|
func (s *Witness) Encode(bw *util.BinWriter) error {
|
|
|
|
|
|
|
|
bw.VarUint(uint64(len(s.InvocationScript)))
|
|
|
|
bw.Write(s.InvocationScript)
|
|
|
|
|
|
|
|
bw.VarUint(uint64(len(s.VerificationScript)))
|
|
|
|
bw.Write(s.VerificationScript)
|
|
|
|
|
|
|
|
return bw.Err
|
|
|
|
}
|
|
|
|
|
2019-03-17 18:26:35 +00:00
|
|
|
// Decode decodes a binary reader into a Witness object
|
2019-02-25 22:44:14 +00:00
|
|
|
func (s *Witness) Decode(br *util.BinReader) error {
|
|
|
|
|
|
|
|
lenb := br.VarUint()
|
|
|
|
s.InvocationScript = make([]byte, lenb)
|
|
|
|
br.Read(s.InvocationScript)
|
|
|
|
|
|
|
|
lenb = br.VarUint()
|
|
|
|
s.VerificationScript = make([]byte, lenb)
|
|
|
|
br.Read(s.VerificationScript)
|
|
|
|
|
|
|
|
return br.Err
|
|
|
|
}
|