Skip to content

Commit

Permalink
feat: MigartionFeed mecheanism to force checks added
Browse files Browse the repository at this point in the history
  • Loading branch information
donosonaumczuk committed Jan 6, 2025
1 parent 76164f1 commit 7935992
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion contracts/migration/MigrationFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {KeyValue, RuleProcessingParams} from "contracts/core/types/Types.sol";
import {CreatePostParams} from "contracts/core/interfaces/IFeed.sol";
import {FeedCore as Core, PostStorage} from "contracts/core/primitives/feed/FeedCore.sol";
import {Feed} from "contracts/core/primitives/feed/Feed.sol";
import {IAccessControl} from "contracts/core/interfaces/IAccessControl.sol";

contract MigrationFeed is Feed {
function createPost(
Expand All @@ -26,6 +25,11 @@ contract MigrationFeed is Feed {
) = abi.decode(customParams[0].value, (uint256, uint256, uint256, uint256, uint80, address));
_createPost(postParams, postId, rootPostId, postSequentialId, authorPostSequentialId, creationTimestamp);

if (customParams.length > 1 && abi.decode(customParams[1].value, (bool))) {
// If customParams[1] is present, it must be an ABI-encoded bool representing `forceChecks`
_forceChecks(postId, rootPostId, postParams);
}

if (source != address(0)) {
// Trust the migrator, no source verification
_setPrimitiveInternalExtraDataForEntity(postId, KeyValue(DATA__SOURCE, abi.encode(source)));
Expand Down Expand Up @@ -77,4 +81,22 @@ contract MigrationFeed is Feed {
_newPost.creationTimestamp = creationTimestamp;
_newPost.lastUpdatedTimestamp = creationTimestamp;
}

function _forceChecks(uint256 postId, uint256 rootPostId, CreatePostParams calldata postParams) internal view {
if (rootPostId != postId) {
require(Core._postExists(rootPostId));
}
if (postParams.quotedPostId != 0) {
require(Core._postExists(postParams.quotedPostId));
}
if (postParams.repliedPostId != 0) {
require(Core._postExists(postParams.repliedPostId));
require(rootPostId == Core.$storage().posts[postParams.repliedPostId].rootPostId);
}
if (postParams.repostedPostId != 0) {
require(Core._postExists(postParams.repostedPostId));
require(postParams.quotedPostId == 0 && postParams.repliedPostId == 0);
require(rootPostId == Core.$storage().posts[postParams.repostedPostId].rootPostId);
}
}
}

0 comments on commit 7935992

Please sign in to comment.