store

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2019 License: MIT Imports: 33 Imported by: 12

Documentation

Overview

Package store is used to keep application events in sync between the database on the node and the blockchain.

Config

Config contains the local configuration options that the application will adhere to.

EthCallerSubscriber

This makes use of Go-Ethereum's functions to interact with the blockchain. The underlying functions can be viewed here:

go-ethereum/rpc/client.go

KeyStore

KeyStore also utilizes Go-Ethereum's functions to store encrypted keys on the local file system. The underlying functions can be viewed here:

go-ethereum/accounts/keystore/keystore.go

Store

The Store is the persistence layer for the application. It saves the the application state and most interaction with the node needs to occur through the store.

Tx Manager

The transaction manager is used to syncronize interactions on the Ethereum blockchain with the application and database.

Index

Constants

View Source
const DefaultGasLimit uint64 = 500000

DefaultGasLimit sets the default gas limit for outgoing transactions. if updating DefaultGasLimit, be sure it matches with the DefaultGasLimit specified in evm/test/Oracle_test.js

Variables

View Source
var ErrPendingConnection = errors.New("Cannot talk to chain, pending connection")

ErrPendingConnection is the error returned if TxManager is not connected.

View Source
var Sha = "unset"

Sha string "unset"

View Source
var Version = "unset"

Version the version of application

Functions

This section is empty.

Types

type AttemptState

type AttemptState int

AttemptState enumerates the possible states of a transaction attempt as it gets accepted and confirmed by the blockchain

const (
	// Unknown is returned when the state of a transaction could not be
	// determined because of an error
	Unknown AttemptState = iota
	// Unconfirmed means that a transaction has had no confirmations at all
	Unconfirmed
	// Confirmed means that a transaftion has had at least one transaction, but
	// not enough to satisfy the minimum number of confirmations configuration
	// option
	Confirmed
	// Safe has the required number of confirmations or more
	Safe
)

func (AttemptState) String

func (a AttemptState) String() string

String conforms to the Stringer interface for AttemptState

type CallArgs added in v0.6.6

type CallArgs struct {
	To   common.Address `json:"to"`
	Data hexutil.Bytes  `json:"data"`
}

CallArgs represents the data used to call the balance method of an ERC contract. "To" is the address of the ERC contract. "Data" is the message sent to the contract.

type CallerSubscriber

type CallerSubscriber interface {
	Call(result interface{}, method string, args ...interface{}) error
	EthSubscribe(context.Context, interface{}, ...interface{}) (models.EthSubscription, error)
}

CallerSubscriber implements the Call and EthSubscribe functions. Call performs a JSON-RPC call with the given arguments and EthSubscribe registers a subscription.

type Contract

type Contract struct {
	ABI abi.ABI
}

Contract holds the solidity contract's parsed ABI

func GetContract

func GetContract(name string) (*Contract, error)

GetContract loads the contract JSON file from ../evm/build/contracts and parses the ABI JSON contents into an abi.ABI object

func (*Contract) EncodeMessageCall

func (contract *Contract) EncodeMessageCall(method string, args ...interface{}) ([]byte, error)

EncodeMessageCall encodes method name and arguments into a byte array to conform with the contract's ABI

type Dialer

type Dialer interface {
	Dial(string) (CallerSubscriber, error)
}

Dialer implements Dial which is a function that creates a client for that url

type EthCallerSubscriber added in v0.6.6

type EthCallerSubscriber struct {
	CallerSubscriber
}

EthCallerSubscriber holds the CallerSubscriber interface for the Ethereum blockchain.

func (*EthCallerSubscriber) GetBlockByNumber added in v0.6.6

func (eth *EthCallerSubscriber) GetBlockByNumber(hex string) (models.BlockHeader, error)

GetBlockByNumber returns the block for the passed hex, or "latest", "earliest", "pending".

func (*EthCallerSubscriber) GetChainID added in v0.6.6

func (eth *EthCallerSubscriber) GetChainID() (*big.Int, error)

GetChainID returns the ethereum ChainID.

func (*EthCallerSubscriber) GetERC20Balance added in v0.6.6

func (eth *EthCallerSubscriber) GetERC20Balance(address common.Address, contractAddress common.Address) (*big.Int, error)

GetERC20Balance returns the balance of the given address for the token contract address.

func (*EthCallerSubscriber) GetEthBalance added in v0.6.6

func (eth *EthCallerSubscriber) GetEthBalance(address common.Address) (*assets.Eth, error)

GetEthBalance returns the balance of the given addresses in Ether.

func (*EthCallerSubscriber) GetLogs added in v0.6.6

func (eth *EthCallerSubscriber) GetLogs(q ethereum.FilterQuery) ([]models.Log, error)

GetLogs returns all logs that respect the passed filter query.

func (*EthCallerSubscriber) GetNonce added in v0.6.6

func (eth *EthCallerSubscriber) GetNonce(address common.Address) (uint64, error)

GetNonce returns the nonce (transaction count) for a given address.

func (*EthCallerSubscriber) GetTxReceipt added in v0.6.6

func (eth *EthCallerSubscriber) GetTxReceipt(hash common.Hash) (*models.TxReceipt, error)

GetTxReceipt returns the transaction receipt for the given transaction hash.

func (*EthCallerSubscriber) SendRawTx added in v0.6.6

func (eth *EthCallerSubscriber) SendRawTx(hex string) (common.Hash, error)

SendRawTx sends a signed transaction to the transaction pool.

func (*EthCallerSubscriber) SubscribeToLogs added in v0.6.6

func (eth *EthCallerSubscriber) SubscribeToLogs(
	channel chan<- models.Log,
	q ethereum.FilterQuery,
) (models.EthSubscription, error)

SubscribeToLogs registers a subscription for push notifications of logs from a given address.

func (*EthCallerSubscriber) SubscribeToNewHeads added in v0.6.6

func (eth *EthCallerSubscriber) SubscribeToNewHeads(
	channel chan<- models.BlockHeader,
) (models.EthSubscription, error)

SubscribeToNewHeads registers a subscription for push notifications of new blocks.

type EthClient

type EthClient interface {
	GetNonce(address common.Address) (uint64, error)
	GetEthBalance(address common.Address) (*assets.Eth, error)
	GetERC20Balance(address common.Address, contractAddress common.Address) (*big.Int, error)
	SendRawTx(hex string) (common.Hash, error)
	GetTxReceipt(hash common.Hash) (*models.TxReceipt, error)
	GetBlockByNumber(hex string) (models.BlockHeader, error)
	GetLogs(q ethereum.FilterQuery) ([]models.Log, error)
	GetChainID() (*big.Int, error)
	SubscribeToLogs(channel chan<- models.Log, q ethereum.FilterQuery) (models.EthSubscription, error)
	SubscribeToNewHeads(channel chan<- models.BlockHeader) (models.EthSubscription, error)
}

EthClient is the interface supplied by EthCallerSubscriber

type EthDialer

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

EthDialer is Dialer which accesses rpc urls

func NewEthDialer added in v0.6.6

func NewEthDialer(rateLimit uint64) *EthDialer

NewEthDialer returns an eth dialer with the specified rate limit

func (*EthDialer) Dial

func (ed *EthDialer) Dial(urlString string) (CallerSubscriber, error)

Dial will dial the given url and return a CallerSubscriber

type EthTxManager

type EthTxManager struct {
	EthClient
	// contains filtered or unexported fields
}

EthTxManager contains fields for the Ethereum client, the KeyStore, the local Config for the application, and the database.

func NewEthTxManager

func NewEthTxManager(client EthClient, config orm.ConfigReader, keyStore *KeyStore, orm *orm.ORM) *EthTxManager

NewEthTxManager constructs an EthTxManager using the passed variables and initializing internal variables.

func (*EthTxManager) BumpGasUntilSafe

func (txm *EthTxManager) BumpGasUntilSafe(hash common.Hash) (*models.TxReceipt, AttemptState, error)

BumpGasUntilSafe process a collection of related TxAttempts, trying to get at least one TxAttempt into a safe state, bumping gas if needed

func (*EthTxManager) CheckAttempt

func (txm *EthTxManager) CheckAttempt(txAttempt *models.TxAttempt, blockHeight uint64) (*models.TxReceipt, AttemptState, error)

CheckAttempt retrieves a receipt for a TxAttempt, and check if it meets the minimum number of confirmations

func (*EthTxManager) Connect

func (txm *EthTxManager) Connect(bn *models.Head) error

Connect iterates over the available accounts to retrieve their nonce for client side management.

func (*EthTxManager) Connected

func (txm *EthTxManager) Connected() bool

Connected returns a bool indicating whether or not it is connected.

func (*EthTxManager) ContractLINKBalance

func (txm *EthTxManager) ContractLINKBalance(wr models.WithdrawalRequest) (assets.Link, error)

ContractLINKBalance returns the balance for the contract associated with this withdrawal request, or any errors

func (*EthTxManager) CreateTx

func (txm *EthTxManager) CreateTx(to common.Address, data []byte) (*models.Tx, error)

CreateTx signs and sends a transaction to the Ethereum blockchain.

func (*EthTxManager) CreateTxWithEth

func (txm *EthTxManager) CreateTxWithEth(from, to common.Address, value *assets.Eth) (*models.Tx, error)

CreateTxWithEth signs and sends a transaction with some ETH to transfer.

func (*EthTxManager) CreateTxWithGas

func (txm *EthTxManager) CreateTxWithGas(surrogateID null.String, to common.Address, data []byte, gasPriceWei *big.Int, gasLimit uint64) (*models.Tx, error)

CreateTxWithGas signs and sends a transaction to the Ethereum blockchain.

func (*EthTxManager) Disconnect

func (txm *EthTxManager) Disconnect()

Disconnect marks this instance as disconnected.

func (*EthTxManager) GetETHAndLINKBalances

func (txm *EthTxManager) GetETHAndLINKBalances(address common.Address) (*assets.Eth, *assets.Link, error)

GetETHAndLINKBalances attempts to retrieve the ethereum node's perception of the latest ETH and LINK balances for the active account on the txm, or an error on failure.

func (*EthTxManager) GetLINKBalance

func (txm *EthTxManager) GetLINKBalance(address common.Address) (*assets.Link, error)

GetLINKBalance returns the balance of LINK at the given address

func (*EthTxManager) NextActiveAccount

func (txm *EthTxManager) NextActiveAccount() *ManagedAccount

NextActiveAccount uses round robin to select a managed account from the list of available accounts as defined in Register(...)

func (*EthTxManager) OnNewHead

func (txm *EthTxManager) OnNewHead(head *models.Head)

OnNewHead does nothing; exists to comply with interface.

func (*EthTxManager) Register

func (txm *EthTxManager) Register(accts []accounts.Account)

Register activates accounts for outgoing transactions and client side nonce management.

func (txm *EthTxManager) WithdrawLINK(wr models.WithdrawalRequest) (common.Hash, error)

WithdrawLINK withdraws the given amount of LINK from the contract to the configured withdrawal address. If wr.ContractAddress is empty (zero address), funds are withdrawn from configured OracleContractAddress.

type HeadTrackable

type HeadTrackable interface {
	Connect(*models.Head) error
	Disconnect()
	OnNewHead(*models.Head)
}

HeadTrackable represents any object that wishes to respond to ethereum events, after being attached to HeadTracker.

type KeyStore

type KeyStore struct {
	*keystore.KeyStore
}

KeyStore manages a key storage directory on disk.

func NewKeyStore

func NewKeyStore(keyDir string) *KeyStore

NewKeyStore creates a keystore for the given directory.

func (*KeyStore) GetAccounts

func (ks *KeyStore) GetAccounts() []accounts.Account

GetAccounts returns all accounts

func (*KeyStore) GetFirstAccount

func (ks *KeyStore) GetFirstAccount() (accounts.Account, error)

GetFirstAccount returns the unlocked account in the KeyStore object. The client ensures that an account exists during authentication.

func (*KeyStore) HasAccounts

func (ks *KeyStore) HasAccounts() bool

HasAccounts returns true if there are accounts located at the keystore directory.

func (*KeyStore) NewAccount

func (ks *KeyStore) NewAccount(passphrase string) (accounts.Account, error)

NewAccount adds an account to the keystore

func (*KeyStore) Sign

func (ks *KeyStore) Sign(input []byte) (models.Signature, error)

Sign creates an HMAC from some input data using the account's private key

func (*KeyStore) SignTx

func (ks *KeyStore) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)

SignTx uses the unlocked account to sign the given transaction.

func (*KeyStore) Unlock

func (ks *KeyStore) Unlock(phrase string) error

Unlock uses the given password to try to unlock accounts located in the keystore directory.

type ManagedAccount

type ManagedAccount struct {
	accounts.Account
	// contains filtered or unexported fields
}

ManagedAccount holds the account information alongside a client managed nonce to coordinate outgoing transactions.

func NewManagedAccount

func NewManagedAccount(a accounts.Account, nonce uint64) *ManagedAccount

NewManagedAccount creates a managed account that handles nonce increments locally.

func (*ManagedAccount) GetAndIncrementNonce

func (a *ManagedAccount) GetAndIncrementNonce(callback func(uint64) error) error

GetAndIncrementNonce will Yield the current nonce to a callback function and increment it once the callback has finished executing

func (*ManagedAccount) Nonce

func (a *ManagedAccount) Nonce() uint64

Nonce returns the client side managed nonce.

func (*ManagedAccount) ReloadNonce

func (a *ManagedAccount) ReloadNonce(txm *EthTxManager) error

ReloadNonce fetch and update the current nonce via eth_getTransactionCount

type QueuedRunChannel

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

QueuedRunChannel manages incoming results and blocks by enqueuing them in a queue per run.

func (*QueuedRunChannel) Close

func (rq *QueuedRunChannel) Close()

Close closes the QueuedRunChannel so that no runs can be added to it without throwing an error.

func (*QueuedRunChannel) Receive

func (rq *QueuedRunChannel) Receive() <-chan RunRequest

Receive returns a channel for listening to sent runs.

func (*QueuedRunChannel) Send

func (rq *QueuedRunChannel) Send(jobRunID *models.ID) error

Send adds another entry to the queue of runs.

type RunChannel

type RunChannel interface {
	Send(jobRunID *models.ID) error
	Receive() <-chan RunRequest
	Close()
}

RunChannel manages and dispatches incoming runs.

func NewQueuedRunChannel

func NewQueuedRunChannel() RunChannel

NewQueuedRunChannel initializes a QueuedRunChannel.

type RunRequest

type RunRequest struct {
	ID *models.ID
}

RunRequest is the type that the RunChannel uses to package all the necessary pieces to execute a Job Run.

type Store

type Store struct {
	*orm.ORM
	Config      *orm.Config
	Clock       utils.AfterNower
	KeyStore    *KeyStore
	RunChannel  RunChannel
	TxManager   TxManager
	StatsPusher *synchronization.StatsPusher
}

Store contains fields for the database, Config, KeyStore, and TxManager for keeping the application state in sync with the database.

func NewStore

func NewStore(config *orm.Config) *Store

NewStore will create a new database file at the config's RootDir if it is not already present, otherwise it will use the existing db.sqlite3 file.

func NewStoreWithDialer

func NewStoreWithDialer(config *orm.Config, dialer Dialer) *Store

NewStoreWithDialer creates a new store with the given config and dialer

func (*Store) AuthorizedUserWithSession

func (s *Store) AuthorizedUserWithSession(sessionID string) (models.User, error)

AuthorizedUserWithSession will return the one API user if the Session ID exists and hasn't expired, and update session's LastUsed field.

func (*Store) Close

func (s *Store) Close() error

Close shuts down all of the working parts of the store.

func (*Store) Start

func (s *Store) Start() error

Start initiates all of Store's dependencies including the TxManager.

func (*Store) SyncDiskKeyStoreToDB

func (s *Store) SyncDiskKeyStoreToDB() error

SyncDiskKeyStoreToDB writes all keys in the keys directory to the underlying orm.

func (*Store) Unscoped

func (s *Store) Unscoped() *Store

Unscoped returns a shallow copy of the store, with an unscoped ORM allowing one to work with soft deleted records.

type TxManager

type TxManager interface {
	HeadTrackable
	Connected() bool
	Register(accounts []accounts.Account)

	CreateTx(to common.Address, data []byte) (*models.Tx, error)
	CreateTxWithGas(surrogateID null.String, to common.Address, data []byte, gasPriceWei *big.Int, gasLimit uint64) (*models.Tx, error)
	CreateTxWithEth(from, to common.Address, value *assets.Eth) (*models.Tx, error)
	CheckAttempt(txAttempt *models.TxAttempt, blockHeight uint64) (*models.TxReceipt, AttemptState, error)

	BumpGasUntilSafe(hash common.Hash) (*models.TxReceipt, AttemptState, error)

	ContractLINKBalance(wr models.WithdrawalRequest) (assets.Link, error)
	WithdrawLINK(wr models.WithdrawalRequest) (common.Hash, error)
	GetLINKBalance(address common.Address) (*assets.Link, error)
	NextActiveAccount() *ManagedAccount

	GetEthBalance(address common.Address) (*assets.Eth, error)
	SubscribeToNewHeads(channel chan<- models.BlockHeader) (models.EthSubscription, error)
	GetBlockByNumber(hex string) (models.BlockHeader, error)
	SubscribeToLogs(channel chan<- models.Log, q ethereum.FilterQuery) (models.EthSubscription, error)
	GetLogs(q ethereum.FilterQuery) ([]models.Log, error)
	GetTxReceipt(common.Hash) (*models.TxReceipt, error)
	GetChainID() (*big.Int, error)
}

TxManager represents an interface for interacting with the blockchain

Directories

Path Synopsis
Package models contain the key job components used by the Chainlink application.
Package models contain the key job components used by the Chainlink application.
Package presenters allow for the specification and result of a Job, its associated TaskSpecs, and every JobRun and TaskRun to be returned in a user friendly human readable format.
Package presenters allow for the specification and result of a Job, its associated TaskSpecs, and every JobRun and TaskRun to be returned in a user friendly human readable format.

Jump to

Keyboard shortcuts

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