package arbitrage

import (
	"github.com/ethereum/go-ethereum/internal/ethapi"
	"github.com/ethereum/go-ethereum/node"
	"github.com/urfave/cli/v2"
	"time"
)

type HistoryArbitrage struct {
	stack         *node.Node
	ctx           *cli.Context
	apiBackend    ethapi.Backend
	blockChainApi *ethapi.BlockChainAPI
	ethereumApi   *ethapi.EthereumAPI
}

func NewHistoryArbitrage(stack *node.Node, ctx *cli.Context, apiBackend ethapi.Backend) *HistoryArbitrage {
	return &HistoryArbitrage{
		stack:         stack,
		ctx:           ctx,
		apiBackend:    apiBackend,
		blockChainApi: ethapi.NewBlockChainAPI(apiBackend),
		ethereumApi:   ethapi.NewEthereumAPI(apiBackend),
	}
}

func (h HistoryArbitrage) Register() {
	// 注册成节点生命周期
	h.stack.RegisterLifecycle(h)
}

func (h HistoryArbitrage) Start() error {
	HistoryLog("Hi, I am history arbitrage bot.")

	for {
		HistoryLog("Bot log",
			"BlockNumber", h.blockChainApi.BlockNumber().String(),
			"ChainID: ", h.blockChainApi.ChainId().ToInt())

		time.Sleep(time.Second)
	}
}

func (h HistoryArbitrage) Stop() error {
	return nil
}
