lib/equestreum/chain.rb in equestreum-0.1.0 vs lib/equestreum/chain.rb in equestreum-0.1.1
- old
+ new
@@ -1,9 +1,11 @@
module Equestreum
class Chain < Array
+ private :push, :append, :<<
+
def initialize genesis
- self.push genesis
+ push genesis
end
def grow data
block = Block.new do |b|
b.data = data
@@ -11,11 +13,11 @@
b.difficulty = self.last.difficulty
end
block.mine
- self.push block
+ push block
end
def hash_ok? index
block = self[index]
@@ -71,8 +73,18 @@
def blocks_get_newer?
self.length.times do |index|
raise EquestreumException.new "Block at #{index} seems older than its predecessor" unless newer_than_last? index
end
true
+ end
+
+ def save
+ File.open Config.instance.config['chain_path'], 'w' do |f|
+ f.write Marshal.dump self
+ end
+ end
+
+ def self.revive
+ Marshal.load File.read Config.instance.config['chain_path']
end
end
end