transfer

package
v0.147.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MPL-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EventNewTransfers emitted when new block was added to the same canonical chan.
	EventNewTransfers walletevent.EventType = "new-transfers"
	// EventFetchingRecentHistory emitted when fetching of lastest tx history is started
	EventFetchingRecentHistory walletevent.EventType = "recent-history-fetching"
	// EventRecentHistoryReady emitted when fetching of lastest tx history is started
	EventRecentHistoryReady walletevent.EventType = "recent-history-ready"
	// EventFetchingHistoryError emitted when fetching of tx history failed
	EventFetchingHistoryError walletevent.EventType = "fetching-history-error"
	// EventNonArchivalNodeDetected emitted when a connection to a non archival node is detected
	EventNonArchivalNodeDetected walletevent.EventType = "non-archival-node-detected"
)
View Source
const (
	MultiTransactionSend = iota
	MultiTransactionSwap
	MultiTransactionBridge
)
View Source
const (
	NoMultiTransactionID = MultiTransactionIDType(0)
)

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, transferFeed *event.Feed, transactionManager *TransactionManager) *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 *big.Int, limit int64, 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()

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) ProcessTransfers added in v0.135.2

func (db *Database) ProcessTransfers(chainID uint64, transfers []Transfer, removed []*DBHeader) (err error)

ProcessTransfers atomically adds/removes blocks and adds new transfers.

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) SaveTransfers added in v0.135.2

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

SaveTransfers

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 and erc721 tokens transfers. Since both transaction types share the same signature, both will be assigned type erc20Transfer. Until the downloader gets refactored and a migration of the database gets implemented, differentiation between erc20 and erc721 will handled in the controller.

func NewERC20TransfersDownloader

func NewERC20TransfersDownloader(client *chain.ClientWithFallback, 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 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) (*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 MultiTransaction added in v0.135.2

type MultiTransaction struct {
	ID          uint                 `json:"id"`
	Timestamp   uint64               `json:"timestamp"`
	FromAddress common.Address       `json:"fromAddress"`
	ToAddress   common.Address       `json:"toAddress"`
	FromAsset   string               `json:"fromAsset"`
	ToAsset     string               `json:"toAsset"`
	FromAmount  *hexutil.Big         `json:"fromAmount"`
	Type        MultiTransactionType `json:"type"`
}

type MultiTransactionIDType added in v0.135.2

type MultiTransactionIDType int64

type MultiTransactionResult added in v0.135.2

type MultiTransactionResult struct {
	ID     int64                   `json:"id"`
	Hashes map[uint64][]types.Hash `json:"hashes"`
}

type MultiTransactionType added in v0.135.2

type MultiTransactionType uint8

type PendingTransaction added in v0.135.2

type PendingTransaction struct {
	Hash               common.Hash            `json:"hash"`
	Timestamp          uint64                 `json:"timestamp"`
	Value              bigint.BigInt          `json:"value"`
	From               common.Address         `json:"from"`
	To                 common.Address         `json:"to"`
	Data               string                 `json:"data"`
	Symbol             string                 `json:"symbol"`
	GasPrice           bigint.BigInt          `json:"gasPrice"`
	GasLimit           bigint.BigInt          `json:"gasLimit"`
	Type               PendingTrxType         `json:"type"`
	AdditionalData     string                 `json:"additionalData"`
	ChainID            uint64                 `json:"network_id"`
	MultiTransactionID MultiTransactionIDType `json:"multi_transaction_id"`
}

type PendingTrxType added in v0.135.2

type PendingTrxType string
const (
	RegisterENS           PendingTrxType = "RegisterENS"
	ReleaseENS            PendingTrxType = "ReleaseENS"
	SetPubKey             PendingTrxType = "SetPubKey"
	BuyStickerPack        PendingTrxType = "BuyStickerPack"
	WalletTransfer        PendingTrxType = "WalletTransfer"
	CollectibleDeployment PendingTrxType = "CollectibleDeployment"
	CollectibleAirdrop    PendingTrxType = "CollectibleAirdrop"
)

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 SyncOption

type SyncOption uint

SyncOption is used to specify that application processed transfers for that block.

type TransactionManager added in v0.135.2

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

func NewTransactionManager added in v0.135.2

func NewTransactionManager(db *sql.DB, gethManager *account.GethManager, transactor *transactions.Transactor,
	config *params.NodeConfig, accountsDB *accounts.Database) *TransactionManager

func (*TransactionManager) AddPending added in v0.135.2

func (tm *TransactionManager) AddPending(transaction PendingTransaction) error

func (*TransactionManager) CreateMultiTransaction added in v0.135.2

func (tm *TransactionManager) CreateMultiTransaction(ctx context.Context, multiTransaction *MultiTransaction, data []*bridge.TransactionBridge, bridges map[string]bridge.Bridge, password string) (*MultiTransactionResult, error)

func (*TransactionManager) DeletePending added in v0.135.2

func (tm *TransactionManager) DeletePending(chainID uint64, hash common.Hash) error

func (*TransactionManager) GetAllPending added in v0.135.2

func (tm *TransactionManager) GetAllPending(chainIDs []uint64) ([]*PendingTransaction, error)

func (*TransactionManager) GetMultiTransactions added in v0.138.1

func (tm *TransactionManager) GetMultiTransactions(ctx context.Context, ids []MultiTransactionIDType) ([]*MultiTransaction, error)

func (*TransactionManager) GetPendingByAddress added in v0.135.2

func (tm *TransactionManager) GetPendingByAddress(chainIDs []uint64, address common.Address) ([]*PendingTransaction, error)

func (*TransactionManager) GetPendingEntry added in v0.135.2

func (tm *TransactionManager) GetPendingEntry(chainID uint64, hash common.Hash) (*PendingTransaction, error)

GetPendingEntry returns sql.ErrNoRows if no pending transaction is found for the given identity

func (*TransactionManager) Watch added in v0.135.2

func (tm *TransactionManager) Watch(ctx context.Context, transactionHash common.Hash, client *chain.ClientWithFallback) error

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"`
	BaseGasFees string
	// Internal field that is used to track multi-transaction transfers.
	MultiTransactionID MultiTransactionIDType `json:"multi_transaction_id"`
}

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"`
	EffectiveTip         *hexutil.Big   `json:"effectiveTip"`
	EffectiveGasPrice    *hexutil.Big   `json:"effectiveGasPrice"`
	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"`   // Only used for Type ethTransfer and erc20Transfer
	TokenID              *hexutil.Big   `json:"tokenId"` // Only used for Type erc721Transfer
	From                 common.Address `json:"from"`
	To                   common.Address `json:"to"`
	Contract             common.Address `json:"contract"`
	NetworkID            uint64         `json:"networkId"`
	MultiTransactionID   int64          `json:"multiTransactionID"`
	BaseGasFees          string         `json:"base_gas_fee"`
}

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