eth

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2020 License: AGPL-3.0 Imports: 27 Imported by: 1

Documentation

Index

Constants

View Source
const APIName = "eth"

APIName is the namespace for the watcher's eth api

View Source
const APIVersion = "0.0.1"

APIVersion is the version of the watcher's eth api

Variables

This section is empty.

Functions

func ChainConfig

func ChainConfig(chainID uint64) (*params.ChainConfig, error)

ChainConfig returns the appropriate ethereum chain config for the provided chain id

func RPCMarshalBlock

func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error)

RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain transaction hashes.

func RPCMarshalHeader

func RPCMarshalHeader(head *types.Header) map[string]interface{}

RPCMarshalHeader converts the given header to the RPC output. This function is eth/internal so we have to make our own version here...

func ReceiptModelsContainsCID

func ReceiptModelsContainsCID(rcts []eth.ReceiptModel, cid string) bool

ListContainsBytes used to check if a list of byte arrays contains a particular byte array

func ResolveFromNodeType

func ResolveFromNodeType(nodeType statediff.NodeType) int

func ResolveToNodeType

func ResolveToNodeType(nodeType int) statediff.NodeType

func TearDownDB

func TearDownDB(db *postgres.DB)

TearDownDB is used to tear down the watcher dbs after tests

func TxModelsContainsCID

func TxModelsContainsCID(txs []eth.TxModel, cid string) bool

TxModelsContainsCID used to check if a list of TxModels contains a specific cid string

Types

type Backend

type Backend struct {
	Retriever *CIDRetriever
	Fetcher   *IPLDFetcher
	DB        *postgres.DB
	EthDB     ethdb.Database
}

func NewEthBackend

func NewEthBackend(db *postgres.DB) (*Backend, error)

func (*Backend) BlockByHash

func (b *Backend) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)

BlockByHash returns the requested block. When fullTx is true all transactions in the block are returned in full detail, otherwise only the transaction hash is returned.

func (*Backend) BlockByNumber

func (b *Backend) BlockByNumber(ctx context.Context, blockNumber rpc.BlockNumber) (*types.Block, error)

BlockByNumber returns the requested canonical block. Since the ipld-eth-server database can contain forked blocks, it is recommended to fetch BlockByHash as fetching by number can return non-deterministic results (returns the first block found at that height)

func (*Backend) GetLogs

func (b *Backend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error)

GetLogs returns all the logs for the given block hash

func (*Backend) GetTd

func (b *Backend) GetTd(blockHash common.Hash) (*big.Int, error)

GetTd retrieves and returns the total difficulty at the given block hash

func (*Backend) GetTransaction

func (b *Backend) GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error)

GetTransaction retrieves a tx by hash It also returns the blockhash, blocknumber, and tx index associated with the transaction

func (*Backend) HeaderByNumber

func (b *Backend) HeaderByNumber(ctx context.Context, blockNumber rpc.BlockNumber) (*types.Header, error)

type CIDRetriever

type CIDRetriever struct {
	// contains filtered or unexported fields
}

CIDRetriever satisfies the CIDRetriever interface for ethereum

func NewCIDRetriever

func NewCIDRetriever(db *postgres.DB) *CIDRetriever

NewCIDRetriever returns a pointer to a new CIDRetriever which supports the CIDRetriever interface

func (*CIDRetriever) Retrieve

func (ecr *CIDRetriever) Retrieve(filter SubscriptionSettings, blockNumber int64) ([]eth2.CIDWrapper, bool, error)

Retrieve is used to retrieve all of the CIDs which conform to the passed StreamFilters

func (*CIDRetriever) RetrieveBlockByHash

func (ecr *CIDRetriever) RetrieveBlockByHash(blockHash common.Hash) (eth2.HeaderModel, []eth2.UncleModel, []eth2.TxModel, []eth2.ReceiptModel, error)

RetrieveBlockByHash returns all of the CIDs needed to compose an entire block, for a given block hash

func (*CIDRetriever) RetrieveBlockByNumber

func (ecr *CIDRetriever) RetrieveBlockByNumber(blockNumber int64) (eth2.HeaderModel, []eth2.UncleModel, []eth2.TxModel, []eth2.ReceiptModel, error)

RetrieveBlockByNumber returns all of the CIDs needed to compose an entire block, for a given block number

func (*CIDRetriever) RetrieveFirstBlockNumber

func (ecr *CIDRetriever) RetrieveFirstBlockNumber() (int64, error)

RetrieveFirstBlockNumber is used to retrieve the first block number in the db

func (*CIDRetriever) RetrieveHeaderCIDByHash

func (ecr *CIDRetriever) RetrieveHeaderCIDByHash(tx *sqlx.Tx, blockHash common.Hash) (eth2.HeaderModel, error)

RetrieveHeaderCIDByHash returns the header for the given block hash

func (*CIDRetriever) RetrieveHeaderCIDs

func (ecr *CIDRetriever) RetrieveHeaderCIDs(tx *sqlx.Tx, blockNumber int64) ([]eth2.HeaderModel, error)

RetrieveHeaderCIDs retrieves and returns all of the header cids at the provided blockheight

func (*CIDRetriever) RetrieveLastBlockNumber

func (ecr *CIDRetriever) RetrieveLastBlockNumber() (int64, error)

RetrieveLastBlockNumber is used to retrieve the latest block number in the db

func (*CIDRetriever) RetrieveRctCIDs

func (ecr *CIDRetriever) RetrieveRctCIDs(tx *sqlx.Tx, rctFilter ReceiptFilter, blockNumber int64, blockHash *common.Hash, trxIds []int64) ([]eth2.ReceiptModel, error)

RetrieveRctCIDs retrieves and returns all of the rct cids at the provided blockheight or block hash that conform to the provided filter parameters and correspond to the provided tx ids

func (*CIDRetriever) RetrieveRctCIDsByHeaderID

func (ecr *CIDRetriever) RetrieveRctCIDsByHeaderID(tx *sqlx.Tx, rctFilter ReceiptFilter, headerID int64, trxIds []int64) ([]eth2.ReceiptModel, error)

RetrieveRctCIDsByHeaderID retrieves and returns all of the rct cids at the provided header ID that conform to the provided filter parameters and correspond to the provided tx ids

func (*CIDRetriever) RetrieveReceiptCIDsByTxIDs

func (ecr *CIDRetriever) RetrieveReceiptCIDsByTxIDs(tx *sqlx.Tx, txIDs []int64) ([]eth2.ReceiptModel, error)

RetrieveReceiptCIDsByTxIDs retrieves receipt CIDs by their associated tx IDs

func (*CIDRetriever) RetrieveStateCIDs

func (ecr *CIDRetriever) RetrieveStateCIDs(tx *sqlx.Tx, stateFilter StateFilter, headerID int64) ([]eth2.StateNodeModel, error)

RetrieveStateCIDs retrieves and returns all of the state node cids at the provided header ID that conform to the provided filter parameters

func (*CIDRetriever) RetrieveStorageCIDs

func (ecr *CIDRetriever) RetrieveStorageCIDs(tx *sqlx.Tx, storageFilter StorageFilter, headerID int64) ([]eth2.StorageNodeWithStateKeyModel, error)

RetrieveStorageCIDs retrieves and returns all of the storage node cids at the provided header id that conform to the provided filter parameters

func (*CIDRetriever) RetrieveTxCIDs

func (ecr *CIDRetriever) RetrieveTxCIDs(tx *sqlx.Tx, txFilter TxFilter, headerID int64) ([]eth2.TxModel, error)

RetrieveTxCIDs retrieves and returns all of the trx cids at the provided blockheight that conform to the provided filter parameters also returns the ids for the returned transaction cids

func (*CIDRetriever) RetrieveTxCIDsByHeaderID

func (ecr *CIDRetriever) RetrieveTxCIDsByHeaderID(tx *sqlx.Tx, headerID int64) ([]eth2.TxModel, error)

RetrieveTxCIDsByHeaderID retrieves all tx CIDs for the given header id

func (*CIDRetriever) RetrieveUncleCIDsByHeaderID

func (ecr *CIDRetriever) RetrieveUncleCIDsByHeaderID(tx *sqlx.Tx, headerID int64) ([]eth2.UncleModel, error)

RetrieveUncleCIDsByHeaderID retrieves and returns all of the uncle cids for the provided header

type Fetcher

type Fetcher interface {
	Fetch(cids eth.CIDWrapper) (*eth.IPLDs, error)
}

Fetcher interface for substituting mocks in tests

type Filterer

type Filterer interface {
	Filter(filter SubscriptionSettings, payload eth.ConvertedPayload) (*eth.IPLDs, error)
}

Filterer interface for substituing mocks in tests

type HeaderFilter

type HeaderFilter struct {
	Off    bool
	Uncles bool
}

HeaderFilter contains filter settings for headers

type IPLDFetcher

type IPLDFetcher struct {
	// contains filtered or unexported fields
}

IPLDFetcher satisfies the IPLDFetcher interface for ethereum It interfaces directly with PG-IPFS

func NewIPLDFetcher

func NewIPLDFetcher(db *postgres.DB) *IPLDFetcher

NewIPLDFetcher creates a pointer to a new IPLDFetcher

func (*IPLDFetcher) Fetch

func (f *IPLDFetcher) Fetch(cids eth.CIDWrapper) (*eth.IPLDs, error)

Fetch is the exported method for fetching and returning all the IPLDS specified in the CIDWrapper

func (*IPLDFetcher) FetchHeader

func (f *IPLDFetcher) FetchHeader(tx *sqlx.Tx, c eth.HeaderModel) (ipfs.BlockModel, error)

FetchHeaders fetches headers

func (*IPLDFetcher) FetchRcts

func (f *IPLDFetcher) FetchRcts(tx *sqlx.Tx, cids []eth.ReceiptModel) ([]ipfs.BlockModel, error)

FetchRcts fetches receipts

func (*IPLDFetcher) FetchState

func (f *IPLDFetcher) FetchState(tx *sqlx.Tx, cids []eth.StateNodeModel) ([]eth.StateNode, error)

FetchState fetches state nodes

func (*IPLDFetcher) FetchStorage

func (f *IPLDFetcher) FetchStorage(tx *sqlx.Tx, cids []eth.StorageNodeWithStateKeyModel) ([]eth.StorageNode, error)

FetchStorage fetches storage nodes

func (*IPLDFetcher) FetchTrxs

func (f *IPLDFetcher) FetchTrxs(tx *sqlx.Tx, cids []eth.TxModel) ([]ipfs.BlockModel, error)

FetchTrxs fetches transactions

func (*IPLDFetcher) FetchUncles

func (f *IPLDFetcher) FetchUncles(tx *sqlx.Tx, cids []eth.UncleModel) ([]ipfs.BlockModel, error)

FetchUncles fetches uncles

type PublicEthAPI

type PublicEthAPI struct {
	B *Backend
}

func NewPublicEthAPI

func NewPublicEthAPI(b *Backend) *PublicEthAPI

NewPublicEthAPI creates a new PublicEthAPI with the provided underlying Backend

func (*PublicEthAPI) BlockNumber

func (pea *PublicEthAPI) BlockNumber() hexutil.Uint64

BlockNumber returns the block number of the chain head.

func (*PublicEthAPI) GetBlockByHash

func (pea *PublicEthAPI) GetBlockByHash(ctx context.Context, hash common.Hash, fullTx bool) (map[string]interface{}, error)

GetBlockByHash returns the requested block. When fullTx is true all transactions in the block are returned in full detail, otherwise only the transaction hash is returned.

func (*PublicEthAPI) GetBlockByNumber

func (pea *PublicEthAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error)

GetBlockByNumber returns the requested canonical block.

  • When blockNr is -1 the chain head is returned.
  • We cannot support pending block calls since we do not have an active miner
  • When fullTx is true all transactions in the block are returned, otherwise only the transaction hash is returned.

func (*PublicEthAPI) GetHeaderByNumber

func (pea *PublicEthAPI) GetHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (map[string]interface{}, error)

GetHeaderByNumber returns the requested canonical block header. * When blockNr is -1 the chain head is returned. * We cannot support pending block calls since we do not have an active miner

func (*PublicEthAPI) GetLogs

func (pea *PublicEthAPI) GetLogs(ctx context.Context, crit ethereum.FilterQuery) ([]*types.Log, error)

GetLogs returns logs matching the given argument that are stored within the state.

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getlogs

func (*PublicEthAPI) GetTransactionByHash

func (pea *PublicEthAPI) GetTransactionByHash(ctx context.Context, hash common.Hash) (*RPCTransaction, error)

GetTransactionByHash returns the transaction for the given hash eth ipld-eth-server cannot currently handle pending/tx_pool txs

type RPCTransaction

type RPCTransaction struct {
	BlockHash        *common.Hash    `json:"blockHash"`
	BlockNumber      *hexutil.Big    `json:"blockNumber"`
	From             common.Address  `json:"from"`
	Gas              hexutil.Uint64  `json:"gas"`
	GasPrice         *hexutil.Big    `json:"gasPrice"`
	Hash             common.Hash     `json:"hash"`
	Input            hexutil.Bytes   `json:"input"`
	Nonce            hexutil.Uint64  `json:"nonce"`
	To               *common.Address `json:"to"`
	TransactionIndex *hexutil.Uint64 `json:"transactionIndex"`
	Value            *hexutil.Big    `json:"value"`
	V                *hexutil.Big    `json:"v"`
	R                *hexutil.Big    `json:"r"`
	S                *hexutil.Big    `json:"s"`
}

RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction

func NewRPCTransaction

func NewRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber uint64, index uint64) *RPCTransaction

NewRPCTransaction returns a transaction that will serialize to the RPC representation, with the given location metadata set (if available).

func NewRPCTransactionFromBlockHash

func NewRPCTransactionFromBlockHash(b *types.Block, hash common.Hash) *RPCTransaction

NewRPCTransactionFromBlockHash returns a transaction that will serialize to the RPC representation.

type ReceiptFilter

type ReceiptFilter struct {
	Off bool
	// TODO: change this so that we filter for receipts first and we always return the corresponding transaction
	MatchTxs     bool     // turn on to retrieve receipts that pair with retrieved transactions
	LogAddresses []string // receipt contains logs from the provided addresses
	Topics       [][]string
}

ReceiptFilter contains filter settings for receipts

type ResponseFilterer

type ResponseFilterer struct{}

ResponseFilterer satisfies the ResponseFilterer interface for ethereum

func NewResponseFilterer

func NewResponseFilterer() *ResponseFilterer

NewResponseFilterer creates a new Filterer satisfying the ResponseFilterer interface

func (*ResponseFilterer) Filter

func (s *ResponseFilterer) Filter(filter SubscriptionSettings, payload eth.ConvertedPayload) (*eth.IPLDs, error)

Filter is used to filter through eth data to extract and package requested data into a Payload

type Retriever

type Retriever interface {
	RetrieveFirstBlockNumber() (int64, error)
	RetrieveLastBlockNumber() (int64, error)
	Retrieve(filter SubscriptionSettings, blockNumber int64) ([]eth2.CIDWrapper, bool, error)
}

Retriever interface for substituting mocks in tests

type StateFilter

type StateFilter struct {
	Off               bool
	Addresses         []string // is converted to state key by taking its keccak256 hash
	IntermediateNodes bool
}

StateFilter contains filter settings for state

type StorageFilter

type StorageFilter struct {
	Off               bool
	Addresses         []string
	StorageKeys       []string // need to be the hashs key themselves not slot position
	IntermediateNodes bool
}

StorageFilter contains filter settings for storage

type SubscriptionSettings

type SubscriptionSettings struct {
	BackFill      bool
	BackFillOnly  bool
	Start         *big.Int
	End           *big.Int // set to 0 or a negative value to have no ending block
	HeaderFilter  HeaderFilter
	TxFilter      TxFilter
	ReceiptFilter ReceiptFilter
	StateFilter   StateFilter
	StorageFilter StorageFilter
}

SubscriptionSettings config is used by a subscriber to specify what eth data to stream from the watcher

func NewEthSubscriptionConfig

func NewEthSubscriptionConfig() (*SubscriptionSettings, error)

Init is used to initialize a EthSubscription struct with env variables

type TxFilter

type TxFilter struct {
	Off bool
	Src []string
	Dst []string
}

TxFilter contains filter settings for txs

Jump to

Keyboard shortcuts

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