diff --git a/packages/api-main/drizzle/schema.ts b/packages/api-main/drizzle/schema.ts index 80cde5ba..dfa76e94 100644 --- a/packages/api-main/drizzle/schema.ts +++ b/packages/api-main/drizzle/schema.ts @@ -6,6 +6,7 @@ const MEMO_LENGTH = 512; export const FeedTable = pgTable( 'feed', { + block_height: bigint({ mode: 'bigint' }), // Height of the block that contains the transaction hash: varchar({ length: 64 }).primaryKey(), // Main hash from the transaction post_hash: varchar({ length: 64 }), // Optional, this makes a post a reply, provided through memo author: varchar({ length: 44 }).notNull(), // Address of user, usually in the transfer message diff --git a/packages/api-main/src/posts/post.ts b/packages/api-main/src/posts/post.ts index bb80d51a..d654e594 100644 --- a/packages/api-main/src/posts/post.ts +++ b/packages/api-main/src/posts/post.ts @@ -9,6 +9,7 @@ import { postToDiscord } from '../utility'; const statement = getDatabase() .insert(FeedTable) .values({ + block_height: sql.placeholder('block_height'), hash: sql.placeholder('hash'), timestamp: sql.placeholder('timestamp'), author: sql.placeholder('author'), @@ -25,6 +26,7 @@ export async function Post(body: Posts.PostBody) { } await statement.execute({ + block_height: body.block_height, hash: body.hash.toLowerCase(), timestamp: new Date(body.timestamp), author: body.from.toLowerCase(), @@ -50,7 +52,7 @@ async function removePostIfBanned(body: Posts.PostBody) { .where(eq(AuditTable.user_address, body.from)) .orderBy(desc(AuditTable.created_at)) .limit(1); - // If there are not action over the user of they were restored (unbanned), do nothing + // If there are not action over the user of they were restored (unbanned), do nothing if (!lastAuditOnUser || lastAuditOnUser.restored_at) { return; } diff --git a/packages/feed-sync/src/feed/replication.ts b/packages/feed-sync/src/feed/replication.ts index 8c284929..a65747b3 100644 --- a/packages/feed-sync/src/feed/replication.ts +++ b/packages/feed-sync/src/feed/replication.ts @@ -133,6 +133,7 @@ export class FeedReplicationService { await this.publish(lsn, post, publishRetries); logger.info('Post published', { lsn, + height: post.block_height, hash: post.hash, timestamp: post.timestamp, }); @@ -186,6 +187,7 @@ export class FeedReplicationService { logger.warn('Post publish failed', { attempt, hash: post.hash, + height: post.block_height, cause: (e as Error).message, }); } diff --git a/packages/feed-sync/src/index.ts b/packages/feed-sync/src/index.ts index 9a799bd2..82149070 100644 --- a/packages/feed-sync/src/index.ts +++ b/packages/feed-sync/src/index.ts @@ -39,8 +39,8 @@ export async function main() { const res = await client.query(query); for (const post of res.rows) { - const { hash, timestamp } = post; - logger.debug('Replaying post', { hash, timestamp }); + const { block_height, hash, timestamp } = post; + logger.debug('Replaying post', { block_height, hash, timestamp }); await publisher.publish(post); } } diff --git a/packages/lib-api-types/src/posts/index.ts b/packages/lib-api-types/src/posts/index.ts index 446dfca2..b2e488fe 100644 --- a/packages/lib-api-types/src/posts/index.ts +++ b/packages/lib-api-types/src/posts/index.ts @@ -66,6 +66,7 @@ export const ModBanBodySchema = t.Object({ export type ModBanBody = Static; export const PostBodySchema = t.Object({ + block_height: t.String(), hash: t.String(), timestamp: t.String(), from: t.String(), diff --git a/packages/reader-main/src/messages/post.ts b/packages/reader-main/src/messages/post.ts index a9b7beb7..082613ae 100644 --- a/packages/reader-main/src/messages/post.ts +++ b/packages/reader-main/src/messages/post.ts @@ -24,6 +24,7 @@ export async function Post(action: ActionWithData): Promise { try { const [message] = extractMemoContent(action.memo, 'dither.Post'); const postBody: Posts.PostBody = { + block_height: action.height, hash: action.hash, from: action.sender, msg: message,