lens-modules 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,567 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
|
|
3
|
-
pragma solidity ^0.8.15;
|
|
4
|
-
|
|
5
|
-
import {ValidationLib} from './ValidationLib.sol';
|
|
6
|
-
import {Types} from './constants/Types.sol';
|
|
7
|
-
import {Events} from './constants/Events.sol';
|
|
8
|
-
import {Errors} from './constants/Errors.sol';
|
|
9
|
-
import {IReferenceModule} from '../interfaces/IReferenceModule.sol';
|
|
10
|
-
import {ILegacyReferenceModule} from '../interfaces/ILegacyReferenceModule.sol';
|
|
11
|
-
import {StorageLib} from './StorageLib.sol';
|
|
12
|
-
import {IPublicationActionModule} from '../interfaces/IPublicationActionModule.sol';
|
|
13
|
-
import {IModuleRegistry} from '../interfaces/IModuleRegistry.sol';
|
|
14
|
-
import {ILensHub} from '../interfaces/ILensHub.sol';
|
|
15
|
-
|
|
16
|
-
library PublicationLib {
|
|
17
|
-
function MODULE_REGISTRY() internal view returns (IModuleRegistry) {
|
|
18
|
-
return IModuleRegistry(ILensHub(address(this)).getModuleRegistry());
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @notice Publishes a post to a given profile.
|
|
23
|
-
*
|
|
24
|
-
* @param postParams The PostParams struct.
|
|
25
|
-
*
|
|
26
|
-
* @return uint256 The created publication's pubId.
|
|
27
|
-
*/
|
|
28
|
-
function post(Types.PostParams calldata postParams, address transactionExecutor) external returns (uint256) {
|
|
29
|
-
uint256 pubIdAssigned = ++StorageLib.getProfile(postParams.profileId).pubCount;
|
|
30
|
-
|
|
31
|
-
Types.Publication storage _post = StorageLib.getPublication(postParams.profileId, pubIdAssigned);
|
|
32
|
-
_post.contentURI = postParams.contentURI;
|
|
33
|
-
_post.pubType = Types.PublicationType.Post;
|
|
34
|
-
|
|
35
|
-
bytes memory referenceModuleReturnData = _initPubReferenceModule(
|
|
36
|
-
InitReferenceModuleParams(
|
|
37
|
-
postParams.profileId,
|
|
38
|
-
transactionExecutor,
|
|
39
|
-
pubIdAssigned,
|
|
40
|
-
postParams.referenceModule,
|
|
41
|
-
postParams.referenceModuleInitData
|
|
42
|
-
)
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
bytes[] memory actionModulesReturnDatas = _initPubActionModules(
|
|
46
|
-
InitActionModuleParams(
|
|
47
|
-
postParams.profileId,
|
|
48
|
-
transactionExecutor,
|
|
49
|
-
pubIdAssigned,
|
|
50
|
-
postParams.actionModules,
|
|
51
|
-
postParams.actionModulesInitDatas
|
|
52
|
-
)
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
emit Events.PostCreated(
|
|
56
|
-
postParams,
|
|
57
|
-
pubIdAssigned,
|
|
58
|
-
actionModulesReturnDatas,
|
|
59
|
-
referenceModuleReturnData,
|
|
60
|
-
transactionExecutor,
|
|
61
|
-
block.timestamp
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
return pubIdAssigned;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* @notice Publishes a comment to a given profile via signature.
|
|
69
|
-
*
|
|
70
|
-
* @param commentParams the CommentParams struct.
|
|
71
|
-
*
|
|
72
|
-
* @return uint256 The created publication's pubId.
|
|
73
|
-
*/
|
|
74
|
-
function comment(
|
|
75
|
-
Types.CommentParams calldata commentParams,
|
|
76
|
-
address transactionExecutor
|
|
77
|
-
) external returns (uint256) {
|
|
78
|
-
(
|
|
79
|
-
uint256 pubIdAssigned,
|
|
80
|
-
bytes[] memory actionModulesInitReturnDatas,
|
|
81
|
-
bytes memory referenceModuleInitReturnData,
|
|
82
|
-
Types.PublicationType[] memory referrerPubTypes
|
|
83
|
-
) = _createReferencePublication(
|
|
84
|
-
_asReferencePubParams(commentParams),
|
|
85
|
-
transactionExecutor,
|
|
86
|
-
Types.PublicationType.Comment
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
bytes memory referenceModuleReturnData = _processCommentIfNeeded(
|
|
90
|
-
commentParams,
|
|
91
|
-
pubIdAssigned,
|
|
92
|
-
transactionExecutor,
|
|
93
|
-
referrerPubTypes
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
emit Events.CommentCreated(
|
|
97
|
-
commentParams,
|
|
98
|
-
pubIdAssigned,
|
|
99
|
-
referenceModuleReturnData,
|
|
100
|
-
actionModulesInitReturnDatas,
|
|
101
|
-
referenceModuleInitReturnData,
|
|
102
|
-
transactionExecutor,
|
|
103
|
-
block.timestamp
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
return pubIdAssigned;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @notice Publishes a mirror to a given profile.
|
|
111
|
-
*
|
|
112
|
-
* @param mirrorParams the MirrorParams struct.
|
|
113
|
-
*
|
|
114
|
-
* @return uint256 The created publication's pubId.
|
|
115
|
-
*/
|
|
116
|
-
function mirror(Types.MirrorParams calldata mirrorParams, address transactionExecutor) external returns (uint256) {
|
|
117
|
-
ValidationLib.validatePointedPub(mirrorParams.pointedProfileId, mirrorParams.pointedPubId);
|
|
118
|
-
ValidationLib.validateNotBlocked({profile: mirrorParams.profileId, byProfile: mirrorParams.pointedProfileId});
|
|
119
|
-
|
|
120
|
-
Types.PublicationType[] memory referrerPubTypes = ValidationLib.validateReferrersAndGetReferrersPubTypes(
|
|
121
|
-
mirrorParams.referrerProfileIds,
|
|
122
|
-
mirrorParams.referrerPubIds,
|
|
123
|
-
mirrorParams.pointedProfileId,
|
|
124
|
-
mirrorParams.pointedPubId
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
uint256 pubIdAssigned = ++StorageLib.getProfile(mirrorParams.profileId).pubCount;
|
|
128
|
-
|
|
129
|
-
Types.Publication storage _publication = StorageLib.getPublication(mirrorParams.profileId, pubIdAssigned);
|
|
130
|
-
_publication.pointedProfileId = mirrorParams.pointedProfileId;
|
|
131
|
-
_publication.pointedPubId = mirrorParams.pointedPubId;
|
|
132
|
-
_publication.contentURI = mirrorParams.metadataURI;
|
|
133
|
-
_publication.pubType = Types.PublicationType.Mirror;
|
|
134
|
-
_fillRootOfPublicationInStorage(_publication, mirrorParams.pointedProfileId, mirrorParams.pointedPubId);
|
|
135
|
-
|
|
136
|
-
bytes memory referenceModuleReturnData = _processMirrorIfNeeded(
|
|
137
|
-
mirrorParams,
|
|
138
|
-
pubIdAssigned,
|
|
139
|
-
transactionExecutor,
|
|
140
|
-
referrerPubTypes
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
emit Events.MirrorCreated(
|
|
144
|
-
mirrorParams,
|
|
145
|
-
pubIdAssigned,
|
|
146
|
-
referenceModuleReturnData,
|
|
147
|
-
transactionExecutor,
|
|
148
|
-
block.timestamp
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
return pubIdAssigned;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* @notice Publishes a quote publication to a given profile via signature.
|
|
156
|
-
*
|
|
157
|
-
* @param quoteParams the QuoteParams struct.
|
|
158
|
-
*
|
|
159
|
-
* @return uint256 The created publication's pubId.
|
|
160
|
-
*/
|
|
161
|
-
function quote(Types.QuoteParams calldata quoteParams, address transactionExecutor) external returns (uint256) {
|
|
162
|
-
(
|
|
163
|
-
uint256 pubIdAssigned,
|
|
164
|
-
bytes[] memory actionModulesReturnDatas,
|
|
165
|
-
bytes memory referenceModuleInitReturnData,
|
|
166
|
-
Types.PublicationType[] memory referrerPubTypes
|
|
167
|
-
) = _createReferencePublication(
|
|
168
|
-
_asReferencePubParams(quoteParams),
|
|
169
|
-
transactionExecutor,
|
|
170
|
-
Types.PublicationType.Quote
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
bytes memory referenceModuleReturnData = _processQuoteIfNeeded(
|
|
174
|
-
quoteParams,
|
|
175
|
-
pubIdAssigned,
|
|
176
|
-
transactionExecutor,
|
|
177
|
-
referrerPubTypes
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
emit Events.QuoteCreated(
|
|
181
|
-
quoteParams,
|
|
182
|
-
pubIdAssigned,
|
|
183
|
-
referenceModuleReturnData,
|
|
184
|
-
actionModulesReturnDatas,
|
|
185
|
-
referenceModuleInitReturnData,
|
|
186
|
-
transactionExecutor,
|
|
187
|
-
block.timestamp
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
return pubIdAssigned;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function getPublicationType(uint256 profileId, uint256 pubId) internal view returns (Types.PublicationType) {
|
|
194
|
-
Types.Publication storage _publication = StorageLib.getPublication(profileId, pubId);
|
|
195
|
-
Types.PublicationType pubType = _publication.pubType;
|
|
196
|
-
if (uint8(pubType) == 0) {
|
|
197
|
-
// Legacy V1: If the publication type is 0, we check using the legacy rules.
|
|
198
|
-
if (_publication.pointedProfileId != 0) {
|
|
199
|
-
// It is pointing to a publication, so it can be either a comment or a mirror, depending on if it has a
|
|
200
|
-
// collect module or not.
|
|
201
|
-
if (_publication.__DEPRECATED__collectModule == address(0)) {
|
|
202
|
-
return Types.PublicationType.Mirror;
|
|
203
|
-
} else {
|
|
204
|
-
return Types.PublicationType.Comment;
|
|
205
|
-
}
|
|
206
|
-
} else if (_publication.__DEPRECATED__collectModule != address(0)) {
|
|
207
|
-
return Types.PublicationType.Post;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return pubType;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function getContentURI(uint256 profileId, uint256 pubId) external view returns (string memory) {
|
|
214
|
-
Types.Publication storage _publication = StorageLib.getPublication(profileId, pubId);
|
|
215
|
-
Types.PublicationType pubType = _publication.pubType;
|
|
216
|
-
if (pubType == Types.PublicationType.Nonexistent) {
|
|
217
|
-
pubType = getPublicationType(profileId, pubId);
|
|
218
|
-
}
|
|
219
|
-
if (pubType == Types.PublicationType.Mirror) {
|
|
220
|
-
return StorageLib.getPublication(_publication.pointedProfileId, _publication.pointedPubId).contentURI;
|
|
221
|
-
} else {
|
|
222
|
-
return StorageLib.getPublication(profileId, pubId).contentURI;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function _asReferencePubParams(
|
|
227
|
-
Types.QuoteParams calldata quoteParams
|
|
228
|
-
) private pure returns (Types.ReferencePubParams calldata referencePubParams) {
|
|
229
|
-
// We use assembly to cast the types keeping the params in calldata, as they match the fields.
|
|
230
|
-
assembly {
|
|
231
|
-
referencePubParams := quoteParams
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function _asReferencePubParams(
|
|
236
|
-
Types.CommentParams calldata commentParams
|
|
237
|
-
) private pure returns (Types.ReferencePubParams calldata referencePubParams) {
|
|
238
|
-
// We use assembly to cast the types keeping the params in calldata, as they match the fields.
|
|
239
|
-
assembly {
|
|
240
|
-
referencePubParams := commentParams
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function _createReferencePublication(
|
|
245
|
-
Types.ReferencePubParams calldata referencePubParams,
|
|
246
|
-
address transactionExecutor,
|
|
247
|
-
Types.PublicationType referencePubType
|
|
248
|
-
) private returns (uint256, bytes[] memory, bytes memory, Types.PublicationType[] memory) {
|
|
249
|
-
ValidationLib.validatePointedPub(referencePubParams.pointedProfileId, referencePubParams.pointedPubId);
|
|
250
|
-
ValidationLib.validateNotBlocked({
|
|
251
|
-
profile: referencePubParams.profileId,
|
|
252
|
-
byProfile: referencePubParams.pointedProfileId
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
Types.PublicationType[] memory referrerPubTypes = ValidationLib.validateReferrersAndGetReferrersPubTypes(
|
|
256
|
-
referencePubParams.referrerProfileIds,
|
|
257
|
-
referencePubParams.referrerPubIds,
|
|
258
|
-
referencePubParams.pointedProfileId,
|
|
259
|
-
referencePubParams.pointedPubId
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
(uint256 pubIdAssigned, uint256 rootProfileId) = _fillReferencePublicationStorage(
|
|
263
|
-
referencePubParams,
|
|
264
|
-
referencePubType
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
if (rootProfileId != referencePubParams.pointedProfileId) {
|
|
268
|
-
// We check the block state between the profile commenting/quoting and the root publication's author.
|
|
269
|
-
ValidationLib.validateNotBlocked({profile: referencePubParams.profileId, byProfile: rootProfileId});
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
bytes memory referenceModuleReturnData = _initPubReferenceModule(
|
|
273
|
-
InitReferenceModuleParams(
|
|
274
|
-
referencePubParams.profileId,
|
|
275
|
-
transactionExecutor,
|
|
276
|
-
pubIdAssigned,
|
|
277
|
-
referencePubParams.referenceModule,
|
|
278
|
-
referencePubParams.referenceModuleInitData
|
|
279
|
-
)
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
bytes[] memory actionModulesReturnDatas = _initPubActionModules(
|
|
283
|
-
InitActionModuleParams(
|
|
284
|
-
referencePubParams.profileId,
|
|
285
|
-
transactionExecutor,
|
|
286
|
-
pubIdAssigned,
|
|
287
|
-
referencePubParams.actionModules,
|
|
288
|
-
referencePubParams.actionModulesInitDatas
|
|
289
|
-
)
|
|
290
|
-
);
|
|
291
|
-
|
|
292
|
-
return (pubIdAssigned, actionModulesReturnDatas, referenceModuleReturnData, referrerPubTypes);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
function _fillReferencePublicationStorage(
|
|
296
|
-
Types.ReferencePubParams calldata referencePubParams,
|
|
297
|
-
Types.PublicationType referencePubType
|
|
298
|
-
) private returns (uint256, uint256) {
|
|
299
|
-
uint256 pubIdAssigned = ++StorageLib.getProfile(referencePubParams.profileId).pubCount;
|
|
300
|
-
Types.Publication storage _referencePub;
|
|
301
|
-
_referencePub = StorageLib.getPublication(referencePubParams.profileId, pubIdAssigned);
|
|
302
|
-
_referencePub.pointedProfileId = referencePubParams.pointedProfileId;
|
|
303
|
-
_referencePub.pointedPubId = referencePubParams.pointedPubId;
|
|
304
|
-
_referencePub.contentURI = referencePubParams.contentURI;
|
|
305
|
-
_referencePub.pubType = referencePubType;
|
|
306
|
-
uint256 rootProfileId = _fillRootOfPublicationInStorage(
|
|
307
|
-
_referencePub,
|
|
308
|
-
referencePubParams.pointedProfileId,
|
|
309
|
-
referencePubParams.pointedPubId
|
|
310
|
-
);
|
|
311
|
-
return (pubIdAssigned, rootProfileId);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
function _fillRootOfPublicationInStorage(
|
|
315
|
-
Types.Publication storage _publication,
|
|
316
|
-
uint256 pointedProfileId,
|
|
317
|
-
uint256 pointedPubId
|
|
318
|
-
) internal returns (uint256) {
|
|
319
|
-
Types.Publication storage _pubPointed = StorageLib.getPublication(pointedProfileId, pointedPubId);
|
|
320
|
-
Types.PublicationType pubPointedType = _pubPointed.pubType;
|
|
321
|
-
if (pubPointedType == Types.PublicationType.Post) {
|
|
322
|
-
// The publication pointed is a Lens V2 post.
|
|
323
|
-
_publication.rootPubId = pointedPubId;
|
|
324
|
-
return _publication.rootProfileId = pointedProfileId;
|
|
325
|
-
} else if (pubPointedType == Types.PublicationType.Comment || pubPointedType == Types.PublicationType.Quote) {
|
|
326
|
-
// The publication pointed is either a Lens V2 comment or a Lens V2 quote.
|
|
327
|
-
// Note that even when the publication pointed is a V2 one, it will lack `rootProfileId` and `rootPubId` if
|
|
328
|
-
// there is a Lens V1 Legacy publication in the thread of interactions (including the root post itself).
|
|
329
|
-
_publication.rootPubId = _pubPointed.rootPubId;
|
|
330
|
-
return _publication.rootProfileId = _pubPointed.rootProfileId;
|
|
331
|
-
}
|
|
332
|
-
// Otherwise the root is not filled, as the pointed publication is a Lens V1 Legacy publication, which does not
|
|
333
|
-
// support Lens V2 referral system.
|
|
334
|
-
return 0;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
function _processCommentIfNeeded(
|
|
338
|
-
Types.CommentParams calldata commentParams,
|
|
339
|
-
uint256 pubIdAssigned,
|
|
340
|
-
address transactionExecutor,
|
|
341
|
-
Types.PublicationType[] memory referrerPubTypes
|
|
342
|
-
) private returns (bytes memory) {
|
|
343
|
-
address refModule = StorageLib
|
|
344
|
-
.getPublication(commentParams.pointedProfileId, commentParams.pointedPubId)
|
|
345
|
-
.referenceModule;
|
|
346
|
-
if (refModule != address(0)) {
|
|
347
|
-
try
|
|
348
|
-
IReferenceModule(refModule).processComment(
|
|
349
|
-
Types.ProcessCommentParams({
|
|
350
|
-
profileId: commentParams.profileId,
|
|
351
|
-
pubId: pubIdAssigned,
|
|
352
|
-
transactionExecutor: transactionExecutor,
|
|
353
|
-
pointedProfileId: commentParams.pointedProfileId,
|
|
354
|
-
pointedPubId: commentParams.pointedPubId,
|
|
355
|
-
referrerProfileIds: commentParams.referrerProfileIds,
|
|
356
|
-
referrerPubIds: commentParams.referrerPubIds,
|
|
357
|
-
referrerPubTypes: referrerPubTypes,
|
|
358
|
-
data: commentParams.referenceModuleData
|
|
359
|
-
})
|
|
360
|
-
)
|
|
361
|
-
returns (bytes memory returnData) {
|
|
362
|
-
return (returnData);
|
|
363
|
-
} catch (bytes memory err) {
|
|
364
|
-
assembly {
|
|
365
|
-
/// Equivalent to reverting with the returned error selector if
|
|
366
|
-
/// the length is not zero.
|
|
367
|
-
let length := mload(err)
|
|
368
|
-
if iszero(iszero(length)) {
|
|
369
|
-
revert(add(err, 32), length)
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
if (commentParams.referrerProfileIds.length > 0) {
|
|
373
|
-
// Deprecated reference modules don't support referrers.
|
|
374
|
-
revert Errors.InvalidReferrer();
|
|
375
|
-
}
|
|
376
|
-
ILegacyReferenceModule(refModule).processComment(
|
|
377
|
-
commentParams.profileId,
|
|
378
|
-
commentParams.pointedProfileId,
|
|
379
|
-
commentParams.pointedPubId,
|
|
380
|
-
commentParams.referenceModuleData
|
|
381
|
-
);
|
|
382
|
-
}
|
|
383
|
-
} else {
|
|
384
|
-
if (commentParams.referrerProfileIds.length > 0) {
|
|
385
|
-
// We don't allow referrers if the reference module is not set.
|
|
386
|
-
revert Errors.InvalidReferrer();
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
return '';
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
function _processQuoteIfNeeded(
|
|
393
|
-
Types.QuoteParams calldata quoteParams,
|
|
394
|
-
uint256 pubIdAssigned,
|
|
395
|
-
address transactionExecutor,
|
|
396
|
-
Types.PublicationType[] memory referrerPubTypes
|
|
397
|
-
) private returns (bytes memory) {
|
|
398
|
-
address refModule = StorageLib
|
|
399
|
-
.getPublication(quoteParams.pointedProfileId, quoteParams.pointedPubId)
|
|
400
|
-
.referenceModule;
|
|
401
|
-
if (refModule != address(0)) {
|
|
402
|
-
try
|
|
403
|
-
IReferenceModule(refModule).processQuote(
|
|
404
|
-
Types.ProcessQuoteParams({
|
|
405
|
-
profileId: quoteParams.profileId,
|
|
406
|
-
pubId: pubIdAssigned,
|
|
407
|
-
transactionExecutor: transactionExecutor,
|
|
408
|
-
pointedProfileId: quoteParams.pointedProfileId,
|
|
409
|
-
pointedPubId: quoteParams.pointedPubId,
|
|
410
|
-
referrerProfileIds: quoteParams.referrerProfileIds,
|
|
411
|
-
referrerPubIds: quoteParams.referrerPubIds,
|
|
412
|
-
referrerPubTypes: referrerPubTypes,
|
|
413
|
-
data: quoteParams.referenceModuleData
|
|
414
|
-
})
|
|
415
|
-
)
|
|
416
|
-
returns (bytes memory returnData) {
|
|
417
|
-
return (returnData);
|
|
418
|
-
} catch (bytes memory err) {
|
|
419
|
-
assembly {
|
|
420
|
-
/// Equivalent to reverting with the returned error selector if
|
|
421
|
-
/// the length is not zero.
|
|
422
|
-
let length := mload(err)
|
|
423
|
-
if iszero(iszero(length)) {
|
|
424
|
-
revert(add(err, 32), length)
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
if (quoteParams.referrerProfileIds.length > 0) {
|
|
428
|
-
// Deprecated reference modules don't support referrers.
|
|
429
|
-
revert Errors.InvalidReferrer();
|
|
430
|
-
}
|
|
431
|
-
ILegacyReferenceModule(refModule).processComment(
|
|
432
|
-
quoteParams.profileId,
|
|
433
|
-
quoteParams.pointedProfileId,
|
|
434
|
-
quoteParams.pointedPubId,
|
|
435
|
-
quoteParams.referenceModuleData
|
|
436
|
-
);
|
|
437
|
-
}
|
|
438
|
-
} else {
|
|
439
|
-
if (quoteParams.referrerProfileIds.length > 0) {
|
|
440
|
-
// We don't allow referrers if the reference module is not set.
|
|
441
|
-
revert Errors.InvalidReferrer();
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
return '';
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
function _processMirrorIfNeeded(
|
|
448
|
-
Types.MirrorParams calldata mirrorParams,
|
|
449
|
-
uint256 pubIdAssigned,
|
|
450
|
-
address transactionExecutor,
|
|
451
|
-
Types.PublicationType[] memory referrerPubTypes
|
|
452
|
-
) private returns (bytes memory) {
|
|
453
|
-
address refModule = StorageLib
|
|
454
|
-
.getPublication(mirrorParams.pointedProfileId, mirrorParams.pointedPubId)
|
|
455
|
-
.referenceModule;
|
|
456
|
-
if (refModule != address(0)) {
|
|
457
|
-
try
|
|
458
|
-
IReferenceModule(refModule).processMirror(
|
|
459
|
-
Types.ProcessMirrorParams({
|
|
460
|
-
profileId: mirrorParams.profileId,
|
|
461
|
-
pubId: pubIdAssigned,
|
|
462
|
-
transactionExecutor: transactionExecutor,
|
|
463
|
-
pointedProfileId: mirrorParams.pointedProfileId,
|
|
464
|
-
pointedPubId: mirrorParams.pointedPubId,
|
|
465
|
-
referrerProfileIds: mirrorParams.referrerProfileIds,
|
|
466
|
-
referrerPubIds: mirrorParams.referrerPubIds,
|
|
467
|
-
referrerPubTypes: referrerPubTypes,
|
|
468
|
-
data: mirrorParams.referenceModuleData
|
|
469
|
-
})
|
|
470
|
-
)
|
|
471
|
-
returns (bytes memory returnData) {
|
|
472
|
-
return (returnData);
|
|
473
|
-
} catch (bytes memory err) {
|
|
474
|
-
assembly {
|
|
475
|
-
/// Equivalent to reverting with the returned error selector if
|
|
476
|
-
/// the length is not zero.
|
|
477
|
-
let length := mload(err)
|
|
478
|
-
if iszero(iszero(length)) {
|
|
479
|
-
revert(add(err, 32), length)
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
if (mirrorParams.referrerProfileIds.length > 0) {
|
|
483
|
-
// Deprecated reference modules don't support referrers.
|
|
484
|
-
revert Errors.InvalidReferrer();
|
|
485
|
-
}
|
|
486
|
-
ILegacyReferenceModule(refModule).processMirror(
|
|
487
|
-
mirrorParams.profileId,
|
|
488
|
-
mirrorParams.pointedProfileId,
|
|
489
|
-
mirrorParams.pointedPubId,
|
|
490
|
-
mirrorParams.referenceModuleData
|
|
491
|
-
);
|
|
492
|
-
}
|
|
493
|
-
} else {
|
|
494
|
-
if (mirrorParams.referrerProfileIds.length > 0) {
|
|
495
|
-
// We don't allow referrers if the reference module is not set.
|
|
496
|
-
revert Errors.InvalidReferrer();
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
return '';
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
// Needed to avoid 'stack too deep' issue.
|
|
503
|
-
struct InitActionModuleParams {
|
|
504
|
-
uint256 profileId;
|
|
505
|
-
address transactionExecutor;
|
|
506
|
-
uint256 pubId;
|
|
507
|
-
address[] actionModules;
|
|
508
|
-
bytes[] actionModulesInitDatas;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
function _initPubActionModules(InitActionModuleParams memory params) private returns (bytes[] memory) {
|
|
512
|
-
if (params.actionModules.length != params.actionModulesInitDatas.length) {
|
|
513
|
-
revert Errors.ArrayMismatch();
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
bytes[] memory actionModuleInitResults = new bytes[](params.actionModules.length);
|
|
517
|
-
|
|
518
|
-
uint256 i;
|
|
519
|
-
while (i < params.actionModules.length) {
|
|
520
|
-
MODULE_REGISTRY().verifyModule(
|
|
521
|
-
params.actionModules[i],
|
|
522
|
-
uint256(IModuleRegistry.ModuleType.PUBLICATION_ACTION_MODULE)
|
|
523
|
-
);
|
|
524
|
-
|
|
525
|
-
StorageLib.getPublication(params.profileId, params.pubId).actionModuleEnabled[
|
|
526
|
-
params.actionModules[i]
|
|
527
|
-
] = true;
|
|
528
|
-
|
|
529
|
-
actionModuleInitResults[i] = IPublicationActionModule(params.actionModules[i]).initializePublicationAction(
|
|
530
|
-
params.profileId,
|
|
531
|
-
params.pubId,
|
|
532
|
-
params.transactionExecutor,
|
|
533
|
-
params.actionModulesInitDatas[i]
|
|
534
|
-
);
|
|
535
|
-
|
|
536
|
-
unchecked {
|
|
537
|
-
++i;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
return actionModuleInitResults;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
// Needed to avoid 'stack too deep' issue.
|
|
545
|
-
struct InitReferenceModuleParams {
|
|
546
|
-
uint256 profileId;
|
|
547
|
-
address transactionExecutor;
|
|
548
|
-
uint256 pubId;
|
|
549
|
-
address referenceModule;
|
|
550
|
-
bytes referenceModuleInitData;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
function _initPubReferenceModule(InitReferenceModuleParams memory params) private returns (bytes memory) {
|
|
554
|
-
if (params.referenceModule == address(0)) {
|
|
555
|
-
return new bytes(0);
|
|
556
|
-
}
|
|
557
|
-
MODULE_REGISTRY().verifyModule(params.referenceModule, uint256(IModuleRegistry.ModuleType.REFERENCE_MODULE));
|
|
558
|
-
StorageLib.getPublication(params.profileId, params.pubId).referenceModule = params.referenceModule;
|
|
559
|
-
return
|
|
560
|
-
IReferenceModule(params.referenceModule).initializeReferenceModule(
|
|
561
|
-
params.profileId,
|
|
562
|
-
params.pubId,
|
|
563
|
-
params.transactionExecutor,
|
|
564
|
-
params.referenceModuleInitData
|
|
565
|
-
);
|
|
566
|
-
}
|
|
567
|
-
}
|