Controller contract anatomy
Dive into into the Tableland controller contract's design.
A controller needs to implement the TablelandController abstract contract (or the ITablelandController interface). This enables advanced, custom access control features. Note the default access controls define that only the owner can control everything on the table—this is implemented by default in the TablelandTables registry contract, so if you don't create/set your own controller, those rules are applied.
Controller anatomy
getPolicy method
The TablelandController inherits from the ITablelandController. It implements a single getPolicy method that returns a TablelandPolicy; this is the core of the access control logic.
The getPolicy method signature is the following:
function getPolicy(address caller, uint256 tableId)
external
payable
virtual
override
returns (TablelandPolicy memory);
Here's how it works:
caller: The address that is attempting to access the table.- For example, the address calling the registry contract's
createormutatemethod.
- For example, the address calling the registry contract's
tableId: The ID of the table that is being mutated.payable: Used to allow the controller to, optionally, charge a fee for the access control (e.g., require payment to mutate data).
Once you create a controller contract, you then call the setController method on the TablelandTables registry contract—see here for more details. This will set the controller for the specified table ID so that it returns a unique policy for the specific table.