fremantle-industries / slurp

An EVM block ingestion toolkit for Elixir
MIT License
28 stars 3 forks source link

Support events watching from specific contracts #4

Open vbaranov opened 3 years ago

vbaranov commented 3 years ago

Is your feature request related to a problem? Please describe. It is not possible to specify contract addresses which events I would like to subscribe in log_subscriptions command. Am I right?

Describe the solution you'd like Together with events specification, I would like to indicate in the config at which contracts those events happen.

Describe alternatives you've considered Though it is possible to filter from the output in the log file, it would be awesome to have pre-filtering before output. Possibly, it is already implemented. However, I didn't find anything regarding this in the docs. If it exists, please point me out.

rupurt commented 3 years ago

:100: want to have this. Just haven't got around to it yet :smile:

PR's welcome if you want to have a stab at it :wink:

rupurt commented 3 years ago

@vbaranov @AwaitFuture

I've added an example of how I think the configuration DSL should work to support specific contract addresses https://github.com/fremantle-industries/slurp/blob/watch-events-from-specific-contract/config/dev.exs#L91

It should look something like this

config :slurp,
  log_subscriptions: %{
    "*" => %{
      {"Approval(address,address,uint256)",
       [
         "0x26CdfbAeD9F97ecBdc76cA5cC544f052Bd9Ac795",
         "0xFc979087305A826c2B2a0056cFAbA50aad3E6439"
       ]} => [
        %{
          enabled: true,
          struct: Examples.Erc20.Events.Approval,
          handler: {Examples.EventHandler, :handle_erc20_specific_address_approval, []},
          abi: [
            %{
              "anonymous" => false,
              "inputs" => [
                %{
                  "indexed" => true,
                  "name" => "owner",
                  "type" => "address"
                },
                %{
                  "indexed" => true,
                  "name" => "spender",
                  "type" => "address"
                },
                %{
                  "indexed" => false,
                  "name" => "value",
                  "type" => "uint256"
                }
              ],
              "name" => "Approval",
              "type" => "event"
            }
          ]
        }
      ],
    }
  }