forked from cerc-io/ipld-eth-server
Commandline (#135)
* Add cmd line tool and Makefile * Add shared utils pkg * Add cmdline README * Update godo for new structure
This commit is contained in:
@@ -6,9 +6,9 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
||||
"github.com/8thlight/vulcanizedb/cmd"
|
||||
"github.com/8thlight/vulcanizedb/pkg/filters"
|
||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||
"github.com/8thlight/vulcanizedb/utils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -17,10 +17,10 @@ func main() {
|
||||
|
||||
flag.Parse()
|
||||
var logFilters filters.LogFilters
|
||||
config := cmd.LoadConfig(*environment)
|
||||
config := utils.LoadConfig(*environment)
|
||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||
absFilePath := cmd.AbsFilePath(*filterFilePath)
|
||||
repository := utils.LoadPostgres(config.Database, blockchain.Node())
|
||||
absFilePath := utils.AbsFilePath(*filterFilePath)
|
||||
logFilterBytes, err := ioutil.ReadFile(absFilePath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
@@ -5,18 +5,18 @@ import (
|
||||
|
||||
"fmt"
|
||||
|
||||
"github.com/8thlight/vulcanizedb/cmd"
|
||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||
"github.com/8thlight/vulcanizedb/pkg/history"
|
||||
"github.com/8thlight/vulcanizedb/utils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
environment := flag.String("environment", "", "Environment name")
|
||||
startingBlockNumber := flag.Int("starting-number", -1, "First block to fill from")
|
||||
flag.Parse()
|
||||
config := cmd.LoadConfig(*environment)
|
||||
config := utils.LoadConfig(*environment)
|
||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||
repository := utils.LoadPostgres(config.Database, blockchain.Node())
|
||||
numberOfBlocksCreated := history.PopulateMissingBlocks(blockchain, repository, int64(*startingBlockNumber))
|
||||
fmt.Printf("Populated %d blocks", numberOfBlocksCreated)
|
||||
}
|
||||
|
||||
+3
-3
@@ -7,9 +7,9 @@ import (
|
||||
|
||||
"os"
|
||||
|
||||
"github.com/8thlight/vulcanizedb/cmd"
|
||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||
"github.com/8thlight/vulcanizedb/pkg/history"
|
||||
"github.com/8thlight/vulcanizedb/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -23,9 +23,9 @@ func main() {
|
||||
ticker := time.NewTicker(pollingInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
config := cmd.LoadConfig(*environment)
|
||||
config := utils.LoadConfig(*environment)
|
||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||
repository := utils.LoadPostgres(config.Database, blockchain.Node())
|
||||
validator := history.NewBlockValidator(blockchain, repository, 15)
|
||||
|
||||
for range ticker.C {
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/8thlight/vulcanizedb/cmd"
|
||||
"github.com/8thlight/vulcanizedb/pkg/contract_summary"
|
||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||
"github.com/8thlight/vulcanizedb/utils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -21,10 +21,10 @@ func main() {
|
||||
flag.Parse()
|
||||
|
||||
contractHashLowered := strings.ToLower(*contractHash)
|
||||
config := cmd.LoadConfig(*environment)
|
||||
config := utils.LoadConfig(*environment)
|
||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||
blockNumber := cmd.RequestedBlockNumber(_blockNumber)
|
||||
repository := utils.LoadPostgres(config.Database, blockchain.Node())
|
||||
blockNumber := utils.RequestedBlockNumber(_blockNumber)
|
||||
|
||||
contractSummary, err := contract_summary.NewSummary(blockchain, repository, contractHashLowered, blockNumber)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"path/filepath"
|
||||
|
||||
"math/big"
|
||||
|
||||
"github.com/8thlight/vulcanizedb/pkg/config"
|
||||
"github.com/8thlight/vulcanizedb/pkg/core"
|
||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||
"github.com/8thlight/vulcanizedb/pkg/repositories"
|
||||
)
|
||||
|
||||
func LoadConfig(environment string) config.Config {
|
||||
cfg, err := config.NewConfig(environment)
|
||||
if err != nil {
|
||||
log.Fatalf("Error loading config\n%v", err)
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
func LoadPostgres(database config.Database, node core.Node) repositories.Postgres {
|
||||
repository, err := repositories.NewPostgres(database, node)
|
||||
if err != nil {
|
||||
log.Fatalf("Error loading postgres\n%v", err)
|
||||
}
|
||||
return repository
|
||||
}
|
||||
|
||||
func ReadAbiFile(abiFilepath string) string {
|
||||
abiFilepath = AbsFilePath(abiFilepath)
|
||||
abi, err := geth.ReadAbiFile(abiFilepath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading ABI file at \"%s\"\n %v", abiFilepath, err)
|
||||
}
|
||||
return abi
|
||||
}
|
||||
|
||||
func AbsFilePath(filePath string) string {
|
||||
if !filepath.IsAbs(filePath) {
|
||||
filePath = filepath.Join(config.ProjectRoot(), filePath)
|
||||
}
|
||||
return filePath
|
||||
}
|
||||
|
||||
func GetAbi(abiFilepath string, contractHash string, network string) string {
|
||||
var contractAbiString string
|
||||
if abiFilepath != "" {
|
||||
contractAbiString = ReadAbiFile(abiFilepath)
|
||||
} else {
|
||||
url := geth.GenUrl(network)
|
||||
etherscan := geth.NewEtherScanClient(url)
|
||||
log.Printf("No ABI supplied. Retrieving ABI from Etherscan: %s", url)
|
||||
contractAbiString, _ = etherscan.GetAbi(contractHash)
|
||||
}
|
||||
_, err := geth.ParseAbi(contractAbiString)
|
||||
if err != nil {
|
||||
log.Fatalln("Invalid ABI")
|
||||
}
|
||||
return contractAbiString
|
||||
}
|
||||
|
||||
func RequestedBlockNumber(blockNumber *int64) *big.Int {
|
||||
var _blockNumber *big.Int
|
||||
if *blockNumber == -1 {
|
||||
_blockNumber = nil
|
||||
} else {
|
||||
_blockNumber = big.NewInt(*blockNumber)
|
||||
}
|
||||
return _blockNumber
|
||||
}
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
|
||||
"os"
|
||||
|
||||
"github.com/8thlight/vulcanizedb/cmd"
|
||||
"github.com/8thlight/vulcanizedb/pkg/core"
|
||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||
"github.com/8thlight/vulcanizedb/pkg/history"
|
||||
"github.com/8thlight/vulcanizedb/pkg/repositories"
|
||||
"github.com/8thlight/vulcanizedb/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -32,9 +32,9 @@ func main() {
|
||||
ticker := time.NewTicker(pollingInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
config := cmd.LoadConfig(*environment)
|
||||
config := utils.LoadConfig(*environment)
|
||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||
repository := utils.LoadPostgres(config.Database, blockchain.Node())
|
||||
validator := history.NewBlockValidator(blockchain, repository, 15)
|
||||
|
||||
missingBlocksPopulated := make(chan int)
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/8thlight/vulcanizedb/cmd"
|
||||
"github.com/8thlight/vulcanizedb/pkg/core"
|
||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||
"github.com/8thlight/vulcanizedb/utils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -19,10 +19,10 @@ func main() {
|
||||
flag.Parse()
|
||||
contractHashLowered := strings.ToLower(*contractHash)
|
||||
|
||||
contractAbiString := cmd.GetAbi(*abiFilepath, contractHashLowered, *network)
|
||||
config := cmd.LoadConfig(*environment)
|
||||
contractAbiString := utils.GetAbi(*abiFilepath, contractHashLowered, *network)
|
||||
config := utils.LoadConfig(*environment)
|
||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||
repository := utils.LoadPostgres(config.Database, blockchain.Node())
|
||||
watchedContract := core.Contract{
|
||||
Abi: contractAbiString,
|
||||
Hash: contractHashLowered,
|
||||
|
||||
Reference in New Issue
Block a user