Documentation ¶
Index ¶
- Constants
- type Scanner
- func (s *Scanner) SaveHolders(ctx context.Context, token *ScannerToken, holders map[common.Address]*big.Int, ...) error
- func (s *Scanner) ScanHolders(ctx context.Context, token *ScannerToken) (map[common.Address]*big.Int, uint64, uint64, bool, *big.Int, error)
- func (s *Scanner) SetProviders(newProviders ...providers.HolderProvider) error
- func (s *Scanner) Start(ctx context.Context)
- func (s *Scanner) Stop()
- func (s *Scanner) TokensToScan(ctx context.Context) ([]*ScannerToken, error)
- type ScannerToken
Constants ¶
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner is the scanner that scans the tokens and saves the holders in the database. It has a list of tokens to scan and a list of providers to get the holders of the tokens. It has a cool down time between iterations to avoid overloading the providers.
func NewScanner ¶
NewScanner returns a new scanner instance with the required parameters initialized.
func (*Scanner) SaveHolders ¶
func (s *Scanner) SaveHolders(ctx context.Context, token *ScannerToken, holders map[common.Address]*big.Int, newTransfers, lastBlock uint64, synced bool, totalSupply *big.Int, ) error
SaveHolders saves the given holders in the database. It updates the token synced status if it is different from the received one. Then, it creates, updates or deletes the token holders in the database depending on the calculated balance. WARNING: the following code could produce holders with negative balances in the database. This is because the scanner does not know if the token holder is a contract or not, so it does not know if the balance is correct or not. The scanner assumes that the balance is correct and updates it in the database:
- To get the correct holders from the database you must filter the holders with negative balances.
- To get the correct balances you must use the contract methods to get the balances of the holders.
func (*Scanner) ScanHolders ¶
func (s *Scanner) ScanHolders(ctx context.Context, token *ScannerToken) ( map[common.Address]*big.Int, uint64, uint64, bool, *big.Int, error, )
ScanHolders scans the holders of the given token. It get the current holders from the database, set them into the provider and get the new ones. It returns the new holders, the last block scanned and if the token is synced after the scan.
func (*Scanner) SetProviders ¶
func (s *Scanner) SetProviders(newProviders ...providers.HolderProvider) error
SetProviders sets the providers that the scanner will use to get the holders of the tokens. It also creates the token types in the database if they do not exist. It returns an error something goes wrong creating the token types in the database.
func (*Scanner) Start ¶
Start starts the scanner. It starts a loop that scans the tokens in the database and saves the holders in the database. It stops when the context is cancelled.
func (*Scanner) Stop ¶
func (s *Scanner) Stop()
Stop stops the scanner. It cancels the context and waits for the scanner to finish. It also closes the providers.
func (*Scanner) TokensToScan ¶
func (s *Scanner) TokensToScan(ctx context.Context) ([]*ScannerToken, error)
TokensToScan returns the tokens that the scanner has to scan. It returns the the tokens to scan from the database in the following order:
- The tokens that were created in the last 60 minutes and are not synced.
- The rest of no synced tokens, sorted by the difference between their block number and the last block number of their chain.
- The tokens that were synced in previous iterations.