mirror of
https://github.com/eosswedenorg/thalos
synced 2026-07-03 11:53:41 +02:00
Move config into it's own package.
This commit is contained in:
parent
545474be4e
commit
97a3f0e2f3
2 changed files with 16 additions and 15 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
package main
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
@ -27,7 +27,7 @@ type Config struct {
|
||||||
EndBlockNum uint32 `json:"end_block_num"`
|
EndBlockNum uint32 `json:"end_block_num"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadConfig(filename string) (Config, error) {
|
func Load(filename string) (Config, error) {
|
||||||
|
|
||||||
cfg := Config{
|
cfg := Config{
|
||||||
StartBlockNum: NULL_BLOCK_NUMBER,
|
StartBlockNum: NULL_BLOCK_NUMBER,
|
||||||
27
main.go
27
main.go
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
"github.com/pborman/getopt/v2"
|
"github.com/pborman/getopt/v2"
|
||||||
"github.com/eosswedenorg-go/pid"
|
"github.com/eosswedenorg-go/pid"
|
||||||
|
"eosio-ship-trace-reader/config"
|
||||||
eos "github.com/eoscanada/eos-go"
|
eos "github.com/eoscanada/eos-go"
|
||||||
shipclient "github.com/eosswedenorg-go/eos-ship-client"
|
shipclient "github.com/eosswedenorg-go/eos-ship-client"
|
||||||
)
|
)
|
||||||
|
|
@ -18,7 +19,7 @@ import (
|
||||||
// Global variables
|
// Global variables
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
|
|
||||||
var config Config
|
var conf config.Config
|
||||||
|
|
||||||
var chainInfo *eos.InfoResp
|
var chainInfo *eos.InfoResp
|
||||||
|
|
||||||
|
|
@ -39,8 +40,8 @@ func readerLoop() {
|
||||||
for {
|
for {
|
||||||
switch state {
|
switch state {
|
||||||
case RS_CONNECT :
|
case RS_CONNECT :
|
||||||
log.Printf("Connecting to ship at: %s", config.ShipApi)
|
log.Printf("Connecting to ship at: %s", conf.ShipApi)
|
||||||
err := shClient.Connect(config.ShipApi)
|
err := shClient.Connect(conf.ShipApi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
log.Printf("Trying again in 5 seconds ....")
|
log.Printf("Trying again in 5 seconds ....")
|
||||||
|
|
@ -149,25 +150,25 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse config
|
// Parse config
|
||||||
config, err = LoadConfig(*configFile)
|
conf, err = config.Load(*configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect to redis
|
// Connect to redis
|
||||||
err = RedisConnect(config.Redis.Addr, config.Redis.Password, config.Redis.DB)
|
err = RedisConnect(conf.Redis.Addr, conf.Redis.Password, conf.Redis.DB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Failed to connect to redis:", err)
|
log.Println("Failed to connect to redis:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init Abi cache
|
// Init Abi cache
|
||||||
InitAbiCache(config.Redis.CacheID)
|
InitAbiCache(conf.Redis.CacheID)
|
||||||
|
|
||||||
// Connect client and get chain info.
|
// Connect client and get chain info.
|
||||||
log.Printf("Get chain info from api at: %s", config.Api)
|
log.Printf("Get chain info from api at: %s", conf.Api)
|
||||||
eosClient = eos.New(config.Api)
|
eosClient = eos.New(conf.Api)
|
||||||
chainInfo, err = eosClient.GetInfo(eosClientCtx)
|
chainInfo, err = eosClient.GetInfo(eosClientCtx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Failed to get info:", err)
|
log.Println("Failed to get info:", err)
|
||||||
|
|
@ -176,17 +177,17 @@ func main() {
|
||||||
|
|
||||||
redisPrefix += chainInfo.ChainID.String() + "."
|
redisPrefix += chainInfo.ChainID.String() + "."
|
||||||
|
|
||||||
if config.StartBlockNum == NULL_BLOCK_NUMBER {
|
if conf.StartBlockNum == config.NULL_BLOCK_NUMBER {
|
||||||
|
|
||||||
if config.IrreversibleOnly {
|
if conf.IrreversibleOnly {
|
||||||
config.StartBlockNum = uint32(chainInfo.LastIrreversibleBlockNum)
|
conf.StartBlockNum = uint32(chainInfo.LastIrreversibleBlockNum)
|
||||||
} else {
|
} else {
|
||||||
config.StartBlockNum = uint32(chainInfo.HeadBlockNum)
|
conf.StartBlockNum = uint32(chainInfo.HeadBlockNum)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct ship client
|
// Construct ship client
|
||||||
shClient = shipclient.NewClient(config.StartBlockNum, config.EndBlockNum, config.IrreversibleOnly)
|
shClient = shipclient.NewClient(conf.StartBlockNum, conf.EndBlockNum, conf.IrreversibleOnly)
|
||||||
shClient.BlockHandler = processBlock
|
shClient.BlockHandler = processBlock
|
||||||
shClient.TraceHandler = processTraces
|
shClient.TraceHandler = processTraces
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue