Remove godo (#136)

This commit is contained in:
Matt K
2018-01-25 15:46:55 -06:00
committed by GitHub
parent 572023cdf5
commit d09c2ae9bb
17 changed files with 74 additions and 523 deletions
+75
View File
@@ -0,0 +1,75 @@
package cmd
import (
"encoding/json"
"io/ioutil"
"log"
"github.com/8thlight/vulcanizedb/pkg/filters"
"github.com/8thlight/vulcanizedb/pkg/geth"
"github.com/8thlight/vulcanizedb/utils"
"github.com/spf13/cobra"
)
// addFilterCmd represents the addFilter command
var addFilterCmd = &cobra.Command{
Use: "addFilter",
Short: "Adds event filter to vulcanizedb",
Long: `An event filter is added to the vulcanize_db.
All events matching the filter conitions will be tracked
in vulcanizedb.
vulcanizedb addFilter --config config.toml --filter-filepath filter.json
The event filters are expected to match
the format described in the ethereum RPC wiki:
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newfilter
[{
"fromBlock": "0x1",
"toBlock": "0x2",
"address": "0x8888f1f195afa192cfee860698584c030f4c9db1",
"topics": ["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b",
null,
"0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"0x0000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebccc"]
}]
`,
Run: func(cmd *cobra.Command, args []string) {
addFilter()
},
}
var filterFilepath string
func init() {
rootCmd.AddCommand(addFilterCmd)
addFilterCmd.PersistentFlags().StringVar(&filterFilepath, "filter-filepath", "", "path/to/filter.json")
addFilterCmd.MarkFlagRequired("filter-filepath")
}
func addFilter() {
if filterFilepath == "" {
log.Fatal("filter-filepath required")
}
var logFilters filters.LogFilters
blockchain := geth.NewBlockchain(ipc)
repository := utils.LoadPostgres(databaseConfig, blockchain.Node())
absFilePath := utils.AbsFilePath(filterFilepath)
logFilterBytes, err := ioutil.ReadFile(absFilePath)
if err != nil {
log.Fatal(err)
}
err = json.Unmarshal(logFilterBytes, &logFilters)
if err != nil {
log.Fatal(err)
}
for _, filter := range logFilters {
err = repository.AddFilter(filter)
if err != nil {
log.Fatal(err)
}
}
}
-38
View File
@@ -1,38 +0,0 @@
package main
import (
"encoding/json"
"flag"
"io/ioutil"
"log"
"github.com/8thlight/vulcanizedb/pkg/filters"
"github.com/8thlight/vulcanizedb/pkg/geth"
"github.com/8thlight/vulcanizedb/utils"
)
func main() {
environment := flag.String("environment", "", "Environment name")
filterFilePath := flag.String("filter-filepath", "", "path/to/filter.json")
flag.Parse()
var logFilters filters.LogFilters
config := utils.LoadConfig(*environment)
blockchain := geth.NewBlockchain(config.Client.IPCPath)
repository := utils.LoadPostgres(config.Database, blockchain.Node())
absFilePath := utils.AbsFilePath(*filterFilePath)
logFilterBytes, err := ioutil.ReadFile(absFilePath)
if err != nil {
log.Fatal(err)
}
err = json.Unmarshal(logFilterBytes, &logFilters)
if err != nil {
log.Fatal(err)
}
for _, filter := range logFilters {
err = repository.AddFilter(filter)
if err != nil {
log.Fatal(err)
}
}
}
-22
View File
@@ -1,22 +0,0 @@
package main
import (
"flag"
"fmt"
"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 := utils.LoadConfig(*environment)
blockchain := geth.NewBlockchain(config.Client.IPCPath)
repository := utils.LoadPostgres(config.Database, blockchain.Node())
numberOfBlocksCreated := history.PopulateMissingBlocks(blockchain, repository, int64(*startingBlockNumber))
fmt.Printf("Populated %d blocks", numberOfBlocksCreated)
}
+74
View File
@@ -0,0 +1,74 @@
package cmd
import (
"fmt"
"os"
"github.com/8thlight/vulcanizedb/pkg/config"
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var cfgFile string
var databaseConfig config.Database
var ipc string
var rootCmd = &cobra.Command{
Use: "vulcanizedb",
PersistentPreRun: database,
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func database(cmd *cobra.Command, args []string) {
ipc = viper.GetString("client.ipcpath")
databaseConfig = config.Database{
Name: viper.GetString("database.name"),
Hostname: viper.GetString("database.hostname"),
Port: viper.GetInt("database.port"),
}
viper.Set("database.config", databaseConfig)
}
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "environment/public.toml", "config file location")
rootCmd.PersistentFlags().String("database-name", "vulcanize_public", "database name")
rootCmd.PersistentFlags().Int("database-port", 5432, "database port")
rootCmd.PersistentFlags().String("database-hostname", "localhost", "database hostname")
rootCmd.PersistentFlags().String("client-ipcPath", "", "location of geth.ipc file")
viper.BindPFlag("database.name", rootCmd.PersistentFlags().Lookup("database-name"))
viper.BindPFlag("database.port", rootCmd.PersistentFlags().Lookup("database-port"))
viper.BindPFlag("database.hostname", rootCmd.PersistentFlags().Lookup("database-hostname"))
viper.BindPFlag("client.ipcPath", rootCmd.PersistentFlags().Lookup("client-ipcPath"))
}
func initConfig() {
if cfgFile != "" {
viper.SetConfigFile(cfgFile)
} else {
home, err := homedir.Dir()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
viper.AddConfigPath(home)
viper.SetConfigName(".vulcanizedb")
}
viper.AutomaticEnv()
if err := viper.ReadInConfig(); err == nil {
fmt.Printf("Using config file: %s\n\n", viper.ConfigFileUsed())
}
}
-35
View File
@@ -1,35 +0,0 @@
package main
import (
"flag"
"time"
"os"
"github.com/8thlight/vulcanizedb/pkg/geth"
"github.com/8thlight/vulcanizedb/pkg/history"
"github.com/8thlight/vulcanizedb/utils"
)
const (
pollingInterval = 7 * time.Second
)
func main() {
environment := flag.String("environment", "", "Environment name")
flag.Parse()
ticker := time.NewTicker(pollingInterval)
defer ticker.Stop()
config := utils.LoadConfig(*environment)
blockchain := geth.NewBlockchain(config.Client.IPCPath)
repository := utils.LoadPostgres(config.Database, blockchain.Node())
validator := history.NewBlockValidator(blockchain, repository, 15)
for range ticker.C {
window := validator.ValidateBlocks()
validator.Log(os.Stdout, window)
}
}
-35
View File
@@ -1,35 +0,0 @@
package main
import (
"flag"
"log"
"fmt"
"strings"
"github.com/8thlight/vulcanizedb/pkg/contract_summary"
"github.com/8thlight/vulcanizedb/pkg/geth"
"github.com/8thlight/vulcanizedb/utils"
)
func main() {
environment := flag.String("environment", "", "Environment name")
contractHash := flag.String("contract-hash", "", "Contract hash to show summary")
_blockNumber := flag.Int64("block-number", -1, "Block number of summary")
flag.Parse()
contractHashLowered := strings.ToLower(*contractHash)
config := utils.LoadConfig(*environment)
blockchain := geth.NewBlockchain(config.Client.IPCPath)
repository := utils.LoadPostgres(config.Database, blockchain.Node())
blockNumber := utils.RequestedBlockNumber(_blockNumber)
contractSummary, err := contract_summary.NewSummary(blockchain, repository, contractHashLowered, blockNumber)
if err != nil {
log.Fatalln(err)
}
output := contract_summary.GenerateConsoleOutput(contractSummary)
fmt.Println(output)
}
+37 -13
View File
@@ -1,44 +1,68 @@
package main
package cmd
import (
"flag"
"os"
"time"
"os"
"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"
"github.com/spf13/cobra"
)
// syncCmd represents the sync command
var syncCmd = &cobra.Command{
Use: "sync",
Short: "Syncs vulcanizedb with local ethereum node",
Long: `Syncs vulcanizedb with local ethereum node.
vulcanizedb sync --startingBlockNumber 0 --config public.toml
Expects ethereum node to be running and requires a .toml config:
[database]
name = "vulcanize_public"
hostname = "localhost"
port = 5432
[client]
ipcPath = "/Users/mattkrump/Library/Ethereum/geth.ipc"
`,
Run: func(cmd *cobra.Command, args []string) {
sync()
},
}
const (
pollingInterval = 7 * time.Second
)
var startingBlockNumber int
func init() {
rootCmd.AddCommand(syncCmd)
syncCmd.Flags().IntVarP(&startingBlockNumber, "starting-block-number", "s", 0, "Block number to start syncing from")
}
func backFillAllBlocks(blockchain core.Blockchain, repository repositories.Postgres, missingBlocksPopulated chan int, startingBlockNumber int64) {
go func() {
missingBlocksPopulated <- history.PopulateMissingBlocks(blockchain, repository, startingBlockNumber)
}()
}
func main() {
environment := flag.String("environment", "", "Environment name")
startingBlockNumber := flag.Int("starting-number", 0, "First block to fill from")
flag.Parse()
func sync() {
ticker := time.NewTicker(pollingInterval)
defer ticker.Stop()
config := utils.LoadConfig(*environment)
blockchain := geth.NewBlockchain(config.Client.IPCPath)
repository := utils.LoadPostgres(config.Database, blockchain.Node())
blockchain := geth.NewBlockchain(ipc)
repository := utils.LoadPostgres(databaseConfig, blockchain.Node())
validator := history.NewBlockValidator(blockchain, repository, 15)
missingBlocksPopulated := make(chan int)
_startingBlockNumber := int64(*startingBlockNumber)
_startingBlockNumber := int64(startingBlockNumber)
go backFillAllBlocks(blockchain, repository, missingBlocksPopulated, _startingBlockNumber)
for {
-31
View File
@@ -1,31 +0,0 @@
package main
import (
"flag"
"strings"
"github.com/8thlight/vulcanizedb/pkg/core"
"github.com/8thlight/vulcanizedb/pkg/geth"
"github.com/8thlight/vulcanizedb/utils"
)
func main() {
environment := flag.String("environment", "", "Environment name")
contractHash := flag.String("contract-hash", "", "contract-hash=x1234")
abiFilepath := flag.String("abi-filepath", "", "path/to/abifile.json")
network := flag.String("network", "", "ropsten")
flag.Parse()
contractHashLowered := strings.ToLower(*contractHash)
contractAbiString := utils.GetAbi(*abiFilepath, contractHashLowered, *network)
config := utils.LoadConfig(*environment)
blockchain := geth.NewBlockchain(config.Client.IPCPath)
repository := utils.LoadPostgres(config.Database, blockchain.Node())
watchedContract := core.Contract{
Abi: contractAbiString,
Hash: contractHashLowered,
}
repository.CreateContract(watchedContract)
}