Class: BlockGiven::Event

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

Overview

A decoded event log.

event.name           # => "Transfer"
event.args           # => { from: "0x...", to: "0x...", value: 1000000 }
event[:value]        # => 1000000
event.block_number   # => 12345

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, signature:, args:, log:) ⇒ Event

Returns a new instance of Event.



13
14
15
16
17
18
# File 'lib/block_given/event.rb', line 13

def initialize(name:, signature:, args:, log:)
  @name = name
  @signature = signature
  @args = args
  @log = log
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



11
12
13
# File 'lib/block_given/event.rb', line 11

def args
  @args
end

#logObject (readonly)

Returns the value of attribute log.



11
12
13
# File 'lib/block_given/event.rb', line 11

def log
  @log
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/block_given/event.rb', line 11

def name
  @name
end

#signatureObject (readonly)

Returns the value of attribute signature.



11
12
13
# File 'lib/block_given/event.rb', line 11

def signature
  @signature
end

Instance Method Details

#[](key) ⇒ Object



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

def [](key) = args[Utils.snake_case(key).to_sym]

#addressObject



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

def address = log[:address] && Utils.checksum_address(log[:address])

#block_hashObject



23
# File 'lib/block_given/event.rb', line 23

def block_hash = log[:block_hash]

#block_numberObject



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

def block_number = log[:block_number]

#inspectObject



34
# File 'lib/block_given/event.rb', line 34

def inspect = "#<BlockGiven::Event #{name} #{args.inspect} block=#{block_number}>"

#log_indexObject



26
# File 'lib/block_given/event.rb', line 26

def log_index = log[:log_index]

#removed?Boolean

Returns:

  • (Boolean)


27
# File 'lib/block_given/event.rb', line 27

def removed? = !!log[:removed]

#to_hObject



29
30
31
32
# File 'lib/block_given/event.rb', line 29

def to_h
  { name: name, args: args, address: address, block_number: block_number,
    transaction_hash: transaction_hash, log_index: log_index }
end

#transaction_hashObject



24
# File 'lib/block_given/event.rb', line 24

def transaction_hash = log[:transaction_hash]

#transaction_indexObject



25
# File 'lib/block_given/event.rb', line 25

def transaction_index = log[:transaction_index]