-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan_task.go
57 lines (42 loc) · 1.69 KB
/
scan_task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package scanner
import (
"context"
"math/big"
"time"
"github.com/ethereum/go-ethereum"
"gorm.io/gorm"
)
// ScanTask defines an interface where developers can extend to implements different
// block scanner.
type ScanTask interface {
// Name returns the name of a task. The name should be unique
Name() string
// Enabled returns whether the task is enabled
Enabled() bool
// StartBlock returns the start block of the task if the task is new
StartBlock() uint64
// BlockBatchSize returns the maxmium range of new blocks that this task wants to be notified
BlockBatchSize() *big.Int
// PullInterval returns the interval of polling for new block
PullInterval() time.Duration
// SetEthClient is called by the scanner to set an ethereum client to this task
SetEthClient(client *RetryableEthclient)
// NeedBlockInfo returns a boolean value to indicate whether the scanner should pass block information or not
NeedBlockInfo() bool
// SkipWhenNoLogs returns a boolean value to indicate whether the scanner should skip block
SkipWhenNoLogs() bool
// LogFilter returns the filters use to query logs. If nil is returned, no logs will be downloaded
LogFilter() []*ethereum.FilterQuery
// OnNewBlock is fired when new block is downloaded
OnNewBlock(ctx context.Context, block *BlockInfo, db *gorm.DB) error
// OnBlockCommited is fired after the scanner commited the database changed
OnBlockCommitted(ctx context.Context, block *BlockInfo) error
}
type ScanTaskOverridesEthRpcURL interface {
// EthRpcUrl returns the URL to an etheruem network RPC endpoint
EthRpcUrl() string
}
type ScanTaskStopable interface {
// StopAtBlock returns at which block the scanner should stop
StopAtBlock() uint64
}