lib/bitcoin/storage/storage.rb in bitcoin-ruby-0.0.4 vs lib/bitcoin/storage/storage.rb in bitcoin-ruby-0.0.5
- old
+ new
@@ -179,11 +179,11 @@
log.debug { "=> genesis (0)" }
return persist_block(blk, MAIN, 0)
else
depth = prev_block ? prev_block.depth + 1 : 0
log.debug { "=> orphan (#{depth})" }
- return [0, 2] unless in_sync?
+ return [0, 2] unless (in_sync? || Bitcoin.network_name =~ /testnet/)
return persist_block(blk, ORPHAN, depth)
end
end
depth = prev_block.depth + 1
@@ -417,10 +417,15 @@
if File.file?(filename)
log.info { "Importing #{filename}" }
File.open(filename) do |file|
until file.eof?
magic = file.read(4)
- raise "invalid network magic" unless Bitcoin.network[:magic_head] == magic
+
+ # bitcoind pads the ends of the block files so that it doesn't
+ # have to reallocate space on every new block.
+ break if magic == "\0\0\0\0"
+ raise "invalid network magic" unless Bitcoin.network[:magic_head] == magic
+
size = file.read(4).unpack("L")[0]
blk = Bitcoin::P::Block.new(file.read(size))
depth, chain = new_block(blk)
break if max_depth && depth >= max_depth
end