Class: Blockchain::Block
- Inherits:
-
Object
- Object
- Blockchain::Block
- Defined in:
- lib/block.rb
Instance Attribute Summary collapse
-
#bits ⇒ Object
readonly
Returns the value of attribute bits.
-
#block_index ⇒ Object
readonly
Returns the value of attribute block_index.
-
#fee ⇒ Object
readonly
Returns the value of attribute fee.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#hsh ⇒ Object
readonly
Returns the value of attribute hsh.
-
#main_chain ⇒ Object
readonly
Returns the value of attribute main_chain.
-
#mrkl_root ⇒ Object
readonly
Returns the value of attribute mrkl_root.
-
#n_tx ⇒ Object
readonly
Returns the value of attribute n_tx.
-
#nonce ⇒ Object
readonly
Returns the value of attribute nonce.
-
#prev_block ⇒ Object
readonly
Returns the value of attribute prev_block.
-
#received_time ⇒ Object
readonly
Returns the value of attribute received_time.
-
#relayed_by ⇒ Object
readonly
Returns the value of attribute relayed_by.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#tx ⇒ Object
readonly
Returns the value of attribute tx.
-
#ver ⇒ Object
readonly
Returns the value of attribute ver.
Class Method Summary collapse
-
.find(id) ⇒ Object
id can be block_hash or block_index.
Instance Method Summary collapse
-
#initialize(b) ⇒ Block
constructor
A new instance of Block.
- #previous ⇒ Object
Constructor Details
#initialize(b) ⇒ Block
Returns a new instance of Block.
13 14 15 16 17 18 19 20 |
# File 'lib/block.rb', line 13 def initialize(b) @hsh = b.delete('hash') # hash is an unfortunate word b.each_key { |k| instance_variable_set("@#{k}", b[k]) } @time = DateTime.strptime(@time.to_s, '%s') @received_time = DateTime.strptime(@received_time.to_s, '%s') @tx.map! { |t| Blockchain::Transaction.new(t) } @fee = Btc.from_satoshis(fee) end |
Instance Attribute Details
#bits ⇒ Object (readonly)
Returns the value of attribute bits.
4 5 6 |
# File 'lib/block.rb', line 4 def bits @bits end |
#block_index ⇒ Object (readonly)
Returns the value of attribute block_index.
5 6 7 |
# File 'lib/block.rb', line 5 def block_index @block_index end |
#fee ⇒ Object (readonly)
Returns the value of attribute fee.
4 5 6 |
# File 'lib/block.rb', line 4 def fee @fee end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
5 6 7 |
# File 'lib/block.rb', line 5 def height @height end |
#hsh ⇒ Object (readonly)
Returns the value of attribute hsh.
3 4 5 |
# File 'lib/block.rb', line 3 def hsh @hsh end |
#main_chain ⇒ Object (readonly)
Returns the value of attribute main_chain.
5 6 7 |
# File 'lib/block.rb', line 5 def main_chain @main_chain end |
#mrkl_root ⇒ Object (readonly)
Returns the value of attribute mrkl_root.
3 4 5 |
# File 'lib/block.rb', line 3 def mrkl_root @mrkl_root end |
#n_tx ⇒ Object (readonly)
Returns the value of attribute n_tx.
4 5 6 |
# File 'lib/block.rb', line 4 def n_tx @n_tx end |
#nonce ⇒ Object (readonly)
Returns the value of attribute nonce.
4 5 6 |
# File 'lib/block.rb', line 4 def nonce @nonce end |
#prev_block ⇒ Object (readonly)
Returns the value of attribute prev_block.
3 4 5 |
# File 'lib/block.rb', line 3 def prev_block @prev_block end |
#received_time ⇒ Object (readonly)
Returns the value of attribute received_time.
5 6 7 |
# File 'lib/block.rb', line 5 def received_time @received_time end |
#relayed_by ⇒ Object (readonly)
Returns the value of attribute relayed_by.
6 7 8 |
# File 'lib/block.rb', line 6 def relayed_by @relayed_by end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
4 5 6 |
# File 'lib/block.rb', line 4 def size @size end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
4 5 6 |
# File 'lib/block.rb', line 4 def time @time end |
#tx ⇒ Object (readonly)
Returns the value of attribute tx.
6 7 8 |
# File 'lib/block.rb', line 6 def tx @tx end |
#ver ⇒ Object (readonly)
Returns the value of attribute ver.
3 4 5 |
# File 'lib/block.rb', line 3 def ver @ver end |
Class Method Details
.find(id) ⇒ Object
id can be block_hash or block_index
9 10 11 |
# File 'lib/block.rb', line 9 def self.find(id) self.new(Blockchain.rawblock(id)) rescue nil end |
Instance Method Details
#previous ⇒ Object
22 23 24 |
# File 'lib/block.rb', line 22 def previous Block.find(@prev_block) end |