Skip to content

Commit

Permalink
Seperate gatekeeper initialization from network creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Leonard authored and Robert Leonard committed May 28, 2024
1 parent 416f98d commit 0b68faa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions smart-contract/contracts/GatewayNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ contract GatewayNetwork is ParameterizedAccessControl, IGatewayNetwork {

_networks[networkName] = network;
_networks[networkName].lastFeeUpdateTimestamp = block.timestamp;
// reset gatekeeper list so that primary authority can add gatekeepers manually
// The creator os the network probably won't be the primary authority of the network so they can't initialize gatekeepers
_networks[networkName].gatekeepers = new address[](20);


emit GatekeeperNetworkCreated(network.primaryAuthority, networkName, network.passExpireDurationInSeconds);
}
Expand Down Expand Up @@ -113,6 +117,12 @@ contract GatewayNetwork is ParameterizedAccessControl, IGatewayNetwork {
emit GatekeeperNetworkDeleted(networkName);
}

function addGatekeepers(address[] memory gatekeepers, bytes32 networkName) external override {
for(uint i = 0; i < gatekeepers.length; i++) {
this.addGatekeeper(gatekeepers[i], networkName);
}
}

function addGatekeeper(address gatekeeper, bytes32 networkName) external override onlyPrimaryNetworkAuthority(networkName){
require(_networks[networkName].primaryAuthority != address(0), "Network does not exist");
require(gatekeeper != address(0), "Zero address cannot be added as a gatekeeper");
Expand Down
1 change: 1 addition & 0 deletions smart-contract/contracts/interfaces/IGatewayNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ abstract contract IGatewayNetwork {
function withdrawNetworkFees(bytes32 networkName) external payable virtual;
function closeNetwork(bytes32 networkName) external virtual;
function updatePassExpirationTime(uint newExpirationTimeInSeconds, bytes32 networkName) external virtual;
function addGatekeepers(address[] memory gatekeeper, bytes32 network) external virtual;
function addGatekeeper(address gatekeeper, bytes32 network) external virtual;
function removeGatekeeper(address gatekeeper, bytes32 network) external virtual;
function updatePrimaryAuthority(address newPrimaryAuthortiy, bytes32 networkName) external virtual;
Expand Down
3 changes: 2 additions & 1 deletion smart-contract/test/gatewayNetwork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ describe('GatewayNetwork', () => {
const defaultNetwork = getDefaultNetwork(primaryAuthority.address, [alice.address]);
await gatekeeperNetworkContract.connect(deployer).createNetwork(defaultNetwork, {gasLimit: 300000});

const isGatekeeper = await gatekeeperNetworkContract.isGateKeeper(defaultNetwork.name, alice.address);
await gatekeeperNetworkContract.connect(primaryAuthority).addGatekeeper(alice.address, defaultNetwork.name, {gasLimit: 300000});

const isGatekeeper = await gatekeeperNetworkContract.isGateKeeper(defaultNetwork.name, alice.address);
expect(isGatekeeper).to.be.true;
});
it('cannot create a new network zero address primary authority', async () => {
Expand Down

0 comments on commit 0b68faa

Please sign in to comment.