store

package
v0.0.0-...-e348512 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2021 License: MIT Imports: 30 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.

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

View Source
var Sha = "unset"

Sha string "unset"

View Source
var Version = "unset"

Version the version of application

Functions

func PromUpdateEthBalance

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

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 NewInsecureKeyStore

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 (*KeyStore) GetAccountByAddress

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

func (ks *KeyStore) SignHash(hash common.Hash) (models.Signature, error)

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

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 KeyStoreInterface

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 NotifyNewEthTx

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

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

NewStore will create a new store

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

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

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

func NewVRFKeyStore(store *Store) *VRFKeyStore

NewVRFKeyStore returns an empty VRFKeyStore

func (*VRFKeyStore) Archive

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

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

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

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

func (ks *VRFKeyStore) Forget(k vrfkey.PublicKey) error

func (*VRFKeyStore) GenerateProof

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

Get retrieves all EncryptedVRFKey's associated with k, or all encrypted keys if k is nil, or errors

func (*VRFKeyStore) GetSpecificKey

func (ks *VRFKeyStore) GetSpecificKey(
	k vrfkey.PublicKey) (*vrfkey.EncryptedVRFKey, error)

func (*VRFKeyStore) Import

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

func (ks *VRFKeyStore) ListKeys() (publicKeys []*vrfkey.PublicKey, err error)

ListKeys lists the public keys contained in the db

func (*VRFKeyStore) Store

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

func (ks *VRFKeyStore) StoreInMemoryXXXTestingOnly(key *vrfkey.PrivateKey)

StoreInMemoryXXXTestingOnly memorizes key, only in in-memory store.

func (*VRFKeyStore) Unlock

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