Skip to content

Commit

Permalink
fix: remove duplicates abitype definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
agparadiso committed Feb 19, 2024
1 parent 561b8fb commit fad8945
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 28 deletions.
14 changes: 0 additions & 14 deletions core/services/relay/evm/functions/coordinator_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,6 @@ func (c *CoordinatorV1) OracleResponseLogTopic() (common.Hash, error) {
func (c *CoordinatorV1) LogsToRequests(requestLogs []logpoller.Log) ([]evmRelayTypes.OracleRequest, error) {
var requests []evmRelayTypes.OracleRequest

uint32Type, errType1 := abi.NewType("uint32", "uint32", nil)
uint40Type, errType2 := abi.NewType("uint40", "uint40", nil)
uint64Type, errType3 := abi.NewType("uint64", "uint64", nil)
uint72Type, errType4 := abi.NewType("uint72", "uint72", nil)
uint96Type, errType5 := abi.NewType("uint96", "uint96", nil)
addressType, errType6 := abi.NewType("address", "address", nil)
bytes32Type, errType7 := abi.NewType("bytes32", "bytes32", nil)

if errType1 != nil || errType2 != nil || errType3 != nil || errType4 != nil || errType5 != nil || errType6 != nil || errType7 != nil {
c.lggr.Errorw("LogsToRequests: failed to initialize types", "errType1", errType1,
"errType2", errType2, "errType3", errType3, "errType4", errType4, "errType5", errType5, "errType6", errType6, "errType7", errType7,
)
}

parsingContract, err := functions_coordinator_1_1_0.NewFunctionsCoordinator110(c.address, c.client)
if err != nil {
return nil, errors.Errorf("LogsToRequests: creating a contract instance for NewFunctionsCoordinator110 parsing failed")
Expand Down
14 changes: 0 additions & 14 deletions core/services/relay/evm/functions/coordinator_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,6 @@ func (c *CoordinatorV2) OracleResponseLogTopic() (common.Hash, error) {
func (c *CoordinatorV2) LogsToRequests(requestLogs []logpoller.Log) ([]evmRelayTypes.OracleRequest, error) {
var requests []evmRelayTypes.OracleRequest

uint32Type, errType1 := abi.NewType("uint32", "uint32", nil)
uint40Type, errType2 := abi.NewType("uint40", "uint40", nil)
uint64Type, errType3 := abi.NewType("uint64", "uint64", nil)
uint72Type, errType4 := abi.NewType("uint72", "uint72", nil)
uint96Type, errType5 := abi.NewType("uint96", "uint96", nil)
addressType, errType6 := abi.NewType("address", "address", nil)
bytes32Type, errType7 := abi.NewType("bytes32", "bytes32", nil)

if errType1 != nil || errType2 != nil || errType3 != nil || errType4 != nil || errType5 != nil || errType6 != nil || errType7 != nil {
c.lggr.Errorw("LogsToRequests: failed to initialize types", "errType1", errType1,
"errType2", errType2, "errType3", errType3, "errType4", errType4, "errType5", errType5, "errType6", errType6, "errType7", errType7,
)
}

parsingContract, err := functions_coordinator.NewFunctionsCoordinator(c.address, c.client)
if err != nil {
return nil, errors.Errorf("LogsToRequests: creating a contract instance for NewFunctionsCoordinator parsing failed")
Expand Down
53 changes: 53 additions & 0 deletions core/services/relay/evm/functions/logpoller_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package functions

import (
"context"
"fmt"
"strings"
"sync"
"time"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
Expand Down Expand Up @@ -70,6 +72,23 @@ const logPollerCacheDurationSecDefault = 300
const pastBlocksToPollDefault = 50
const maxLogsToProcess = 1000

var (
uint32Type abi.Type
uint40Type abi.Type
uint64Type abi.Type
uint72Type abi.Type
uint96Type abi.Type
addressType abi.Type
bytes32Type abi.Type
)

func init() {
err := initAbiTypes()
if err != nil {
panic(err)
}
}

var _ evmRelayTypes.LogPollerWrapper = &logPollerWrapper{}

func NewLogPollerWrapper(routerContractAddress common.Address, pluginConfig config.PluginConfig, client client.Client, logPoller logpoller.LogPoller, lggr logger.Logger) (evmRelayTypes.LogPollerWrapper, error) {
Expand Down Expand Up @@ -416,3 +435,37 @@ func (l *logPollerWrapper) handleRouteUpdate(activeCoordinatorAddress common.Add
}
}
}

func initAbiTypes() error {
var err error
uint32Type, err = abi.NewType("uint32", "uint32", nil)
if err != nil {
return fmt.Errorf("LogsToRequests: failed to initialize uint32Type type: %w", err)
}
uint40Type, err = abi.NewType("uint40", "uint40", nil)
if err != nil {
return fmt.Errorf("LogsToRequests: failed to initialize uint40Type type: %w", err)
}
uint64Type, err = abi.NewType("uint64", "uint64", nil)
if err != nil {
return fmt.Errorf("LogsToRequests: failed to initialize uint64Type type: %w", err)
}
uint72Type, err = abi.NewType("uint72", "uint72", nil)
if err != nil {
return fmt.Errorf("LogsToRequests: failed to initialize uint72Type type: %w", err)
}
uint96Type, err = abi.NewType("uint96", "uint96", nil)
if err != nil {
return fmt.Errorf("LogsToRequests: failed to initialize uint96Type type: %w", err)
}
addressType, err = abi.NewType("address", "address", nil)
if err != nil {
return fmt.Errorf("LogsToRequests: failed to initialize addressType type: %w", err)
}
bytes32Type, err = abi.NewType("bytes32", "bytes32", nil)
if err != nil {
return fmt.Errorf("LogsToRequests: failed to initialize bytes32Type type: %w", err)
}

return nil
}

0 comments on commit fad8945

Please sign in to comment.