@@ -17,21 +17,19 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
1717 State variables
1818 //////////////////////////////////////////////////////////////*/
1919
20- /// @dev The global Id for publicly published contracts.
21- uint256 public nextPublicId = 1 ;
22-
2320 /// @dev Whether the registry is paused.
2421 bool public isPaused;
2522
2623 /*///////////////////////////////////////////////////////////////
2724 Mappings
2825 //////////////////////////////////////////////////////////////*/
2926
30- /// @dev Mapping from public Id => publicly published contract.
31- mapping (uint256 => PublicContract) private publicContracts;
32-
3327 /// @dev Mapping from publisher address => set of published contracts.
3428 mapping (address => CustomContractSet) private contractsOfPublisher;
29+ /// @dev Mapping publisher address => profile uri
30+ mapping (address => string ) private profileUriOfPublisher;
31+ /// @dev Mapping compilerMetadataUri => publishedMetadataUri
32+ mapping (string => PublishedMetadataSet) private compilerMetadataUriToPublishedMetadataUris;
3533
3634 /*///////////////////////////////////////////////////////////////
3735 Constructor + modifiers
@@ -59,29 +57,6 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
5957 Getter logic
6058 //////////////////////////////////////////////////////////////*/
6159
62- /// @notice Returns the latest version of all contracts published by a publisher.
63- function getAllPublicPublishedContracts () external view returns (CustomContractInstance[] memory published ) {
64- uint256 net;
65-
66- for (uint256 i = 0 ; i < nextPublicId; i += 1 ) {
67- PublicContract memory publicContract = publicContracts[i];
68- if (publicContract.publisher != address (0 )) {
69- net += 1 ;
70- }
71- }
72-
73- published = new CustomContractInstance [](net);
74-
75- for (uint256 i = 0 ; i < net; i += 1 ) {
76- PublicContract memory publicContract = publicContracts[i];
77- if (publicContract.publisher != address (0 )) {
78- published[i] = contractsOfPublisher[publicContract.publisher]
79- .contracts[keccak256 (bytes (publicContract.contractId))]
80- .latest;
81- }
82- }
83- }
84-
8560 /// @notice Returns the latest version of all contracts published by a publisher.
8661 function getAllPublishedContracts (address _publisher )
8762 external
@@ -123,23 +98,18 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
12398 published = contractsOfPublisher[_publisher].contracts[keccak256 (bytes (_contractId))].latest;
12499 }
125100
126- /// @notice Returns the public id of a published contract, if it is public.
127- function getPublicId (address _publisher , string memory _contractId ) external view returns (uint256 publicId ) {
128- bytes32 contractIdInBytes = keccak256 (bytes (_contractId));
129- publicId = contractsOfPublisher[_publisher].contracts[contractIdInBytes].publicId;
130- }
131-
132101 /*///////////////////////////////////////////////////////////////
133102 Publish logic
134103 //////////////////////////////////////////////////////////////*/
135104
136105 /// @notice Let's an account publish a contract. The account must be approved by the publisher, or be the publisher.
137106 function publishContract (
138107 address _publisher ,
108+ string memory _contractId ,
139109 string memory _publishMetadataUri ,
110+ string memory _compilerMetadataUri ,
140111 bytes32 _bytecodeHash ,
141- address _implementation ,
142- string memory _contractId
112+ address _implementation
143113 ) external onlyPublisher (_publisher) onlyUnpausedOrAdmin {
144114 CustomContractInstance memory publishedContract = CustomContractInstance ({
145115 contractId: _contractId,
@@ -156,9 +126,12 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
156126
157127 uint256 index = contractsOfPublisher[_publisher].contracts[contractIdInBytes].total;
158128 contractsOfPublisher[_publisher].contracts[contractIdInBytes].total += 1 ;
159-
160129 contractsOfPublisher[_publisher].contracts[contractIdInBytes].instances[index] = publishedContract;
161130
131+ uint256 metadataIndex = compilerMetadataUriToPublishedMetadataUris[_compilerMetadataUri].index;
132+ compilerMetadataUriToPublishedMetadataUris[_compilerMetadataUri].uris[index] = _publishMetadataUri;
133+ compilerMetadataUriToPublishedMetadataUris[_compilerMetadataUri].index = metadataIndex + 1 ;
134+
162135 emit ContractPublished (_msgSender (), _publisher, publishedContract);
163136 }
164137
@@ -178,31 +151,27 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
178151 emit ContractUnpublished (_msgSender (), _publisher, _contractId);
179152 }
180153
181- /// @notice Lets an account add a published contract (and all its versions). The account must be approved by the publisher, or be the publisher.
182- function addToPublicList (address _publisher , string memory _contractId ) external {
183- uint256 publicId = nextPublicId;
184- nextPublicId += 1 ;
185-
186- bytes32 contractIdInBytes = keccak256 (bytes (_contractId));
187-
188- PublicContract memory publicContract = PublicContract ({ publisher: _publisher, contractId: _contractId });
189-
190- contractsOfPublisher[_publisher].contracts[contractIdInBytes].publicId = publicId;
191- publicContracts[publicId] = publicContract;
192-
193- emit AddedContractToPublicList (_publisher, _contractId);
154+ /// @notice Lets an account set its own publisher profile uri
155+ function setPublisherProfileUri (address publisher , string memory uri ) public onlyPublisher (publisher) {
156+ profileUriOfPublisher[publisher] = uri;
194157 }
195158
196- /// @notice Lets an account remove a published contract (and all its versions). The account must be approved by the publisher, or be the publisher.
197- function removeFromPublicList (address _publisher , string memory _contractId ) external {
198- bytes32 contractIdInBytes = keccak256 (bytes (_contractId));
199- uint256 publicId = contractsOfPublisher[_publisher].contracts[contractIdInBytes].publicId;
200-
201- delete contractsOfPublisher[_publisher].contracts[contractIdInBytes].publicId;
202-
203- delete publicContracts[publicId];
159+ // @notice Get a publisher profile uri
160+ function getPublisherProfileUri (address publisher ) public view returns (string memory uri ) {
161+ uri = profileUriOfPublisher[publisher];
162+ }
204163
205- emit RemovedContractToPublicList (_publisher, _contractId);
164+ /// @notice Retrieve the published metadata URI from a compiler metadata URI
165+ function getPublishedUriFromCompilerUri (string memory compilerMetadataUri )
166+ public
167+ view
168+ returns (string [] memory publishedMetadataUris )
169+ {
170+ uint256 length = compilerMetadataUriToPublishedMetadataUris[compilerMetadataUri].index;
171+ publishedMetadataUris = new string [](length);
172+ for (uint256 i = 0 ; i < length; i += 1 ) {
173+ publishedMetadataUris[i] = compilerMetadataUriToPublishedMetadataUris[compilerMetadataUri].uris[i];
174+ }
206175 }
207176
208177 /*///////////////////////////////////////////////////////////////
0 commit comments