From 79359926826f33cfecda3c91020ce181b27cc734 Mon Sep 17 00:00:00 2001 From: Alan Donoso Naumczuk Date: Mon, 6 Jan 2025 00:22:08 -0300 Subject: [PATCH] feat: MigartionFeed mecheanism to force checks added --- contracts/migration/MigrationFeed.sol | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/contracts/migration/MigrationFeed.sol b/contracts/migration/MigrationFeed.sol index 82596c9..cd8c6a6 100644 --- a/contracts/migration/MigrationFeed.sol +++ b/contracts/migration/MigrationFeed.sol @@ -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( @@ -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))); @@ -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); + } + } }