Class: PolarLoop::EventParser

Inherits:
Object
  • Object
show all
Defined in:
lib/polarloop/event_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(contract_caller) ⇒ EventParser

Returns a new instance of EventParser.



5
6
7
# File 'lib/polarloop/event_parser.rb', line 5

def initialize(contract_caller)
  @caller = contract_caller
end

Instance Method Details

#events_for_tx(tx_hash) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/polarloop/event_parser.rb', line 39

def events_for_tx(tx_hash)
  receipt = @caller.get_transaction_receipt(tx_hash)
  logs = receipt.dig("result", "logs") || []

  created_topic = Abi.topic_hex(Abi::MANDATE_CREATED_TOPIC)
  charged_topic = Abi.topic_hex(Abi::MANDATE_CHARGED_TOPIC)
  revoked_topic = Abi.topic_hex(Abi::MANDATE_REVOKED_TOPIC)

  logs.filter_map do |log|
    topic0 = log["topics"]&.first
    case topic0
    when created_topic then parse_mandate_created(log)
    when charged_topic then parse_mandate_charged(log)
    when revoked_topic then parse_mandate_revoked(log)
    end
  end
end

#mandate_charged_events(from_block:, to_block: "latest") ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/polarloop/event_parser.rb', line 19

def mandate_charged_events(from_block:, to_block: "latest")
  logs = @caller.get_logs(
    topics: [Abi.topic_hex(Abi::MANDATE_CHARGED_TOPIC)],
    from_block: from_block,
    to_block: to_block
  )

  logs.map { |log| parse_mandate_charged(log) }
end

#mandate_created_events(from_block:, to_block: "latest") ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/polarloop/event_parser.rb', line 9

def mandate_created_events(from_block:, to_block: "latest")
  logs = @caller.get_logs(
    topics: [Abi.topic_hex(Abi::MANDATE_CREATED_TOPIC)],
    from_block: from_block,
    to_block: to_block
  )

  logs.map { |log| parse_mandate_created(log) }
end

#mandate_revoked_events(from_block:, to_block: "latest") ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/polarloop/event_parser.rb', line 29

def mandate_revoked_events(from_block:, to_block: "latest")
  logs = @caller.get_logs(
    topics: [Abi.topic_hex(Abi::MANDATE_REVOKED_TOPIC)],
    from_block: from_block,
    to_block: to_block
  )

  logs.map { |log| parse_mandate_revoked(log) }
end