Search
Search

Transaction: DdxZZod...turZ

Status
Succeeded
Transaction Fee
0.0008 
Deposit Value
0 
Gas Used
8 Tgas
Attached Gas
200 Tgas
Created
February 07, 2024 at 9:09:11pm
Hash
DdxZZodQrmCS6733zUqZ9WXMm2GXpxAZJEmYL4QUturZ

Actions

Called method: 'register_indexer_function' in contract: query…tform.near
Arguments:
{ "function_name": "social_feed_reposts_v12", "code": "\n function base64decode(encodedValue) {\n let buff = Buffer.from(encodedValue, \"base64\");\n return JSON.parse(buff.toString(\"utf-8\"));\n }\n\n async function handlePostCreation(\n accountId,\n blockHeight,\n blockTimestamp,\n receiptId,\n content\n ) {\n try {\n const postData = {\n account_id: accountId,\n block_height: blockHeight,\n block_timestamp: blockTimestamp,\n content: content,\n receipt_id: receiptId,\n };\n\n // Call GraphQL mutation to insert a new post\n await context.db.Posts.insert(postData);\n\n console.log(`Post by ${accountId} has been added to the database`);\n } catch (e) {\n console.log(\n `Failed to store post by ${accountId} to the database (perhaps it is already stored)`\n );\n }\n }\n\n async function handleCommentCreation(\n accountId,\n blockHeight,\n blockTimestamp,\n receiptId,\n commentString\n ) {\n try {\n const comment = JSON.parse(commentString);\n const postAuthor = comment.item.path.split(\"/\")[0];\n const postBlockHeight = comment.item.blockHeight;\n\n // find post to retrieve Id or print a warning that we don't have it\n try {\n // Call GraphQL query to fetch posts that match specified criteria\n const posts = await context.db.Posts.select(\n { account_id: postAuthor, block_height: postBlockHeight },\n 1\n );\n console.log(`posts: ${JSON.stringify(posts)}`);\n if (posts.length === 0) {\n return;\n }\n\n const post = posts[0];\n\n try {\n delete comment[\"item\"];\n const commentData = {\n account_id: accountId,\n receipt_id: receiptId,\n block_height: blockHeight,\n block_timestamp: blockTimestamp,\n content: JSON.stringify(comment),\n post_id: post.id,\n };\n // Call GraphQL mutation to insert a new comment\n await context.db.Comments.insert(commentData);\n\n // Update last comment timestamp in Post table\n const currentTimestamp = Date.now();\n await context.db.Posts.update(\n { id: post.id },\n { last_comment_timestamp: currentTimestamp }\n );\n console.log(`Comment by ${accountId} has been added to the database`);\n } catch (e) {\n console.log(\n `Failed to store comment to the post ${postAuthor}/${postBlockHeight} by ${accountId} perhaps it has already been stored. Error ${e}`\n );\n }\n } catch (e) {\n console.log(\n `Failed to store comment to the post ${postAuthor}/${postBlockHeight} as we don't have the post stored.`\n );\n }\n } catch (error) {\n console.log(\"Failed to parse comment content. Skipping...\", error);\n }\n }\n\n async function handleLike(\n accountId,\n blockHeight,\n blockTimestamp,\n receiptId,\n likeContent\n ) {\n try {\n const like = JSON.parse(likeContent);\n const likeAction = like.value.type; // like or unlike\n const [itemAuthor, _, itemType] = like.key.path.split(\"/\", 3);\n const itemBlockHeight = like.key.blockHeight;\n console.log(\"handling like\", receiptId, accountId);\n switch (itemType) {\n case \"main\":\n try {\n const posts = await context.db.Posts.select(\n { account_id: itemAuthor, block_height: itemBlockHeight },\n 1\n );\n if (posts.length == 0) {\n return;\n }\n\n const post = posts[0];\n switch (likeAction) {\n case \"like\":\n await _handlePostLike(\n post.id,\n accountId,\n blockHeight,\n blockTimestamp,\n receiptId\n );\n break;\n case \"unlike\":\n await _handlePostUnlike(post.id, accountId);\n break;\n }\n } catch (e) {\n console.log(\n `Failed to store like to post ${itemAuthor}/${itemBlockHeight} as we don't have it stored in the first place.`\n );\n }\n break;\n case \"comment\":\n // Comment\n console.log(`Likes to comments are not supported yet. Skipping`);\n break;\n default:\n // something else\n console.log(`Got unsupported like type \"${itemType}\". Skipping...`);\n break;\n }\n } catch (error) {\n console.log(\"Failed to parse like content. Skipping...\", error);\n }\n }\n\n async function _handlePostLike(\n postId,\n likeAuthorAccountId,\n likeBlockHeight,\n blockTimestamp,\n receiptId\n ) {\n try {\n const posts = await context.db.Posts.select({ id: postId });\n if (posts.length == 0) {\n return;\n }\n const post = posts[0];\n let accountsLiked =\n post.accounts_liked.length === 0\n ? post.accounts_liked\n : JSON.parse(post.accounts_liked);\n\n if (accountsLiked.indexOf(likeAuthorAccountId) === -1) {\n accountsLiked.push(likeAuthorAccountId);\n }\n\n // Call GraphQL mutation to update a post's liked accounts list\n await context.db.Posts.update(\n { id: postId },\n { accounts_liked: JSON.stringify(accountsLiked) }\n );\n\n const postLikeData = {\n post_id: postId,\n account_id: likeAuthorAccountId,\n block_height: likeBlockHeight,\n block_timestamp: blockTimestamp,\n receipt_id: receiptId,\n };\n // Call GraphQL mutation to insert a new like for a post\n await context.db.PostLikes.insert(postLikeData);\n } catch (e) {\n console.log(`Failed to store like to in the database: ${e}`);\n }\n }\n\n async function _handlePostUnlike(postId, likeAuthorAccountId) {\n try {\n const posts = await context.db.Posts.select({ id: postId });\n if (posts.length == 0) {\n return;\n }\n const post = posts[0];\n let accountsLiked =\n post.accounts_liked.length === 0\n ? post.accounts_liked\n : JSON.parse(post.accounts_liked);\n\n console.log(accountsLiked);\n\n let indexOfLikeAuthorAccountIdInPost =\n accountsLiked.indexOf(likeAuthorAccountId);\n if (indexOfLikeAuthorAccountIdInPost > -1) {\n accountsLiked.splice(indexOfLikeAuthorAccountIdInPost, 1);\n // Call GraphQL mutation to update a post's liked accounts list\n await context.db.Posts.update(\n { id: postId },\n { accounts_liked: JSON.stringify(accountsLiked) }\n );\n }\n // Call GraphQL mutation to delete a like for a post\n await context.db.PostLikes.delete({\n account_id: likeAuthorAccountId,\n post_id: postId,\n });\n } catch (e) {\n console.log(`Failed to delete like from the database: ${e}`);\n }\n }\n\n async function handleRepost(\n accountId,\n blockHeight,\n blockTimestamp,\n receiptId,\n repostContent\n ) {\n try {\n console.log(\"Reposts are a WIP repostContent:\", repostContent);\n\n const content = JSON.parse(repostContent);\n\n if (content[1]?.value?.type !== \"repost\") {\n console.log(\"Skipping non-repost content\", content);\n return;\n }\n\n console.log(\"Reposts are a WIP content:\", content);\n const postAuthor = content[1].key.path.split(\"/\")[0];\n const postBlockHeight = content[1].key.blockHeight;\n\n console.log(\"Reposts are a WIP postAuthor:\", postAuthor);\n console.log(\"Reposts are a WIP blockHeight:\", postBlockHeight);\n\n try {\n const posts = await context.db.Posts.select(\n { account_id: postAuthor, block_height: postBlockHeight },\n 1\n );\n console.log(`posts: ${JSON.stringify(posts)}`, posts);\n if (posts.length == 0) {\n return;\n }\n\n const post = posts[0];\n const accountsReposted =\n post.accounts_reposted.length === 0\n ? post.accounts_reposted\n : JSON.parse(post.accounts_reposted);\n if (accountsReposted.indexOf(accountId) === -1) {\n accountsReposted.push(accountId);\n }\n\n try {\n const repostData = {\n post_id: post.id,\n account_id: accountId,\n content: JSON.stringify(content),\n block_height: blockHeight,\n block_timestamp: blockTimestamp,\n receipt_id: receiptId,\n };\n // Call GraphQL mutation to insert a new repost\n await context.db.Reposts.insert(repostData);\n console.log(`Repost by ${accountId} has been added to the database`);\n\n // Call GraphQL mutation to update a post's reposted accounts list\n await context.db.Posts.update(\n { id: post.id },\n { accounts_reposted: JSON.stringify(accountsReposted) }\n );\n console.log(`Repost by ${accountId} has been added to the database`);\n } catch (e) {\n console.log(\n `Failed to store repost to the post ${postAuthor}/${postBlockHeight} by ${accountId} perhaps it has already been stored. Error ${e}`\n );\n }\n } catch (e) {\n console.log(\n `Failed to store repost to the post ${postAuthor}/${postBlockHeight} as we don't have it stored in the first place.`\n );\n }\n } catch (error) {\n console.log(\"Failed to parse repost content. Skipping...\", error);\n }\n }\n\n // Add your code here\n const SOCIAL_DB = \"social.near\";\n\n let nearSocialPosts = [];\n try {\n const actions = block.actions();\n if (!actions) {\n console.log(\"Block has no actions\");\n return;\n }\n const contractActions = actions.filter(\n (action) => action.receiverId === SOCIAL_DB\n );\n if (!contractActions) {\n console.log(\"Block has no actions\");\n return;\n }\n nearSocialPosts = contractActions.flatMap((action) =>\n action.operations\n .map((operation) => operation[\"FunctionCall\"])\n .filter((operation) => operation?.methodName === \"set\")\n .map((functionCallOperation) => {\n try {\n return {\n ...functionCallOperation,\n args: base64decode(functionCallOperation.args),\n receiptId: action.receiptId, // providing receiptId as we need it\n };\n } catch (e) {\n console.log(\"Error parsing function call\", e);\n }\n })\n .filter((functionCall) => {\n try {\n if (\n !functionCall ||\n !functionCall.args ||\n !functionCall.args.data ||\n !Object.keys(functionCall.args.data) ||\n !Object.keys(functionCall.args.data)[0]\n ) {\n console.log(\n \"Set operation did not have arg data in expected format\"\n );\n return;\n }\n const accountId = Object.keys(functionCall.args.data)[0];\n return (\n Object.keys(functionCall.args.data[accountId]).includes(\"post\") ||\n Object.keys(functionCall.args.data[accountId]).includes(\"index\")\n );\n } catch (e) {\n console.log(\"Error parsing social args\", functionCall);\n }\n })\n );\n } catch (e) {\n console.log(\"Error parsing social operations\", block.actions());\n }\n\n if (nearSocialPosts.length > 0) {\n console.log(\"Found Near Social Posts in Block...\");\n const blockHeight = block.blockHeight;\n const blockTimestamp = block.header().timestampNanosec;\n await Promise.all(\n nearSocialPosts.map(async (postAction) => {\n const accountId = Object.keys(postAction.args.data)[0];\n console.log(`ACCOUNT_ID: ${accountId}`);\n\n // if creates a post\n if (\n postAction.args.data[accountId].post &&\n Object.keys(postAction.args.data[accountId].post).includes(\"main\")\n ) {\n console.log(\"Creating a post...\");\n await handlePostCreation(\n accountId,\n blockHeight,\n blockTimestamp,\n postAction.receiptId,\n postAction.args.data[accountId].post.main\n );\n } else if (\n postAction.args.data[accountId].post &&\n Object.keys(postAction.args.data[accountId].post).includes(\"comment\")\n ) {\n // if creates a comment\n await handleCommentCreation(\n accountId,\n blockHeight,\n blockTimestamp,\n postAction.receiptId,\n postAction.args.data[accountId].post.comment\n );\n } else if (\n Object.keys(postAction.args.data[accountId]).includes(\"index\")\n ) {\n // Probably like or unlike action is happening\n if (\n Object.keys(postAction.args.data[accountId].index).includes(\"like\")\n ) {\n console.log(\"handling like\");\n await handleLike(\n accountId,\n blockHeight,\n blockTimestamp,\n postAction.receiptId,\n postAction.args.data[accountId].index.like\n );\n }\n\n // Probably repost action is happening\n if (\n Object.keys(postAction.args.data[accountId].index).includes(\n \"repost\"\n )\n ) {\n console.log(\"handling repost\");\n await handleRepost(\n accountId,\n blockHeight,\n blockTimestamp,\n postAction.receiptId,\n postAction.args.data[accountId].index.repost\n );\n }\n }\n })\n );\n }\n", "schema": "CREATE TABLE\n \"posts\" (\n \"id\" SERIAL NOT NULL,\n \"account_id\" VARCHAR NOT NULL,\n \"block_height\" DECIMAL(58, 0) NOT NULL,\n \"receipt_id\" VARCHAR NOT NULL,\n \"content\" TEXT NOT NULL,\n \"block_timestamp\" DECIMAL(20, 0) NOT NULL,\n \"accounts_liked\" JSONB NOT NULL DEFAULT '[]',\n \"accounts_reposted\" JSONB NOT NULL DEFAULT '[]',\n \"last_comment_timestamp\" DECIMAL(20, 0),\n CONSTRAINT \"posts_pkey\" PRIMARY KEY (\"id\")\n );\n\nCREATE TABLE\n \"comments\" (\n \"id\" SERIAL NOT NULL,\n \"post_id\" SERIAL NOT NULL,\n \"account_id\" VARCHAR NOT NULL,\n \"block_height\" DECIMAL(58, 0) NOT NULL,\n \"content\" TEXT NOT NULL,\n \"block_timestamp\" DECIMAL(20, 0) NOT NULL,\n \"receipt_id\" VARCHAR NOT NULL,\n CONSTRAINT \"comments_pkey\" PRIMARY KEY (\"id\")\n );\n\nCREATE TABLE\n \"post_likes\" (\n \"id\" SERIAL NOT NULL,\n \"post_id\" SERIAL NOT NULL,\n \"account_id\" VARCHAR NOT NULL,\n \"block_height\" DECIMAL(58, 0),\n \"block_timestamp\" DECIMAL(20, 0) NOT NULL,\n \"receipt_id\" VARCHAR NOT NULL,\n CONSTRAINT \"post_likes_pkey\" PRIMARY KEY (\"post_id\", \"account_id\")\n );\n\nCREATE TABLE\n \"reposts\" (\n \"id\" SERIAL NOT NULL,\n \"post_id\" SERIAL NOT NULL,\n \"account_id\" VARCHAR NOT NULL,\n \"content\" TEXT NOT NULL,\n \"block_height\" DECIMAL(58, 0) NOT NULL,\n \"block_timestamp\" DECIMAL(20, 0) NOT NULL,\n \"receipt_id\" VARCHAR NOT NULL,\n CONSTRAINT \"reposts_pkey\" PRIMARY KEY (\"post_id\", \"account_id\")\n );\n\nCREATE UNIQUE INDEX \"posts_account_id_block_height_key\" ON \"posts\" (\"account_id\" ASC, \"block_height\" ASC);\n\nCREATE UNIQUE INDEX \"comments_post_id_account_id_block_height_key\" ON \"comments\" (\n \"post_id\" ASC,\n \"account_id\" ASC,\n \"block_height\" ASC\n);\n\nCREATE INDEX\n \"posts_last_comment_timestamp_idx\" ON \"posts\" (\"last_comment_timestamp\" DESC);\n\nALTER TABLE\n \"comments\"\nADD\n CONSTRAINT \"comments_post_id_fkey\" FOREIGN KEY (\"post_id\") REFERENCES \"posts\" (\"id\") ON DELETE NO ACTION ON UPDATE NO ACTION;\n\nALTER TABLE\n \"post_likes\"\nADD\n CONSTRAINT \"post_likes_post_id_fkey\" FOREIGN KEY (\"post_id\") REFERENCES \"posts\" (\"id\") ON DELETE CASCADE ON UPDATE NO ACTION;\n\nALTER TABLE\n \"reposts\"\nADD\n CONSTRAINT \"reposts_post_id_fkey\" FOREIGN KEY (\"post_id\") REFERENCES \"posts\" (\"id\") ON DELETE CASCADE ON UPDATE NO ACTION;\n", "start_block_height": 111970835, "filter_json": "{\"indexer_rule_kind\":\"Action\",\"matching_rule\":{\"rule\":\"ACTION_ANY\",\"affected_account_id\":\"social.near\",\"status\":\"SUCCESS\"}}" }

Transaction Execution Plan

Convert Transaction To Receipt
Gas Burned:
2 Tgas
Tokens Burned:
0.00025 
Receipt:
Predecessor ID:
Receiver ID:
Gas Burned:
5 Tgas
Tokens Burned:
0.00056 
Called method: 'register_indexer_function' in contract: query…tform.near
Arguments:
{ "function_name": "social_feed_reposts_v12", "code": "\n function base64decode(encodedValue) {\n let buff = Buffer.from(encodedValue, \"base64\");\n return JSON.parse(buff.toString(\"utf-8\"));\n }\n\n async function handlePostCreation(\n accountId,\n blockHeight,\n blockTimestamp,\n receiptId,\n content\n ) {\n try {\n const postData = {\n account_id: accountId,\n block_height: blockHeight,\n block_timestamp: blockTimestamp,\n content: content,\n receipt_id: receiptId,\n };\n\n // Call GraphQL mutation to insert a new post\n await context.db.Posts.insert(postData);\n\n console.log(`Post by ${accountId} has been added to the database`);\n } catch (e) {\n console.log(\n `Failed to store post by ${accountId} to the database (perhaps it is already stored)`\n );\n }\n }\n\n async function handleCommentCreation(\n accountId,\n blockHeight,\n blockTimestamp,\n receiptId,\n commentString\n ) {\n try {\n const comment = JSON.parse(commentString);\n const postAuthor = comment.item.path.split(\"/\")[0];\n const postBlockHeight = comment.item.blockHeight;\n\n // find post to retrieve Id or print a warning that we don't have it\n try {\n // Call GraphQL query to fetch posts that match specified criteria\n const posts = await context.db.Posts.select(\n { account_id: postAuthor, block_height: postBlockHeight },\n 1\n );\n console.log(`posts: ${JSON.stringify(posts)}`);\n if (posts.length === 0) {\n return;\n }\n\n const post = posts[0];\n\n try {\n delete comment[\"item\"];\n const commentData = {\n account_id: accountId,\n receipt_id: receiptId,\n block_height: blockHeight,\n block_timestamp: blockTimestamp,\n content: JSON.stringify(comment),\n post_id: post.id,\n };\n // Call GraphQL mutation to insert a new comment\n await context.db.Comments.insert(commentData);\n\n // Update last comment timestamp in Post table\n const currentTimestamp = Date.now();\n await context.db.Posts.update(\n { id: post.id },\n { last_comment_timestamp: currentTimestamp }\n );\n console.log(`Comment by ${accountId} has been added to the database`);\n } catch (e) {\n console.log(\n `Failed to store comment to the post ${postAuthor}/${postBlockHeight} by ${accountId} perhaps it has already been stored. Error ${e}`\n );\n }\n } catch (e) {\n console.log(\n `Failed to store comment to the post ${postAuthor}/${postBlockHeight} as we don't have the post stored.`\n );\n }\n } catch (error) {\n console.log(\"Failed to parse comment content. Skipping...\", error);\n }\n }\n\n async function handleLike(\n accountId,\n blockHeight,\n blockTimestamp,\n receiptId,\n likeContent\n ) {\n try {\n const like = JSON.parse(likeContent);\n const likeAction = like.value.type; // like or unlike\n const [itemAuthor, _, itemType] = like.key.path.split(\"/\", 3);\n const itemBlockHeight = like.key.blockHeight;\n console.log(\"handling like\", receiptId, accountId);\n switch (itemType) {\n case \"main\":\n try {\n const posts = await context.db.Posts.select(\n { account_id: itemAuthor, block_height: itemBlockHeight },\n 1\n );\n if (posts.length == 0) {\n return;\n }\n\n const post = posts[0];\n switch (likeAction) {\n case \"like\":\n await _handlePostLike(\n post.id,\n accountId,\n blockHeight,\n blockTimestamp,\n receiptId\n );\n break;\n case \"unlike\":\n await _handlePostUnlike(post.id, accountId);\n break;\n }\n } catch (e) {\n console.log(\n `Failed to store like to post ${itemAuthor}/${itemBlockHeight} as we don't have it stored in the first place.`\n );\n }\n break;\n case \"comment\":\n // Comment\n console.log(`Likes to comments are not supported yet. Skipping`);\n break;\n default:\n // something else\n console.log(`Got unsupported like type \"${itemType}\". Skipping...`);\n break;\n }\n } catch (error) {\n console.log(\"Failed to parse like content. Skipping...\", error);\n }\n }\n\n async function _handlePostLike(\n postId,\n likeAuthorAccountId,\n likeBlockHeight,\n blockTimestamp,\n receiptId\n ) {\n try {\n const posts = await context.db.Posts.select({ id: postId });\n if (posts.length == 0) {\n return;\n }\n const post = posts[0];\n let accountsLiked =\n post.accounts_liked.length === 0\n ? post.accounts_liked\n : JSON.parse(post.accounts_liked);\n\n if (accountsLiked.indexOf(likeAuthorAccountId) === -1) {\n accountsLiked.push(likeAuthorAccountId);\n }\n\n // Call GraphQL mutation to update a post's liked accounts list\n await context.db.Posts.update(\n { id: postId },\n { accounts_liked: JSON.stringify(accountsLiked) }\n );\n\n const postLikeData = {\n post_id: postId,\n account_id: likeAuthorAccountId,\n block_height: likeBlockHeight,\n block_timestamp: blockTimestamp,\n receipt_id: receiptId,\n };\n // Call GraphQL mutation to insert a new like for a post\n await context.db.PostLikes.insert(postLikeData);\n } catch (e) {\n console.log(`Failed to store like to in the database: ${e}`);\n }\n }\n\n async function _handlePostUnlike(postId, likeAuthorAccountId) {\n try {\n const posts = await context.db.Posts.select({ id: postId });\n if (posts.length == 0) {\n return;\n }\n const post = posts[0];\n let accountsLiked =\n post.accounts_liked.length === 0\n ? post.accounts_liked\n : JSON.parse(post.accounts_liked);\n\n console.log(accountsLiked);\n\n let indexOfLikeAuthorAccountIdInPost =\n accountsLiked.indexOf(likeAuthorAccountId);\n if (indexOfLikeAuthorAccountIdInPost > -1) {\n accountsLiked.splice(indexOfLikeAuthorAccountIdInPost, 1);\n // Call GraphQL mutation to update a post's liked accounts list\n await context.db.Posts.update(\n { id: postId },\n { accounts_liked: JSON.stringify(accountsLiked) }\n );\n }\n // Call GraphQL mutation to delete a like for a post\n await context.db.PostLikes.delete({\n account_id: likeAuthorAccountId,\n post_id: postId,\n });\n } catch (e) {\n console.log(`Failed to delete like from the database: ${e}`);\n }\n }\n\n async function handleRepost(\n accountId,\n blockHeight,\n blockTimestamp,\n receiptId,\n repostContent\n ) {\n try {\n console.log(\"Reposts are a WIP repostContent:\", repostContent);\n\n const content = JSON.parse(repostContent);\n\n if (content[1]?.value?.type !== \"repost\") {\n console.log(\"Skipping non-repost content\", content);\n return;\n }\n\n console.log(\"Reposts are a WIP content:\", content);\n const postAuthor = content[1].key.path.split(\"/\")[0];\n const postBlockHeight = content[1].key.blockHeight;\n\n console.log(\"Reposts are a WIP postAuthor:\", postAuthor);\n console.log(\"Reposts are a WIP blockHeight:\", postBlockHeight);\n\n try {\n const posts = await context.db.Posts.select(\n { account_id: postAuthor, block_height: postBlockHeight },\n 1\n );\n console.log(`posts: ${JSON.stringify(posts)}`, posts);\n if (posts.length == 0) {\n return;\n }\n\n const post = posts[0];\n const accountsReposted =\n post.accounts_reposted.length === 0\n ? post.accounts_reposted\n : JSON.parse(post.accounts_reposted);\n if (accountsReposted.indexOf(accountId) === -1) {\n accountsReposted.push(accountId);\n }\n\n try {\n const repostData = {\n post_id: post.id,\n account_id: accountId,\n content: JSON.stringify(content),\n block_height: blockHeight,\n block_timestamp: blockTimestamp,\n receipt_id: receiptId,\n };\n // Call GraphQL mutation to insert a new repost\n await context.db.Reposts.insert(repostData);\n console.log(`Repost by ${accountId} has been added to the database`);\n\n // Call GraphQL mutation to update a post's reposted accounts list\n await context.db.Posts.update(\n { id: post.id },\n { accounts_reposted: JSON.stringify(accountsReposted) }\n );\n console.log(`Repost by ${accountId} has been added to the database`);\n } catch (e) {\n console.log(\n `Failed to store repost to the post ${postAuthor}/${postBlockHeight} by ${accountId} perhaps it has already been stored. Error ${e}`\n );\n }\n } catch (e) {\n console.log(\n `Failed to store repost to the post ${postAuthor}/${postBlockHeight} as we don't have it stored in the first place.`\n );\n }\n } catch (error) {\n console.log(\"Failed to parse repost content. Skipping...\", error);\n }\n }\n\n // Add your code here\n const SOCIAL_DB = \"social.near\";\n\n let nearSocialPosts = [];\n try {\n const actions = block.actions();\n if (!actions) {\n console.log(\"Block has no actions\");\n return;\n }\n const contractActions = actions.filter(\n (action) => action.receiverId === SOCIAL_DB\n );\n if (!contractActions) {\n console.log(\"Block has no actions\");\n return;\n }\n nearSocialPosts = contractActions.flatMap((action) =>\n action.operations\n .map((operation) => operation[\"FunctionCall\"])\n .filter((operation) => operation?.methodName === \"set\")\n .map((functionCallOperation) => {\n try {\n return {\n ...functionCallOperation,\n args: base64decode(functionCallOperation.args),\n receiptId: action.receiptId, // providing receiptId as we need it\n };\n } catch (e) {\n console.log(\"Error parsing function call\", e);\n }\n })\n .filter((functionCall) => {\n try {\n if (\n !functionCall ||\n !functionCall.args ||\n !functionCall.args.data ||\n !Object.keys(functionCall.args.data) ||\n !Object.keys(functionCall.args.data)[0]\n ) {\n console.log(\n \"Set operation did not have arg data in expected format\"\n );\n return;\n }\n const accountId = Object.keys(functionCall.args.data)[0];\n return (\n Object.keys(functionCall.args.data[accountId]).includes(\"post\") ||\n Object.keys(functionCall.args.data[accountId]).includes(\"index\")\n );\n } catch (e) {\n console.log(\"Error parsing social args\", functionCall);\n }\n })\n );\n } catch (e) {\n console.log(\"Error parsing social operations\", block.actions());\n }\n\n if (nearSocialPosts.length > 0) {\n console.log(\"Found Near Social Posts in Block...\");\n const blockHeight = block.blockHeight;\n const blockTimestamp = block.header().timestampNanosec;\n await Promise.all(\n nearSocialPosts.map(async (postAction) => {\n const accountId = Object.keys(postAction.args.data)[0];\n console.log(`ACCOUNT_ID: ${accountId}`);\n\n // if creates a post\n if (\n postAction.args.data[accountId].post &&\n Object.keys(postAction.args.data[accountId].post).includes(\"main\")\n ) {\n console.log(\"Creating a post...\");\n await handlePostCreation(\n accountId,\n blockHeight,\n blockTimestamp,\n postAction.receiptId,\n postAction.args.data[accountId].post.main\n );\n } else if (\n postAction.args.data[accountId].post &&\n Object.keys(postAction.args.data[accountId].post).includes(\"comment\")\n ) {\n // if creates a comment\n await handleCommentCreation(\n accountId,\n blockHeight,\n blockTimestamp,\n postAction.receiptId,\n postAction.args.data[accountId].post.comment\n );\n } else if (\n Object.keys(postAction.args.data[accountId]).includes(\"index\")\n ) {\n // Probably like or unlike action is happening\n if (\n Object.keys(postAction.args.data[accountId].index).includes(\"like\")\n ) {\n console.log(\"handling like\");\n await handleLike(\n accountId,\n blockHeight,\n blockTimestamp,\n postAction.receiptId,\n postAction.args.data[accountId].index.like\n );\n }\n\n // Probably repost action is happening\n if (\n Object.keys(postAction.args.data[accountId].index).includes(\n \"repost\"\n )\n ) {\n console.log(\"handling repost\");\n await handleRepost(\n accountId,\n blockHeight,\n blockTimestamp,\n postAction.receiptId,\n postAction.args.data[accountId].index.repost\n );\n }\n }\n })\n );\n }\n", "schema": "CREATE TABLE\n \"posts\" (\n \"id\" SERIAL NOT NULL,\n \"account_id\" VARCHAR NOT NULL,\n \"block_height\" DECIMAL(58, 0) NOT NULL,\n \"receipt_id\" VARCHAR NOT NULL,\n \"content\" TEXT NOT NULL,\n \"block_timestamp\" DECIMAL(20, 0) NOT NULL,\n \"accounts_liked\" JSONB NOT NULL DEFAULT '[]',\n \"accounts_reposted\" JSONB NOT NULL DEFAULT '[]',\n \"last_comment_timestamp\" DECIMAL(20, 0),\n CONSTRAINT \"posts_pkey\" PRIMARY KEY (\"id\")\n );\n\nCREATE TABLE\n \"comments\" (\n \"id\" SERIAL NOT NULL,\n \"post_id\" SERIAL NOT NULL,\n \"account_id\" VARCHAR NOT NULL,\n \"block_height\" DECIMAL(58, 0) NOT NULL,\n \"content\" TEXT NOT NULL,\n \"block_timestamp\" DECIMAL(20, 0) NOT NULL,\n \"receipt_id\" VARCHAR NOT NULL,\n CONSTRAINT \"comments_pkey\" PRIMARY KEY (\"id\")\n );\n\nCREATE TABLE\n \"post_likes\" (\n \"id\" SERIAL NOT NULL,\n \"post_id\" SERIAL NOT NULL,\n \"account_id\" VARCHAR NOT NULL,\n \"block_height\" DECIMAL(58, 0),\n \"block_timestamp\" DECIMAL(20, 0) NOT NULL,\n \"receipt_id\" VARCHAR NOT NULL,\n CONSTRAINT \"post_likes_pkey\" PRIMARY KEY (\"post_id\", \"account_id\")\n );\n\nCREATE TABLE\n \"reposts\" (\n \"id\" SERIAL NOT NULL,\n \"post_id\" SERIAL NOT NULL,\n \"account_id\" VARCHAR NOT NULL,\n \"content\" TEXT NOT NULL,\n \"block_height\" DECIMAL(58, 0) NOT NULL,\n \"block_timestamp\" DECIMAL(20, 0) NOT NULL,\n \"receipt_id\" VARCHAR NOT NULL,\n CONSTRAINT \"reposts_pkey\" PRIMARY KEY (\"post_id\", \"account_id\")\n );\n\nCREATE UNIQUE INDEX \"posts_account_id_block_height_key\" ON \"posts\" (\"account_id\" ASC, \"block_height\" ASC);\n\nCREATE UNIQUE INDEX \"comments_post_id_account_id_block_height_key\" ON \"comments\" (\n \"post_id\" ASC,\n \"account_id\" ASC,\n \"block_height\" ASC\n);\n\nCREATE INDEX\n \"posts_last_comment_timestamp_idx\" ON \"posts\" (\"last_comment_timestamp\" DESC);\n\nALTER TABLE\n \"comments\"\nADD\n CONSTRAINT \"comments_post_id_fkey\" FOREIGN KEY (\"post_id\") REFERENCES \"posts\" (\"id\") ON DELETE NO ACTION ON UPDATE NO ACTION;\n\nALTER TABLE\n \"post_likes\"\nADD\n CONSTRAINT \"post_likes_post_id_fkey\" FOREIGN KEY (\"post_id\") REFERENCES \"posts\" (\"id\") ON DELETE CASCADE ON UPDATE NO ACTION;\n\nALTER TABLE\n \"reposts\"\nADD\n CONSTRAINT \"reposts_post_id_fkey\" FOREIGN KEY (\"post_id\") REFERENCES \"posts\" (\"id\") ON DELETE CASCADE ON UPDATE NO ACTION;\n", "start_block_height": 111970835, "filter_json": "{\"indexer_rule_kind\":\"Action\",\"matching_rule\":{\"rule\":\"ACTION_ANY\",\"affected_account_id\":\"social.near\",\"status\":\"SUCCESS\"}}" }
Empty result
Registering function social_feed_reposts_v12 for account jacksonthedev.near
Receipt:
Predecessor ID:
Receiver ID:
Gas Burned:
223 Ggas
Tokens Burned:
0 
Transferred 0.06951  to jacksonthedev.near
Empty result
No logs