Creating controllers
Understand how to create a controller contract.
This page highlights a few examples of how to create a controller contract in Solidity.
"Allow all" policy
Default ownership grants the owner the following "allow all" abilities to only the owner, but a custom controller could enable this for anyone:
allowInsert
⇒true
AllowINSERT
s into the table.allowUpdate
⇒true
AllowUPDATE
on all columns.allowDelete
⇒true
AllowDELETE
, including usingWHERE
statements.whereCheck
⇒""
Defaults to an empty string, meaning, noWHERE
clause additions are implemented.withCheck
⇒""
Defaults to an empty string, meaning, noCHECK
clause additions are implemented.updatableColumns
⇒new string[](0)
Defaults to an empty list, meaning, there are no restrictions on which columns can be updated.
In other words, if a custom TablelandController
contract has not been set, the default values for the Policy
are those defined above.
"Allow none" policy
Similar to the example above, you could choose to disable everything by setting false
or empty values:
ITablelandController.Policy({
allowInsert: false,
allowUpdate: false,
allowDelete: false,
whereClause: Policies.joinClauses(new string[](0)),
withCheck: Policies.joinClauses(new string[](0)),
updatableColumns: new string[](0)
});
Example implementation
The following example shows how to import the ITablelandController
interface and then create a policy that only allows INSERT
s on a table, from any address.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
import "@tableland/evm/contracts/ITablelandController.sol";
import "@tableland/evm/contracts/policies/Policies.sol";
contract ExamplePolicy {
function getPolicy(address sender)
public
payable
override
returns (ITablelandController.Policy memory)
{
/*
* Add any custom ACL check here, like token ownership.
*/
// Return allow-insert policy
return
ITablelandController.Policy({
allowInsert: true,
allowUpdate: false,
allowDelete: false,
whereClause: Policies.joinClauses(new string[](0)),
withCheck: Policies.joinClauses(new string[](0)),
updatableColumns: new string[](0)
});
}
}
Alternatively, you could lock down your table to "allow none" for now, and then unlock your policy with a modification later. A dynamic policy could be interesting in cases such as post-reveal during your NFT launch.