store

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: 24 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

View Source
const Version string = "0.2.0"

Variables

View Source
var Sha string = "unset"

Functions

This section is empty.

Types

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 {
	LogLevel            LogLevel `env:"LOG_LEVEL" envDefault:"info"`
	RootDir             string   `env:"ROOT" envDefault:"~/.chainlink"`
	Port                string   `env:"PORT" envDefault:"6688"`
	BasicAuthUsername   string   `env:"USERNAME" envDefault:"chainlink"`
	BasicAuthPassword   string   `env:"PASSWORD" envDefault:"twochains"`
	EthereumURL         string   `env:"ETH_URL" envDefault:"ws://localhost:8546"`
	ChainID             uint64   `env:"ETH_CHAIN_ID" envDefault:"0"`
	ClientNodeURL       string   `env:"CLIENT_NODE_URL" envDefault:"http://localhost:6688"`
	EthMinConfirmations uint64   `env:"ETH_MIN_CONFIRMATIONS" envDefault:"12"`
	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"`
}

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

func (c Config) KeysDir() string

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

type EthClient

type EthClient struct {
	CallerSubscriber
}

EthClient holds the CallerSubscriber interface for the Ethereum blockchain.

func (*EthClient) GetBlockNumber

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

GetBlockNumber returns the block number of the chain head.

func (*EthClient) GetEthBalance

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

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)

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

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

type Store struct {
	*models.ORM
	Config    Config
	Clock     AfterNower
	Exiter    func(int)
	KeyStore  *KeyStore
	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 (*Store) Start

func (s *Store) Start()

Start listens for interrupt signals from the operating system so that the database can be properly closed before the application exits.

type TxManager

type TxManager struct {
	*EthClient
	KeyStore *KeyStore
	Config   Config
	ORM      *models.ORM
}

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

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

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

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

type TxReceipt

type TxReceipt struct {
	BlockNumber hexutil.Big `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