diff --git a/pkg/rpc/client/native.go b/pkg/rpc/client/native.go new file mode 100644 index 000000000..54eb5de5e --- /dev/null +++ b/pkg/rpc/client/native.go @@ -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") +} diff --git a/pkg/rpc/client/policy.go b/pkg/rpc/client/policy.go index 81cdb34a8..674d7314e 100644 --- a/pkg/rpc/client/policy.go +++ b/pkg/rpc/client/policy.go @@ -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) diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index e34302c70..43eceec4d 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -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",