Skip to content

Commit

Permalink
Use Sui event's timestamp instead of checkpoint's
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Picco committed Oct 17, 2024
1 parent ab561cb commit 6de709e
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const suiLogMessagePublishedMapper = (

const logMessage = extractEventInfo(event);
if (!logMessage) return undefined;
const { nonce, sender, sequence, payload, consistencyLevel } = logMessage;
const { nonce, sender, sequence, payload, consistencyLevel, timestamp } = logMessage;

logger.info(
`[sui] Source event info: [digest: ${receipt.digest}][VAA: ${CHAIN_ID_SUI}/${sender}/${sequence}]`
Expand All @@ -28,7 +28,7 @@ export const suiLogMessagePublishedMapper = (
name: "log-message-published",
address: event.packageId,
blockHeight: BigInt(receipt.checkpoint || 0),
blockTime: Math.floor(Number(receipt.timestampMs) / 1000), // convert to seconds
blockTime: Math.floor(timestamp / 1000), // convert to seconds
chainId: CHAIN_ID_SUI,
txHash: receipt.digest,
attributes: {
Expand All @@ -41,7 +41,7 @@ export const suiLogMessagePublishedMapper = (
};
};

function extractEventInfo(event: SuiEvent): LogMessagePublished | undefined {
function extractEventInfo(event: SuiEvent): SuiLogMessagePublished | undefined {
const json = event.parsedJson as SuiSourceEvent;

return {
Expand All @@ -50,6 +50,7 @@ function extractEventInfo(event: SuiEvent): LogMessagePublished | undefined {
sequence: Number(json.sequence),
payload: Buffer.from(json.payload).toString("hex"),
consistencyLevel: json.consistency_level,
timestamp: json.timestamp,
};
}

Expand All @@ -59,4 +60,7 @@ interface SuiSourceEvent {
sequence: string;
payload: number[];
consistency_level: number;
timestamp: number;
}

type SuiLogMessagePublished = LogMessagePublished & { timestamp: number };

0 comments on commit 6de709e

Please sign in to comment.