Skip to content

Latest commit

 

History

History
144 lines (117 loc) · 3.83 KB

CONFIGURATION.md

File metadata and controls

144 lines (117 loc) · 3.83 KB

Configuration

Built with Slurp | Install | Usage | Commands | Configuration

Use the example dev configuration to get started.

Global

slurp is configured with standard Elixir constructs under the :slurp key. Details for each configuration option are provided below:

# [default: %{}] [optional] Map of configured advisor groups. See below for more details.
config :slurp, blockchains: %{}

# [default: %{}] [optional] Map of configured advisor groups. See below for more details.
config :slurp, log_subscriptions: %{}

Blockchains

blockchains abstract a common interface for subscribing and requesting data. They are configured under the :slurp, :blockchains key.

config :slurp,
  blockchains: %{
    "ethereum-mainnet" => [
      # [default: true] [optional] Starts the blockchain on initial boot
      start_on_boot: true
    ]
  }

New Head Subscriptions

new_head_subscriptions abstract a common interface for streaming incoming blocks. They are configured under the :slurp, :new_head_subscriptions key.

config :slurp,
  new_head_subscriptions: %{
    "*" => [
      %{
        enabled: true,
        handler: {Examples.NewHeadHandler, :handle_new_head, []}
      }
    ]
  }

Log Subscriptions

log_subscriptions abstract a common interface for scanning events emitted from contracts. They are configured under the :slurp, :log_subscriptions key.

They can be configured in 2 ways:

  1. explicit config map - A map containing keys of event signatures and a list decode handlers
  2. mfa - A module, function, arguments tuple that returns an explicit config map from (1)
config :slurp,
  log_subscriptions: %{
    "ethereum-mainnet" => %{
      "Transfer(address,address,uint256)" => [
        %{
          enabled: true,
          handler: {Examples.EventHandler, :handle_erc20_transfer, []},
          event_mappings: [
            {
              Examples.Tokens.Events.Transfer,
              %{
                "anonymous" => false,
                "inputs" => [
                  %{
                    "indexed" => true,
                    "name" => "from",
                    "type" => "address"
                  },
                  %{
                    "indexed" => true,
                    "name" => "to",
                    "type" => "address"
                  },
                  %{
                    "indexed" => false,
                    "name" => "value",
                    "type" => "uint256"
                  }
                ],
                "name" => "Transfer",
                "type" => "event"
              }
            }
          ]
        }
      ]
    },
    "*" => [
      {Examples.Tokens.EventFactory, :create, [[approval_enabled: true, transfer_enabled: true]]}
    ]
  }

Logging

By default Elixir will use the console logger to print logs to stdout in the main process running slurp. You can configure your Elixir logger to format or change the location of the output.

For example. To write to a file, add a file logger:

# mix.exs
defp deps do
  {:logger_file_backend, "~> 0.0.10"}
end

And configure it's log location:

# config/config.exs
use Mix.Config

config :logger, :file_log, path: "./log/#{Mix.env()}.log"
config :logger, backends: [{LoggerFileBackend, :file_log}]

If you intend to deploy slurp to a service that ingests structured logs, you will need to use a supported backed. For Google Cloud Stackdriver you can use logger_json

# mix.exs
defp deps do
  {:logger_json, "~> 2.0.1"}
end

# config/config.exs
use Mix.Config

config :logger_json, :backend, metadata: :all
config :logger, backends: [LoggerJSON]