2018-03-31 04:07:42 +00:00
|
|
|
package collator
|
|
|
|
|
|
|
|
import (
|
2018-03-31 06:13:51 +00:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2018-03-31 18:25:39 +00:00
|
|
|
"github.com/ethereum/go-ethereum/sharding/client"
|
2018-03-31 04:07:42 +00:00
|
|
|
cli "gopkg.in/urfave/cli.v1"
|
|
|
|
)
|
|
|
|
|
2018-03-31 18:25:39 +00:00
|
|
|
type Collator interface {
|
|
|
|
Start() error
|
|
|
|
}
|
2018-03-31 04:07:42 +00:00
|
|
|
|
2018-03-31 18:25:39 +00:00
|
|
|
type collator struct {
|
|
|
|
client client.Client
|
2018-03-31 04:07:42 +00:00
|
|
|
}
|
|
|
|
|
2018-03-31 18:25:39 +00:00
|
|
|
// NewCollator creates a new collator instance.
|
|
|
|
func NewCollator(ctx *cli.Context) Collator {
|
|
|
|
return &collator{
|
|
|
|
client: client.NewClient(ctx),
|
2018-03-31 06:13:51 +00:00
|
|
|
}
|
2018-03-31 18:25:39 +00:00
|
|
|
}
|
2018-03-31 04:07:42 +00:00
|
|
|
|
2018-03-31 18:25:39 +00:00
|
|
|
// Start the main routine for a collator.
|
|
|
|
func (c *collator) Start() error {
|
|
|
|
log.Info("Starting collator client")
|
|
|
|
err := c.client.Start()
|
|
|
|
if err != nil {
|
2018-03-31 04:07:42 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-03-31 18:25:39 +00:00
|
|
|
defer c.client.Close()
|
2018-03-31 04:07:42 +00:00
|
|
|
|
2018-03-31 18:25:39 +00:00
|
|
|
if err := joinCollatorPool(c.client); err != nil {
|
2018-03-31 04:07:42 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-03-31 22:05:22 +00:00
|
|
|
return subscribeBlockHeaders(c.client)
|
2018-03-31 04:07:42 +00:00
|
|
|
}
|