From a224917229714f091e8c85a7db1e15116b292869 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 14 Apr 2020 17:45:02 +0300 Subject: [PATCH] consensus: implement Verifiable interface for Payload --- pkg/consensus/payload.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/consensus/payload.go b/pkg/consensus/payload.go index ee9af07bd..c9f78a0eb 100644 --- a/pkg/consensus/payload.go +++ b/pkg/consensus/payload.go @@ -186,7 +186,7 @@ func (p *Payload) EncodeBinary(w *io.BinWriter) { // Sign signs payload using the private key. // It also sets corresponding verification and invocation scripts. func (p *Payload) Sign(key *privateKey) error { - sig, err := key.Sign(p.MarshalUnsigned()) + sig, err := key.Sign(p.GetSignedPart()) if err != nil { return err } @@ -197,6 +197,11 @@ func (p *Payload) Sign(key *privateKey) error { return nil } +// GetSignedPart implements crypto.Verifiable interface. +func (p *Payload) GetSignedPart() []byte { + return p.MarshalUnsigned() +} + // Verify verifies payload using provided Witness. func (p *Payload) Verify(scriptHash util.Uint160) bool { verification, err := core.ScriptFromWitness(scriptHash, &p.Witness) @@ -205,7 +210,7 @@ func (p *Payload) Verify(scriptHash util.Uint160) bool { } v := vm.New() - h := sha256.Sum256(p.MarshalUnsigned()) + h := sha256.Sum256(p.GetSignedPart()) v.SetCheckedHash(h[:]) v.LoadScript(verification)