Skip to content

Commit

Permalink
verbose err in listener
Browse files Browse the repository at this point in the history
  • Loading branch information
boojamya committed Nov 13, 2023
1 parent 5dae9aa commit b29d803
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
9 changes: 5 additions & 4 deletions cmd/ethereum/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package ethereum
import (
"bytes"
"context"
"cosmossdk.io/log"
"embed"
"fmt"
"math/big"
"os"

"cosmossdk.io/log"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/pascaldekloe/etherstream"
"github.com/strangelove-ventures/noble-cctp-relayer/config"
"github.com/strangelove-ventures/noble-cctp-relayer/types"
"math/big"
"os"
)

//go:embed abi/MessageTransmitter.json
Expand Down Expand Up @@ -88,7 +89,7 @@ func StartListener(cfg config.Config, logger log.Logger, processingQueue chan *t
case streamLog := <-stream:
parsedMsg, err := types.EvmLogToMessageState(messageTransmitterABI, messageSent, &streamLog)
if err != nil {
logger.Error("Unable to parse ws log into MessageState, skipping")
logger.Error("Unable to parse ws log into MessageState, skipping", "err", err)
continue
}
logger.Info(fmt.Sprintf("New stream msg from %d with tx hash %s", parsedMsg.SourceDomain, parsedMsg.SourceTxHash))
Expand Down
13 changes: 8 additions & 5 deletions types/message_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"encoding/json"
"errors"
"fmt"
"strconv"
"time"

"github.com/circlefin/noble-cctp/x/cctp/types"
"github.com/cosmos/cosmos-sdk/types/bech32"
"github.com/ethereum/go-ethereum/accounts/abi"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"strconv"
"time"
)

const (
Expand Down Expand Up @@ -47,7 +48,9 @@ type MessageState struct {
func EvmLogToMessageState(abi abi.ABI, messageSent abi.Event, log *ethtypes.Log) (messageState *MessageState, err error) {

event := make(map[string]interface{})
_ = abi.UnpackIntoMap(event, messageSent.Name, log.Data)
if err = abi.UnpackIntoMap(event, messageSent.Name, log.Data); err != nil {
return nil, err
}

rawMessageSentBytes := event["message"].([]byte)
message, _ := new(types.Message).Parse(rawMessageSentBytes)
Expand Down Expand Up @@ -80,7 +83,7 @@ func EvmLogToMessageState(abi abi.ABI, messageSent abi.Event, log *ethtypes.Log)
return messageState, nil
}

return nil, errors.New(fmt.Sprintf("unable to parse txn into message. tx hash %s", log.TxHash.Hex()))
return nil, fmt.Errorf("unable to parse txn into message. tx hash %s", log.TxHash.Hex())
}

// NobleLogToMessageState transforms a Noble log into a messageState
Expand Down Expand Up @@ -131,7 +134,7 @@ func NobleLogToMessageState(tx Tx) (messageState *MessageState, err error) {
}
}

return nil, errors.New(fmt.Sprintf("unable to parse txn into message. tx hash %s", tx.Hash))
return nil, fmt.Errorf("unable to parse txn into message. tx hash %s", tx.Hash)
}

// DecodeDestinationCaller transforms an encoded Noble cctp address into a noble bech32 address
Expand Down
8 changes: 5 additions & 3 deletions types/message_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package types_test
import (
"context"
"fmt"
"math/big"
"os"
"testing"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -12,9 +16,6 @@ import (
"github.com/strangelove-ventures/noble-cctp-relayer/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"math/big"
"os"
"testing"
)

var cfg config.Config
Expand All @@ -36,6 +37,7 @@ func TestToMessageStateSuccess(t *testing.T) {
ethClient, err := ethclient.DialContext(context.Background(), cfg.Networks.Source.Ethereum.RPC)
require.Nil(t, err)

// this is circles message transmitter contract. We are listenting for messageSent events emitted from this contract address
messageTransmitterAddress := common.HexToAddress("0x26413e8157CD32011E726065a5462e97dD4d03D9")

query := ethereum.FilterQuery{
Expand Down

0 comments on commit b29d803

Please sign in to comment.