Skip to content

Commit

Permalink
feat: allow for listen or execute only networks (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrun5 authored Sep 3, 2024
1 parent 258996b commit b4b6389
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions chains/evm/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package evm

import (
"context"
"fmt"
"math/big"

"github.com/rs/zerolog"
Expand Down Expand Up @@ -51,15 +52,27 @@ func NewEVMChain(listener EventListener, messageHandler MessageHandler, executor
// PollEvents is the goroutine that polls blocks and searches Deposit events in them.
// Events are then sent to eventsChan.
func (c *EVMChain) PollEvents(ctx context.Context) {
if c.listener == nil {
return
}

c.logger.Info().Str("startBlock", c.startBlock.String()).Msg("Polling Blocks...")
go c.listener.ListenToEvents(ctx, c.startBlock)
}

func (c *EVMChain) ReceiveMessage(m *message.Message) (*proposal.Proposal, error) {
if c.messageHandler == nil {
return nil, fmt.Errorf("message handler not configured")
}

return c.messageHandler.HandleMessage(m)
}

func (c *EVMChain) Write(props []*proposal.Proposal) error {
if c.executor == nil {
return fmt.Errorf("executor not configured")
}

err := c.executor.Execute(props)
if err != nil {
c.logger.Err(err).Str("messageID", props[0].MessageID).Msgf("error writing proposals %+v on network %d", props, c.DomainID())
Expand Down
13 changes: 13 additions & 0 deletions chains/substrate/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package substrate

import (
"context"
"fmt"
"math/big"

"github.com/rs/zerolog"
Expand Down Expand Up @@ -46,15 +47,27 @@ func NewSubstrateChain(listener EventListener, messageHandler MessageHandler, ex
// PollEvents is the goroutine that polls blocks and searches Deposit events in them.
// Events are then sent to eventsChan.
func (c *SubstrateChain) PollEvents(ctx context.Context) {
if c.listener == nil {
return
}

c.logger.Info().Str("startBlock", c.startBlock.String()).Msg("Polling Blocks...")
go c.listener.ListenToEvents(ctx, c.startBlock)
}

func (c *SubstrateChain) ReceiveMessage(m *message.Message) (*proposal.Proposal, error) {
if c.messageHandler == nil {
return nil, fmt.Errorf("message handler not configured")
}

return c.messageHandler.HandleMessage(m)
}

func (c *SubstrateChain) Write(props []*proposal.Proposal) error {
if c.executor == nil {
return fmt.Errorf("executor not configured")
}

err := c.executor.Execute(props)
if err != nil {
c.logger.Err(err).Str("messageID", props[0].MessageID).Msgf("error writing proposals %+v on network %d", props, c.DomainID())
Expand Down

0 comments on commit b4b6389

Please sign in to comment.