adapters

package
v0.0.0-...-537fcec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package adapters contain the core adapters used by the Chainlink node.

HTTPGet

The HTTPGet adapter is used to grab the JSON data from the given URL.

{ "type": "HTTPGet", "url": "https://some-api-example.net/api" }

HTTPPost

Sends a POST request to the specified URL and will return the response.

{ "type": "HTTPPost", "url": "https://weiwatchers.com/api" }

JSONParse

The JSONParse adapter will obtain the value(s) for the given field(s).

{ "type": "JSONParse", "path": ["someField"] }

EthBytes32

The EthBytes32 adapter will take the given values and format them for the Ethereum blockhain.

{ "type": "EthBytes32" }

EthTx

The EthTx adapter will write the data to the given address and functionSelector.

{
  "type": "EthTx",
  "address": "0x0000000000000000000000000000000000000000",
  "functionSelector": "0xffffffff"
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	Perform(models.RunResult, *store.Store) models.RunResult
}

The Adapter interface applies to all core adapters. Each implementation must return a RunResult.

func For

func For(task models.TaskSpec, store *store.Store) (ac Adapter, err error)

For determines the adapter type to use for a given task

type Bridge

type Bridge struct {
	models.BridgeType
}

Bridge adapter is responsible for connecting the task pipeline to external adapters, allowing for custom computations to be executed and included in runs.

func (*Bridge) Perform

func (ba *Bridge) Perform(input models.RunResult, _ *store.Store) models.RunResult

Perform sends a POST request containing the JSON of the input RunResult to the external adapter specified in the BridgeType. It records the RunResult returned to it, and optionally marks the RunResult pending.

If the Perform is resumed with a pending RunResult, the RunResult is marked not pending and the RunResult is returned.

type EthBytes32

type EthBytes32 struct{}

EthBytes32 holds no fields.

func (*EthBytes32) Perform

func (*EthBytes32) Perform(input models.RunResult, _ *store.Store) models.RunResult

Perform returns the hex value of the first 32 bytes of a string so that it is in the proper format to be written to the blockchain.

For example, after converting the string "123.99" to hex for the blockchain, it would be: "0x000000000000000000000000000000000000000000000000000000000000007b"

type EthTx

type EthTx struct {
	Address          common.Address          `json:"address"`
	FunctionSelector models.FunctionSelector `json:"functionSelector"`
	DataPrefix       hexutil.Bytes           `json:"dataPrefix"`
}

EthTx holds the Address to send the result to and the FunctionSelector to execute.

func (*EthTx) Perform

func (etx *EthTx) Perform(input models.RunResult, store *store.Store) models.RunResult

Perform creates the run result for the transaction if the existing run result is not currently pending. Then it confirms the transaction was confirmed on the blockchain.

type EthUint256

type EthUint256 struct{}

EthUint256 holds no fields.

func (*EthUint256) Perform

func (*EthUint256) Perform(input models.RunResult, _ *store.Store) models.RunResult

Perform returns the hex value of a given string so that it is in the proper format to be written to the blockchain.

For example, after converting the string "16800.00" to hex for the blockchain, it would be: "0x31363830302e3030000000000000000000000000000000000000000000000000"

type HTTPGet

type HTTPGet struct {
	URL models.WebURL `json:"url"`
}

HTTPGet requires a URL which is used for a GET request when the adapter is called.

func (*HTTPGet) Perform

func (hga *HTTPGet) Perform(input models.RunResult, _ *store.Store) models.RunResult

Perform ensures that the adapter's URL responds to a GET request without errors and returns the response body as the "value" field of the result.

type HTTPPost

type HTTPPost struct {
	URL models.WebURL `json:"url"`
}

HTTPPost requires a URL which is used for a POST request when the adapter is called.

func (*HTTPPost) Perform

func (hpa *HTTPPost) Perform(input models.RunResult, _ *store.Store) models.RunResult

Perform ensures that the adapter's URL responds to a POST request without errors and returns the response body as the "value" field of the result.

type JSONParse

type JSONParse struct {
	Path []string `json:"path"`
}

JSONParse holds a path to the desired field in a JSON object, made up of an array of strings.

func (*JSONParse) Perform

func (jpa *JSONParse) Perform(input models.RunResult, _ *store.Store) models.RunResult

Perform returns the value associated to the desired field for a given JSON object.

For example, if the JSON data looks like this:

{
  "data": [
    {"last": "1111"},
    {"last": "2222"}
  ]
}

Then ["0","last"] would be the path, and "111" would be the returned value

type Multiplier

type Multiplier float64

Multiplier represents the number to multiply by in Multiply adapter.

func (*Multiplier) UnmarshalJSON

func (m *Multiplier) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Multiply

type Multiply struct {
	Times Multiplier `json:"times"`
}

Multiply holds the a number to multiply the given value by.

func (*Multiply) Perform

func (ma *Multiply) Perform(input models.RunResult, _ *store.Store) models.RunResult

Perform returns the input's "value" field, multiplied times the adapter's "times" field.

For example, if input value is "99.994" and the adapter's "times" is set to "100", the result's value will be "9999.4".

type NoOp

type NoOp struct{}

NoOp adapter type holds no fields

func (*NoOp) Perform

func (noa *NoOp) Perform(input models.RunResult, _ *store.Store) models.RunResult

Perform returns the empty RunResult

type NoOpPend

type NoOpPend struct{}

NoOpPend adapter type holds no fields

func (*NoOpPend) Perform

func (noa *NoOpPend) Perform(input models.RunResult, _ *store.Store) models.RunResult

Perform on this adapter type returns an empty RunResult with an added field for the status to indicate the task is Pending

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL