models

package
v0.0.0-...-5cb58b4 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2018 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package models contain the key job components used by the Chainlink application.

Common

Common contains types and functions that are useful across the application. Particularly dealing with the URL field, dates, and time.

Eth

Eth creates transactions and tracks transaction attempts on the Ethereum blockchain.

JobSpec

A JobSpec is the largest unit of work that a Chainlink node can take on. It will have Initiators, which is how a JobRun is started from the job definition, and Tasks, which are the specific instructions for what work needs to be performed. The BridgeType is also located here, and is used to define the location (URL) of external adapters.

ORM

The ORM is the wrapper around the database. It gives a limited set of functions to allow for safe storing and withdrawing of information.

Run

A Run is the actual invocation of work being done on the Job and Task. This comprises of JobRuns and TaskRuns. A JobRun is like a workflow where the steps are the TaskRuns.

i.e. We have a Scheduler Initiator that creates a JobRun every monday based on a JobDefinition. And in turn, those JobRuns have TaskRuns based on the JobDefinition's TaskDefinitions.

V1

V1 contains the backwards compatibility for the Chainlink Ruby node. The Ruby node used a different JSON schema for Assignments, Subtasks, and Snapshots (now Specs, Tasks, and Runs). The functions in V1 allow for the node to accept and store V1-spec JSON with the same functionality of the V2 spec.

Index

Constants

View Source
const (
	// RunStatusUnstarted is the default state of any run status.
	RunStatusUnstarted = RunStatus("")
	// RunStatusInProgress is used for when a run is actively being executed.
	RunStatusInProgress = RunStatus("in_progress")
	// RunStatusPendingConfirmations is used for when a run is awaiting for block confirmations.
	RunStatusPendingConfirmations = RunStatus("pending_confirmations")
	// RunStatusPendingBridge is used for when a run is waiting on the completion
	// of another event.
	RunStatusPendingBridge = RunStatus("pending_bridge")
	// RunStatusPendingSleep is used for when a run is waiting on a sleep function to finish.
	RunStatusPendingSleep = RunStatus("pending_sleep")
	// RunStatusErrored is used for when a run has errored and will not complete.
	RunStatusErrored = RunStatus("errored")
	// RunStatusCompleted is used for when a run has successfully completed execution.
	RunStatusCompleted = RunStatus("completed")
)
View Source
const (
	// InitiatorRunLog for tasks in a job to watch an ethereum address
	// and expect a JSON payload from a log event.
	InitiatorRunLog = "runlog"
	// InitiatorCron for tasks in a job to be ran on a schedule.
	InitiatorCron = "cron"
	// InitiatorEthLog for tasks in a job to use the Ethereum blockchain.
	InitiatorEthLog = "ethlog"
	// InitiatorRunAt for tasks in a job to be ran once.
	InitiatorRunAt = "runat"
	// InitiatorWeb for tasks in a job making a web request.
	InitiatorWeb = "web"
)
View Source
const FunctionSelectorLength = 4

FunctionSelectorLength should always be a length of 4 as a byte.

View Source
const (
	// SignatureLength is the length of the signature in bytes: v = 1, r = 32, s
	// = 32; v + r + s = 65
	SignatureLength = 65
)

Variables

This section is empty.

Functions

func NewDatabaseAccessError

func NewDatabaseAccessError(msg string) error

NewDatabaseAccessError returns a database access error.

func NewValidationError

func NewValidationError(msg string, values ...interface{}) error

NewValidationError returns a validation error.

Types

type Assignment

type Assignment struct {
	Subtasks []Subtask `json:"subtasks"`
}

Assignment contains all the subtasks to perform

type AssignmentSpec

type AssignmentSpec struct {
	Assignment Assignment `json:"assignment"`
	Schedule   Schedule   `json:"schedule"`
}

AssignmentSpec represents a specification of work to be given to an oracle this consists of an Assignment and a Schedule

func ConvertToAssignment

func ConvertToAssignment(j JobSpec) (AssignmentSpec, error)

ConvertToAssignment converts JobSpec to AssignmentSpec

func (AssignmentSpec) ConvertToJobSpec

func (s AssignmentSpec) ConvertToJobSpec() (JobSpec, error)

ConvertToJobSpec converts an AssignmentSpec to a JobSpec

type BlockHeader

type BlockHeader struct {
	ParentHash  common.Hash      `json:"parentHash"`
	UncleHash   common.Hash      `json:"sha3Uncles"`
	Coinbase    common.Address   `json:"miner"`
	Root        common.Hash      `json:"stateRoot"`
	TxHash      common.Hash      `json:"transactionsRoot"`
	ReceiptHash common.Hash      `json:"receiptsRoot"`
	Bloom       types.Bloom      `json:"logsBloom"`
	Difficulty  hexutil.Big      `json:"difficulty"`
	Number      hexutil.Big      `json:"number"`
	GasLimit    hexutil.Uint64   `json:"gasLimit"`
	GasUsed     hexutil.Uint64   `json:"gasUsed"`
	Time        hexutil.Big      `json:"timestamp"`
	Extra       hexutil.Bytes    `json:"extraData"`
	Nonce       types.BlockNonce `json:"nonce"`
	GethHash    common.Hash      `json:"mixHash"`
	ParityHash  common.Hash      `json:"hash"`
}

BlockHeader represents a block header in the Ethereum blockchain. Deliberately does not have required fields because some fields aren't present depending on the Ethereum node. i.e. Parity does not always send mixHash

func (BlockHeader) Hash

func (h BlockHeader) Hash() common.Hash

Hash will return GethHash if it exists otherwise it returns the ParityHash

func (BlockHeader) ToIndexableBlockNumber

func (h BlockHeader) ToIndexableBlockNumber() *IndexableBlockNumber

ToIndexableBlockNumber converts a given BlockHeader to an IndexableBlockNumber

type BridgeRunResult

type BridgeRunResult struct {
	RunResult
	ExternalPending bool   `json:"pending"`
	AccessToken     string `json:"accessToken"`
}

BridgeRunResult handles the parsing of RunResults from external adapters.

func (*BridgeRunResult) UnmarshalJSON

func (brr *BridgeRunResult) UnmarshalJSON(input []byte) error

UnmarshalJSON parses the given input and updates the BridgeRunResult in the external adapter format.

type BridgeType

type BridgeType struct {
	Name          TaskType `json:"name" storm:"id,unique"`
	URL           WebURL   `json:"url"`
	Confirmations uint64   `json:"confirmations"`
	IncomingToken string   `json:"incomingToken"`
	OutgoingToken string   `json:"outgoingToken"`
}

BridgeType is used for external adapters and has fields for the name of the adapter and its URL.

func (BridgeType) Authenticate

func (bt BridgeType) Authenticate(token string) (bool, error)

Authenticate returns true if the passed token matches its IncomingToken, or returns false with an error.

func (BridgeType) GetID

func (bt BridgeType) GetID() string

GetID returns the ID of this structure for jsonapi serialization.

func (BridgeType) GetName

func (bt BridgeType) GetName() string

GetName returns the pluralized "type" of this structure for jsonapi serialization.

func (*BridgeType) SetID

func (bt *BridgeType) SetID(value string) error

SetID is used to set the ID of this structure when deserializing from jsonapi documents.

type Cron

type Cron string

Cron holds the string that will represent the spec of the cron-job. It uses 6 fields to represent the seconds (1), minutes (2), hours (3), day of the month (4), month (5), and day of the week (6).

func (Cron) String

func (c Cron) String() string

String returns the current Cron spec string.

func (*Cron) UnmarshalJSON

func (c *Cron) UnmarshalJSON(b []byte) error

UnmarshalJSON parses the raw spec stored in JSON-encoded data and stores it to the Cron string.

type DatabaseAccessError

type DatabaseAccessError struct {
	// contains filtered or unexported fields
}

DatabaseAccessError is an error that occurs during database access.

func (*DatabaseAccessError) Error

func (e *DatabaseAccessError) Error() string

type EIP55Address

type EIP55Address string

EIP55Address is a newtype for string which persists an ethereum address in its original string representation which includes a leading 0x, and EIP55 checksum which is represented by the case of digits A-F.

func NewEIP55Address

func NewEIP55Address(s string) (EIP55Address, error)

NewEIP55Address creates an EIP55Address from a string, an error is returned if:

1) There is no leading 0x 2) The length is wrong 3) There are any non hexadecimal characters 4) The checksum fails

func (EIP55Address) Address

func (a EIP55Address) Address() common.Address

Address returns EIP55Address as a go-ethereum Address type

func (EIP55Address) Big

func (a EIP55Address) Big() *big.Int

Big returns a big.Int representation

func (EIP55Address) Bytes

func (a EIP55Address) Bytes() []byte

Bytes returns the raw bytes

func (EIP55Address) Format

func (a EIP55Address) Format(s fmt.State, c rune)

Format implements fmt.Formatter

func (EIP55Address) Hash

func (a EIP55Address) Hash() common.Hash

Hash returns the Hash

func (EIP55Address) String

func (a EIP55Address) String() string

String implements the stringer interface and is used also by the logger.

func (*EIP55Address) UnmarshalJSON

func (a *EIP55Address) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash from a JSON string

func (*EIP55Address) UnmarshalText

func (a *EIP55Address) UnmarshalText(input []byte) error

UnmarshalText parses a hash from plain text

type Encumbrance

type Encumbrance struct {
	Payment    *assets.Link   `json:"payment"`
	Expiration uint64         `json:"expiration"`
	Oracles    []EIP55Address `json:"oracles"`
}

Encumbrance connects job specifications with on-chain encumbrances.

func (Encumbrance) ABI

func (e Encumbrance) ABI() ([]byte, error)

ABI packs the encumberance as a byte array using the same technique as abi.encodePacked, meaning that addresses are padded with left 0s to match hashes in the oracle list

type EthSubscription

type EthSubscription interface {
	Err() <-chan error
	Unsubscribe()
}

EthSubscription should implement Err() <-chan error and Unsubscribe()

type FunctionSelector

type FunctionSelector [FunctionSelectorLength]byte

FunctionSelector is the first four bytes of the call data for a function call and specifies the function to be called.

func BytesToFunctionSelector

func BytesToFunctionSelector(b []byte) FunctionSelector

BytesToFunctionSelector converts the given bytes to a FunctionSelector.

func HexToFunctionSelector

func HexToFunctionSelector(s string) FunctionSelector

HexToFunctionSelector converts the given string to a FunctionSelector.

func (*FunctionSelector) SetBytes

func (f *FunctionSelector) SetBytes(b []byte)

SetBytes sets the FunctionSelector to that of the given bytes (will trim).

func (FunctionSelector) String

func (f FunctionSelector) String() string

String returns the FunctionSelector as a string type.

func (*FunctionSelector) UnmarshalJSON

func (f *FunctionSelector) UnmarshalJSON(input []byte) error

UnmarshalJSON parses the raw FunctionSelector and sets the FunctionSelector type to the given input.

func (FunctionSelector) WithoutPrefix

func (f FunctionSelector) WithoutPrefix() string

WithoutPrefix returns the FunctionSelector as a string without the '0x' prefix.

type IndexableBlockNumber

type IndexableBlockNumber struct {
	Number hexutil.Big `json:"number" storm:"id,unique"`
	Digits int         `json:"digits" storm:"index"`
	Hash   common.Hash `json:"hash"`
}

IndexableBlockNumber represents a BlockNumber, BlockHash and the number of Digits in the BlockNumber

func NewIndexableBlockNumber

func NewIndexableBlockNumber(bigint *big.Int, hash common.Hash) *IndexableBlockNumber

NewIndexableBlockNumber creates an IndexableBlockNumber given a BlockNumber and BlockHash

func (*IndexableBlockNumber) GreaterThan

func (l *IndexableBlockNumber) GreaterThan(r *IndexableBlockNumber) bool

GreaterThan compares BlockNumbers and returns true if the reciever BlockNumber is greater than the supplied BlockNumber

func (*IndexableBlockNumber) NextInt

func (l *IndexableBlockNumber) NextInt() *big.Int

NextInt returns the next BlockNumber as big.int

func (*IndexableBlockNumber) ToInt

func (l *IndexableBlockNumber) ToInt() *big.Int

ToInt Coerces the value into *big.Int. Also handles nil *IndexableBlockNumber values to nil *big.Int.

type Initiator

type Initiator struct {
	ID              int    `json:"id" storm:"id,increment"`
	JobID           string `json:"jobId" storm:"index"`
	Type            string `json:"type" storm:"index"`
	InitiatorParams `json:"params,omitempty"`
}

Initiator could be thought of as a trigger, defines how a Job can be started, or rather, how a JobRun can be created from a Job. Initiators will have their own unique ID, but will be associated to a parent JobID.

func (Initiator) IsLogInitiated

func (i Initiator) IsLogInitiated() bool

IsLogInitiated Returns true if triggered by event logs.

func (*Initiator) UnmarshalJSON

func (i *Initiator) UnmarshalJSON(input []byte) error

UnmarshalJSON parses the raw initiator data and updates the initiator as long as the type is valid.

type InitiatorParams

type InitiatorParams struct {
	Schedule Cron           `json:"schedule,omitempty"`
	Time     Time           `json:"time,omitempty"`
	Ran      bool           `json:"ran,omitempty"`
	Address  common.Address `json:"address,omitempty" storm:"index"`
}

InitiatorParams is a collection of the possible parameters that different Initiators may require.

type Int

type Int big.Int

Int stores large integers and can deserialize a variety of inputs.

func (*Int) ToBig

func (i *Int) ToBig() *big.Int

ToBig converts *Int to *big.Int.

func (*Int) UnmarshalJSON

func (i *Int) UnmarshalJSON(input []byte) error

UnmarshalJSON implements encoding.JSONUnmarshaler.

func (*Int) UnmarshalText

func (i *Int) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type JSON

type JSON struct {
	gjson.Result
}

JSON stores the json types string, number, bool, and null. Arrays and Objects are returned as their raw json types.

func ParseCBOR

func ParseCBOR(b []byte) (JSON, error)

ParseCBOR attempts to coerce the input byte array into valid CBOR and then coerces it into a JSON object.

func ParseJSON

func ParseJSON(b []byte) (JSON, error)

ParseJSON attempts to coerce the input byte array into valid JSON and parse it into a JSON object.

func (JSON) Add

func (j JSON) Add(key string, val interface{}) (JSON, error)

Add returns a new instance of JSON with the new value added.

func (JSON) Bytes

func (j JSON) Bytes() []byte

Bytes returns the raw JSON.

func (JSON) CBOR

func (j JSON) CBOR() ([]byte, error)

CBOR returns a bytes array of the JSON map or array encoded to CBOR.

func (JSON) Delete

func (j JSON) Delete(key string) (JSON, error)

Delete returns a new instance of JSON with the specified key removed.

func (JSON) Empty

func (j JSON) Empty() bool

Empty returns true if the JSON does not exist.

func (JSON) MarshalJSON

func (j JSON) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON data if it already exists, returns an empty JSON object as bytes if not.

func (JSON) Merge

func (j JSON) Merge(j2 JSON) (JSON, error)

Merge combines the given JSON with the existing JSON.

func (*JSON) UnmarshalJSON

func (j *JSON) UnmarshalJSON(b []byte) error

UnmarshalJSON parses the JSON bytes and stores in the *JSON pointer.

type JSONAPIError

type JSONAPIError struct {
	Detail string `json:"detail"`
}

JSONAPIError is an individual JSONAPI Error.

type JSONAPIErrors

type JSONAPIErrors struct {
	Errors []JSONAPIError `json:"errors"`
}

JSONAPIErrors holds errors conforming to the JSONAPI spec.

func NewJSONAPIErrors

func NewJSONAPIErrors() *JSONAPIErrors

NewJSONAPIErrors creates an instance of JSONAPIErrors, with the intention of managing a collection of them.

func NewJSONAPIErrorsWith

func NewJSONAPIErrorsWith(detail string) *JSONAPIErrors

NewJSONAPIErrorsWith creates an instance of JSONAPIErrors populated with this single detail.

func (*JSONAPIErrors) Add

func (jae *JSONAPIErrors) Add(detail string)

Add adds a new error to JSONAPIErrors with the passed detail.

func (*JSONAPIErrors) CoerceEmptyToNil

func (jae *JSONAPIErrors) CoerceEmptyToNil() error

CoerceEmptyToNil will return nil if JSONAPIErrors has no errors.

func (*JSONAPIErrors) Error

func (jae *JSONAPIErrors) Error() string

Error collapses the collection of errors into a collection of comma separated strings.

func (*JSONAPIErrors) Merge

func (jae *JSONAPIErrors) Merge(e error)

Merge combines the arrays of the passed error if it is of type JSONAPIErrors, otherwise simply adds a single error with the error string as detail.

type JobRun

type JobRun struct {
	ID             string       `json:"id" storm:"id,unique"`
	JobID          string       `json:"jobId" storm:"index"`
	Result         RunResult    `json:"result" storm:"inline"`
	Status         RunStatus    `json:"status" storm:"index"`
	TaskRuns       []TaskRun    `json:"taskRuns" storm:"inline"`
	CreatedAt      time.Time    `json:"createdAt" storm:"index"`
	CompletedAt    null.Time    `json:"completedAt"`
	Initiator      Initiator    `json:"initiator"`
	CreationHeight *hexutil.Big `json:"creationHeight"`
	Overrides      RunResult    `json:"overrides"`
}

JobRun tracks the status of a job by holding its TaskRuns and the Result of each Run.

func (JobRun) ApplyResult

func (jr JobRun) ApplyResult(result RunResult) JobRun

ApplyResult updates the JobRun's Result and Status

func (JobRun) ForLogger

func (jr JobRun) ForLogger(kvs ...interface{}) []interface{}

ForLogger formats the JobRun for a common formatting in the log.

func (JobRun) GetID

func (jr JobRun) GetID() string

GetID returns the ID of this structure for jsonapi serialization.

func (JobRun) GetName

func (jr JobRun) GetName() string

GetName returns the pluralized "type" of this structure for jsonapi serialization.

func (JobRun) MarkCompleted

func (jr JobRun) MarkCompleted() JobRun

MarkCompleted sets the JobRun's status to completed and records the completed at time.

func (JobRun) NextTaskRun

func (jr JobRun) NextTaskRun() TaskRun

NextTaskRun returns the next immediate TaskRun in the list of unfinished TaskRuns.

func (JobRun) Runnable

func (jr JobRun) Runnable(currentHeight *IndexableBlockNumber, minConfs uint64) bool

Runnable checks that the number of confirmations have passed since the job's creation height to determine if the JobRun can be started. Returns true for non-JobSubscriber (runlog & ethlog) initiators.

func (*JobRun) SetID

func (jr *JobRun) SetID(value string) error

SetID is used to set the ID of this structure when deserializing from jsonapi documents.

func (JobRun) UnfinishedTaskRuns

func (jr JobRun) UnfinishedTaskRuns() []TaskRun

UnfinishedTaskRuns returns a list of TaskRuns for a JobRun which are not Completed or Errored.

type JobSpec

type JobSpec struct {
	ID        string `json:"id" storm:"id,unique"`
	CreatedAt Time   `json:"createdAt" storm:"index"`
	JobSpecRequest
}

JobSpec is the definition for all the work to be carried out by the node for a given contract. It contains the Initiators, Tasks (which are the individual steps to be carried out), StartAt, EndAt, and CreatedAt fields.

func NewJob

func NewJob() JobSpec

NewJob initializes a new job by generating a unique ID and setting the CreatedAt field to the time of invokation.

func (JobSpec) Ended

func (j JobSpec) Ended(t time.Time) bool

Ended returns true if the job has ended.

func (JobSpec) GetID

func (j JobSpec) GetID() string

GetID returns the ID of this structure for jsonapi serialization.

func (JobSpec) GetName

func (j JobSpec) GetName() string

GetName returns the pluralized "type" of this structure for jsonapi serialization.

func (JobSpec) InitiatorsFor

func (j JobSpec) InitiatorsFor(types ...string) []Initiator

InitiatorsFor returns an array of Initiators for the given list of Initiator types.

func (JobSpec) IsLogInitiated

func (j JobSpec) IsLogInitiated() bool

IsLogInitiated Returns true if any of the job's initiators are triggered by event logs.

func (JobSpec) NewRun

func (j JobSpec) NewRun(i Initiator) JobRun

NewRun initializes the job by creating the IDs for the job and all associated tasks, and setting the CreatedAt field.

func (*JobSpec) SetID

func (j *JobSpec) SetID(value string) error

SetID is used to set the ID of this structure when deserializing from jsonapi documents.

func (JobSpec) Started

func (j JobSpec) Started(t time.Time) bool

Started returns true if the job has started.

func (JobSpec) WebAuthorized

func (j JobSpec) WebAuthorized() bool

WebAuthorized returns true if the "web" initiator is present.

type JobSpecRequest

type JobSpecRequest struct {
	Initiators []Initiator `json:"initiators"`
	Tasks      []TaskSpec  `json:"tasks" storm:"inline"`
	StartAt    null.Time   `json:"startAt" storm:"index"`
	EndAt      null.Time   `json:"endAt" storm:"index"`
}

JobSpecRequest represents a schema for the incoming job spec request as used by the API.

type RunResult

type RunResult struct {
	JobRunID     string       `json:"jobRunId"`
	Data         JSON         `json:"data"`
	Status       RunStatus    `json:"status"`
	ErrorMessage null.String  `json:"error"`
	Amount       *assets.Link `json:"amount,omitempty"`
}

RunResult keeps track of the outcome of a TaskRun or JobRun. It stores the Data and ErrorMessage, and contains a Pending field to track the status.

func (RunResult) Error

func (rr RunResult) Error() string

Error returns the string value of the ErrorMessage field.

func (RunResult) Get

func (rr RunResult) Get(path string) gjson.Result

Get searches for and returns the JSON at the given path.

func (RunResult) GetError

func (rr RunResult) GetError() error

GetError returns the error of a RunResult if it is present.

func (RunResult) HasError

func (rr RunResult) HasError() bool

HasError returns true if the ErrorMessage is present.

func (RunResult) MarkPendingBridge

func (rr RunResult) MarkPendingBridge() RunResult

MarkPendingBridge returns a copy of RunResult but with status set to pending_bridge.

func (RunResult) MarkPendingConfirmations

func (rr RunResult) MarkPendingConfirmations() RunResult

MarkPendingConfirmations returns a copy of RunResult but with status set to pending_confirmations.

func (RunResult) Merge

func (rr RunResult) Merge(in RunResult) (RunResult, error)

Merge returns a copy which is the result of joining the input RunResult with the instance it is called on, preferring the RunResult values passed in, but using the existing values if the input RunResult values are of their respective zero value.

Returns an error if called on a RunResult that already has an error.

func (RunResult) Value

func (rr RunResult) Value() (string, error)

Value returns the string value of the Data JSON field.

func (RunResult) WithError

func (rr RunResult) WithError(err error) RunResult

WithError returns a copy of the RunResult, setting the error field and setting the status to in progress.

func (RunResult) WithNull

func (rr RunResult) WithNull() RunResult

WithNull returns a copy of the RunResult, overriding the "value" field of Data to null.

func (RunResult) WithValue

func (rr RunResult) WithValue(val string) RunResult

WithValue returns a copy of the RunResult, overriding the "value" field of Data and setting the status to completed.

type RunStatus

type RunStatus string

RunStatus is a string that represents the run status

func (RunStatus) CanStart

func (s RunStatus) CanStart() bool

CanStart returns true if the run is ready to begin processed.

func (RunStatus) Completed

func (s RunStatus) Completed() bool

Completed returns true if the status is RunStatusCompleted.

func (RunStatus) Errored

func (s RunStatus) Errored() bool

Errored returns true if the status is RunStatusErrored.

func (RunStatus) Finished

func (s RunStatus) Finished() bool

Finished returns true if the status is final and can't be changed.

func (RunStatus) Pending

func (s RunStatus) Pending() bool

Pending returns true if the status is pending external or confirmations.

func (RunStatus) PendingBridge

func (s RunStatus) PendingBridge() bool

PendingBridge returns true if the status is pending_bridge.

func (RunStatus) PendingConfirmations

func (s RunStatus) PendingConfirmations() bool

PendingConfirmations returns true if the status is pending_confirmations.

func (RunStatus) PendingSleep

func (s RunStatus) PendingSleep() bool

PendingSleep returns true if the status is pending_sleep.

func (RunStatus) Runnable

func (s RunStatus) Runnable() bool

Runnable returns true if the status is ready to be run.

func (RunStatus) Unstarted

func (s RunStatus) Unstarted() bool

Unstarted returns true if the status is the initial state.

type Schedule

type Schedule struct {
	EndAt       Time        `json:"endAt"`
	Hour        null.String `json:"hour"`
	Minute      null.String `json:"minute"`
	DayOfMonth  null.String `json:"dayOfMonth"`
	MonthOfYear null.String `json:"monthOfYear"`
	DayOfWeek   null.String `json:"dayOfWeek"`
	RunAt       []Time      `json:"runAt"`
}

Schedule defines the frequency to run the Assignment Schedule uses standard cron syntax

type ServiceAgreement

type ServiceAgreement struct {
	CreatedAt   Time        `json:"createdAt" storm:"index"`
	Encumbrance Encumbrance `json:"encumbrance" storm:"inline"`
	ID          string      `json:"id" storm:"id,unique"`
	JobSpecID   string      `json:"jobSpecID"`
	RequestBody string      `json:"requestBody"`
	Signature   Signature   `json:"signature"`
	JobSpec     JobSpec     // JobSpec is used during the initial SA creation.

}

ServiceAgreement connects job specifications with on-chain encumbrances.

func NewServiceAgreementFromRequest

func NewServiceAgreementFromRequest(reader io.Reader, signer Signer) (ServiceAgreement, error)

NewServiceAgreementFromRequest builds a new ServiceAgreement.

func (ServiceAgreement) GetID

func (sa ServiceAgreement) GetID() string

GetID returns the ID of this structure for jsonapi serialization.

func (ServiceAgreement) GetName

func (sa ServiceAgreement) GetName() string

GetName returns the pluralized "type" of this structure for jsonapi serialization.

func (*ServiceAgreement) SetID

func (sa *ServiceAgreement) SetID(value string) error

SetID is used to set the ID of this structure when deserializing from jsonapi documents.

type ServiceAgreementRequest

type ServiceAgreementRequest struct {
	Payment    *assets.Link   `json:"payment"`
	Expiration uint64         `json:"expiration"`
	Oracles    []EIP55Address `json:"oracles"`
	JobSpecRequest
}

ServiceAgreementRequest represents a service agreement as requested over the wire.

type Session

type Session struct {
	ID       string `json:"id" storm:"id,unique"`
	LastUsed Time   `json:"lastUsed" storm:"index"`
}

Session holds the unique id for the authenticated session.

func NewSession

func NewSession() Session

NewSession returns a session instance with ID set to a random ID and LastUsed to to now.

type SessionRequest

type SessionRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

SessionRequest encapsulates the fields needed to generate a new SessionID, including the hashed password.

type Signature

type Signature [SignatureLength]byte

Signature is a byte array fixed to the size of a signature

func BytesToSignature

func BytesToSignature(b []byte) Signature

BytesToSignature converts an arbitrary length byte array to a Signature

func NewSignature

func NewSignature(s string) (Signature, error)

NewSignature returns a new Signature

func (Signature) Big

func (s Signature) Big() *big.Int

Big returns a big.Int representation

func (Signature) Bytes

func (s Signature) Bytes() []byte

Bytes returns the raw bytes

func (Signature) Format

func (s Signature) Format(state fmt.State, c rune)

Format implements fmt.Formatter

func (Signature) Hex

func (s Signature) Hex() string

Hex returns a hexadecimal string

func (Signature) MarshalJSON

func (s Signature) MarshalJSON() ([]byte, error)

MarshalJSON prints the signature as a hexadecimal encoded string

func (Signature) MarshalText

func (s Signature) MarshalText() ([]byte, error)

MarshalText encodes the signature in hexadecimal

func (*Signature) SetBytes

func (s *Signature) SetBytes(b []byte)

SetBytes assigns the byte array to the signature

func (Signature) String

func (s Signature) String() string

String implements the stringer interface and is used also by the logger.

func (*Signature) UnmarshalJSON

func (s *Signature) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a signature from a JSON string

func (*Signature) UnmarshalText

func (s *Signature) UnmarshalText(input []byte) error

UnmarshalText parses the signature from a hexadecimal representation

type Signer

type Signer interface {
	Sign(input []byte) (Signature, error)
}

Signer is used to produce a HMAC signature from an input digest

type Snapshot

type Snapshot struct {
	Details JSON        `json:"details"`
	ID      string      `json:"xid"`
	Error   null.String `json:"error"`
	Pending bool        `json:"pending"`
}

Snapshot captures the result of an individual subtask

func ConvertToSnapshot

func ConvertToSnapshot(rr RunResult) Snapshot

ConvertToSnapshot convert given RunResult to a Snapshot

type Subtask

type Subtask struct {
	Type   string `json:"adapterType"`
	Params JSON   `json:"adapterParams"`
}

Subtask is a step taken by the oracle to complete an assignment

type TaskRun

type TaskRun struct {
	ID     string    `json:"id" storm:"id,unique"`
	Result RunResult `json:"result"`
	Status RunStatus `json:"status"`
	Task   TaskSpec  `json:"task"`
}

TaskRun stores the Task and represents the status of the Task to be ran.

func (TaskRun) ApplyResult

func (tr TaskRun) ApplyResult(result RunResult) TaskRun

ApplyResult updates the TaskRun's Result and Status

func (TaskRun) ForLogger

func (tr TaskRun) ForLogger(kvs ...interface{}) []interface{}

ForLogger formats the TaskRun info for a common formatting in the log.

func (TaskRun) MarkCompleted

func (tr TaskRun) MarkCompleted() TaskRun

MarkCompleted marks the task's status as completed.

func (TaskRun) MarkPendingConfirmations

func (tr TaskRun) MarkPendingConfirmations() TaskRun

MarkPendingConfirmations marks the task's status as blocked.

func (TaskRun) MergeTaskParams

func (tr TaskRun) MergeTaskParams(j JSON) (TaskRun, error)

MergeTaskParams merges the existing parameters on a TaskRun with the given JSON.

func (TaskRun) String

func (tr TaskRun) String() string

String returns info on the TaskRun as "ID,Type,Status,Result".

type TaskSpec

type TaskSpec struct {
	Type          TaskType `json:"type" storm:"index"`
	Confirmations uint64   `json:"confirmations"`
	Params        JSON     `json:"params"`
}

TaskSpec is the definition of work to be carried out. The Type will be an adapter, and the Params will contain any additional information that adapter would need to operate.

type TaskType

type TaskType string

TaskType defines what Adapter a TaskSpec will use.

func MustNewTaskType

func MustNewTaskType(val string) TaskType

MustNewTaskType instantiates a new TaskType, and panics if a bad input is provided.

func NewTaskType

func NewTaskType(val string) (TaskType, error)

NewTaskType returns a formatted Task type.

func (TaskType) MarshalJSON

func (t TaskType) MarshalJSON() ([]byte, error)

MarshalJSON converts a TaskType to a JSON byte slice.

func (TaskType) String

func (t TaskType) String() string

func (*TaskType) UnmarshalJSON

func (t *TaskType) UnmarshalJSON(input []byte) error

UnmarshalJSON converts a bytes slice of JSON to a TaskType.

type Time

type Time struct {
	time.Time
}

Time holds a common field for time.

func (Time) DurationFromNow

func (t Time) DurationFromNow() time.Duration

DurationFromNow returns the amount of time since the Time field was last updated.

func (Time) HumanString

func (t Time) HumanString() string

HumanString formats and returns the time in RFC 3339 standard.

func (Time) ISO8601

func (t Time) ISO8601() string

ISO8601 formats and returns the time in ISO 8601 standard.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) error

UnmarshalJSON parses the raw time stored in JSON-encoded data and stores it to the Time field.

type Tx

type Tx struct {
	ID       uint64         `storm:"id,increment,index"`
	From     common.Address `storm:"index"`
	To       common.Address
	Data     []byte
	Nonce    uint64 `storm:"index"`
	Value    *big.Int
	GasLimit uint64
	TxAttempt
}

Tx contains fields necessary for an Ethereum transaction with an additional field for the TxAttempt.

func (*Tx) EthTx

func (tx *Tx) EthTx(gasPrice *big.Int) *types.Transaction

EthTx creates a new Ethereum transaction with a given gasPrice that is ready to be signed.

type TxAttempt

type TxAttempt struct {
	Hash      common.Hash `storm:"id,unique"`
	TxID      uint64      `storm:"index"`
	GasPrice  *big.Int
	Confirmed bool
	Hex       string
	SentAt    uint64
}

TxAttempt is used for keeping track of transactions that have been written to the Ethereum blockchain. This makes it so that if the network is busy, a transaction can be resubmitted with a higher GasPrice.

type User

type User struct {
	Email          string `json:"email" storm:"id,unique"`
	HashedPassword string `json:"hashedPassword"`
	CreatedAt      Time   `json:"createdAt" storm:"index"`
}

User holds the credentials for API user.

func NewUser

func NewUser(email, plainPwd string) (User, error)

NewUser creates a new user by hashing the passed plainPwd with bcrypt.

type ValidationError

type ValidationError struct {
	// contains filtered or unexported fields
}

ValidationError is an error that occurs during validation.

func (*ValidationError) Error

func (e *ValidationError) Error() string

type WebURL

type WebURL struct {
	*url.URL
}

WebURL contains the URL of the endpoint.

func (*WebURL) MarshalJSON

func (w *WebURL) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON-encoded string of the given data.

func (*WebURL) String

func (w *WebURL) String() string

String delegates to the wrapped URL struct or an empty string when it is nil

func (*WebURL) UnmarshalJSON

func (w *WebURL) UnmarshalJSON(j []byte) error

UnmarshalJSON parses the raw URL stored in JSON-encoded data to a URL structure and sets it to the URL field.

type WithdrawalRequest

type WithdrawalRequest struct {
	Address common.Address `json:"address"`
	Amount  *assets.Link   `json:"amount"`
}

WithdrawalRequest request to withdraw LINK.

Jump to

Keyboard shortcuts

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