Infernet
SDK
Patterns
Allowlist

Allowlist

Technical Reference

By default, the Infernet SDK enables any node to respond to any Subscription request. For many consumers, especially those operating their own set of nodes, this is not intended functionality.

Via the Allowlist pattern, you can easily specify a set of nodes that are the only nodes permissioned to respond to subscriptions created by your consumer smart contract.

Inherit Allowlist.sol

Starting backwards from the CallbackConsumer example's final-state, we can retrofit an allowlist of nodes.

In your smart contract, you must inherit the Allowlist.sol abstract contract found in infernet/core/pattern/Allowlist.sol:

import {Allowlist} from "infernet/core/pattern/Allowlist.sol";
 
contract MyContract is CallbackConsumer, Allowlist {
    // ...
}

Initialize the Allowlist

Once inherited, you must provide the an array of initially-allowed node addresses:

import {Allowlist} from "infernet/core/pattern/Allowlist.sol";
 
contract MyContract is CallbackConsumer, Allowlist {
    // ...
    constructor(
        address registry,
        address[] memory initialAllowed
    ) CallbackConsumer(registry) Allowlist(initialAllowed) {}
    // ...
}

Allow updating Allowlist

By default, Allowlist exposes an _updateAllowlist function (technical reference) that allows the inheriting smart contract to update the set of allowed nodes. You may choose to optionally expose this function.

import {Allowlist} from "infernet/core/pattern/Allowlist.sol";
 
contract MyContract is CallbackConsumer, Allowlist {
    // ...
    constructor(
        address registry,
        address[] memory initialAllowed
    ) CallbackConsumer(registry) Allowlist(initialAllowed) {}
 
    function updateAllowlist(
      address[] memory nodes,
      bool[] memory statuses
    ) external onlyAuthorized {
        _updateAllowlist(nodes, statuses);
    }
    // ...
}