Skip to content

Instantly share code, notes, and snippets.

@fdemiramon
Last active July 31, 2023 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdemiramon/63c3164b4130e05ee86d85ae70d322be to your computer and use it in GitHub Desktop.
Save fdemiramon/63c3164b4130e05ee86d85ae70d322be to your computer and use it in GitHub Desktop.
Naive implementation for Portal as data (opposed to Portal as SC)
// 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
);
}
}
@fdemiramon
Copy link
Author

fdemiramon commented Jul 31, 2023

  • as a Portal Creator, I create a new Portal with the method portalRegistry.create()
  • as an Attestation Issuer, I create a new Attestation with the method attestationRegistry.create()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment