Class: BlockGiven::Receipt

Inherits:
Object
  • Object
show all
Defined in:
lib/block_given/receipt.rb

Overview

Transaction receipt with symbolized, integer-decoded fields.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Receipt

Returns a new instance of Receipt.



8
9
10
# File 'lib/block_given/receipt.rb', line 8

def initialize(raw)
  @to_h = raw.is_a?(Receipt) ? raw.to_h : Normalizer.normalize(raw)
end

Instance Attribute Details

#to_hObject (readonly)

Returns the value of attribute to_h.



6
7
8
# File 'lib/block_given/receipt.rb', line 6

def to_h
  @to_h
end

Instance Method Details

#[](key) ⇒ Object



37
# File 'lib/block_given/receipt.rb', line 37

def [](key) = to_h[key.to_sym]

#block_hashObject



14
# File 'lib/block_given/receipt.rb', line 14

def block_hash = to_h[:block_hash]

#block_numberObject



13
# File 'lib/block_given/receipt.rb', line 13

def block_number = to_h[:block_number]

#contract_addressObject



17
# File 'lib/block_given/receipt.rb', line 17

def contract_address = to_h[:contract_address]

#cumulative_gas_usedObject



20
# File 'lib/block_given/receipt.rb', line 20

def cumulative_gas_used = to_h[:cumulative_gas_used]

#effective_gas_priceObject



19
# File 'lib/block_given/receipt.rb', line 19

def effective_gas_price = to_h[:effective_gas_price]

#feeObject

Total fee paid in wei.



35
# File 'lib/block_given/receipt.rb', line 35

def fee = gas_used && effective_gas_price ? gas_used * effective_gas_price : nil

#fromObject



15
# File 'lib/block_given/receipt.rb', line 15

def from = to_h[:from]

#gas_usedObject



18
# File 'lib/block_given/receipt.rb', line 18

def gas_used = to_h[:gas_used]

#inspectObject



39
40
41
42
# File 'lib/block_given/receipt.rb', line 39

def inspect
  "#<BlockGiven::Receipt #{transaction_hash} status=#{status} block=#{block_number} " \
    "gas_used=#{gas_used} logs=#{logs.size}>"
end

#logsObject



22
# File 'lib/block_given/receipt.rb', line 22

def logs = to_h[:logs] || []

#reverted?Boolean

Returns:

  • (Boolean)


32
# File 'lib/block_given/receipt.rb', line 32

def reverted? = status == :reverted

#statusObject

:success / :reverted (pre-Byzantium receipts have no status: treated as success).



25
26
27
28
29
# File 'lib/block_given/receipt.rb', line 25

def status
  return :success if to_h[:status].nil?

  to_h[:status] == 1 ? :success : :reverted
end

#success?Boolean

Returns:

  • (Boolean)


31
# File 'lib/block_given/receipt.rb', line 31

def success? = status == :success

#toObject



16
# File 'lib/block_given/receipt.rb', line 16

def to = to_h[:to]

#transaction_hashObject



12
# File 'lib/block_given/receipt.rb', line 12

def transaction_hash = to_h[:transaction_hash]

#transaction_indexObject



21
# File 'lib/block_given/receipt.rb', line 21

def transaction_index = to_h[:transaction_index]