Skip to content

Commit

Permalink
Add supported networks
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetson committed Nov 29, 2023
1 parent 528bcad commit f9cf516
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion packages/hardhat/contracts/Registrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ import "@openzeppelin/contracts/access/Ownable.sol";
* @author Medet Ahmetson
*/
contract Registrar is Ownable {
struct ChainlinkParam {
uint64 selector;
address router;
}

// A supported networks and their oracle parameters
// chain id => Chainlink Param
mapping(uint256 => ChainlinkParam) public supportedNetworks;

// State Variables
string public greeting = "Building Unstoppable Apps!!!";
bool public premium = false;
Expand All @@ -27,7 +36,23 @@ contract Registrar is Ownable {
uint256 value
);

constructor() {}
constructor(uint256[] memory chainIds, ChainlinkParam[] memory chainlinkParams) {
require(chainIds.length == chainlinkParams.length, "invalid length");
require(chainIds.length >= 2, "atleast two chains required");

for (uint64 i = 0; i < chainIds.length; i++) {
require(chainIds[i] > 0, "null");
require(chainlinkParams[i].router != address(0), "empty address");
require(chainlinkParams[i].selector > 0, "empty selecter");

require(chainlinkParams[i].router == address(0), "duplicate network");

supportedNetworks[chainIds[i]] = chainlinkParams[i];
}

// set the destinations and routers
require(supportedNetworks[block.chainid].router != address(0), "current network not set");
}

/**
* Function that allows anyone to change the state variable "greeting" of the contract and increase the counters
Expand Down

0 comments on commit f9cf516

Please sign in to comment.