Documentation ¶
Index ¶
- Variables
- func GetTokensBalances(parent context.Context, client *walletClient, ...) (map[common.Address]map[common.Address]*hexutil.Big, error)
- func IsTokenTransfer(logs []*types.Log) bool
- func WatchAccountsChanges(ctx context.Context, feed *event.Feed, initial []common.Address, ...) error
- type API
- func (api *API) AddCustomToken(ctx context.Context, token Token) error
- func (api *API) AddFavourite(ctx context.Context, favourite Favourite) error
- func (api *API) CheckRecentHistory(ctx context.Context, addresses []common.Address) error
- func (api *API) DeleteCustomToken(ctx context.Context, address common.Address) error
- func (api *API) DeletePendingTransaction(ctx context.Context, transactionHash common.Hash) error
- func (api *API) GetCryptoOnRamps(ctx context.Context) ([]CryptoOnRamp, error)
- func (api *API) GetCustomTokens(ctx context.Context) ([]*Token, error)
- func (api *API) GetFavourites(ctx context.Context) ([]*Favourite, error)
- func (api *API) GetPendingOutboundTransactionsByAddress(ctx context.Context, address common.Address) ([]*PendingTransaction, error)
- func (api *API) GetPendingTransactions(ctx context.Context) ([]*PendingTransaction, error)
- func (api *API) GetTokensBalances(ctx context.Context, accounts, tokens []common.Address) (map[common.Address]map[common.Address]*hexutil.Big, error)
- func (api *API) GetTransfersByAddress(ctx context.Context, address common.Address, toBlock, limit *hexutil.Big, ...) ([]TransferView, error)
- func (api *API) SetInitialBlocksRange(ctx context.Context) error
- func (api *API) StorePendingTransaction(ctx context.Context, trx PendingTransaction) error
- func (api *API) WatchTransaction(ctx context.Context, transactionHash common.Hash) error
- type AtomicGroup
- type BalanceCache
- type BalanceReader
- type BatchDownloader
- type BlocksRange
- type Command
- type ConcurrentDownloader
- type CryptoOnRamp
- type CryptoOnRampManager
- type CryptoOnRampOptions
- type DBHeader
- type DataSourceType
- type Database
- func (db *Database) AddCustomToken(token Token) error
- func (db *Database) AddFavourite(favourite Favourite) error
- func (db Database) Close() error
- func (db *Database) DeleteCustomToken(address common.Address) error
- func (db *Database) DeletePendingTransaction(transactionHash common.Hash) error
- func (db *Database) GetBlocks() (rst []*DBHeader, err error)
- func (db *Database) GetBlocksByAddress(address common.Address, limit int) (rst []*big.Int, err error)
- func (db *Database) GetCustomTokens() ([]*Token, error)
- func (db *Database) GetFavourites() ([]*Favourite, error)
- func (db *Database) GetFirstKnownBlock(address common.Address) (rst *big.Int, err error)
- func (db *Database) GetHeaderByNumber(number *big.Int) (header *DBHeader, err error)
- func (db *Database) GetLastBlockByAddress(address common.Address, limit int) (rst *big.Int, err error)
- func (db *Database) GetLastKnownBlockByAddress(address common.Address) (block *LastKnownBlock, err error)
- func (db *Database) GetLastKnownBlockByAddresses(addresses []common.Address) (map[common.Address]*LastKnownBlock, []common.Address, error)
- func (db *Database) GetLastSavedBlock() (rst *DBHeader, err error)
- func (db *Database) GetLastSavedBlockBefore(block *big.Int) (rst *DBHeader, err error)
- func (db *Database) GetPendingOutboundTransactionsByAddress(address common.Address) ([]*PendingTransaction, error)
- func (db *Database) GetPendingTransactions() ([]*PendingTransaction, error)
- func (db *Database) GetPreloadedTransactions(address common.Address, blockHash common.Hash) (rst []Transfer, err error)
- func (db *Database) GetTransactionsLog(address common.Address, transactionHash common.Hash) (*types.Log, error)
- func (db *Database) GetTransfers(start, end *big.Int) (rst []Transfer, err error)
- func (db *Database) GetTransfersByAddress(address common.Address, toBlock *big.Int, limit int64) (rst []Transfer, err error)
- func (db *Database) GetTransfersByAddressAndBlock(address common.Address, block *big.Int, limit int64) (rst []Transfer, err error)
- func (db *Database) GetTransfersInRange(address common.Address, start, end *big.Int) (rst []Transfer, err error)
- func (db Database) ProcessBlocks(account common.Address, from *big.Int, to *LastKnownBlock, headers []*DBHeader) (err error)
- func (db Database) ProcessTranfers(transfers []Transfer, removed []*DBHeader) (err error)
- func (db *Database) RemoveBlockWithTransfer(address common.Address, block *big.Int) error
- func (db Database) SaveBlocks(account common.Address, headers []*DBHeader) (err error)
- func (db *Database) SaveHeaders(headers []*types.Header, address common.Address) (err error)
- func (db Database) SaveTranfers(address common.Address, transfers []Transfer, blocks []*big.Int) (err error)
- func (db *Database) StorePendingTransaction(trx PendingTransaction) error
- func (db *Database) UpsertRange(account common.Address, network uint64, from, to, balance *big.Int, ...) error
- type ERC20TransfersDownloader
- type ETHTransferDownloader
- type Event
- type EventType
- type Favourite
- type FiniteCommand
- type Group
- type HeaderReader
- type InfiniteCommand
- type IterativeDownloader
- type JSONBlob
- type LastKnownBlock
- type PendingTransaction
- type PendingTrxType
- type Reactor
- type Result
- type SQLBigInt
- type SQLBigIntBytes
- type Service
- func (s *Service) APIs() []rpc.API
- func (s *Service) GetFeed() *event.Feed
- func (s *Service) IsStarted() bool
- func (s *Service) MergeBlocksRanges(accounts []common.Address, chain uint64) error
- func (s *Service) Protocols() []p2p.Protocol
- func (s *Service) SetClient(client *ethclient.Client)
- func (s *Service) SetInitialBlocksRange(network uint64) error
- func (s *Service) Start(*p2p.Server) error
- func (s *Service) StartReactor(client *ethclient.Client, accounts []common.Address, chain *big.Int) error
- func (s *Service) Stop() error
- func (s *Service) StopReactor() error
- type SignalsTransmitter
- type SyncOption
- type Token
- type Transfer
- type TransferDownloader
- type TransferType
- type TransferView
Constants ¶
This section is empty.
Variables ¶
var ( // ErrServiceNotInitialized returned when wallet is not initialized/started,. ErrServiceNotInitialized = errors.New("wallet service is not initialized") )
Functions ¶
func GetTokensBalances ¶
func GetTokensBalances(parent context.Context, client *walletClient, accounts, tokens []common.Address) (map[common.Address]map[common.Address]*hexutil.Big, error)
GetTokensBalances takes list of accounts and tokens and returns mapping of token balances for each account.
func IsTokenTransfer ¶ added in v0.39.6
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API is class with methods available over RPC.
func (*API) AddCustomToken ¶ added in v0.38.1
func (*API) AddFavourite ¶ added in v0.62.2
func (*API) CheckRecentHistory ¶ added in v0.75.0
func (*API) DeleteCustomToken ¶ added in v0.38.1
func (*API) DeletePendingTransaction ¶ added in v0.62.0
func (*API) GetCryptoOnRamps ¶ added in v0.71.4
func (api *API) GetCryptoOnRamps(ctx context.Context) ([]CryptoOnRamp, error)
func (*API) GetCustomTokens ¶ added in v0.38.1
func (*API) GetFavourites ¶ added in v0.62.2
func (*API) GetPendingOutboundTransactionsByAddress ¶ added in v0.62.0
func (*API) GetPendingTransactions ¶ added in v0.62.0
func (api *API) GetPendingTransactions(ctx context.Context) ([]*PendingTransaction, error)
func (*API) GetTokensBalances ¶
func (api *API) GetTokensBalances(ctx context.Context, accounts, tokens []common.Address) (map[common.Address]map[common.Address]*hexutil.Big, error)
GetTokensBalances return mapping of token balances for every account.
func (*API) GetTransfersByAddress ¶
func (api *API) GetTransfersByAddress(ctx context.Context, address common.Address, toBlock, limit *hexutil.Big, fetchMore bool) ([]TransferView, error)
GetTransfersByAddress returns transfers for a single address
func (*API) SetInitialBlocksRange ¶ added in v0.73.1
SetInitialBlocksRange sets initial blocks range
func (*API) StorePendingTransaction ¶ added in v0.62.0
func (api *API) StorePendingTransaction(ctx context.Context, trx PendingTransaction) error
type AtomicGroup ¶
type AtomicGroup struct {
// contains filtered or unexported fields
}
AtomicGroup terminates as soon as first goroutine terminates..
func NewAtomicGroup ¶
func NewAtomicGroup(parent context.Context) *AtomicGroup
func (*AtomicGroup) Add ¶
func (d *AtomicGroup) Add(cmd Command)
Go spawns function in a goroutine and stores results or errors.
func (*AtomicGroup) Error ¶
func (d *AtomicGroup) Error() error
Error stores an error that was reported by any of the downloader. Should be called after Wait.
func (*AtomicGroup) Stop ¶
func (d *AtomicGroup) Stop()
func (*AtomicGroup) WaitAsync ¶
func (d *AtomicGroup) WaitAsync() <-chan struct{}
type BalanceCache ¶ added in v0.40.0
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 BlocksRange ¶ added in v0.70.1
type BlocksRange struct {
// contains filtered or unexported fields
}
type ConcurrentDownloader ¶
type ConcurrentDownloader struct { *AtomicGroup *Result }
func NewConcurrentDownloader ¶
func NewConcurrentDownloader(ctx context.Context) *ConcurrentDownloader
NewConcurrentDownloader creates ConcurrentDownloader instance.
type CryptoOnRamp ¶ added in v0.71.4
type CryptoOnRampManager ¶ added in v0.71.4
func NewCryptoOnRampManager ¶ added in v0.71.4
func NewCryptoOnRampManager(options *CryptoOnRampOptions) *CryptoOnRampManager
func (*CryptoOnRampManager) Get ¶ added in v0.71.4
func (c *CryptoOnRampManager) Get() ([]CryptoOnRamp, error)
type CryptoOnRampOptions ¶ added in v0.71.4
type CryptoOnRampOptions struct {
// contains filtered or unexported fields
}
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 DataSourceType ¶ added in v0.71.4
type DataSourceType int
const ( DataSourceHTTP DataSourceType = iota + 1 DataSourceStatic )
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database sql wrapper for operations with wallet objects.
func (*Database) AddCustomToken ¶ added in v0.38.1
func (*Database) AddFavourite ¶ added in v0.62.2
func (*Database) DeleteCustomToken ¶ added in v0.38.1
func (*Database) DeletePendingTransaction ¶ added in v0.62.0
func (*Database) GetBlocksByAddress ¶ added in v0.40.0
func (db *Database) GetBlocksByAddress(address common.Address, limit int) (rst []*big.Int, err error)
GetBlocksByAddress loads blocks for a given address.
func (*Database) GetCustomTokens ¶ added in v0.38.1
func (*Database) GetFavourites ¶ added in v0.62.2
func (*Database) GetFirstKnownBlock ¶ added in v0.40.0
func (*Database) GetHeaderByNumber ¶
GetHeaderByNumber selects header using block number.
func (*Database) GetLastBlockByAddress ¶ added in v0.40.0
func (*Database) GetLastKnownBlockByAddress ¶ added in v0.40.0
func (db *Database) GetLastKnownBlockByAddress(address common.Address) (block *LastKnownBlock, err error)
func (*Database) GetLastKnownBlockByAddresses ¶ added in v0.40.0
func (*Database) GetLastSavedBlock ¶ added in v0.40.0
func (*Database) GetLastSavedBlockBefore ¶ added in v0.40.0
func (*Database) GetPendingOutboundTransactionsByAddress ¶ added in v0.62.0
func (db *Database) GetPendingOutboundTransactionsByAddress(address common.Address) ([]*PendingTransaction, error)
func (*Database) GetPendingTransactions ¶ added in v0.62.0
func (db *Database) GetPendingTransactions() ([]*PendingTransaction, error)
func (*Database) GetPreloadedTransactions ¶ added in v0.40.0
func (*Database) GetTransactionsLog ¶ added in v0.40.0
func (*Database) GetTransfers ¶
GetTransfers load transfers transfer betweeen two blocks.
func (*Database) GetTransfersByAddress ¶
func (db *Database) GetTransfersByAddress(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 ¶ added in v0.62.16
func (db *Database) GetTransfersByAddressAndBlock(address common.Address, block *big.Int, limit int64) (rst []Transfer, err error)
GetTransfersByAddressAndBlock loads transfers for a given address and block.
func (*Database) GetTransfersInRange ¶ added in v0.40.0
func (db *Database) GetTransfersInRange(address common.Address, start, end *big.Int) (rst []Transfer, err error)
GetTransfersInRange loads transfers for a given address between two blocks.
func (Database) ProcessBlocks ¶ added in v0.40.0
func (Database) ProcessTranfers ¶
ProcessTranfers atomically adds/removes blocks and adds new tranfers.
func (*Database) RemoveBlockWithTransfer ¶ added in v0.40.0
func (Database) SaveBlocks ¶ added in v0.40.0
func (*Database) SaveHeaders ¶
SaveHeaders stores a list of headers atomically.
func (Database) SaveTranfers ¶ added in v0.40.0
func (db Database) SaveTranfers(address common.Address, transfers []Transfer, blocks []*big.Int) (err error)
SaveTranfers
func (*Database) StorePendingTransaction ¶ added in v0.62.0
func (db *Database) StorePendingTransaction(trx PendingTransaction) error
type ERC20TransfersDownloader ¶
type ERC20TransfersDownloader struct {
// contains filtered or unexported fields
}
ERC20TransfersDownloader is a downloader for erc20 tokens transfers.
func NewERC20TransfersDownloader ¶
func NewERC20TransfersDownloader(client *walletClient, accounts []common.Address, signer types.Signer) *ERC20TransfersDownloader
NewERC20TransfersDownloader returns new instance.
func (*ERC20TransfersDownloader) GetHeadersInRange ¶ added in v0.40.0
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 ETHTransferDownloader ¶
type ETHTransferDownloader struct {
// contains filtered or unexported fields
}
ETHTransferDownloader downloads regular eth transfers.
func (*ETHTransferDownloader) GetTransfers ¶
func (d *ETHTransferDownloader) 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 (*ETHTransferDownloader) 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 wallet 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 FiniteCommand ¶
FiniteCommand terminates when error is nil.
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 InfiniteCommand ¶
InfiniteCommand runs until context is closed.
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) 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 LastKnownBlock ¶ added in v0.73.4
type PendingTransaction ¶ added in v0.62.0
type PendingTrxType ¶ added in v0.62.0
type PendingTrxType string
const ( RegisterENS PendingTrxType = "RegisterENS" ReleaseENS PendingTrxType = "ReleaseENS" SetPubKey PendingTrxType = "SetPubKey" BuyStickerPack PendingTrxType = "BuyStickerPack" WalletTransfer PendingTrxType = "WalletTransfer" )
type Reactor ¶
type Reactor struct {
// contains filtered or unexported fields
}
Reactor listens to new blocks and stores transfers into the database.
func NewReactor ¶
NewReactor creates instance of the Reactor.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
func (*Result) GetHeaders ¶ added in v0.40.0
func (*Result) PushHeader ¶ added in v0.40.0
type SQLBigInt ¶
SQLBigInt type for storing uint256 in the databse. FIXME(dshulyak) SQL big int is max 64 bits. Maybe store as bytes in big endian and hope that lexographical sorting will work.
type SQLBigIntBytes ¶ added in v0.73.4
SQLBigIntBytes type for storing big.Int as BLOB in the databse.
func (*SQLBigIntBytes) Scan ¶ added in v0.73.4
func (i *SQLBigIntBytes) Scan(value interface{}) error
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is a wallet service.
func NewService ¶
NewService initializes service instance.
func (*Service) MergeBlocksRanges ¶ added in v0.70.1
MergeBlocksRanges merge old blocks ranges if possible
func (*Service) SetInitialBlocksRange ¶ added in v0.73.1
func (*Service) StartReactor ¶
func (s *Service) StartReactor(client *ethclient.Client, accounts []common.Address, chain *big.Int) error
StartReactor separately because it requires known ethereum address, which will become available only after login.
func (*Service) StopReactor ¶
StopReactor stops reactor and closes database.
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 Token ¶ added in v0.38.1
type Token struct { Address common.Address `json:"address"` Name string `json:"name"` Symbol string `json:"symbol"` Color string `json:"color"` // Decimals defines how divisible the token is. For example, 0 would be // indivisible, whereas 18 would allow very small amounts of the token // to be traded. Decimals uint `json:"decimals"` }
type Transfer ¶
type Transfer struct { Type TransferType `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 TransferDownloader ¶
type TransferDownloader interface {
GetTransfersByNumber(context.Context, *big.Int) ([]Transfer, error)
}
TransferDownloader downloads transfers from single block using number.
type TransferView ¶
type TransferView struct { ID common.Hash `json:"id"` Type TransferType `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"` 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 }
TransferView stores only fields used by a client and ensures that all relevant fields are encoded in hex.
func CastToTransferView ¶ added in v0.62.16
func CastToTransferView(t Transfer) TransferView
CastToTransferView transforms a raw Transfer into an enriched one