forked from TrueCloudLab/neoneo-go
03ff2976ed
goal is to be consistent with C# implementation. For writing []byte WriteBytes used and for byte - WriteVarByte.
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package transaction
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
)
|
|
|
|
// Witness contains 2 scripts.
|
|
type Witness struct {
|
|
InvocationScript []byte
|
|
VerificationScript []byte
|
|
}
|
|
|
|
// DecodeBinary implements Serializable interface.
|
|
func (w *Witness) DecodeBinary(br *io.BinReader) {
|
|
w.InvocationScript = br.ReadBytes()
|
|
w.VerificationScript = br.ReadBytes()
|
|
}
|
|
|
|
// EncodeBinary implements Serializable interface.
|
|
func (w *Witness) EncodeBinary(bw *io.BinWriter) {
|
|
bw.WriteVarBytes(w.InvocationScript)
|
|
bw.WriteVarBytes(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)
|
|
}
|
|
|
|
// ScriptHash returns the hash of the VerificationScript.
|
|
func (w Witness) ScriptHash() util.Uint160 {
|
|
return hash.Hash160(w.VerificationScript)
|
|
}
|