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⇒trueAllowINSERTs into the table.allowUpdate⇒trueAllowUPDATEon all columns.allowDelete⇒trueAllowDELETE, including usingWHEREstatements.whereCheck⇒""Defaults to an empty string, meaning, noWHEREclause additions are implemented.withCheck⇒""Defaults to an empty string, meaning, noCHECKclause 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 INSERTs 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.