github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/core/transaction/witness.go (about) 1 package transaction 2 3 import ( 4 "bytes" 5 6 "github.com/nspcc-dev/neo-go/pkg/crypto/hash" 7 "github.com/nspcc-dev/neo-go/pkg/io" 8 "github.com/nspcc-dev/neo-go/pkg/util" 9 ) 10 11 const ( 12 // MaxInvocationScript is the maximum length of allowed invocation 13 // script. It should fit 11/21 multisignature for the committee. 14 MaxInvocationScript = 1024 15 16 // MaxVerificationScript is the maximum allowed length of verification 17 // script. It should be appropriate for 11/21 multisignature committee. 18 MaxVerificationScript = 1024 19 ) 20 21 // Witness contains 2 scripts. 22 type Witness struct { 23 InvocationScript []byte `json:"invocation"` 24 VerificationScript []byte `json:"verification"` 25 } 26 27 // DecodeBinary implements the Serializable interface. 28 func (w *Witness) DecodeBinary(br *io.BinReader) { 29 w.InvocationScript = br.ReadVarBytes(MaxInvocationScript) 30 w.VerificationScript = br.ReadVarBytes(MaxVerificationScript) 31 } 32 33 // EncodeBinary implements the Serializable interface. 34 func (w *Witness) EncodeBinary(bw *io.BinWriter) { 35 bw.WriteVarBytes(w.InvocationScript) 36 bw.WriteVarBytes(w.VerificationScript) 37 } 38 39 // ScriptHash returns the hash of the VerificationScript. 40 func (w Witness) ScriptHash() util.Uint160 { 41 return hash.Hash160(w.VerificationScript) 42 } 43 44 // Copy creates a deep copy of the Witness. 45 func (w Witness) Copy() Witness { 46 return Witness{ 47 InvocationScript: bytes.Clone(w.InvocationScript), 48 VerificationScript: bytes.Clone(w.VerificationScript), 49 } 50 }