Last active
July 31, 2023 20:28
-
-
Save fdemiramon/63c3164b4130e05ee86d85ae70d322be to your computer and use it in GitHub Desktop.
Naive implementation for Portal as data (opposed to Portal as SC)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity 0.8.21; | |
struct Portal { | |
string name; | |
string context; | |
bool isRevocable; | |
bytes32[] moduleIds; | |
} | |
struct Attestation { | |
bytes32 schemaId; | |
bytes32 portalId; | |
bytes attestationPayload; | |
bool isRevoked; | |
// createdAt? revokedAt? createdBy? revokedBy? ... | |
} | |
interface IModule { | |
function run(bytes memory attestationPayload, bytes memory validationPayload, bytes32 schemaId, address msgSender) external payable returns (bytes memory); | |
} | |
interface IModuleRegistry { | |
function modules(bytes32 moduleId) external view returns (IModule); | |
} | |
interface IPortalRegistry { | |
function portals(bytes32 portalId) external view returns (Portal memory); | |
} | |
contract PortalRegistry is IPortalRegistry { | |
// @dev: map portalId with its struct | |
mapping(bytes32 => Portal) public portals; | |
// @dev: create a new "data" Portal and store its parameters into the mapping `portals | |
function create(string memory name, string memory context, bool isRevocable, bytes32[] memory moduleIds) public { | |
// @dev: Generate unique id | |
bytes32 id = keccak256(abi.encodePacked("all the metadata of the Portal?")); | |
// @dev: perform all preliminary checks | |
// @todo: name not null, context not null, capped number of modules, id not already used and moduleIds exist | |
// @dev: actually store the portal info | |
portals[id] = Portal( | |
name, | |
context, | |
isRevocable, | |
moduleIds | |
); | |
} | |
} | |
contract AttestationRegistry { | |
// @dev: locate the PortalRegistry | |
IPortalRegistry portalRegistry; | |
// @dev: locate the ModuleRegistry | |
IModuleRegistry moduleRegistry; | |
// @dev: map attestationId with its struct | |
mapping(bytes32 => Attestation) public attestations; | |
function initialize(address _portalRegistry, address _moduleRegistry) public { // onlyInitializer | |
portalRegistry = IPortalRegistry(_portalRegistry); | |
moduleRegistry = IModuleRegistry(_moduleRegistry); | |
} | |
// @dev: create a new Attestation | |
function create(bytes32 schemaId, bytes32 portalId, bytes memory attestationPayload, bytes memory validationPayload) public { | |
// @dev: Generate unique id | |
bytes32 id = keccak256(abi.encodePacked("all the metadata of the Attestation? add some more salt like block.timestamp?")); | |
// @dev: perform all preliminary checks | |
// @todo: schemaId exist, portalId exist, id not already existing | |
// @dev: get Portal's moduleIds | |
bytes32[] memory moduleIds = portalRegistry.portals(portalId).moduleIds; | |
// @dev: run the modules in the order they have been configured by the Portal creator | |
// @todo: | |
// - eth sent to module MUST be much more controlled | |
// - call to module should be encapsulated with a try catch (bool success, bytes data) = address.call... | |
for (uint8 i = 0; i < moduleIds.length; i++) { | |
moduleRegistry.modules(moduleIds[i]).run{value: address(this).balance}(attestationPayload, validationPayload, schemaId, msg.sender); | |
} | |
// @dev: actually store the Attestation | |
attestations[id] = Attestation( | |
portalId, | |
schemaId, | |
attestationPayload, | |
false // default value for isRevoked | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
portalRegistry.create()
attestationRegistry.create()