store

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: 34 Imported by: 0

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.

EthClient

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

This section is empty.

Variables

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 ActiveAccount

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

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

func (*ActiveAccount) GetAndIncrementNonce

func (a *ActiveAccount) 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 (*ActiveAccount) GetNonce

func (a *ActiveAccount) GetNonce() uint64

GetNonce returns the client side managed nonce.

type AfterNower

type AfterNower interface {
	After(d time.Duration) <-chan time.Time
	Now() time.Time
}

AfterNower is an interface that fulfills the `After()` and `Now()` methods.

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 Clock

type Clock struct{}

Clock is a basic type for scheduling events in the application.

func (Clock) After

func (Clock) After(d time.Duration) <-chan time.Time

After returns the current time if the given duration has elapsed.

func (Clock) Now

func (Clock) Now() time.Time

Now returns the current time.

type Config

type Config struct {
	AllowOrigins             string          `env:"ALLOW_ORIGINS" envDefault:"http://localhost:3000,http://localhost:6688"`
	ChainID                  uint64          `env:"ETH_CHAIN_ID" envDefault:"0"`
	ClientNodeURL            string          `env:"CLIENT_NODE_URL" envDefault:"http://localhost:6688"`
	DatabaseTimeout          Duration        `env:"DATABASE_TIMEOUT" envDefault:"500ms"`
	Dev                      bool            `env:"CHAINLINK_DEV" envDefault:"false"`
	EthGasBumpThreshold      uint64          `env:"ETH_GAS_BUMP_THRESHOLD" envDefault:"12"`
	EthGasBumpWei            big.Int         `env:"ETH_GAS_BUMP_WEI" envDefault:"5000000000"`
	EthGasPriceDefault       big.Int         `env:"ETH_GAS_PRICE_DEFAULT" envDefault:"20000000000"`
	EthereumURL              string          `env:"ETH_URL" envDefault:"ws://localhost:8546"`
	LinkContractAddress      string          `env:"LINK_CONTRACT_ADDRESS" envDefault:"0x514910771AF9Ca656af840dff83E8264EcF986CA"`
	LogLevel                 LogLevel        `env:"LOG_LEVEL" envDefault:"info"`
	MinIncomingConfirmations uint64          `env:"MIN_INCOMING_CONFIRMATIONS" envDefault:"0"`
	MinOutgoingConfirmations uint64          `env:"MIN_OUTGOING_CONFIRMATIONS" envDefault:"12"`
	MinimumContractPayment   assets.Link     `env:"MINIMUM_CONTRACT_PAYMENT" envDefault:"1000000000000000000"`
	MinimumRequestExpiration uint64          `env:"MINIMUM_REQUEST_EXPIRATION" envDefault:"300"`
	OracleContractAddress    *common.Address `env:"ORACLE_CONTRACT_ADDRESS"`
	Port                     uint16          `env:"CHAINLINK_PORT" envDefault:"6688"`
	TLSPort                  uint16          `env:"CHAINLINK_TLS_PORT" envDefault:"6689"`
	TLSHost                  string          `env:"CHAINLINK_TLS_HOST" envDefault:""`
	RootDir                  string          `env:"ROOT" envDefault:"~/.chainlink"`
	SecretGenerator          SecretGenerator
	TLSCertPath              string   `env:"TLS_CERT_PATH" envDefault:""`
	TLSKeyPath               string   `env:"TLS_KEY_PATH" envDefault:""`
	SessionTimeout           Duration `env:"SESSION_TIMEOUT" envDefault:"15m"`
	ReaperExpiration         Duration `env:"REAPER_EXPIRATION" envDefault:"240h"`
}

Config holds parameters used by the application which can be overridden by setting environment variables.

func NewConfig

func NewConfig() Config

NewConfig returns the config with the environment variables set to their respective fields, or defaults if not present.

func (Config) CertFile

func (c Config) CertFile() string

CertFile returns the path where the server certificate is kept

func (Config) CreateProductionLogger

func (c Config) CreateProductionLogger() *zap.Logger

CreateProductionLogger returns a custom logger for the config's root directory and LogLevel, with pretty printing for stdout.

func (Config) KeyFile

func (c Config) KeyFile() string

KeyFile returns the path where the server key is kept

func (Config) KeysDir

func (c Config) KeysDir() string

KeysDir returns the path of the keys directory (used for keystore files).

func (Config) SessionOptions

func (c Config) SessionOptions() sessions.Options

SessionOptions returns the sesssions.Options struct used to configure the session store.

func (Config) SessionSecret

func (c Config) SessionSecret() ([]byte, error)

SessionSecret returns a sequence of bytes to be used as a private key for session signing or encryption.

type Dialer

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

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

type Duration

type Duration struct {
	time.Duration
}

Duration returns a time duration with the supported units of "ns", "us", "ms", "s", "m", "h".

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText returns the byte slice of the formatted duration e.g. "500ms"

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText parses the time.Duration and assigns it

type EthClient

type EthClient struct {
	CallerSubscriber
}

EthClient holds the CallerSubscriber interface for the Ethereum blockchain.

func (*EthClient) GetBlockByNumber

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

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

func (*EthClient) GetBlockNumber

func (eth *EthClient) GetBlockNumber() (uint64, error)

GetBlockNumber returns the block number of the chain head.

func (*EthClient) GetERC20Balance

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

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

func (*EthClient) GetEthBalance

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

GetEthBalance returns the balance of the given addresses in Ether.

func (*EthClient) GetLogs

func (eth *EthClient) GetLogs(q ethereum.FilterQuery) ([]types.Log, error)

GetLogs returns all logs that respect the passed filter query.

func (*EthClient) GetNonce

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

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

func (*EthClient) GetTxReceipt

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

GetTxReceipt returns the transaction receipt for the given transaction hash.

func (*EthClient) GetWeiBalance

func (eth *EthClient) GetWeiBalance(address common.Address) (*big.Int, error)

GetWeiBalance returns the balance of the given address in Wei.

func (*EthClient) SendRawTx

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

SendRawTx sends a signed transaction to the transaction pool.

func (*EthClient) SubscribeToLogs

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

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

func (*EthClient) SubscribeToNewHeads

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

SubscribeToNewHeads registers a subscription for push notifications of new blocks.

type EthDialer

type EthDialer struct{}

EthDialer is Dialer which accesses rpc urls

func (EthDialer) Dial

func (EthDialer) Dial(url string) (CallerSubscriber, error)

Dial will dial the given url and return a CallerSubscriber

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) GetAccount

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

GetAccount 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) 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(tx *types.Transaction, chainID uint64) (*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 LogLevel

type LogLevel struct {
	zapcore.Level
}

LogLevel determines the verbosity of the events to be logged.

func (LogLevel) ForGin

func (ll LogLevel) ForGin() string

ForGin keeps Gin's mode at the appropriate level with the LogLevel.

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

Send adds another entry to the queue of runs.

type RunChannel

type RunChannel interface {
	Send(rr models.RunResult, ibn *models.IndexableBlockNumber) 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 {
	Input       models.RunResult
	BlockNumber *models.IndexableBlockNumber
}

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

type SecretGenerator

type SecretGenerator interface {
	Generate(Config) ([]byte, error)
}

SecretGenerator is the interface for objects that generate a secret used to sign or encrypt.

type Store

type Store struct {
	*orm.ORM
	Config     Config
	Clock      AfterNower
	KeyStore   *KeyStore
	RunChannel RunChannel
	TxManager  *TxManager
	// contains filtered or unexported fields
}

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 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.bolt file.

func NewStoreWithDialer

func NewStoreWithDialer(config 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.

type TxManager

type TxManager struct {
	*EthClient
	// contains filtered or unexported fields
}

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

func (*TxManager) ActivateAccount

func (txm *TxManager) ActivateAccount(account accounts.Account) error

ActivateAccount retrieves an account's nonce from the blockchain for client side management in ActiveAccount.

func (*TxManager) CreateTx

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

CreateTx signs and sends a transaction to the Ethereum blockchain.

func (*TxManager) GetActiveAccount

func (txm *TxManager) GetActiveAccount() *ActiveAccount

GetActiveAccount returns a copy of the TxManager's active nonce managed account.

func (*TxManager) GetLinkBalance

func (txm *TxManager) GetLinkBalance(address common.Address) (*assets.Link, error)

GetLinkBalance returns the balance of LINK at the given address

func (*TxManager) MeetsMinConfirmations

func (txm *TxManager) MeetsMinConfirmations(hash common.Hash) (bool, error)

MeetsMinConfirmations returns true if the given transaction hash has been confirmed on the blockchain.

func (txm *TxManager) WithdrawLink(wr models.WithdrawalRequest) (common.Hash, error)

WithdrawLink withdraws the given amount of LINK from the contract to the configured withdrawal address

type TxReceipt

type TxReceipt struct {
	BlockNumber *models.Int `json:"blockNumber"`
	Hash        common.Hash `json:"transactionHash"`
}

TxReceipt holds the block number and the transaction hash of a signed transaction that has been written to the blockchain.

func (*TxReceipt) Unconfirmed

func (txr *TxReceipt) Unconfirmed() bool

Unconfirmed returns true if the transaction is not confirmed.

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