Remove fatal from pkg
* Functions in pkg should return errors * If aborting is desired, that behavior should be left to the consumer
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/8thlight/vulcanizedb/cmd"
|
||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||
"github.com/8thlight/vulcanizedb/pkg/history"
|
||||
"github.com/8thlight/vulcanizedb/pkg/repositories"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -16,9 +15,8 @@ func main() {
|
||||
startingBlockNumber := flag.Int("starting-number", -1, "First block to fill from")
|
||||
flag.Parse()
|
||||
config := cmd.LoadConfig(*environment)
|
||||
|
||||
blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
||||
repository := repositories.NewPostgres(config.Database)
|
||||
repository := cmd.LoadPostgres(config.Database)
|
||||
numberOfBlocksCreated := history.PopulateBlocks(blockchain, repository, int64(*startingBlockNumber))
|
||||
fmt.Printf("Populated %d blocks", numberOfBlocksCreated)
|
||||
}
|
||||
|
||||
+1
-3
@@ -10,15 +10,13 @@ import (
|
||||
"github.com/8thlight/vulcanizedb/pkg/core"
|
||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||
"github.com/8thlight/vulcanizedb/pkg/observers"
|
||||
"github.com/8thlight/vulcanizedb/pkg/repositories"
|
||||
)
|
||||
|
||||
func main() {
|
||||
environment := flag.String("environment", "", "Environment name")
|
||||
flag.Parse()
|
||||
config := cmd.LoadConfig(*environment)
|
||||
|
||||
repository := repositories.NewPostgres(config.Database)
|
||||
repository := cmd.LoadPostgres(config.Database)
|
||||
fmt.Printf("Creating Geth Blockchain to: %s\n", config.Client.IPCPath)
|
||||
listener := blockchain_listener.NewBlockchainListener(
|
||||
geth.NewGethBlockchain(config.Client.IPCPath),
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/8thlight/vulcanizedb/cmd"
|
||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||
"github.com/8thlight/vulcanizedb/pkg/repositories"
|
||||
"github.com/8thlight/vulcanizedb/pkg/watched_contracts"
|
||||
)
|
||||
|
||||
@@ -18,9 +17,8 @@ func main() {
|
||||
contractHash := flag.String("contract-hash", "", "Contract hash to show summary")
|
||||
flag.Parse()
|
||||
config := cmd.LoadConfig(*environment)
|
||||
|
||||
blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
||||
repository := repositories.NewPostgres(config.Database)
|
||||
repository := cmd.LoadPostgres(config.Database)
|
||||
contractSummary, err := watched_contracts.NewSummary(blockchain, repository, *contractHash)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/8thlight/vulcanizedb/cmd"
|
||||
"github.com/8thlight/vulcanizedb/pkg/core"
|
||||
"github.com/8thlight/vulcanizedb/pkg/repositories"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -13,6 +12,6 @@ func main() {
|
||||
contractHash := flag.String("contract-hash", "", "contract-hash=x1234")
|
||||
flag.Parse()
|
||||
config := cmd.LoadConfig(*environment)
|
||||
repository := repositories.NewPostgres(config.Database)
|
||||
repository := cmd.LoadPostgres(config.Database)
|
||||
repository.CreateWatchedContract(core.WatchedContract{Hash: *contractHash})
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/8thlight/vulcanizedb/pkg/config"
|
||||
"github.com/8thlight/vulcanizedb/pkg/repositories"
|
||||
)
|
||||
|
||||
func LoadConfig(environment string) config.Config {
|
||||
@@ -13,3 +14,11 @@ func LoadConfig(environment string) config.Config {
|
||||
}
|
||||
return *cfg
|
||||
}
|
||||
|
||||
func LoadPostgres(database config.Database) repositories.Postgres {
|
||||
repository, err := repositories.NewPostgres(database)
|
||||
if err != nil {
|
||||
log.Fatalf("Error loading postgres\n%v", err)
|
||||
}
|
||||
return repository
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user