aboutsummaryrefslogtreecommitdiffstats
path: root/indexer/config.go
diff options
context:
space:
mode:
authorMeng-Ying Yang <garfield@dexon.org>2018-12-27 19:22:41 +0800
committerWei-Ning Huang <w@dexon.org>2019-03-12 12:19:09 +0800
commitd124aec39f0e346b67434795b433797528084a57 (patch)
tree1b4038f2eca3cbb4b5c04391980a64d00a13134e /indexer/config.go
parent37e5d4b0f6a3ab072a8d41e3414048f8546df237 (diff)
downloaddexon-d124aec39f0e346b67434795b433797528084a57.tar.gz
dexon-d124aec39f0e346b67434795b433797528084a57.tar.zst
dexon-d124aec39f0e346b67434795b433797528084a57.zip
indexer: support data exporting/forwarding (#103)
To support more effective and flexible blockchain info exploring, we add `indexer` package, defines the flow of indexer dameon, and integrate into dex.Dexon fullnode. For more export options, we use Golang built-in `plugin` package to support mulitple implementations.
Diffstat (limited to 'indexer/config.go')
-rw-r--r--indexer/config.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/indexer/config.go b/indexer/config.go
new file mode 100644
index 000000000..3b626272a
--- /dev/null
+++ b/indexer/config.go
@@ -0,0 +1,35 @@
+package indexer
+
+import (
+ "plugin"
+)
+
+// 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
+}
+
+// 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
+}