scanner

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	READ_TIMEOUT = time.Minute
	SCAN_TIMEOUT = 5 * time.Minute
	SAVE_TIMEOUT = time.Minute
)

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

func NewScanner(db *db.DB, networks web3.NetworkEndpoints, coolDown time.Duration) *Scanner

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:

  1. To get the correct holders from the database you must filter the holders with negative balances.
  2. 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

func (s *Scanner) Start(ctx context.Context)

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:

  1. The tokens that were created in the last 60 minutes and are not synced.
  2. The rest of no synced tokens, sorted by the difference between their block number and the last block number of their chain.
  3. The tokens that were synced in previous iterations.

type ScannerToken

type ScannerToken struct {
	Address    common.Address
	ChainID    uint64
	Type       uint64
	ExternalID string
	LastBlock  uint64
	Ready      bool
	Synced     bool
	// contains filtered or unexported fields
}

ScannerToken includes the information of a token that the scanner needs to scan it.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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