Bitcoin Forum
April 23, 2024, 07:09:31 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Block number from getwork  (Read 1577 times)
geebus (OP)
Sr. Member
****
Offline Offline

Activity: 258
Merit: 250



View Profile WWW
March 02, 2011, 04:19:56 AM
 #1

How would one go about getting the current block number, in a readable format (i.e. the height of the block) from a getwork?

How could/would this be done in python?

Feel like donating to me? BTC Address: 14eUVSgBSzLpHXGAfbN9BojXTWvTb91SHJ
1713856171
Hero Member
*
Offline Offline

Posts: 1713856171

View Profile Personal Message (Offline)

Ignore
1713856171
Reply with quote  #2

1713856171
Report to moderator
1713856171
Hero Member
*
Offline Offline

Posts: 1713856171

View Profile Personal Message (Offline)

Ignore
1713856171
Reply with quote  #2

1713856171
Report to moderator
1713856171
Hero Member
*
Offline Offline

Posts: 1713856171

View Profile Personal Message (Offline)

Ignore
1713856171
Reply with quote  #2

1713856171
Report to moderator
It is a common myth that Bitcoin is ruled by a majority of miners. This is not true. Bitcoin miners "vote" on the ordering of transactions, but that's all they do. They can't vote to change the network rules.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713856171
Hero Member
*
Offline Offline

Posts: 1713856171

View Profile Personal Message (Offline)

Ignore
1713856171
Reply with quote  #2

1713856171
Report to moderator
1713856171
Hero Member
*
Offline Offline

Posts: 1713856171

View Profile Personal Message (Offline)

Ignore
1713856171
Reply with quote  #2

1713856171
Report to moderator
jgarzik
Legendary
*
qt
Offline Offline

Activity: 1596
Merit: 1091


View Profile
March 02, 2011, 04:31:54 AM
 #2

How would one go about getting the current block number, in a readable format (i.e. the height of the block) from a getwork?

Current block chain height is not stored in the getwork data.

getwork data returns a block header, which includes things like previous-block-hash (forms the block chain).  See this example of a block:  http://blockexplorer.com/rawblock/000000000000aaa7a48683e8a184ebd4de700d3c7f29524d95a417b086793ac6

Jeff Garzik, Bloq CEO, former bitcoin core dev team; opinions are my own.
Visit bloq.com / metronome.io
Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
geebus (OP)
Sr. Member
****
Offline Offline

Activity: 258
Merit: 250



View Profile WWW
March 02, 2011, 04:59:27 AM
 #3

I'm looking for a way to verify if the current getwork I'm on is from the current, or last block. Would I be able to do that by looking at "prev_block", and checking against a stored array of the "prev_block" from the previous two blocks?

Like, I have an array with the two last known prev_block values in it. If the prev_block value from the getwork matches the newest stored prev_block value, I know it's from the current block. If it matches the oldest prev_block value, it's from the block prior to the current. Correct?

Feel like donating to me? BTC Address: 14eUVSgBSzLpHXGAfbN9BojXTWvTb91SHJ
theymos
Administrator
Legendary
*
Offline Offline

Activity: 5180
Merit: 12873


View Profile
March 02, 2011, 05:23:29 AM
 #4

I'm looking for a way to verify if the current getwork I'm on is from the current, or last block. Would I be able to do that by looking at "prev_block", and checking against a stored array of the "prev_block" from the previous two blocks?

Like, I have an array with the two last known prev_block values in it. If the prev_block value from the getwork matches the newest stored prev_block value, I know it's from the current block. If it matches the oldest prev_block value, it's from the block prior to the current. Correct?

That won't work unless your getwork is putting you back to a block you've already seen, which it shouldn't do. The problem is getting the hash for the most recent block, which you have never seen before.

If you only need to get this data once in a while, you could use this:
http://blockexplorer.com/q/latesthash
Otherwise, you could patch your Bitcoin to support jgarzik's getblockbycount and then combine getblockbycount with getblockcount to get the hash of the latest block. If you have access to Bitcoin's debug.log, you can search it to find the latest block hash.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
lfm
Full Member
***
Offline Offline

Activity: 196
Merit: 104



View Profile
March 03, 2011, 05:22:18 PM
 #5

I'm looking for a way to verify if the current getwork I'm on is from the current, or last block. Would I be able to do that by looking at "prev_block", and checking against a stored array of the "prev_block" from the previous two blocks?

Like, I have an array with the two last known prev_block values in it. If the prev_block value from the getwork matches the newest stored prev_block value, I know it's from the current block. If it matches the oldest prev_block value, it's from the block prior to the current. Correct?


You would need to get the hash of the current "top" block and compare it to prev-hash in the getwork block.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!