Push and Pull Flows and Contracts
In decentralized oracle networks, the way data is retrieved and published on-chain can follow two primary mechanisms: push and pull. Each mechanism serves different use cases and requires specific contract implementations to facilitate seamless interaction with on-chain systems.
Pull Execution Flow
In a pull mechanism, data is fetched by the oracle from an external source only when explicitly requested by a smart contract. This method is useful for cases where data is only needed at specific times during contract execution, allowing for more efficient use of resources by avoiding constant data updates.
The pull mechanism involves the following steps, which are illustrated in the diagram below:
How the Pull Mechanism Works
Smart Contract Requests Data: The smart contract initiates a data request by calling the
requestDatafunction on the oracle. It simply provides thecallbackAddress(its own address) and thecallbackFunctionId(the function in the smart contract that will handle the response).Oracle Generates
jobId: The oracle generates a uniquejobIdfor the request and returns it to the smart contract. The smart contract can store thisjobIdto track the request if needed.Oracle Fetches Data: The oracle proceeds to fetch the requested data from the external data source.
Data Source Responds: The external data source returns the fetched data to the oracle.
Oracle Calls
fulfillData: The oracle calls thefulfillDatafunction on the smart contract using thecallbackAddressandcallbackFunctionIdprovided earlier. It passes both thejobId(for identification) and the fetched data to the smart contract.Smart Contract Processes Data: The smart contract receives the data through the
fulfillDatafunction and processes it according to its logic.
Contracts for the Pull Mechanism
In a pull-based oracle system, two key contracts are involved in the data fetching process:
Oracle Interface: This defines the function that a smart contract uses to request data from the oracle.
Callback Interface: This defines the function that the oracle uses to return the fetched data back to the smart contract.
Oracle Interface
The Oracle Interface exposes the method through which a smart contract can request data from the oracle. This interface defines the requestData function, which allows the smart contract to initiate a data request. A jobId is generated by the oracle and returned to the calling contract.
Callback Interface for Smart Contracts
The Callback Interface must be implemented by the smart contract to handle the data returned by the oracle. The fulfillData function in this interface is called by the oracle once the requested data is fetched, using the callbackAddress and callbackFunctionId provided during the data request.
Push Execution Flow
Last updated