-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Job Pipeline
The core functionality of a single ChainLink node is to run a set of sequential processes, feeding the results of each process into the subsequent process, until a final result is reached. This is known as the "job pipeline."
When specifying a job, you must declare the job's Initiators and the job's Tasks. Initiators are the entry points for the job pipeline, and are covered in more detail here. Tasks define the actual processes that will be run in order to produce a result. Each task has a type, and most tasks take additional parameters to specify their behavior. Each task type is handled by an Adapter which specializes in running the computations associated with each task. The result of each Adapter's computation is passed on as the input to the next adapter, until the final adapter is reached and its result is the result of the entire Job Run.
Take the common job definition:
{
"initiators": [{ "type": "web" }],
"tasks": [
{ "type": "HttpGet", "url": "https://bitstamp.net/api/ticker/" },
{ "type": "JsonParse", "path": ["last"] },
{ "type": "EthBytes32" },
{
"type": "EthTx",
"address": "0x356a04bce728ba4c62a30294a55e6a8600a320b3",
"functionSelector": "0x609ff1bd"
}
]
}
This job has a single initiator, web
, which means new runs can be created via POST requests to the ChainLink node. Once a new run is created, it starts processing the first task, in this case HttpGet
.
HttpGet
performs a GET
request to the url
parameter, which may respond with {"last":"11394.86","timestamp":"1519087731","volume": "12229.25870700"}
. That response becomes the result of the HttpGet
adapter, which is passed on to the JsonParse
adapter.
JsonParse
takes the input, parses it into JSON and looks up the value in the JSON path specified as the path
parameter. In this case, it will find "11394.86"
for the last
key, and pass that along as the result of this task to the EthBytes32
adapter.
EthBytes32
takes the input, converts it to a string and then formats that string into Solidity's Bytes32 format. In this example, "11394.86" would be formatted as "0x31313339342e3836000000000000000000000000000000000000000000000000", which is passed on to the EthTx
adapter.
EthTx
is an adapter which will write transactions to the Ethereum blockchain. It sends the transaction to the Ethereum account specified in the address
field. Additionally, it selects which function to call on an Ethereum contract with the functionSelector
field. Once EthTx
has built up and signed a transaction it sends that transaction into the blockchain and returns the transaction hash as the result. Being the last task in this job, the resulting transaction hash is also the result of the entire job run.