@@ -17,21 +17,19 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
17
17
State variables
18
18
//////////////////////////////////////////////////////////////*/
19
19
20
- /// @dev The global Id for publicly published contracts.
21
- uint256 public nextPublicId = 1 ;
22
-
23
20
/// @dev Whether the registry is paused.
24
21
bool public isPaused;
25
22
26
23
/*///////////////////////////////////////////////////////////////
27
24
Mappings
28
25
//////////////////////////////////////////////////////////////*/
29
26
30
- /// @dev Mapping from public Id => publicly published contract.
31
- mapping (uint256 => PublicContract) private publicContracts;
32
-
33
27
/// @dev Mapping from publisher address => set of published contracts.
34
28
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;
35
33
36
34
/*///////////////////////////////////////////////////////////////
37
35
Constructor + modifiers
@@ -59,29 +57,6 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
59
57
Getter logic
60
58
//////////////////////////////////////////////////////////////*/
61
59
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
-
85
60
/// @notice Returns the latest version of all contracts published by a publisher.
86
61
function getAllPublishedContracts (address _publisher )
87
62
external
@@ -123,23 +98,18 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
123
98
published = contractsOfPublisher[_publisher].contracts[keccak256 (bytes (_contractId))].latest;
124
99
}
125
100
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
-
132
101
/*///////////////////////////////////////////////////////////////
133
102
Publish logic
134
103
//////////////////////////////////////////////////////////////*/
135
104
136
105
/// @notice Let's an account publish a contract. The account must be approved by the publisher, or be the publisher.
137
106
function publishContract (
138
107
address _publisher ,
108
+ string memory _contractId ,
139
109
string memory _publishMetadataUri ,
110
+ string memory _compilerMetadataUri ,
140
111
bytes32 _bytecodeHash ,
141
- address _implementation ,
142
- string memory _contractId
112
+ address _implementation
143
113
) external onlyPublisher (_publisher) onlyUnpausedOrAdmin {
144
114
CustomContractInstance memory publishedContract = CustomContractInstance ({
145
115
contractId: _contractId,
@@ -156,9 +126,12 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
156
126
157
127
uint256 index = contractsOfPublisher[_publisher].contracts[contractIdInBytes].total;
158
128
contractsOfPublisher[_publisher].contracts[contractIdInBytes].total += 1 ;
159
-
160
129
contractsOfPublisher[_publisher].contracts[contractIdInBytes].instances[index] = publishedContract;
161
130
131
+ uint256 metadataIndex = compilerMetadataUriToPublishedMetadataUris[_compilerMetadataUri].index;
132
+ compilerMetadataUriToPublishedMetadataUris[_compilerMetadataUri].uris[index] = _publishMetadataUri;
133
+ compilerMetadataUriToPublishedMetadataUris[_compilerMetadataUri].index = metadataIndex + 1 ;
134
+
162
135
emit ContractPublished (_msgSender (), _publisher, publishedContract);
163
136
}
164
137
@@ -178,31 +151,27 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
178
151
emit ContractUnpublished (_msgSender (), _publisher, _contractId);
179
152
}
180
153
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;
194
157
}
195
158
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
+ }
204
163
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
+ }
206
175
}
207
176
208
177
/*///////////////////////////////////////////////////////////////
0 commit comments