Skip to content

Commit

Permalink
ContractPublisher updates for new publish flow (#184)
Browse files Browse the repository at this point in the history
* ContractPublisher updates for new publish flow

* more efficient uri mapping, delete unused contracts

* docs + remove extra function in interface
  • Loading branch information
joaquim-verges authored Jun 30, 2022
1 parent b4eedaf commit 5bdf436
Show file tree
Hide file tree
Showing 18 changed files with 151 additions and 650 deletions.
154 changes: 0 additions & 154 deletions contracts/ContractDeployer.sol

This file was deleted.

57 changes: 0 additions & 57 deletions contracts/ContractMetadataRegistry.sol

This file was deleted.

89 changes: 29 additions & 60 deletions contracts/ContractPublisher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
State variables
//////////////////////////////////////////////////////////////*/

/// @dev The global Id for publicly published contracts.
uint256 public nextPublicId = 1;

/// @dev Whether the registry is paused.
bool public isPaused;

/*///////////////////////////////////////////////////////////////
Mappings
//////////////////////////////////////////////////////////////*/

/// @dev Mapping from public Id => publicly published contract.
mapping(uint256 => PublicContract) private publicContracts;

/// @dev Mapping from publisher address => set of published contracts.
mapping(address => CustomContractSet) private contractsOfPublisher;
/// @dev Mapping publisher address => profile uri
mapping(address => string) private profileUriOfPublisher;
/// @dev Mapping compilerMetadataUri => publishedMetadataUri
mapping(string => PublishedMetadataSet) private compilerMetadataUriToPublishedMetadataUris;

/*///////////////////////////////////////////////////////////////
Constructor + modifiers
Expand Down Expand Up @@ -59,29 +57,6 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
Getter logic
//////////////////////////////////////////////////////////////*/

/// @notice Returns the latest version of all contracts published by a publisher.
function getAllPublicPublishedContracts() external view returns (CustomContractInstance[] memory published) {
uint256 net;

for (uint256 i = 0; i < nextPublicId; i += 1) {
PublicContract memory publicContract = publicContracts[i];
if (publicContract.publisher != address(0)) {
net += 1;
}
}

published = new CustomContractInstance[](net);

for (uint256 i = 0; i < net; i += 1) {
PublicContract memory publicContract = publicContracts[i];
if (publicContract.publisher != address(0)) {
published[i] = contractsOfPublisher[publicContract.publisher]
.contracts[keccak256(bytes(publicContract.contractId))]
.latest;
}
}
}

/// @notice Returns the latest version of all contracts published by a publisher.
function getAllPublishedContracts(address _publisher)
external
Expand Down Expand Up @@ -123,23 +98,18 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
published = contractsOfPublisher[_publisher].contracts[keccak256(bytes(_contractId))].latest;
}

/// @notice Returns the public id of a published contract, if it is public.
function getPublicId(address _publisher, string memory _contractId) external view returns (uint256 publicId) {
bytes32 contractIdInBytes = keccak256(bytes(_contractId));
publicId = contractsOfPublisher[_publisher].contracts[contractIdInBytes].publicId;
}

/*///////////////////////////////////////////////////////////////
Publish logic
//////////////////////////////////////////////////////////////*/

/// @notice Let's an account publish a contract. The account must be approved by the publisher, or be the publisher.
function publishContract(
address _publisher,
string memory _contractId,
string memory _publishMetadataUri,
string memory _compilerMetadataUri,
bytes32 _bytecodeHash,
address _implementation,
string memory _contractId
address _implementation
) external onlyPublisher(_publisher) onlyUnpausedOrAdmin {
CustomContractInstance memory publishedContract = CustomContractInstance({
contractId: _contractId,
Expand All @@ -156,9 +126,12 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE

uint256 index = contractsOfPublisher[_publisher].contracts[contractIdInBytes].total;
contractsOfPublisher[_publisher].contracts[contractIdInBytes].total += 1;

contractsOfPublisher[_publisher].contracts[contractIdInBytes].instances[index] = publishedContract;

uint256 metadataIndex = compilerMetadataUriToPublishedMetadataUris[_compilerMetadataUri].index;
compilerMetadataUriToPublishedMetadataUris[_compilerMetadataUri].uris[index] = _publishMetadataUri;
compilerMetadataUriToPublishedMetadataUris[_compilerMetadataUri].index = metadataIndex + 1;

emit ContractPublished(_msgSender(), _publisher, publishedContract);
}

Expand All @@ -178,31 +151,27 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
emit ContractUnpublished(_msgSender(), _publisher, _contractId);
}

/// @notice Lets an account add a published contract (and all its versions). The account must be approved by the publisher, or be the publisher.
function addToPublicList(address _publisher, string memory _contractId) external {
uint256 publicId = nextPublicId;
nextPublicId += 1;

bytes32 contractIdInBytes = keccak256(bytes(_contractId));

PublicContract memory publicContract = PublicContract({ publisher: _publisher, contractId: _contractId });

contractsOfPublisher[_publisher].contracts[contractIdInBytes].publicId = publicId;
publicContracts[publicId] = publicContract;

emit AddedContractToPublicList(_publisher, _contractId);
/// @notice Lets an account set its own publisher profile uri
function setPublisherProfileUri(address publisher, string memory uri) public onlyPublisher(publisher) {
profileUriOfPublisher[publisher] = uri;
}

/// @notice Lets an account remove a published contract (and all its versions). The account must be approved by the publisher, or be the publisher.
function removeFromPublicList(address _publisher, string memory _contractId) external {
bytes32 contractIdInBytes = keccak256(bytes(_contractId));
uint256 publicId = contractsOfPublisher[_publisher].contracts[contractIdInBytes].publicId;

delete contractsOfPublisher[_publisher].contracts[contractIdInBytes].publicId;

delete publicContracts[publicId];
// @notice Get a publisher profile uri
function getPublisherProfileUri(address publisher) public view returns (string memory uri) {
uri = profileUriOfPublisher[publisher];
}

emit RemovedContractToPublicList(_publisher, _contractId);
/// @notice Retrieve the published metadata URI from a compiler metadata URI
function getPublishedUriFromCompilerUri(string memory compilerMetadataUri)
public
view
returns (string[] memory publishedMetadataUris)
{
uint256 length = compilerMetadataUriToPublishedMetadataUris[compilerMetadataUri].index;
publishedMetadataUris = new string[](length);
for (uint256 i = 0; i < length; i += 1) {
publishedMetadataUris[i] = compilerMetadataUriToPublishedMetadataUris[compilerMetadataUri].uris[i];
}
}

/*///////////////////////////////////////////////////////////////
Expand Down
33 changes: 0 additions & 33 deletions contracts/ThirdwebContract.sol

This file was deleted.

Loading

0 comments on commit 5bdf436

Please sign in to comment.