Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom message handler and decoders #489

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
397 changes: 397 additions & 0 deletions abi-bindings/eventimporter/EventImporter.go

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions abi-bindings/eventimporter/pack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// (c) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package eventimporter

import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
)

// PackImportEvent packs input to form a call to the importEvent function
func PackImportEvent(
blockHeader []byte,
txIndex *big.Int,
receiptProof [][]byte,
logIndex *big.Int,
) ([]byte, error) {
abi, err := EventImporterMetaData.GetAbi()
if err != nil {
return nil, errors.Wrap(err, "failed to get abi")
}

return abi.Pack("importEvent", common.Hash{}, blockHeader, txIndex, receiptProof, logIndex)
}
52 changes: 52 additions & 0 deletions messages/chainlink/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package chainlink

import (
"fmt"
"strconv"

"github.com/ava-labs/avalanchego/ids"
"github.com/ethereum/go-ethereum/common"
)

type RawConfig struct {
AggregatorsToReplicas map[string]string `json:"aggregators-to-replicas"`
MaxFilterAdresses string `json:"max-filter-addresses"`
DestinationBlockchainID string `json:"destination-blockchain-id"`
}

type Config struct {
AggregatorsToReplicas map[common.Address]common.Address
MaxFilterAdresses uint64
DestinationBlockchainID ids.ID
}

func (c *RawConfig) Parse() (*Config, error) {
maxFilterAdresses, err := strconv.ParseUint(c.MaxFilterAdresses, 10, 64)
if err != nil {
return nil, fmt.Errorf("invalid integer for max-filter-addresses cannot be parsed to uint64: %s", c.MaxFilterAdresses)
}
aggregatorToReplicas := make(map[common.Address]common.Address, 0)
for aggregator, replica := range c.AggregatorsToReplicas {
if !common.IsHexAddress(aggregator) {
return nil, fmt.Errorf("invalid price feed aggregator address for EVM source subnet: %s", aggregator)
}
if !common.IsHexAddress(replica) {
return nil, fmt.Errorf("invalid price feed replica address for EVM source subnet: %s", replica)
}
aggregator, replica := common.HexToAddress(aggregator), common.HexToAddress(replica)
if _, ok := aggregatorToReplicas[aggregator]; ok {
return nil, fmt.Errorf("duplicate aggregator entry for %s", aggregator)
}
aggregatorToReplicas[aggregator] = replica
}
destinationBlockchainID, err := ids.FromString(c.DestinationBlockchainID)
if err != nil {
return nil, err
}
config := Config{
AggregatorsToReplicas: aggregatorToReplicas,
MaxFilterAdresses: maxFilterAdresses,
DestinationBlockchainID: destinationBlockchainID,
}
return &config, nil
}
Loading
Loading