Skip to content

Commit

Permalink
fix: nil chain checks (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrun5 authored Sep 16, 2024
1 parent b4b6389 commit aa7e4eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions chains/evm/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"math/big"
"reflect"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -52,7 +53,7 @@ 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 {
if reflect.ValueOf(c.listener).IsNil() {
return
}

Expand All @@ -61,15 +62,15 @@ func (c *EVMChain) PollEvents(ctx context.Context) {
}

func (c *EVMChain) ReceiveMessage(m *message.Message) (*proposal.Proposal, error) {
if c.messageHandler == nil {
if reflect.ValueOf(c.messageHandler).IsNil() {
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 {
if reflect.ValueOf(c.executor).IsNil() {
return fmt.Errorf("executor not configured")
}

Expand Down
7 changes: 4 additions & 3 deletions chains/substrate/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/big"
"reflect"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -47,7 +48,7 @@ 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 {
if reflect.ValueOf(c.listener).IsNil() {
return
}

Expand All @@ -56,15 +57,15 @@ func (c *SubstrateChain) PollEvents(ctx context.Context) {
}

func (c *SubstrateChain) ReceiveMessage(m *message.Message) (*proposal.Proposal, error) {
if c.messageHandler == nil {
if reflect.ValueOf(c.messageHandler).IsNil() {
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 {
if reflect.ValueOf(c.executor).IsNil() {
return fmt.Errorf("executor not configured")
}

Expand Down

0 comments on commit aa7e4eb

Please sign in to comment.