Skip to content
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

Question: How to Get the height of a Block #60

Open
jvxis opened this issue Apr 28, 2023 · 1 comment
Open

Question: How to Get the height of a Block #60

jvxis opened this issue Apr 28, 2023 · 1 comment

Comments

@jvxis
Copy link

jvxis commented Apr 28, 2023

Hello,
I'd like to include the height of the block in PostgreSQL table blocks.

This is part of the code where blocks are persisted

if (share.foundBlock){
var shareId = result.rows[0].id;
db.query(
'INSERT INTO blocks(share_id, from_group, to_group, block_hash, worker, created_date, modified_date) VALUES($1, $2, $3, $4, $5, $6, $7)',
[shareId, share.job.fromGroup, share.job.toGroup, share.blockHash, share.workerAddress, new Date(), new Date()],

Thanks,
Jvx

@Lbqds
Copy link
Member

Lbqds commented Apr 29, 2023

There is no block height information in the job. You can obtain the block height in the following two ways:

  1. Parse the parentHash from job.headerBlob, then query the height of the parent block from the full node using the parentHash.
  2. Wait until the block is submitted, then query the block height using the share.blockHash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants