mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 13:41:37 +00:00
Merge pull request #1838 from nspcc-dev/extend-rpc-client
Extend RPC client
This commit is contained in:
commit
c773f117be
3 changed files with 92 additions and 0 deletions
36
pkg/rpc/client/native.go
Normal file
36
pkg/rpc/client/native.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package client
|
||||
|
||||
// Various non-policy things from native contracs.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||
)
|
||||
|
||||
// GetOraclePrice invokes `getPrice` method on a native Oracle contract.
|
||||
func (c *Client) GetOraclePrice() (int64, error) {
|
||||
oracleHash, err := c.GetNativeContractHash(nativenames.Notary)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to get native Oracle hash: %w", err)
|
||||
}
|
||||
return c.invokeNativeGetMethod(oracleHash, "getPrice")
|
||||
}
|
||||
|
||||
// GetNNSPrice invokes `getPrice` method on a native NameService contract.
|
||||
func (c *Client) GetNNSPrice() (int64, error) {
|
||||
nnsHash, err := c.GetNativeContractHash(nativenames.NameService)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to get native NameService hash: %w", err)
|
||||
}
|
||||
return c.invokeNativeGetMethod(nnsHash, "getPrice")
|
||||
}
|
||||
|
||||
// GetGasPerBlock invokes `getGasPerBlock` method on a native NEO contract.
|
||||
func (c *Client) GetGasPerBlock() (int64, error) {
|
||||
neoHash, err := c.GetNativeContractHash(nativenames.Neo)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to get native NEO hash: %w", err)
|
||||
}
|
||||
return c.invokeNativeGetMethod(neoHash, "getGasPerBlock")
|
||||
}
|
|
@ -25,6 +25,14 @@ func (c *Client) GetExecFeeFactor() (int64, error) {
|
|||
return c.invokeNativePolicyMethod("getExecFeeFactor")
|
||||
}
|
||||
|
||||
// GetStoragePrice invokes `getStoragePrice` method on a native Policy contract.
|
||||
func (c *Client) GetStoragePrice() (int64, error) {
|
||||
if !c.initDone {
|
||||
return 0, errNetworkNotInitialized
|
||||
}
|
||||
return c.invokeNativePolicyMethod("getStoragePrice")
|
||||
}
|
||||
|
||||
// GetMaxNotValidBeforeDelta invokes `getMaxNotValidBeforeDelta` method on a native Notary contract.
|
||||
func (c *Client) GetMaxNotValidBeforeDelta() (int64, error) {
|
||||
notaryHash, err := c.GetNativeContractHash(nativenames.Notary)
|
||||
|
|
|
@ -428,6 +428,54 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
|||
},
|
||||
},
|
||||
},
|
||||
"getStoragePrice": {
|
||||
{
|
||||
name: "positive",
|
||||
invoke: func(c *Client) (interface{}, error) {
|
||||
return c.GetStoragePrice()
|
||||
},
|
||||
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMDWdldEZlZVBlckJ5dGUMFJphpG7sl7iTBtfOgfFbRiCR0AkyQWJ9W1I=","stack":[{"type":"Integer","value":"100000"}],"tx":null}}`,
|
||||
result: func(c *Client) interface{} {
|
||||
return int64(100000)
|
||||
},
|
||||
},
|
||||
},
|
||||
"getOraclePrice": {
|
||||
{
|
||||
name: "positive",
|
||||
invoke: func(c *Client) (interface{}, error) {
|
||||
return c.GetOraclePrice()
|
||||
},
|
||||
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMDWdldEZlZVBlckJ5dGUMFJphpG7sl7iTBtfOgfFbRiCR0AkyQWJ9W1I=","stack":[{"type":"Integer","value":"10000000"}],"tx":null}}`,
|
||||
result: func(c *Client) interface{} {
|
||||
return int64(10000000)
|
||||
},
|
||||
},
|
||||
},
|
||||
"getNNSPrice": {
|
||||
{
|
||||
name: "positive",
|
||||
invoke: func(c *Client) (interface{}, error) {
|
||||
return c.GetNNSPrice()
|
||||
},
|
||||
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMDWdldEZlZVBlckJ5dGUMFJphpG7sl7iTBtfOgfFbRiCR0AkyQWJ9W1I=","stack":[{"type":"Integer","value":"1000000"}],"tx":null}}`,
|
||||
result: func(c *Client) interface{} {
|
||||
return int64(1000000)
|
||||
},
|
||||
},
|
||||
},
|
||||
"getGasPerBlock": {
|
||||
{
|
||||
name: "positive",
|
||||
invoke: func(c *Client) (interface{}, error) {
|
||||
return c.GetGasPerBlock()
|
||||
},
|
||||
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMDWdldEZlZVBlckJ5dGUMFJphpG7sl7iTBtfOgfFbRiCR0AkyQWJ9W1I=","stack":[{"type":"Integer","value":"500000000"}],"tx":null}}`,
|
||||
result: func(c *Client) interface{} {
|
||||
return int64(500000000)
|
||||
},
|
||||
},
|
||||
},
|
||||
"getMaxNotValidBeforeDelta": {
|
||||
{
|
||||
name: "positive",
|
||||
|
|
Loading…
Reference in a new issue