Bitcoin Forum
December 03, 2016, 09:41:34 AM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Block number from getwork  (Read 1347 times)
geebus
Sr. Member
****
Offline Offline

Activity: 258



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
1480758094
Hero Member
*
Offline Offline

Posts: 1480758094

View Profile Personal Message (Offline)

Ignore
1480758094
Reply with quote  #2

1480758094
Report to moderator
1480758094
Hero Member
*
Offline Offline

Posts: 1480758094

View Profile Personal Message (Offline)

Ignore
1480758094
Reply with quote  #2

1480758094
Report to moderator
1480758094
Hero Member
*
Offline Offline

Posts: 1480758094

View Profile Personal Message (Offline)

Ignore
1480758094
Reply with quote  #2

1480758094
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1480758094
Hero Member
*
Offline Offline

Posts: 1480758094

View Profile Personal Message (Offline)

Ignore
1480758094
Reply with quote  #2

1480758094
Report to moderator
1480758094
Hero Member
*
Offline Offline

Posts: 1480758094

View Profile Personal Message (Offline)

Ignore
1480758094
Reply with quote  #2

1480758094
Report to moderator
1480758094
Hero Member
*
Offline Offline

Posts: 1480758094

View Profile Personal Message (Offline)

Ignore
1480758094
Reply with quote  #2

1480758094
Report to moderator
jgarzik
Legendary
*
qt
Offline Offline

Activity: 1470


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, bitcoin core dev team and BitPay engineer; opinions are my own, not my employer.
Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
geebus
Sr. Member
****
Offline Offline

Activity: 258



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
*
expert
Offline Offline

Activity: 2492


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



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:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!