Bitcoin Forum
April 25, 2024, 12:02:28 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Creating a bitcoin block with a user-specified generation address  (Read 1190 times)
runeks (OP)
Legendary
*
Offline Offline

Activity: 980
Merit: 1008



View Profile WWW
September 12, 2012, 02:16:34 AM
 #1

Hello all

What I'm trying to do is basically create the data structure that would qualify as a valid bitcoin block, if its nonce caused its hash to be below the current target, where the address that would receive the generation output is specified by me.

What I've figured out so far is that I need to use bitcoind's getmemorypool request. From this I can construct all the necessary fields, as far as I can gather:

  • prev_block is included directly in the output, that one's easy
  • For merkle_root I first have to calculate the hash of each transaction included in the output, ie. first transaction in the current output is "0100000001da8d10a3b749dbda1658298d84512836c1bfb2bcbe7b61dcdd3e508bcb7e147700000 0006c493046022100e041a6e5df8c8b44231b4fee02b34e2f12d553ab54dc434c1bf95dffb68e5f 8d022100c74e5318b4c209397be7e1ea4f4ef783d036f5fbe894918e8e31c72e49f75fc30121034 ecf9a2859c419500001e05710bec6673db9a8ea5faaf07497c9c996e1d28f81ffffffff0280324c 35800000001976a914fc8e972d3f4c41b44a3ee71051aaf52f107ceb0f88ac005cb2ec220000001 976a914847641ad2efb44d949070bf6e7b1c367c70f194388ac00000000", so that transaction's hash would be SHA256(SHA256(<output>)) (after converting to and from little endian where necessary), and then the merkle_root would be a double SHA256 of a concatenation of all those hashes. Is this correct?
  • timestamp is included in the getmemorypool as "time", and "bits" is there as well

At least one additional question comes to mind: is there a generation transaction included as the first transaction in the list of transactions output by getmemorypool and, if so, which address is the payout sent to?

Thanks! Smiley
1714046548
Hero Member
*
Offline Offline

Posts: 1714046548

View Profile Personal Message (Offline)

Ignore
1714046548
Reply with quote  #2

1714046548
Report to moderator
1714046548
Hero Member
*
Offline Offline

Posts: 1714046548

View Profile Personal Message (Offline)

Ignore
1714046548
Reply with quote  #2

1714046548
Report to moderator
1714046548
Hero Member
*
Offline Offline

Posts: 1714046548

View Profile Personal Message (Offline)

Ignore
1714046548
Reply with quote  #2

1714046548
Report to moderator
Remember that Bitcoin is still beta software. Don't put all of your money into BTC!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714046548
Hero Member
*
Offline Offline

Posts: 1714046548

View Profile Personal Message (Offline)

Ignore
1714046548
Reply with quote  #2

1714046548
Report to moderator
runeks (OP)
Legendary
*
Offline Offline

Activity: 980
Merit: 1008



View Profile WWW
September 13, 2012, 10:39:24 PM
Last edit: September 15, 2012, 08:30:21 PM by runeks
 #2

Well it seems I've succeeded it coding this in Python. The script basically takes all the transactions that the "getmemorypool" RPC call returns, adds a custom generation transaction at the beginning, and crams this into some random block (000000000000034de9c9a67fe15517e8ab93df99f406ab239478714fb825b969 was chosen). bitcointools' parse_Block and deserialize_Block write sensible information about the block, so it seems to work. Here's the code in case anyone finds it interesting. The script needs to reside in the bitcointools directory, since it uses some of its functions for testing if it actually conforms to the protocol. Of course, the hash won't be below the target though.

EDIT: I put up the code on Github: https://github.com/runeksvendsen/findablock/blob/master/createblock.py

Also, to answer a few of my own questions, the idea I had about the Merkle tree were wrong, this is how it's done: http://bitcoin.stackexchange.com/questions/1110/merkle-tree-example
Also, a generation transaction is not included in the transactions-list in the getmemorypool response.

Cheers! Smiley
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!