Documentation ¶
Index ¶
- func IsTokenTransfer(logs []*types.Log) bool
- type BalanceCache
- type BalanceReader
- type BatchDownloader
- type Block
- func (b *Block) GetBlocks(chainID uint64) (rst []*DBHeader, err error)
- func (b *Block) GetBlocksByAddress(chainID uint64, address common.Address, limit int) (rst []*big.Int, err error)
- func (b *Block) GetFirstKnownBlock(chainID uint64, address common.Address) (rst *big.Int, err error)
- func (b *Block) GetLastBlockByAddress(chainID uint64, address common.Address, limit int) (rst *big.Int, err error)
- func (b *Block) GetLastKnownBlockByAddress(chainID uint64, address common.Address) (block *LastKnownBlock, err error)
- func (b *Block) GetLastKnownBlockByAddresses(chainID uint64, addresses []common.Address) (map[common.Address]*LastKnownBlock, []common.Address, error)
- func (b *Block) GetLastSavedBlock(chainID uint64) (rst *DBHeader, err error)
- func (b *Block) GetLastSavedBlockBefore(chainID uint64, block *big.Int) (rst *DBHeader, err error)
- func (b *Block) RemoveBlockWithTransfer(chainID uint64, address common.Address, block *big.Int) error
- type BlocksRange
- type ConcurrentDownloader
- type Controller
- func (c *Controller) CheckRecentHistory(chainIDs []uint64, accounts []common.Address) error
- func (c *Controller) GetCachedBalances(ctx context.Context, chainID uint64, addresses []common.Address) ([]LastKnownBlockView, error)
- func (c *Controller) GetTransfersByAddress(ctx context.Context, chainID uint64, address common.Address, ...) ([]View, error)
- func (c *Controller) LoadTransferByHash(ctx context.Context, rpcClient *rpc.Client, address common.Address, ...) error
- func (c *Controller) SetInitialBlocksRange(chainIDs []uint64) error
- func (c *Controller) Start() error
- func (c *Controller) Stop()
- type DBHeader
- type Database
- func (db *Database) Close() error
- func (db *Database) GetHeaderByNumber(chainID uint64, number *big.Int) (header *DBHeader, err error)
- func (db *Database) GetPreloadedTransactions(chainID uint64, address common.Address, blockHash common.Hash) (rst []Transfer, err error)
- func (db *Database) GetTransactionsLog(chainID uint64, address common.Address, transactionHash common.Hash) (*types.Log, error)
- func (db *Database) GetTransfers(chainID uint64, start, end *big.Int) (rst []Transfer, err error)
- func (db *Database) GetTransfersByAddress(chainID uint64, address common.Address, toBlock *big.Int, limit int64) (rst []Transfer, err error)
- func (db *Database) GetTransfersByAddressAndBlock(chainID uint64, address common.Address, block *big.Int, limit int64) (rst []Transfer, err error)
- func (db *Database) GetTransfersInRange(chainID uint64, address common.Address, start, end *big.Int) (rst []Transfer, err error)
- func (db *Database) InsertBlock(chainID uint64, account common.Address, blockNumber *big.Int, ...) error
- func (db *Database) ProcessBlocks(chainID uint64, account common.Address, from *big.Int, to *LastKnownBlock, ...) (err error)
- func (db *Database) ProcessTranfers(chainID uint64, transfers []Transfer, removed []*DBHeader) (err error)
- func (db *Database) SaveBlocks(chainID uint64, account common.Address, headers []*DBHeader) (err error)
- func (db *Database) SaveHeaders(chainID uint64, headers []*types.Header, address common.Address) (err error)
- func (db *Database) SaveTranfers(chainID uint64, address common.Address, transfers []Transfer, ...) (err error)
- type Downloader
- type ERC20TransfersDownloader
- type ETHDownloader
- type Event
- type EventType
- type HeaderReader
- type IterativeDownloader
- type JSONBlob
- type LastKnownBlock
- type LastKnownBlockView
- type Reactor
- type Result
- type SignalsTransmitter
- type SyncOption
- type Transfer
- type Type
- type View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsTokenTransfer ¶
Types ¶
type BalanceCache ¶
type BalanceReader ¶
type BalanceReader interface { BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) }
BalanceReader interface for reading balance at a specifeid address.
type BatchDownloader ¶
type BatchDownloader interface {
GetHeadersInRange(ctx context.Context, from, to *big.Int) ([]*DBHeader, error)
}
BatchDownloader interface for loading transfers in batches in speificed range of blocks.
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
func (*Block) GetBlocksByAddress ¶
func (b *Block) GetBlocksByAddress(chainID uint64, address common.Address, limit int) (rst []*big.Int, err error)
GetBlocksByAddress loads blocks for a given address.
func (*Block) GetFirstKnownBlock ¶
func (*Block) GetLastBlockByAddress ¶
func (*Block) GetLastKnownBlockByAddress ¶
func (*Block) GetLastKnownBlockByAddresses ¶
func (*Block) GetLastSavedBlock ¶
func (*Block) GetLastSavedBlockBefore ¶
type BlocksRange ¶
type BlocksRange struct {
// contains filtered or unexported fields
}
type ConcurrentDownloader ¶
type ConcurrentDownloader struct { *async.AtomicGroup *Result }
func NewConcurrentDownloader ¶
func NewConcurrentDownloader(ctx context.Context) *ConcurrentDownloader
NewConcurrentDownloader creates ConcurrentDownloader instance.
type Controller ¶
func NewTransferController ¶
func (*Controller) CheckRecentHistory ¶
func (c *Controller) CheckRecentHistory(chainIDs []uint64, accounts []common.Address) error
func (*Controller) GetCachedBalances ¶
func (c *Controller) GetCachedBalances(ctx context.Context, chainID uint64, addresses []common.Address) ([]LastKnownBlockView, error)
func (*Controller) GetTransfersByAddress ¶
func (*Controller) LoadTransferByHash ¶ added in v0.91.10
func (*Controller) SetInitialBlocksRange ¶
func (c *Controller) SetInitialBlocksRange(chainIDs []uint64) error
func (*Controller) Start ¶
func (c *Controller) Start() error
func (*Controller) Stop ¶
func (c *Controller) Stop()
type DBHeader ¶
type DBHeader struct { Number *big.Int Hash common.Hash Timestamp uint64 Erc20Transfers []*Transfer Network uint64 Address common.Address // Head is true if the block was a head at the time it was pulled from chain. Head bool // Loaded is true if trasfers from this block has been already fetched Loaded bool }
DBHeader fields from header that are stored in database.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database sql wrapper for operations with wallet objects.
func (*Database) GetHeaderByNumber ¶
func (db *Database) GetHeaderByNumber(chainID uint64, number *big.Int) (header *DBHeader, err error)
GetHeaderByNumber selects header using block number.
func (*Database) GetPreloadedTransactions ¶
func (*Database) GetTransactionsLog ¶
func (*Database) GetTransfers ¶
GetTransfers load transfers transfer betweeen two blocks.
func (*Database) GetTransfersByAddress ¶
func (db *Database) GetTransfersByAddress(chainID uint64, address common.Address, toBlock *big.Int, limit int64) (rst []Transfer, err error)
GetTransfersByAddress loads transfers for a given address between two blocks.
func (*Database) GetTransfersByAddressAndBlock ¶
func (db *Database) GetTransfersByAddressAndBlock(chainID uint64, address common.Address, block *big.Int, limit int64) (rst []Transfer, err error)
GetTransfersByAddressAndBlock loads transfers for a given address and block.
func (*Database) GetTransfersInRange ¶
func (db *Database) GetTransfersInRange(chainID uint64, address common.Address, start, end *big.Int) (rst []Transfer, err error)
GetTransfersInRange loads transfers for a given address between two blocks.
func (*Database) InsertBlock ¶ added in v0.91.10
func (*Database) ProcessBlocks ¶
func (*Database) ProcessTranfers ¶
func (db *Database) ProcessTranfers(chainID uint64, transfers []Transfer, removed []*DBHeader) (err error)
ProcessTranfers atomically adds/removes blocks and adds new tranfers.
func (*Database) SaveBlocks ¶
type Downloader ¶
Downloader downloads transfers from single block using number.
type ERC20TransfersDownloader ¶
type ERC20TransfersDownloader struct {
// contains filtered or unexported fields
}
ERC20TransfersDownloader is a downloader for erc20 tokens transfers.
func NewERC20TransfersDownloader ¶
func NewERC20TransfersDownloader(client *chain.Client, accounts []common.Address, signer types.Signer) *ERC20TransfersDownloader
NewERC20TransfersDownloader returns new instance.
func (*ERC20TransfersDownloader) GetHeadersInRange ¶
func (d *ERC20TransfersDownloader) GetHeadersInRange(parent context.Context, from, to *big.Int) ([]*DBHeader, error)
GetHeadersInRange returns transfers between two blocks. time to get logs for 100000 blocks = 1.144686979s. with 249 events in the result set.
func (*ERC20TransfersDownloader) GetTransfers ¶
func (d *ERC20TransfersDownloader) GetTransfers(ctx context.Context, header *DBHeader) ([]Transfer, error)
GetTransfers for erc20 uses eth_getLogs rpc with Transfer event signature and our address acount.
type ETHDownloader ¶
type ETHDownloader struct {
// contains filtered or unexported fields
}
ETHDownloader downloads regular eth transfers.
func (*ETHDownloader) GetTransfers ¶
func (d *ETHDownloader) GetTransfers(ctx context.Context, header *DBHeader) (rst []Transfer, err error)
GetTransfers checks if the balance was changed between two blocks. If so it downloads transaction that transfer ethereum from that block.
func (*ETHDownloader) GetTransfersByNumber ¶
type Event ¶
type Event struct { Type EventType `json:"type"` BlockNumber *big.Int `json:"blockNumber"` Accounts []common.Address `json:"accounts"` Message string `json:"message"` }
Event is a type for transfer events.
type EventType ¶
type EventType string
EventType type for event types.
const ( // EventNewTransfers emitted when new block was added to the same canonical chan. EventNewTransfers EventType = "new-transfers" // EventFetchingRecentHistory emitted when fetching of lastest tx history is started EventFetchingRecentHistory EventType = "recent-history-fetching" // EventRecentHistoryReady emitted when fetching of lastest tx history is started EventRecentHistoryReady EventType = "recent-history-ready" // EventFetchingHistoryError emitted when fetching of tx history failed EventFetchingHistoryError EventType = "fetching-history-error" // EventNonArchivalNodeDetected emitted when a connection to a non archival node is detected EventNonArchivalNodeDetected EventType = "non-archival-node-detected" )
type HeaderReader ¶
type HeaderReader interface { HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) }
HeaderReader interface for reading headers using block number or hash.
type IterativeDownloader ¶
type IterativeDownloader struct {
// contains filtered or unexported fields
}
IterativeDownloader downloads batches of transfers in a specified size.
func SetupIterativeDownloader ¶
func SetupIterativeDownloader( db *Database, client HeaderReader, address common.Address, downloader BatchDownloader, size *big.Int, to *big.Int, from *big.Int, isBatchSizeAdjustable bool) (*IterativeDownloader, error)
SetupIterativeDownloader configures IterativeDownloader with last known synced block.
func (*IterativeDownloader) Finished ¶
func (d *IterativeDownloader) Finished() bool
Finished true when earliest block with given sync option is zero.
func (*IterativeDownloader) Header ¶
func (d *IterativeDownloader) Header() *big.Int
Header return last synced header.
func (*IterativeDownloader) Revert ¶
func (d *IterativeDownloader) Revert()
Revert reverts last step progress. Should be used if application failed to process transfers. For example failed to persist them.
type JSONBlob ¶
type JSONBlob struct {
// contains filtered or unexported fields
}
JSONBlob type for marshaling/unmarshaling inner type to json.
type LastKnownBlockView ¶
type Reactor ¶
type Reactor struct {
// contains filtered or unexported fields
}
Reactor listens to new blocks and stores transfers into the database.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
func (*Result) GetHeaders ¶
func (*Result) PushHeader ¶
type SignalsTransmitter ¶
type SignalsTransmitter struct {
// contains filtered or unexported fields
}
SignalsTransmitter transmits received events as wallet signals.
func (*SignalsTransmitter) Start ¶
func (tmr *SignalsTransmitter) Start() error
Start runs loop in background.
func (*SignalsTransmitter) Stop ¶
func (tmr *SignalsTransmitter) Stop()
Stop stops the loop and waits till it exits.
type SyncOption ¶
type SyncOption uint
SyncOption is used to specify that application processed transfers for that block.
type Transfer ¶
type Transfer struct { Type Type `json:"type"` ID common.Hash `json:"-"` Address common.Address `json:"address"` BlockNumber *big.Int `json:"blockNumber"` BlockHash common.Hash `json:"blockhash"` Timestamp uint64 `json:"timestamp"` Transaction *types.Transaction `json:"transaction"` Loaded bool NetworkID uint64 // From is derived from tx signature in order to offload this computation from UI component. From common.Address `json:"from"` Receipt *types.Receipt `json:"receipt"` // Log that was used to generate erc20 transfer. Nil for eth transfer. Log *types.Log `json:"log"` }
Transfer stores information about transfer.
type View ¶
type View struct { ID common.Hash `json:"id"` Type Type `json:"type"` Address common.Address `json:"address"` BlockNumber *hexutil.Big `json:"blockNumber"` BlockHash common.Hash `json:"blockhash"` Timestamp hexutil.Uint64 `json:"timestamp"` GasPrice *hexutil.Big `json:"gasPrice"` MaxFeePerGas *hexutil.Big `json:"maxFeePerGas"` MaxPriorityFeePerGas *hexutil.Big `json:"maxPriorityFeePerGas"` GasLimit hexutil.Uint64 `json:"gasLimit"` GasUsed hexutil.Uint64 `json:"gasUsed"` Nonce hexutil.Uint64 `json:"nonce"` TxStatus hexutil.Uint64 `json:"txStatus"` Input hexutil.Bytes `json:"input"` TxHash common.Hash `json:"txHash"` Value *hexutil.Big `json:"value"` From common.Address `json:"from"` To common.Address `json:"to"` Contract common.Address `json:"contract"` NetworkID uint64 `json:"networkId"` }
View stores only fields used by a client and ensures that all relevant fields are encoded in hex.