Class: Web3::Eth::Block

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/web3/eth/block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utility

#from_hex, #hex, #remove_0x_head, #wei_to_ether

Constructor Details

#initialize(block_data) ⇒ Block

Returns a new instance of Block.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/web3/eth/block.rb', line 10

def initialize block_data
  @raw_data = block_data

  block_data.each do |k, v|
    self.instance_variable_set("@#{k}", v)
    self.class.send(:define_method, k, proc {self.instance_variable_get("@#{k}")})
  end

  @transactions = @transactions.collect {|t|  Web3::Eth::Transaction.new t }

end

Instance Attribute Details

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



8
9
10
# File 'lib/web3/eth/block.rb', line 8

def raw_data
  @raw_data
end

Instance Method Details

#block_difficultyObject



30
31
32
# File 'lib/web3/eth/block.rb', line 30

def block_difficulty
  self.respond_to?(:difficulty) ? from_hex(difficulty) : 0
end

#block_gasLimitObject



34
35
36
# File 'lib/web3/eth/block.rb', line 34

def block_gasLimit
  self.respond_to?(:gasLimit) ? from_hex(gasLimit) : 0
end

#block_gasUsedObject



38
39
40
# File 'lib/web3/eth/block.rb', line 38

def block_gasUsed
  self.respond_to?(:gasUsed) ? from_hex(gasUsed) : 0
end

#block_nonceObject



42
43
44
# File 'lib/web3/eth/block.rb', line 42

def block_nonce
  self.respond_to?(:nonce) ? from_hex(nonce) : 0
end

#block_numberObject



26
27
28
# File 'lib/web3/eth/block.rb', line 26

def block_number
  from_hex number
end

#block_sizeObject



46
47
48
# File 'lib/web3/eth/block.rb', line 46

def block_size
  self.respond_to?(:size) ?  from_hex(size) : 0
end

#block_totalDifficultyObject



50
51
52
# File 'lib/web3/eth/block.rb', line 50

def block_totalDifficulty
  self.respond_to?(:totalDifficulty) ? from_hex(totalDifficulty) : 0
end

#timestamp_timeObject



22
23
24
# File 'lib/web3/eth/block.rb', line 22

def timestamp_time
  Time.at from_hex timestamp
end