class Avalon::Block
Block
contains details about block found by the pool
Constants
- FIELDS
Field formats: name => [width, original name, type/conversion]
Attributes
data[RW]
Public Class Methods
new(hash)
click to toggle source
# File lib/avalon/block.rb, line 71 def initialize hash case hash when Hash @data = hash when String @data = {:hash => hash} bitcoind_update blockchain_update else raise ArgumentError, "Wrong argument to Block.new: #{hash}" end end
print_headers()
click to toggle source
# File lib/avalon/block.rb, line 24 def self.print_headers puts FIELDS.map {|name, (width,_,_ )| name.to_s.ljust(width)}.join(' ') end
Public Instance Methods
bitcoind_update()
click to toggle source
# File lib/avalon/block.rb, line 28 def bitcoind_update # {"hash" : "0000000000000029714fcc1f7bcd43cd13286b665f759eb018cfc539841623a4", # "previousblockhash" : "0000000000000004d388fd4e7bd6aa1c3f3eeae0ceadd7a0bc51ee1fee0be910", # "merkleroot" : "844f841c3fc276023a561503fc21d064bd898d6c9530d34a864efe70f67bfde8", # "version" : 2, # "size" : 249181, # "height" : 238605, # "time" : 1369877473, # "bits" : "1a016164", # "tx" : [..] # --------- # "nonce" : 3370559418, # "confirmations" : 0, # "difficulty" : 12153411.70977583} bitcoind_info = Bitcoind.getblock @data[:hash], "| grep -v -E '^ .*,'" @data.merge! self.class.extract_data_from( bitcoind_info ) if bitcoind_info end
blockchain_update()
click to toggle source
# File lib/avalon/block.rb, line 46 def blockchain_update #{"hash"=>"00000000000000783be7e82df4d8a71bf1fd8073d2bbd60f2b8638e4d042d32c", # "prev_block"=> "00000000000000b277cace9f2556fb8e0545038e83d20846cc4e3a3f61d0f2f2", # "mrkl_root"=> "0a9a292c93ad732e55eeb25633d3e7580894faea908876f2d17589e127e904cd", # "ver"=>2, # "size"=>232091, # "height"=>238557, # "time"=>1369850827, # "bits"=>436298084, # --------- # "fee"=>41058500, # "nonce"=>825834732, # "n_tx"=>504, # "block_index"=>386930, # "main_chain"=>true, # "received_time"=>1369850888, # "relayed_by"=>"37.251.86.21"} blockchain_info = Blockchain.rawblock @data[:hash].rjust(64, '0') @data.merge! self.class.extract_data_from( blockchain_info ) if blockchain_info end
pending?()
click to toggle source
# File lib/avalon/block.rb, line 67 def pending? @data[:reward].nil? && @data[:received].nil? end
to_s()
click to toggle source
# File lib/avalon/block.rb, line 84 def to_s FIELDS.map {|key, (width, _, _ )| @data[key].to_s.ljust(width)}.join(" ") end