store

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 32 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.

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

View Source
const (
	// AutoMigrate is a flag that automatically migrates the DB when passed to initializeORM
	AutoMigrate = "auto_migrate"
)
View Source
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

View Source
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.

View Source
var ErrKeyStoreLocked = errors.New("keystore is locked (HINT: did you forget to call keystore.Unlock?)")
View Source
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

Functions

func CheckSquashUpgrade added in v0.10.0

func CheckSquashUpgrade(db *gorm.DB) error

func PromUpdateEthBalance added in v0.8.11

func PromUpdateEthBalance(balance *assets.Eth, from common.Address)

Types

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

type KeyStore struct {
	*keystore.KeyStore
	// contains filtered or unexported fields
}

KeyStore manages a key storage directory on disk.

func InsecureKeyStoreGen added in v0.9.9

func InsecureKeyStoreGen(config *orm.Config) *KeyStore

func NewInsecureKeyStore added in v0.8.2

func NewInsecureKeyStore(keyDir string) *KeyStore

NewInsecureKeyStore creates an *INSECURE* keystore for the given directory. NOTE: Should only be used for testing!

func NewKeyStore

func NewKeyStore(keyDir string, scryptParams utils.ScryptParams) *KeyStore

NewKeyStore creates a keystore for the given directory.

func StandardKeyStoreGen added in v0.9.9

func StandardKeyStoreGen(config *orm.Config) *KeyStore

func (*KeyStore) Delete added in v0.9.9

func (ks *KeyStore) Delete(address common.Address) error

func (*KeyStore) Export added in v0.9.9

func (ks *KeyStore) Export(address common.Address, newPassword string) ([]byte, error)

func (*KeyStore) GetAccountByAddress added in v0.8.7

func (ks *KeyStore) GetAccountByAddress(address common.Address) (accounts.Account, error)

GetAccountByAddress returns the account matching the address provided, or an error if it is missing

func (*KeyStore) GetAccounts

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

GetAccounts returns all accounts

func (*KeyStore) HasAccountWithAddress added in v0.9.6

func (ks *KeyStore) HasAccountWithAddress(address common.Address) bool

func (*KeyStore) HasAccounts

func (ks *KeyStore) HasAccounts() bool

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

func (*KeyStore) Import added in v0.9.9

func (ks *KeyStore) Import(keyJSON []byte, oldPassword string) (accounts.Account, error)

func (*KeyStore) NewAccount

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

NewAccount adds an account to the keystore

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(password string) error

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

type KeyStoreGenerator added in v0.9.9

type KeyStoreGenerator func(*orm.Config) *KeyStore

type KeyStoreInterface added in v0.8.4

type KeyStoreInterface interface {
	Unlock(password string) error
	Accounts() []accounts.Account
	Wallets() []accounts.Wallet
	HasAccounts() bool
	HasAccountWithAddress(common.Address) bool
	NewAccount() (accounts.Account, error)
	Import(keyJSON []byte, oldPassword string) (accounts.Account, error)
	Export(address common.Address, newPassword string) ([]byte, error)
	Delete(address common.Address) error
	GetAccounts() []accounts.Account
	GetAccountByAddress(common.Address) (accounts.Account, error)

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

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
	OCRKeyStore    *offchainreporting.KeyStore
	EthClient      eth.Client
	NotifyNewEthTx NotifyNewEthTx
	AdvisoryLocker postgres.AdvisoryLocker
	// contains filtered or unexported fields
}

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

func NewInsecureStore added in v0.8.2

func NewInsecureStore(config *orm.Config, ethClient eth.Client, advisoryLocker postgres.AdvisoryLocker, 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, ethClient eth.Client, advisoryLock postgres.AdvisoryLocker, shutdownSignal gracefulpanic.Signal, keyStoreGenerator KeyStoreGenerator) *Store

NewStore will create a new store

func (*Store) ArchiveKey added in v0.9.9

func (s *Store) ArchiveKey(address common.Address) error

ArchiveKey soft-deletes a key whose address matches the supplied address.

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) DeleteKey added in v0.9.9

func (s *Store) DeleteKey(address common.Address) error

DeleteKey hard-deletes a key whose address matches the supplied address.

func (*Store) ImportKey added in v0.9.9

func (s *Store) ImportKey(keyJSON []byte, oldPassword string) error

func (*Store) Start

func (s *Store) Start() error

Start initiates all of Store's dependencies

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 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) Archive added in v0.9.3

func (ks *VRFKeyStore) Archive(key vrfkey.PublicKey) (err error)

Archive soft-deletes keys with this public key from the keystore and the DB, if present.

func (*VRFKeyStore) CreateKey added in v0.8.2

func (ks *VRFKeyStore) CreateKey(phrase string) (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

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

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, scryptParams utils.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.

func (*VRFKeyStore) Unlock added in v0.8.2

func (ks *VRFKeyStore) Unlock(phrase string) (keysUnlocked []vrfkey.PublicKey,
	merr error)

Unlock tries to unlock each vrf key in the db, using the given pass phrase, and returns any keys it manages to unlock, and any errors which result.

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.

Jump to

Keyboard shortcuts

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