-
Notifications
You must be signed in to change notification settings - Fork 77
/
witness.go
43 lines (35 loc) · 1.07 KB
/
witness.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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.WriteBytes(w.InvocationScript)
bw.WriteBytes(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)
}