Class: EvmClient::EventLog

Inherits:
Object
  • Object
show all
Defined in:
lib/evm_client/event_log.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address:, block_hash:, block_number:, data:, log_index:, removed:, topics:, transaction_hash:, transaction_index:, signature:, contract:, event:) ⇒ EventLog

Returns a new instance of EventLog.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/evm_client/event_log.rb', line 26

def initialize( address:, block_hash:, block_number:, data:, log_index:, removed:,
                topics:, transaction_hash:, transaction_index:, signature:, contract:, event:)
  @address            = address
  @block_hash         = block_hash
  @block_number       = block_number
  @data               = data
  @log_index          = log_index
  @removed            = removed
  @topics             = topics
  @transaction_hash   = transaction_hash
  @transaction_index  = transaction_index
  @signature          = signature
  @contract           = contract
  @event              = event
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



3
4
5
# File 'lib/evm_client/event_log.rb', line 3

def address
  @address
end

#block_hashObject (readonly)

Returns the value of attribute block_hash.



3
4
5
# File 'lib/evm_client/event_log.rb', line 3

def block_hash
  @block_hash
end

#block_numberObject (readonly)

Returns the value of attribute block_number.



3
4
5
# File 'lib/evm_client/event_log.rb', line 3

def block_number
  @block_number
end

#contractObject (readonly)

Returns the value of attribute contract.



3
4
5
# File 'lib/evm_client/event_log.rb', line 3

def contract
  @contract
end

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/evm_client/event_log.rb', line 3

def data
  @data
end

#eventObject (readonly)

Returns the value of attribute event.



3
4
5
# File 'lib/evm_client/event_log.rb', line 3

def event
  @event
end

#log_indexObject (readonly)

Returns the value of attribute log_index.



3
4
5
# File 'lib/evm_client/event_log.rb', line 3

def log_index
  @log_index
end

#removedObject (readonly)

Returns the value of attribute removed.



3
4
5
# File 'lib/evm_client/event_log.rb', line 3

def removed
  @removed
end

#signatureObject (readonly)

Returns the value of attribute signature.



3
4
5
# File 'lib/evm_client/event_log.rb', line 3

def signature
  @signature
end

#topicsObject (readonly)

Returns the value of attribute topics.



3
4
5
# File 'lib/evm_client/event_log.rb', line 3

def topics
  @topics
end

#transaction_hashObject (readonly)

Returns the value of attribute transaction_hash.



3
4
5
# File 'lib/evm_client/event_log.rb', line 3

def transaction_hash
  @transaction_hash
end

#transaction_indexObject (readonly)

Returns the value of attribute transaction_index.



3
4
5
# File 'lib/evm_client/event_log.rb', line 3

def transaction_index
  @transaction_index
end

Class Method Details

.build(raw_response:, contract:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/evm_client/event_log.rb', line 6

def self.build(raw_response:, contract:)
  signature = raw_response['topics'][0]
  event     = contract.events.find { |event| signature.match(event.signature) }

  new(
    address:           raw_response['address'],
    block_hash:        raw_response['blockHash'],
    block_number:      raw_response['blockNumber'].to_i(16),
    data:              raw_response['data'],
    log_index:         raw_response['logIndex'],
    removed:           raw_response['removed'],
    topics:            raw_response['topics'],
    transaction_hash:  raw_response['transactionHash'],
    transaction_index: raw_response['transactionIndex'],
    signature:         signature,
    contract:          contract,
    event:             event
  )
end

Instance Method Details

#nameObject



42
43
44
# File 'lib/evm_client/event_log.rb', line 42

def name
  event.name
end

#return_valuesObject



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/evm_client/event_log.rb', line 46

def return_values
  return_values = {}

  indexed_params.each_with_index do |param, index|
    return_values[param.name] = topics[index+1]
  end

  non_indexed_params.each_with_index do |param, index|
    return_values[param.name]  = Decoder.new.decode_arguments(non_indexed_params, data)[index]
  end

  return_values
end

#to_hObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/evm_client/event_log.rb', line 60

def to_h
  {
    address:            address,
    block_hash:         block_hash,
    block_number:       block_number,
    data:               data,
    log_index:          log_index,
    removed:            removed,
    topics:             topics,
    transaction_hash:   transaction_hash,
    transaction_index:  transaction_index,
    signature:          signature,
    name:               name,
    contract_name:      contract.name,
    return_values:      return_values
  }
end