rpc: add getMaxNotValidBeforeDelta method to RPC client

This commit is contained in:
Anna Shaleva 2021-02-09 11:35:45 +03:00
parent 2bb8537151
commit 9d73802244
2 changed files with 46 additions and 3 deletions

View file

@ -22,27 +22,46 @@ func (c *Client) GetMaxBlockSize() (int64, error) {
// GetFeePerByte invokes `getFeePerByte` method on a native Policy contract. // GetFeePerByte invokes `getFeePerByte` method on a native Policy contract.
func (c *Client) GetFeePerByte() (int64, error) { func (c *Client) GetFeePerByte() (int64, error) {
if !c.initDone {
return 0, errNetworkNotInitialized
}
return c.invokeNativePolicyMethod("getFeePerByte") return c.invokeNativePolicyMethod("getFeePerByte")
} }
// GetExecFeeFactor invokes `getExecFeeFactor` method on a native Policy contract. // GetExecFeeFactor invokes `getExecFeeFactor` method on a native Policy contract.
func (c *Client) GetExecFeeFactor() (int64, error) { func (c *Client) GetExecFeeFactor() (int64, error) {
if !c.initDone {
return 0, errNetworkNotInitialized
}
return c.invokeNativePolicyMethod("getExecFeeFactor") 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) { func (c *Client) invokeNativePolicyMethod(operation string) (int64, error) {
if !c.initDone { if !c.initDone {
return 0, errNetworkNotInitialized 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 { if err != nil {
return 0, err return 0, err
} }
err = getInvocationError(result) err = getInvocationError(result)
if err != nil { 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) return topIntFromStack(result.Stack)
} }

View file

@ -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": { "getMaxTransacctionsPerBlock": {
{ {
name: "positive", 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": { "isBlocked": {
{ {
name: "positive", name: "positive",