oracle

class Oracle

Bases: object

Neo Oracle Service is an out-of-chain data access service built into Neo N3. It allows users to request the external data sources in smart contracts, and Oracle nodes designated by the committee will access the specified data source then pass the result in the callback function to continue executing the smart contract logic.

Check out Neo’s Documentation to learn more about Oracles.

hash: UInt160
classmethod request(url: str, request_filter: str | None, callback: str, user_data: Any, gas_for_response: int)

Requests an information from outside the blockchain.

This method just requests data from the oracle, it won’t return the result.

>>> Oracle.request('https://dora.coz.io/api/v1/neo3/testnet/asset/0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5',
...                '', 'callback_name', None, 10 * 10 ** 8)
None
Parameters:
  • url (str) – External url to retrieve the data

  • request_filter (str or None) –

    Filter to the request.

    See JSONPath format https://github.com/atifaziz/JSONPath

  • callback (str) –

    Method name that will be as a callback.

    This method must be public and implement the following interface:

    (url: str, user_data: Any, code: int, result: bytes) -> None

  • user_data (Any) – Optional data. It’ll be returned as the same when the callback is called

  • gas_for_response (int) –

    Amount of GAS needed to run the callback method.

    It MUST NOT be specified as the user representation.

    If it costs 1 gas, this value must be 1_00000000 (with the 8 decimals)

classmethod get_price() int

Gets the price for an Oracle request.

>>> Oracle.get_price()
50000000
Returns:

the price for an Oracle request

class OracleResponseCode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntFlag

Represents the response code for the oracle request.

SUCCESS

Indicates that the request has been successfully completed.

PROTOCOL_NOT_SUPPORTED

Indicates that the protocol of the request is not supported.

CONSENSUS_UNREACHABLE

Indicates that the oracle nodes cannot reach a consensus on the result of the request.

NOT_FOUND

Indicates that the requested Uri does not exist.

TIME_OUT

Indicates that the request was not completed within the specified time.

FORBIDDEN

Indicates that there is no permission to request the resource.

RESPONSE_TOO_LARGE

Indicates that the data for the response is too large.

INSUFFICIENT_FUNDS

Indicates that the request failed due to insufficient balance.

CONTENT_TYPE_NOT_SUPPORTED

Indicates that the content-type of the request is not supported.

ERROR

Indicates that the request failed due to other errors.