forked from TrueCloudLab/neoneo-go
rpc: add getMaxNotValidBeforeDelta
method to RPC client
This commit is contained in:
parent
2bb8537151
commit
9d73802244
2 changed files with 46 additions and 3 deletions
pkg/rpc/client
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue