-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get block time of the block where the transaction is located #452
Comments
on processed commitment level it's not possible to get block time before tx |
Open
issue for this: #228 |
@benjiqq I tried processed commitment. As @fanatid said, transactions come before block meta. There is no way to do this. Temporary workaround: const blocks: Record<string, number> = {};
const handleBlockMeta = async (data: SubscribeUpdate): Promise<void> => {
blocks[data.blockMeta.slot] = parseInt(data.blockMeta.blockTime!.timestamp);
};
const handleTransaction = async (data: SubscribeUpdate): Promise<void> => {
const transaction = data.transaction?.transaction;
const message = transaction?.transaction?.message;
const meta = transaction?.meta;
if (!transaction || !message || !meta)
return;
if (meta?.err)
return;
const slot = parseInt(data.transaction.slot);
const maxSlot = Math.max(...Object.keys(blocks).map(b => parseInt(b)));
const timestamp = Math.floor(((blocks[maxSlot.toString()] * 1000) + ((slot - maxSlot) * 400)) / 1000);
}; I will track issue #228 Thanks a lot. |
@uetkaje thats a good approach, not sure whyat block data comes after tx? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I need to get block time where the transaction is located.
With above subscribe request, the transaction message comes before the block meta message. So I can't get block time using the transaction's slot. Is there any way to achieve this?
Thanks in advance.
Best regards,
Emre
The text was updated successfully, but these errors were encountered: