Module: Dcha::Peer::HasBlockchain
- Included in:
- Dcha::Peer
- Defined in:
- lib/dcha/peer/has_blockchain.rb
Overview
:nodoc:
Instance Method Summary collapse
Instance Method Details
#blocks(_address) ⇒ Object
9 10 11 |
# File 'lib/dcha/peer/has_blockchain.rb', line 9 def blocks(_address) transmit action: :mine, params: [chain.blocks] end |
#chain ⇒ Object
5 6 7 |
# File 'lib/dcha/peer/has_blockchain.rb', line 5 def chain @chain ||= Chain.new end |
#create_block(root_hash) ⇒ Object
19 20 21 22 |
# File 'lib/dcha/peer/has_blockchain.rb', line 19 def create_block(root_hash) return unless chain.create_and_add_block(root_hash) transmit action: :mine, params: [chain.blocks.last(1)] end |
#mine(blocks) ⇒ Object
13 14 15 16 17 |
# File 'lib/dcha/peer/has_blockchain.rb', line 13 def mine(blocks) blocks.sort! { |x, y| x.index <=> y.index } return unless blocks.last.index > chain.blocks.last.index append_blocks(blocks) end |