Documentation
¶
Index ¶
- Variables
- func GetTokensBalances(parent context.Context, client *ethclient.Client, ...) (map[common.Address]map[common.Address]*big.Int, error)
- type API
- func (api *API) GetTokensBalances(ctx context.Context, accounts, tokens []common.Address) (map[common.Address]map[common.Address]*big.Int, error)
- func (api *API) GetTransfers(ctx context.Context, start, end *hexutil.Big) ([]TransferView, error)
- func (api *API) GetTransfersByAddress(ctx context.Context, address common.Address, start, end *hexutil.Big) ([]TransferView, error)
- type AtomicGroup
- type BalanceReader
- type BatchDownloader
- type Command
- type ConcurrentDownloader
- type DBHeader
- type Database
- func (db Database) Close() error
- func (db *Database) GetHeaderByNumber(number *big.Int) (header *DBHeader, err error)
- func (db *Database) GetLastHead() (header *DBHeader, err error)
- func (db *Database) GetLatestSynced(address common.Address, option SyncOption) (header *DBHeader, err error)
- func (db *Database) GetTransfers(start, end *big.Int) (rst []Transfer, err error)
- func (db *Database) GetTransfersByAddress(address common.Address, start, end *big.Int) (rst []Transfer, err error)
- func (db *Database) HeaderExists(hash common.Hash) (bool, error)
- func (db Database) ProcessTranfers(transfers []Transfer, accounts []common.Address, added, removed []*DBHeader, ...) (err error)
- func (db *Database) SaveHeaders(headers []*types.Header) (err error)
- func (db *Database) SaveSyncedHeader(address common.Address, header *types.Header, option SyncOption) (err error)
- type ERC20TransfersDownloader
- type ETHTransferDownloader
- type Event
- type EventType
- type FiniteCommand
- type Group
- type HeaderReader
- type InfiniteCommand
- type IterativeDownloader
- type JSONBlob
- type Reactor
- type Result
- type SQLBigInt
- type Service
- func (s *Service) APIs() []rpc.API
- func (s *Service) Protocols() []p2p.Protocol
- func (s *Service) Start(*p2p.Server) error
- func (s *Service) StartReactor(dbpath, password string, client *ethclient.Client, accounts []common.Address, ...) error
- func (s *Service) Stop() error
- func (s *Service) StopReactor() error
- type SignalsTransmitter
- type SyncOption
- 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 ¶
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API is class with methods available over RPC.
func (*API) GetTokensBalances ¶
func (api *API) GetTokensBalances(ctx context.Context, accounts, tokens []common.Address) (map[common.Address]map[common.Address]*big.Int, error)
GetTokensBalances return mapping of token balances for every account.
func (*API) GetTransfers ¶
GetTransfers returns transfers in range of blocks. If `end` is nil all transfers from `start` will be returned. TODO(dshulyak) benchmark loading many transfers from database. We can avoid json unmarshal/marshal if we will read header, tx and receipt as a raw json.
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 BalanceReader ¶
type BalanceReader interface {
BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
}
BalanceReader interface for reading balance at a specifeid address.
type BatchDownloader ¶
type BatchDownloader interface {
GetTransfersInRange(ctx context.Context, from, to *big.Int) ([]Transfer, error)
}
BatchDownloader interface for loading transfers in batches in speificed range of blocks.
type ConcurrentDownloader ¶
type ConcurrentDownloader struct { *AtomicGroup *Result }
func NewConcurrentDownloader ¶
func NewConcurrentDownloader(ctx context.Context) *ConcurrentDownloader
NewConcurrentDownloader creates ConcurrentDownloader instance.
type DBHeader ¶
type DBHeader struct { Number *big.Int Hash common.Hash Timestamp uint64 // Head is true if the block was a head at the time it was pulled from chain. Head 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 InitializeDB ¶
InitializeDB creates db file at a given path and applies migrations.
func (*Database) GetHeaderByNumber ¶
GetHeaderByNumber selects header using block number.
func (*Database) GetLastHead ¶
func (*Database) GetLatestSynced ¶
func (db *Database) GetLatestSynced(address common.Address, option SyncOption) (header *DBHeader, err error)
GetLatestSynced downloads last synced block with a given option.
func (*Database) GetTransfers ¶
GetTransfers load transfers transfer betweeen two blocks.
func (*Database) GetTransfersByAddress ¶
func (db *Database) GetTransfersByAddress(address common.Address, start, end *big.Int) (rst []Transfer, err error)
GetTransfersByAddress loads transfers for a given address between two blocks.
func (*Database) HeaderExists ¶
HeaderExists checks if header with hash exists in db.
func (Database) ProcessTranfers ¶
func (db Database) ProcessTranfers(transfers []Transfer, accounts []common.Address, added, removed []*DBHeader, option SyncOption) (err error)
ProcessTranfers atomically adds/removes blocks and adds new tranfers.
func (*Database) SaveHeaders ¶
SaveHeaders stores a list of headers atomically.
func (*Database) SaveSyncedHeader ¶
type ERC20TransfersDownloader ¶
type ERC20TransfersDownloader struct {
// contains filtered or unexported fields
}
ERC20TransfersDownloader is a downloader for erc20 tokens transfers.
func NewERC20TransfersDownloader ¶
func NewERC20TransfersDownloader(client *ethclient.Client, accounts []common.Address, signer types.Signer) *ERC20TransfersDownloader
NewERC20TransfersDownloader returns new instance.
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.
func (*ERC20TransfersDownloader) GetTransfersInRange ¶
func (d *ERC20TransfersDownloader) GetTransfersInRange(parent context.Context, from, to *big.Int) ([]Transfer, error)
GetTransfersInRange returns transfers between two blocks. time to get logs for 100000 blocks = 1.144686979s. with 249 events in the result set.
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"` }
Event is a type for wallet events.
type EventType ¶
type EventType string
EventType type for event types.
const ( // EventNewBlock emitted when new block was added to the same canonical chan. EventNewBlock EventType = "newblock" // EventReorg emitted when canonical chain was changed. In this case, BlockNumber will be an earliest added block. EventReorg EventType = "reorg" // EventNewHistory emitted if transfer from older block was added. EventNewHistory EventType = "history" )
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, option SyncOption, downloader BatchDownloader, size *big.Int, to *DBHeader) (*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() *DBHeader
Header return last synced header.
func (*IterativeDownloader) Next ¶
func (d *IterativeDownloader) Next(parent context.Context) ([]Transfer, 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.
type Reactor ¶
type Reactor struct {
// contains filtered or unexported fields
}
Reactor listens to new blocks and stores transfers into the database.
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 Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is a wallet service.
func (*Service) StartReactor ¶
func (s *Service) StartReactor(dbpath, password string, 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 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"` // 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"` }
TransferView stores only fields used by a client and ensures that all relevant fields are encoded in hex.