history.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. ethereumApi *ethapi.EthereumAPI
  14. }
  15. func NewHistoryArbitrage(stack *node.Node, ctx *cli.Context, apiBackend ethapi.Backend) *HistoryArbitrage {
  16. return &HistoryArbitrage{
  17. stack: stack,
  18. ctx: ctx,
  19. apiBackend: apiBackend,
  20. blockChainApi: ethapi.NewBlockChainAPI(apiBackend),
  21. ethereumApi: ethapi.NewEthereumAPI(apiBackend),
  22. }
  23. }
  24. func (h HistoryArbitrage) Register() {
  25. // 注册成节点生命周期
  26. h.stack.RegisterLifecycle(h)
  27. }
  28. func (h HistoryArbitrage) Start() error {
  29. HistoryLog("Hi, I am history arbitrage bot.")
  30. for {
  31. HistoryLog("Bot log",
  32. "BlockNumber", h.blockChainApi.BlockNumber().String(),
  33. "ChainID: ", h.blockChainApi.ChainId().ToInt())
  34. time.Sleep(time.Second)
  35. }
  36. }
  37. func (h HistoryArbitrage) Stop() error {
  38. return nil
  39. }