diff --git a/pkg/rpc/client/policy.go b/pkg/rpc/client/policy.go index 26ff5ae9c..9f2f31d98 100644 --- a/pkg/rpc/client/policy.go +++ b/pkg/rpc/client/policy.go @@ -22,27 +22,46 @@ func (c *Client) GetMaxBlockSize() (int64, error) { // GetFeePerByte invokes `getFeePerByte` method on a native Policy contract. func (c *Client) GetFeePerByte() (int64, error) { + if !c.initDone { + return 0, errNetworkNotInitialized + } return c.invokeNativePolicyMethod("getFeePerByte") } // GetExecFeeFactor invokes `getExecFeeFactor` method on a native Policy contract. func (c *Client) GetExecFeeFactor() (int64, error) { + if !c.initDone { + return 0, errNetworkNotInitialized + } return c.invokeNativePolicyMethod("getExecFeeFactor") } +// GetMaxNotValidBeforeDelta invokes `getMaxNotValidBeforeDelta` method on a native Notary contract. +func (c *Client) GetMaxNotValidBeforeDelta() (int64, error) { + notaryHash, err := c.GetNativeContractHash(nativenames.Notary) + if err != nil { + return 0, fmt.Errorf("failed to get native Notary hash: %w", err) + } + return c.invokeNativeGetMethod(notaryHash, "getMaxNotValidBeforeDelta") +} + +// invokeNativePolicy method invokes Get* method on a native Policy contract. func (c *Client) invokeNativePolicyMethod(operation string) (int64, error) { if !c.initDone { return 0, errNetworkNotInitialized } - result, err := c.InvokeFunction(c.cache.nativeHashes[nativenames.Policy], operation, []smartcontract.Parameter{}, nil) + return c.invokeNativeGetMethod(c.cache.nativeHashes[nativenames.Policy], operation) +} + +func (c *Client) invokeNativeGetMethod(hash util.Uint160, operation string) (int64, error) { + result, err := c.InvokeFunction(hash, operation, []smartcontract.Parameter{}, nil) if err != nil { return 0, err } err = getInvocationError(result) if err != nil { - return 0, fmt.Errorf("failed to invoke %s Policy method: %w", operation, err) + return 0, fmt.Errorf("failed to invoke %s method of native contract %s: %w", operation, hash.StringLE(), err) } - return topIntFromStack(result.Stack) } diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index 30c849233..2e9674420 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -419,6 +419,18 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }, }, }, + "getExecFeeFactor": { + { + name: "positive", + invoke: func(c *Client) (interface{}, error) { + return c.GetExecFeeFactor() + }, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMDWdldEZlZVBlckJ5dGUMFJphpG7sl7iTBtfOgfFbRiCR0AkyQWJ9W1I=","stack":[{"type":"Integer","value":"1000"}],"tx":null}}`, + result: func(c *Client) interface{} { + return int64(1000) + }, + }, + }, "getMaxTransacctionsPerBlock": { { name: "positive", @@ -443,6 +455,18 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }, }, }, + "getMaxNotValidBeforeDelta": { + { + name: "positive", + invoke: func(c *Client) (interface{}, error) { + return c.GetMaxNotValidBeforeDelta() + }, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMD2dldE1heEJsb2NrU2l6ZQwUmmGkbuyXuJMG186B8VtGIJHQCTJBYn1bUg==","stack":[{"type":"Integer","value":"262144"}],"tx":null}}`, + result: func(c *Client) interface{} { + return int64(262144) + }, + }, + }, "isBlocked": { { name: "positive",