|
|
@@ -1,23 +1,43 @@
|
|
|
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
|
|
|
- Context *cli.Context
|
|
|
+ stack *node.Node
|
|
|
+ ctx *cli.Context
|
|
|
+ apiBackend ethapi.Backend
|
|
|
+ blockChainApi *ethapi.BlockChainAPI
|
|
|
+}
|
|
|
+
|
|
|
+func NewHistoryArbitrage(stack *node.Node, ctx *cli.Context, apiBackend ethapi.Backend) *HistoryArbitrage {
|
|
|
+ return &HistoryArbitrage{
|
|
|
+ stack: stack,
|
|
|
+ ctx: ctx,
|
|
|
+ apiBackend: apiBackend,
|
|
|
+ blockChainApi: ethapi.NewBlockChainAPI(apiBackend),
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func (h HistoryArbitrage) Register() {
|
|
|
- h.Stack.RegisterLifecycle(h)
|
|
|
+ // 注册成节点生命周期
|
|
|
+ h.stack.RegisterLifecycle(h)
|
|
|
}
|
|
|
|
|
|
func (h HistoryArbitrage) Start() error {
|
|
|
HistoryLog("Hi, I am history arbitrage bot.")
|
|
|
+ HistoryLog("api: ", h.blockChainApi)
|
|
|
+ //time.Sleep(time.Second * 20)
|
|
|
|
|
|
- return nil
|
|
|
+ for {
|
|
|
+ HistoryLog("BlockNumber: ", h.blockChainApi.BlockNumber(), "ChainID: ", h.blockChainApi.ChainId())
|
|
|
+
|
|
|
+ time.Sleep(time.Second)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func (h HistoryArbitrage) Stop() error {
|