Class: Bitcoin::Builder::BlockBuilder
- Inherits:
-
Object
- Object
- Bitcoin::Builder::BlockBuilder
- Defined in:
- lib/bitcoin/builder.rb
Overview
Instance Method Summary collapse
-
#block(target) ⇒ Object
create the block according to values specified via DSL.
-
#initialize ⇒ BlockBuilder
constructor
A new instance of BlockBuilder.
-
#prev_block(hash) ⇒ Object
set the hash of the previous block.
-
#time(time) ⇒ Object
set the block timestamp (defaults to current time).
-
#tx {|c| ... } ⇒ Object
add transactions to the block (see TxBuilder).
-
#version(v) ⇒ Object
specify block version.
Constructor Details
#initialize ⇒ BlockBuilder
Returns a new instance of BlockBuilder.
52 53 54 |
# File 'lib/bitcoin/builder.rb', line 52 def initialize @block = P::Block.new(nil) end |
Instance Method Details
#block(target) ⇒ Object
create the block according to values specified via DSL.
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/bitcoin/builder.rb', line 79 def block target @block.ver = @version || 1 @block.prev_block = @prev_block.htb.reverse @block.mrkl_root = @mrkl_root @block.time = @time || Time.now.to_i @block.nonce = 0 @block.mrkl_root = Bitcoin.hash_mrkl_tree(@block.tx.map(&:hash)).last.htb.reverse find_hash(target) block = P::Block.new(@block.to_payload) raise "Payload Error" unless block.to_payload == @block.to_payload block end |
#prev_block(hash) ⇒ Object
set the hash of the previous block.
62 63 64 |
# File 'lib/bitcoin/builder.rb', line 62 def prev_block hash @prev_block = hash end |
#time(time) ⇒ Object
set the block timestamp (defaults to current time).
67 68 69 |
# File 'lib/bitcoin/builder.rb', line 67 def time time @time = time end |
#tx {|c| ... } ⇒ Object
add transactions to the block (see TxBuilder).
72 73 74 75 76 |
# File 'lib/bitcoin/builder.rb', line 72 def tx c = TxBuilder.new yield c @block.tx << c.tx end |
#version(v) ⇒ Object
specify block version. this is usually not necessary. defaults to 1.
57 58 59 |
# File 'lib/bitcoin/builder.rb', line 57 def version v @version = v end |