transfer

package
v0.92.7 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: MPL-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTokenTransfer

func IsTokenTransfer(logs []*types.Log) bool

Types

type BalanceCache

type BalanceCache interface {
	BalanceAt(ctx context.Context, client BalanceReader, account common.Address, blockNumber *big.Int) (*big.Int, error)
	NonceAt(ctx context.Context, client BalanceReader, account common.Address, blockNumber *big.Int) (*int64, error)
}

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

func (b *Block) GetBlocks(chainID uint64) (rst []*DBHeader, err error)

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 (b *Block) GetFirstKnownBlock(chainID uint64, address common.Address) (rst *big.Int, err error)

func (*Block) GetLastBlockByAddress

func (b *Block) GetLastBlockByAddress(chainID uint64, address common.Address, limit int) (rst *big.Int, err error)

func (*Block) GetLastKnownBlockByAddress

func (b *Block) GetLastKnownBlockByAddress(chainID uint64, address common.Address) (block *LastKnownBlock, err error)

func (*Block) GetLastKnownBlockByAddresses

func (b *Block) GetLastKnownBlockByAddresses(chainID uint64, addresses []common.Address) (map[common.Address]*LastKnownBlock, []common.Address, error)

func (*Block) GetLastSavedBlock

func (b *Block) GetLastSavedBlock(chainID uint64) (rst *DBHeader, err error)

func (*Block) GetLastSavedBlockBefore

func (b *Block) GetLastSavedBlockBefore(chainID uint64, block *big.Int) (rst *DBHeader, err error)

func (*Block) RemoveBlockWithTransfer

func (b *Block) RemoveBlockWithTransfer(chainID uint64, address common.Address, block *big.Int) error

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

type Controller struct {
	TransferFeed *event.Feed
	// contains filtered or unexported fields
}

func NewTransferController

func NewTransferController(db *sql.DB, rpcClient *rpc.Client, accountFeed *event.Feed) *Controller

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 (c *Controller) GetTransfersByAddress(ctx context.Context, chainID uint64, address common.Address, toBlock, limit *hexutil.Big, fetchMore bool) ([]View, error)

func (*Controller) LoadTransferByHash added in v0.91.10

func (c *Controller) LoadTransferByHash(ctx context.Context, rpcClient *rpc.Client, address common.Address, hash common.Hash) error

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 NewDB

func NewDB(client *sql.DB) *Database

func (*Database) Close

func (db *Database) Close() error

Close closes database.

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 (db *Database) GetPreloadedTransactions(chainID uint64, address common.Address, blockHash common.Hash) (rst []Transfer, err error)

func (*Database) GetTransactionsLog

func (db *Database) GetTransactionsLog(chainID uint64, address common.Address, transactionHash common.Hash) (*types.Log, error)

func (*Database) GetTransfers

func (db *Database) GetTransfers(chainID uint64, start, end *big.Int) (rst []Transfer, err error)

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 (db *Database) InsertBlock(chainID uint64, account common.Address, blockNumber *big.Int, blockHash common.Hash) error

func (*Database) ProcessBlocks

func (db *Database) ProcessBlocks(chainID uint64, account common.Address, from *big.Int, to *LastKnownBlock, headers []*DBHeader) (err error)

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

func (db *Database) SaveBlocks(chainID uint64, account common.Address, headers []*DBHeader) (err error)

func (*Database) SaveHeaders

func (db *Database) SaveHeaders(chainID uint64, headers []*types.Header, address common.Address) (err error)

SaveHeaders stores a list of headers atomically.

func (*Database) SaveTranfers

func (db *Database) SaveTranfers(chainID uint64, address common.Address, transfers []Transfer, blocks []*big.Int) (err error)

SaveTranfers

type Downloader

type Downloader interface {
	GetTransfersByNumber(context.Context, *big.Int) ([]Transfer, error)
}

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

func (d *ETHDownloader) GetTransfersByNumber(ctx context.Context, number *big.Int) ([]Transfer, error)

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

func (d *IterativeDownloader) Next(parent context.Context) ([]*DBHeader, *big.Int, *big.Int, error)

Next moves closer to the end on every new iteration.

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.

func (*JSONBlob) Scan

func (blob *JSONBlob) Scan(value interface{}) error

Scan implements interface.

func (*JSONBlob) Value

func (blob *JSONBlob) Value() (driver.Value, error)

Value implements interface.

type LastKnownBlock

type LastKnownBlock struct {
	Number  *big.Int
	Balance *big.Int
	Nonce   *int64
}

type LastKnownBlockView

type LastKnownBlockView struct {
	Address common.Address `json:"address"`
	Number  *big.Int       `json:"blockNumber"`
	Balance bigint.BigInt  `json:"balance"`
	Nonce   *int64         `json:"nonce"`
}

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

func (r *Result) Get() []Transfer

func (*Result) GetHeaders

func (r *Result) GetHeaders() []*DBHeader

func (*Result) GetRanges

func (r *Result) GetRanges() [][]*big.Int

func (*Result) Push

func (r *Result) Push(transfers ...Transfer)

func (*Result) PushHeader

func (r *Result) PushHeader(block *DBHeader)

func (*Result) PushRange

func (r *Result) PushRange(blockRange []*big.Int)

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 Type

type Type string

Type type of the asset that was transferred.

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.

func CastToTransferView

func CastToTransferView(t Transfer) View

Jump to

Keyboard shortcuts

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