aboutsummaryrefslogtreecommitdiffstats
path: root/indexer/config.go
blob: b6f327538064d20ecf21d303e25645d72ae98d8b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package indexer

import (
    "plugin"

    "github.com/tangerine-network/go-tangerine/core"
    "github.com/tangerine-network/go-tangerine/dex/downloader"
)

// Config is data sources related configs struct.
type Config struct {
    // Used by dex/backend init flow.
    Enable bool

    // Plugin path for building components.
    Plugin string

    // PluginFlags for construction if needed.
    PluginFlags string

    // The genesis block from dex.Config
    Genesis *core.Genesis

    // Protocol options from dex.Config (partial)
    NetworkID uint64
    SyncMode  downloader.SyncMode
}

// NewIndexerFromConfig initialize exporter according to given config.
func NewIndexerFromConfig(bc ReadOnlyBlockChain, c Config) (idx Indexer) {
    if c.Plugin == "" {
        // default
        return
    }

    plug, err := plugin.Open(c.Plugin)
    if err != nil {
        panic(err)
    }

    symbol, err := plug.Lookup(NewIndexerFuncName)
    if err != nil {
        panic(err)
    }

    idx = symbol.(NewIndexerFunc)(bc, c)
    return
}