lib/bitcoin/protocol/block.rb in bitcoin-ruby-0.0.6 vs lib/bitcoin/protocol/block.rb in bitcoin-ruby-0.0.7

- old
+ new

@@ -54,11 +54,11 @@ def prev_block_hex @prev_block_hex ||= @prev_block.reverse.unpack("H*")[0] end # create block from raw binary +data+ - def initialize(data) + def initialize(data=nil) @tx = [] parse_data_from_io(data) if data end # parse raw binary data @@ -71,11 +71,11 @@ def parse_data_from_io(buf, header_only=false) buf = buf.is_a?(String) ? StringIO.new(buf) : buf @ver, @prev_block, @mrkl_root, @time, @bits, @nonce = buf.read(80).unpack("Va32a32VVV") recalc_block_hash - if Bitcoin.network[:project] == :namecoin && (@ver & BLOCK_VERSION_AUXPOW) > 0 + if Bitcoin.network[:auxpow_chain_id] != nil && (@ver & BLOCK_VERSION_AUXPOW) > 0 @aux_pow = AuxPow.new(nil) @aux_pow.parse_data_from_io(buf) end return buf if buf.eof? @@ -195,11 +195,11 @@ unless h['hash'] == recalc_block_hash raise "Block hash mismatch! Claimed: #{h['hash']}, Actual: #{@hash}" if do_raise end @aux_pow = AuxPow.from_hash(h['aux_pow']) if h['aux_pow'] h['tx'].each{|tx| @tx << Tx.from_hash(tx) } - if h['tx'].any? && !Bitcoin.freicoin? + if h['tx'].any? (raise "Block merkle root mismatch! Block: #{h['hash']}" unless verify_mrkl_root) if do_raise end } blk end @@ -228,15 +228,9 @@ # read binary block from a file def self.from_file(path); new( Bitcoin::Protocol.read_binary_file(path) ); end # read json block from a file def self.from_json_file(path); from_json( Bitcoin::Protocol.read_binary_file(path) ); end - - # Get a Bitcoin::Validation object to validate this block. It needs a +store+ - # to validate against, and optionally takes the +prev_block+ for optimization. - def validator(store, prev_block = nil) - @validator ||= Bitcoin::Validation::Block.new(self, store, prev_block) - end # get the (statistical) amount of work that was needed to generate this block. def block_work target = Bitcoin.decode_compact_bits(@bits).to_i(16) return 0 if target <= 0