-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
capabilities: Move evm specific code inside the relayer
- Loading branch information
Showing
5 changed files
with
92 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package evm | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
chainselectors "github.com/smartcontractkit/chain-selectors" | ||
|
||
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types" | ||
"github.com/smartcontractkit/chainlink/v2/core/capabilities/targets" | ||
"github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm" | ||
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/forwarder" | ||
"github.com/smartcontractkit/chainlink/v2/core/logger" | ||
relayevmtypes "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types" | ||
) | ||
|
||
func NewWriteTarget(ctx context.Context, relayer *Relayer, chain legacyevm.Chain, lggr logger.Logger) (*targets.WriteTarget, error) { | ||
// generate ID based on chain selector | ||
name := fmt.Sprintf("write_%v", chain.ID()) | ||
chainName, err := chainselectors.NameFromChainId(chain.ID().Uint64()) | ||
if err == nil { | ||
name = fmt.Sprintf("write_%v", chainName) | ||
} | ||
|
||
// EVM-specific init | ||
config := chain.Config().EVM().ChainWriter() | ||
|
||
// Initialize a reader to check whether a value was already transmitted on chain | ||
contractReaderConfigEncoded, err := json.Marshal(relayevmtypes.ChainReaderConfig{ | ||
Contracts: map[string]relayevmtypes.ChainContractReader{ | ||
"forwarder": { | ||
ContractABI: forwarder.KeystoneForwarderABI, | ||
Configs: map[string]*relayevmtypes.ChainReaderDefinition{ | ||
"getTransmitter": { | ||
ChainSpecificName: "getTransmitter", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to marshal contract reader config %v", err) | ||
} | ||
cr, err := relayer.NewContractReader(contractReaderConfigEncoded) | ||
if err != nil { | ||
return nil, err | ||
} | ||
cr.Bind(ctx, []commontypes.BoundContract{{ | ||
Address: config.ForwarderAddress().String(), | ||
Name: "forwarder", | ||
}}) | ||
|
||
chainWriterConfig := relayevmtypes.ChainWriterConfig{ | ||
Contracts: map[string]relayevmtypes.ChainWriter{ | ||
"forwarder": { | ||
ContractABI: forwarder.KeystoneForwarderABI, | ||
Configs: map[string]*relayevmtypes.ChainWriterDefinition{ | ||
"report": { | ||
ChainSpecificName: "report", | ||
Checker: "simulate", | ||
FromAddress: config.FromAddress().Address(), | ||
GasLimit: 200_000, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
cw := NewChainWriterService(lggr.Named("ChainWriter"), chain.Client(), chain.TxManager(), chainWriterConfig) | ||
|
||
return targets.NewWriteTarget(lggr, name, cr, cw, config.ForwarderAddress().String()), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters