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.
CallerSubscriberClient ¶
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
- Variables
- func BumpGas(config orm.ConfigReader, originalGasPrice *big.Int) (*big.Int, error)
- func PromUpdateEthBalance(balance *assets.Eth, from common.Address)
- type AttemptState
- type EthTxManager
- func (txm *EthTxManager) BumpGasByIncrement(originalGasPrice *big.Int) *big.Int
- func (txm *EthTxManager) BumpGasUntilSafe(hash common.Hash) (*types.Receipt, AttemptState, error)
- func (txm *EthTxManager) CheckAttempt(txAttempt *models.TxAttempt, blockHeight uint64) (*types.Receipt, AttemptState, error)
- func (txm *EthTxManager) Connect(bn *models.Head) error
- func (txm *EthTxManager) Connected() bool
- func (txm *EthTxManager) CreateTx(to common.Address, data []byte) (*models.Tx, error)
- func (txm *EthTxManager) CreateTxWithEth(from, to common.Address, value *assets.Eth) (*models.Tx, error)
- func (txm *EthTxManager) CreateTxWithGas(surrogateID null.String, to common.Address, data []byte, gasPriceWei *big.Int, ...) (*models.Tx, error)
- func (txm *EthTxManager) Disconnect()
- func (txm *EthTxManager) GetAvailableAccount(from common.Address) *ManagedAccount
- func (txm *EthTxManager) GetLINKBalance(address common.Address) (*assets.Link, error)
- func (txm *EthTxManager) NextActiveAccount() *ManagedAccount
- func (txm *EthTxManager) OnNewLongestChain(ctx context.Context, head models.Head)
- func (txm *EthTxManager) Register(accts []accounts.Account)
- func (txm *EthTxManager) SignedRawTxWithBumpedGas(originalTx models.Tx, gasLimit uint64, gasPrice big.Int) ([]byte, error)
- type HeadTrackable
- type InMemoryKeyStore
- type KeyStore
- func (ks *KeyStore) GetAccountByAddress(address common.Address) (accounts.Account, error)
- func (ks *KeyStore) GetAccounts() []accounts.Account
- func (ks *KeyStore) GetFirstAccount() (accounts.Account, error)
- func (ks *KeyStore) HasAccounts() bool
- func (ks *KeyStore) NewAccount(passphrase string) (accounts.Account, error)
- func (ks *KeyStore) SignHash(hash common.Hash) (models.Signature, error)
- func (ks *KeyStore) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)
- func (ks *KeyStore) Unlock(phrase string) error
- type KeyStoreInterface
- type ManagedAccount
- type NotifyNewEthTx
- type Store
- type TxManager
- type VRFKeyStore
- func (ks *VRFKeyStore) CreateKey(phrase string, p ...vrfkey.ScryptParams) (vrfkey.PublicKey, error)
- func (ks *VRFKeyStore) CreateWeakInMemoryEncryptedKeyXXXTestingOnly(phrase string) (*vrfkey.EncryptedVRFKey, error)
- func (ks *VRFKeyStore) Delete(key vrfkey.PublicKey) (err error)
- func (ks *VRFKeyStore) Forget(k vrfkey.PublicKey) error
- func (ks *VRFKeyStore) GenerateProof(k vrfkey.PublicKey, i vrf.PreSeedData) (vrf.MarshaledOnChainResponse, error)
- func (ks *VRFKeyStore) Get(k ...vrfkey.PublicKey) ([]*vrfkey.EncryptedVRFKey, error)
- func (ks *VRFKeyStore) GetSpecificKey(k vrfkey.PublicKey) (*vrfkey.EncryptedVRFKey, error)
- func (ks *VRFKeyStore) Import(keyjson []byte, auth string) error
- func (ks *VRFKeyStore) ListKeys() (publicKeys []*vrfkey.PublicKey, err error)
- func (ks *VRFKeyStore) Store(key *vrfkey.PrivateKey, phrase string, p ...vrfkey.ScryptParams) error
- func (ks *VRFKeyStore) StoreInMemoryXXXTestingOnly(key *vrfkey.PrivateKey)
- func (ks *VRFKeyStore) Unlock(phrase string) (keysUnlocked []vrfkey.PublicKey, merr error)
Constants ¶
const (
// AutoMigrate is a flag that automatically migrates the DB when passed to initializeORM
AutoMigrate = "auto_migrate"
)
const EthereumMessageHashPrefix = "\x19Ethereum Signed Message:\n32"
EthereumMessageHashPrefix is a Geth-originating message prefix that seeks to prevent arbitrary message data to be representable as a valid Ethereum transaction For more information, see: https://github.com/ethereum/go-ethereum/issues/3731
Variables ¶
var AttemptToDeleteNonExistentKeyFromDB = errors.New("key is not present in DB")
AttemptToDeleteNonExistentKeyFromDB is returned when Delete is asked to delete a key it can't find in the DB.
var ( // ErrPendingConnection is the error returned if TxManager is not connected. ErrPendingConnection = errors.New("Cannot talk to chain, pending connection") )
var MatchingVRFKeyError = errors.New(
`key with matching public key already stored in DB`)
MatchingVRFKeyError is returned when Import attempts to import key with a PublicKey matching one already in the database
var Sha = "unset"
Sha string "unset"
var Version = "unset"
Version the version of application
Functions ¶
func BumpGas ¶ added in v0.8.7
BumpGas computes the next gas price to attempt as the largest of: - A configured percentage bump (ETH_GAS_BUMP_PERCENT) on top of the baseline price. - A configured fixed amount of Wei (ETH_GAS_PRICE_WEI) on top of the baseline price. The baseline price is the maximum of the previous gas price attempt and the node's current gas price.
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 transaction has had at least one confirmation, 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 EthTxManager ¶
EthTxManager contains fields for the Ethereum client, the KeyStore, the local Config for the application, and the database.
func NewEthTxManager ¶
func NewEthTxManager(client eth.Client, config orm.ConfigReader, keyStore KeyStoreInterface, orm *orm.ORM) *EthTxManager
NewEthTxManager constructs an EthTxManager using the passed variables and initializing internal variables.
func (*EthTxManager) BumpGasByIncrement ¶ added in v0.8.2
func (txm *EthTxManager) BumpGasByIncrement(originalGasPrice *big.Int) *big.Int
func (*EthTxManager) BumpGasUntilSafe ¶
func (txm *EthTxManager) BumpGasUntilSafe(hash common.Hash) (*types.Receipt, 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) (*types.Receipt, 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) 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) GetAvailableAccount ¶ added in v0.6.8
func (txm *EthTxManager) GetAvailableAccount(from common.Address) *ManagedAccount
GetAvailableAccount retrieves a managed account if it one matches the address given.
func (*EthTxManager) GetLINKBalance ¶
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) OnNewLongestChain ¶ added in v0.8.5
func (txm *EthTxManager) OnNewLongestChain(ctx context.Context, head models.Head)
OnNewLongestChain 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 (*EthTxManager) SignedRawTxWithBumpedGas ¶ added in v0.8.2
func (txm *EthTxManager) SignedRawTxWithBumpedGas(originalTx models.Tx, gasLimit uint64, gasPrice big.Int) ([]byte, error)
SignedRawTxWithBumpedGas takes a transaction and generates a new signed TX from it with the provided params
type HeadTrackable ¶
type HeadTrackable interface { Connect(head *models.Head) error Disconnect() OnNewLongestChain(ctx context.Context, head models.Head) }
HeadTrackable represents any object that wishes to respond to ethereum events, after being attached to HeadTracker.
type InMemoryKeyStore ¶ added in v0.8.2
type InMemoryKeyStore = map[vrfkey.PublicKey]vrfkey.PrivateKey
type KeyStore ¶
KeyStore manages a key storage directory on disk.
func NewInsecureKeyStore ¶ added in v0.8.2
NewInsecureKeyStore creates an *INSECURE* keystore for the given directory. NOTE: Should only be used for testing!
func NewKeyStore ¶
NewKeyStore creates a keystore for the given directory.
func (*KeyStore) GetAccountByAddress ¶ added in v0.8.7
GetAccountByAddress returns the account matching the address provided, or an error if it is missing
func (*KeyStore) GetAccounts ¶
GetAccounts returns all accounts
func (*KeyStore) GetFirstAccount ¶
GetFirstAccount returns the unlocked account in the KeyStore object. The client ensures that an account exists during authentication.
func (*KeyStore) HasAccounts ¶
HasAccounts returns true if there are accounts located at the keystore directory.
func (*KeyStore) NewAccount ¶
NewAccount adds an account to the keystore
func (*KeyStore) SignHash ¶ added in v0.6.10
SignHash signs a precomputed digest, using the first account's private key This method adds an ethereum message prefix to the message before signing it, invalidating any would-be valid Ethereum transactions
type KeyStoreInterface ¶ added in v0.8.4
type KeyStoreInterface interface { Accounts() []accounts.Account Wallets() []accounts.Wallet GetFirstAccount() (accounts.Account, error) HasAccounts() bool Unlock(phrase string) error NewAccount(passphrase string) (accounts.Account, error) SignHash(hash common.Hash) (models.Signature, error) Import(keyJSON []byte, passphrase, newPassphrase string) (accounts.Account, error) Export(a accounts.Account, passphrase, newPassphrase string) ([]byte, error) GetAccounts() []accounts.Account GetAccountByAddress(common.Address) (accounts.Account, error) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) }
type ManagedAccount ¶
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 NotifyNewEthTx ¶ added in v0.8.7
type NotifyNewEthTx interface {
Trigger()
}
NotifyNewEthTx allows to notify the ethBroadcaster of a new transaction
type Store ¶
type Store struct { *orm.ORM Config *orm.Config Clock utils.AfterNower KeyStore KeyStoreInterface VRFKeyStore *VRFKeyStore TxManager TxManager EthClient eth.Client NotifyNewEthTx NotifyNewEthTx // 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 NewInsecureStore ¶ added in v0.8.2
func NewInsecureStore(config *orm.Config, shutdownSignal gracefulpanic.Signal) *Store
NewInsecureStore creates a new store with the given config using an insecure keystore. NOTE: Should only be used for testing!
func NewStore ¶
func NewStore(config *orm.Config, shutdownSignal gracefulpanic.Signal) *Store
NewStore will create a new store
func (*Store) AuthorizedUserWithSession ¶
AuthorizedUserWithSession will return the one API user if the Session ID exists and hasn't expired, and update session's LastUsed field.
func (*Store) SyncDiskKeyStoreToDB ¶
SyncDiskKeyStoreToDB writes all keys in the keys directory to the underlying orm.
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) (*types.Receipt, AttemptState, error) BumpGasUntilSafe(hash common.Hash) (*types.Receipt, AttemptState, error) GetLINKBalance(address common.Address) (*assets.Link, error) NextActiveAccount() *ManagedAccount SignedRawTxWithBumpedGas(originalTx models.Tx, gasLimit uint64, gasPrice big.Int) ([]byte, error) eth.Client }
TxManager represents an interface for interacting with the blockchain
type VRFKeyStore ¶ added in v0.8.2
type VRFKeyStore struct {
// contains filtered or unexported fields
}
VRFKeyStore tracks auxiliary VRF secret keys, and generates their VRF proofs
VRF proofs need access to the actual secret key, which geth does not expose. Similar to the way geth's KeyStore exposes signing capability, VRFKeyStore exposes VRF proof generation without the caller needing explicit knowledge of the secret key.
func NewVRFKeyStore ¶ added in v0.8.2
func NewVRFKeyStore(store *Store) *VRFKeyStore
NewVRFKeyStore returns an empty VRFKeyStore
func (*VRFKeyStore) CreateKey ¶ added in v0.8.2
func (ks *VRFKeyStore) CreateKey(phrase string, p ...vrfkey.ScryptParams, ) (vrfkey.PublicKey, error)
CreateKey returns a public key which is immediately unlocked in memory, and saved in DB encrypted with phrase. If p is given, its parameters are used for key derivation from the phrase.
func (*VRFKeyStore) CreateWeakInMemoryEncryptedKeyXXXTestingOnly ¶ added in v0.8.2
func (ks *VRFKeyStore) CreateWeakInMemoryEncryptedKeyXXXTestingOnly( phrase string) (*vrfkey.EncryptedVRFKey, error)
CreateWeakInMemoryEncryptedKeyXXXTestingOnly is for testing only! It returns an encrypted key which is fast to unlock, but correspondingly easy to brute force. It is not persisted to the DB, because no one should be keeping such keys lying around.
func (*VRFKeyStore) Delete ¶ added in v0.8.2
func (ks *VRFKeyStore) Delete(key vrfkey.PublicKey) (err error)
Delete removes keys with this public key from the keystore and the DB, if present.
func (*VRFKeyStore) Forget ¶ added in v0.8.2
func (ks *VRFKeyStore) Forget(k vrfkey.PublicKey) error
func (*VRFKeyStore) GenerateProof ¶ added in v0.8.2
func (ks *VRFKeyStore) GenerateProof(k vrfkey.PublicKey, i vrf.PreSeedData) ( vrf.MarshaledOnChainResponse, error)
GenerateProof is marshaled randomness proof given k and VRF input seed computed from the SeedData
Key must have already been unlocked in ks, as constructing the VRF proof requires the secret key.
func (*VRFKeyStore) Get ¶ added in v0.8.2
func (ks *VRFKeyStore) Get(k ...vrfkey.PublicKey) ([]*vrfkey.EncryptedVRFKey, error)
Get retrieves all EncryptedVRFKey's associated with k, or all encrypted keys if k is nil, or errors
func (*VRFKeyStore) GetSpecificKey ¶ added in v0.8.2
func (ks *VRFKeyStore) GetSpecificKey( k vrfkey.PublicKey) (*vrfkey.EncryptedVRFKey, error)
func (*VRFKeyStore) Import ¶ added in v0.8.2
func (ks *VRFKeyStore) Import(keyjson []byte, auth string) error
Import adds this encrypted key to the DB and unlocks it in in-memory store with passphrase auth, and returns any resulting errors
func (*VRFKeyStore) ListKeys ¶ added in v0.8.2
func (ks *VRFKeyStore) ListKeys() (publicKeys []*vrfkey.PublicKey, err error)
ListKeys lists the public keys contained in the db
func (*VRFKeyStore) Store ¶ added in v0.8.2
func (ks *VRFKeyStore) Store(key *vrfkey.PrivateKey, phrase string, p ...vrfkey.ScryptParams) error
Store saves key to ks (in memory), and to the DB, encrypted with phrase
func (*VRFKeyStore) StoreInMemoryXXXTestingOnly ¶ added in v0.8.2
func (ks *VRFKeyStore) StoreInMemoryXXXTestingOnly(key *vrfkey.PrivateKey)
StoreInMemoryXXXTestingOnly memorizes key, only in in-memory store.
Source Files ¶
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. |
vrfkey
Package vrfkey tracks the secret keys associated with VRF proofs.
|
Package vrfkey tracks the secret keys associated with VRF proofs. |
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. |