2020-11-15 05:59:46 +00:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (n *Node) subscribeOnEthContracts(ctx context.Context) {
|
|
|
|
eventChan, subscription, err := n.Ethereum.SubscribeOnOracleEvents(ctx)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal("Can't subscribe on ethereum contracts, exiting... ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
EventLoop:
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case event := <-eventChan:
|
|
|
|
{
|
|
|
|
task, err := n.Miner.MineTask(ctx, event, n.Wallet.WalletSign)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal("Error with mining algorithm, exiting... ", err)
|
|
|
|
}
|
2020-11-15 10:11:07 +00:00
|
|
|
if task == nil {
|
|
|
|
continue
|
|
|
|
}
|
2020-11-25 18:54:59 +00:00
|
|
|
logrus.Info("Started new consensus round with ID: ", task.Signature)
|
2020-11-15 13:46:58 +00:00
|
|
|
|
2020-11-25 18:54:59 +00:00
|
|
|
err = n.ConsensusManager.Propose(event.RequestID.String(), string(task.Payload), event.RequestID, event.CallbackAddress)
|
2020-11-15 13:46:58 +00:00
|
|
|
if err != nil {
|
|
|
|
logrus.Errorf("Failed to propose task: %w", err)
|
|
|
|
}
|
2020-11-15 05:59:46 +00:00
|
|
|
}
|
|
|
|
case <-ctx.Done():
|
|
|
|
break EventLoop
|
|
|
|
case <-subscription.Err():
|
|
|
|
logrus.Fatal("Error with ethereum subscription, exiting... ", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|