From f308a9995dae987e91d6f63094b479d5e4380bbc Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 16 Mar 2021 22:55:17 +0300 Subject: [PATCH] client: add GetOraclePrice for oracle price --- pkg/rpc/client/native.go | 18 ++++++++++++++++++ pkg/rpc/client/rpc_test.go | 12 ++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 pkg/rpc/client/native.go diff --git a/pkg/rpc/client/native.go b/pkg/rpc/client/native.go new file mode 100644 index 000000000..5273ac1b0 --- /dev/null +++ b/pkg/rpc/client/native.go @@ -0,0 +1,18 @@ +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") +} diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index 3cb8d382c..c4ba17836 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -440,6 +440,18 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ }, }, }, + "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) + }, + }, + }, "getMaxNotValidBeforeDelta": { { name: "positive",