From 93dce149ba211c7a942e70f758d85391fc5898ef Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 16 Nov 2021 19:20:04 +0300 Subject: [PATCH] [#976] morph/client: Add script verifier Signed-off-by: Alex Vanin --- pkg/morph/client/client.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/morph/client/client.go b/pkg/morph/client/client.go index 41742d7a..04f14aec 100644 --- a/pkg/morph/client/client.go +++ b/pkg/morph/client/client.go @@ -474,3 +474,20 @@ func (c *Client) MsPerBlock() (res int64, err error) { return int64(v.Protocol.MillisecondsPerBlock), nil } + +// IsValidScript returns true if invocation script executes with HALT state. +func (c *Client) IsValidScript(script []byte, signers []transaction.Signer) (res bool, err error) { + if c.multiClient != nil { + return res, c.multiClient.iterateClients(func(c *Client) error { + res, err = c.IsValidScript(script, signers) + return err + }) + } + + result, err := c.client.InvokeScript(script, signers) + if err != nil { + return false, fmt.Errorf("invokeScript: %w", err) + } + + return result.State == vm.HaltState.String(), nil +}