history.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package arbitrage
  2. import (
  3. "github.com/ethereum/go-ethereum/internal/ethapi"
  4. "github.com/ethereum/go-ethereum/node"
  5. "github.com/urfave/cli/v2"
  6. "time"
  7. )
  8. type HistoryArbitrage struct {
  9. stack *node.Node
  10. ctx *cli.Context
  11. apiBackend ethapi.Backend
  12. blockChainApi *ethapi.BlockChainAPI
  13. }
  14. func NewHistoryArbitrage(stack *node.Node, ctx *cli.Context, apiBackend ethapi.Backend) *HistoryArbitrage {
  15. return &HistoryArbitrage{
  16. stack: stack,
  17. ctx: ctx,
  18. apiBackend: apiBackend,
  19. blockChainApi: ethapi.NewBlockChainAPI(apiBackend),
  20. }
  21. }
  22. func (h HistoryArbitrage) Register() {
  23. // 注册成节点生命周期
  24. h.stack.RegisterLifecycle(h)
  25. }
  26. func (h HistoryArbitrage) Start() error {
  27. HistoryLog("Hi, I am history arbitrage bot.")
  28. HistoryLog("api: ", h.blockChainApi)
  29. //time.Sleep(time.Second * 20)
  30. for {
  31. HistoryLog("BlockNumber: ", h.blockChainApi.BlockNumber(), "ChainID: ", h.blockChainApi.ChainId())
  32. time.Sleep(time.Second)
  33. }
  34. }
  35. func (h HistoryArbitrage) Stop() error {
  36. return nil
  37. }