Documentation ¶
Index ¶
- Constants
- Variables
- func InitLogsFromFiles(filenames ...string) []types.Log
- func InitMappedLogsFromFiles(filenames ...string) map[uint64][]types.Log
- func LogsReorgPaths(events []ReorgEvent) ([]common.Hash, map[common.Hash][]uint64, map[common.Hash]uint64)
- func MapLogsToNumber(logs []types.Log) map[uint64][]types.Log
- func NewBlockChain(logs map[uint64][]types.Log, events []ReorgEvent) (BlockChain, []BlockChain)
- func NewReorgSimFromLogs(param Param, events []ReorgEvent, logs map[uint64][]types.Log, ...) (superwatcher.EthClient, error)
- func NewReorgSimFromLogsFiles(param Param, events []ReorgEvent, logsFiles []string, debugName string, ...) (superwatcher.EthClient, error)
- func PRandomHash(i uint64) common.Hash
- func ReorgHash(blockNumber uint64, reorgIndex int) common.Hash
- type Block
- type BlockChain
- type MoveLogs
- type Param
- type ReorgEvent
- type ReorgSim
- func (r *ReorgSim) BatchCallContext(ctx context.Context, elems []rpc.BatchElem) error
- func (r *ReorgSim) BlockNumber(ctx context.Context) (uint64, error)
- func (r *ReorgSim) Chain() BlockChain
- func (r *ReorgSim) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error)
- func (r *ReorgSim) HeaderByNumber(ctx context.Context, number *big.Int) (superwatcher.BlockHeader, error)
- func (r *ReorgSim) ReorgedChain(i int) BlockChain
- func (r *ReorgSim) ReorgedChains() []BlockChain
Constants ¶
const NoReorg uint64 = 0
Use this as ReorgEvent.ReorgBlock to disable chain reorg.
Variables ¶
var ( DefaultParam = Param{ BlockProgress: 20, Debug: true, } )
var ErrExitBlockReached = errors.New("exitBlock reached for reorgsim")
Functions ¶
func InitLogsFromFiles ¶
func InitMappedLogsFromFiles ¶
InitMappedLogsFromFiles returns unmarshaled hard-coded logs. It is export for use in internal/emitter testing.
func LogsReorgPaths ¶
func LogsReorgPaths(events []ReorgEvent) ([]common.Hash, map[common.Hash][]uint64, map[common.Hash]uint64)
LogsReorgPaths iterates through |events| to see which blockNumber is the final destination for a log. The return value is a map of log's TX hash to its destination block number, that is, the most current ReorgEvent.
func NewBlockChain ¶
func NewBlockChain( logs map[uint64][]types.Log, events []ReorgEvent, ) ( BlockChain, []BlockChain, )
NewBlockChain is the preferred way to init reorgsim `blockChain`s. It accept a slice of `ReorgEvent` and uses each event to construct a reorged chain, which will be appended to the second return variable. Each ReorgEvent will result in its own blockChain, with the identical index.
func NewReorgSimFromLogs ¶
func NewReorgSimFromLogs( param Param, events []ReorgEvent, logs map[uint64][]types.Log, debugName string, logLevel uint8, ) ( superwatcher.EthClient, error, )
func NewReorgSimFromLogsFiles ¶
func NewReorgSimFromLogsFiles( param Param, events []ReorgEvent, logsFiles []string, debugName string, logLevel uint8, ) ( superwatcher.EthClient, error, )
func PRandomHash ¶
PRandomHash returns a deterministic, pseudo-random hash for i
Types ¶
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
Block represents the Ethereum Block. It is also used as superwatcher.BlockHeader.
func (*Block) Hash ¶
Implements superwatcher.BlockHeader We'll use block in place of *types.Header, because *types.Header is too packed to mock.
func (*Block) Nonce ¶
func (b *Block) Nonce() types.BlockNonce
Nonce mocks field *types.Header.Nonce
type BlockChain ¶
type MoveLogs ¶
type MoveLogs struct { NewBlock uint64 TxHashes []common.Hash // txHashes of logs to be moved to newBlock }
MoveLogs represent a move of logs to a new blockNumber
type Param ¶
type Param struct { // StartBlock will be used as initial ReorgSim.currentBlock. StartBlock uint64 `json:"startBlock"` // BlockProgress is used to increment ReorgSim.currentBlock. BlockProgress uint64 `json:"blockProgress"` // ExitBlock is checked against ReorgSim.currentBlock for test code to exit at a specify block. ExitBlock uint64 `json:"exitBlock"` Debug bool `json:"-"` }
Param is the basic parameters for the mock client. Chain reorg parameters are NOT included here.
type ReorgEvent ¶
type ReorgEvent struct { // ReorgTrigger is the block which when seen, triggers a reorg from ReorgBlock ReorgTrigger uint64 `json:"reorgTrigger"` // ReorgBlock is the pivot block after which ReorgSim should use ReorgSim.reorgedChain. ReorgBlock uint64 `json:"reorgBlock"` // MovedLogs represents all of the moved logs after a chain reorg event. // The map key is the source block number (the block from which the logs are originally in). MovedLogs map[uint64][]MoveLogs `json:"movedLogs"` }
ReorgEvent is parameters for chain reorg events.
type ReorgSim ¶
ReorgSim is a mock superwatcher.EthClient can simulate multiple on-the-fly chain reorganizations.
func NewReorgSim ¶
func NewReorgSim( param Param, events []ReorgEvent, chain BlockChain, reorgedChains []BlockChain, debugName string, logLevel uint8, ) ( *ReorgSim, error, )
func (*ReorgSim) BatchCallContext ¶
BatchCallContext only processes `"eth_getBlockByNumber" RPC method calls. Each elem.Result in elems will be overwritten with *Block (implements superwatcher.BlockHeader) from the current chain.
func (*ReorgSim) Chain ¶
func (r *ReorgSim) Chain() BlockChain
func (*ReorgSim) FilterLogs ¶
func (*ReorgSim) HeaderByNumber ¶
func (r *ReorgSim) HeaderByNumber(ctx context.Context, number *big.Int) (superwatcher.BlockHeader, error)
func (*ReorgSim) ReorgedChain ¶
func (r *ReorgSim) ReorgedChain(i int) BlockChain
func (*ReorgSim) ReorgedChains ¶
func (r *ReorgSim) ReorgedChains() []BlockChain