Add Filters (#133)
* Add LogFilter struct * Add log_filters table * Add view for events watching * Add cmd line "add_filter" to mimic eventual endpoint * Allow multiple filters in config
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
||||
"github.com/8thlight/vulcanizedb/cmd"
|
||||
"github.com/8thlight/vulcanizedb/pkg/filters"
|
||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||
)
|
||||
|
||||
func main() {
|
||||
environment := flag.String("environment", "", "Environment name")
|
||||
filterFilePath := flag.String("filter-filepath", "", "path/to/filter.json")
|
||||
|
||||
flag.Parse()
|
||||
var logFilters filters.LogFilters
|
||||
config := cmd.LoadConfig(*environment)
|
||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||
absFilePath := cmd.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-3
@@ -30,9 +30,7 @@ func LoadPostgres(database config.Database, node core.Node) repositories.Postgre
|
||||
}
|
||||
|
||||
func ReadAbiFile(abiFilepath string) string {
|
||||
if !filepath.IsAbs(abiFilepath) {
|
||||
abiFilepath = filepath.Join(config.ProjectRoot(), abiFilepath)
|
||||
}
|
||||
abiFilepath = AbsFilePath(abiFilepath)
|
||||
abi, err := geth.ReadAbiFile(abiFilepath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading ABI file at \"%s\"\n %v", abiFilepath, err)
|
||||
@@ -40,6 +38,13 @@ func ReadAbiFile(abiFilepath string) string {
|
||||
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 != "" {
|
||||
|
||||
@@ -18,14 +18,15 @@ const (
|
||||
pollingInterval = 7 * time.Second
|
||||
)
|
||||
|
||||
func backFillAllBlocks(blockchain core.Blockchain, repository repositories.Postgres, missingBlocksPopulated chan int) {
|
||||
func backFillAllBlocks(blockchain core.Blockchain, repository repositories.Postgres, missingBlocksPopulated chan int, startingBlockNumber int64) {
|
||||
go func() {
|
||||
missingBlocksPopulated <- history.PopulateMissingBlocks(blockchain, repository, 0)
|
||||
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()
|
||||
|
||||
ticker := time.NewTicker(pollingInterval)
|
||||
@@ -37,7 +38,8 @@ func main() {
|
||||
validator := history.NewBlockValidator(blockchain, repository, 15)
|
||||
|
||||
missingBlocksPopulated := make(chan int)
|
||||
go backFillAllBlocks(blockchain, repository, missingBlocksPopulated)
|
||||
_startingBlockNumber := int64(*startingBlockNumber)
|
||||
go backFillAllBlocks(blockchain, repository, missingBlocksPopulated, _startingBlockNumber)
|
||||
|
||||
for {
|
||||
select {
|
||||
@@ -45,7 +47,7 @@ func main() {
|
||||
window := validator.ValidateBlocks()
|
||||
validator.Log(os.Stdout, window)
|
||||
case <-missingBlocksPopulated:
|
||||
go backFillAllBlocks(blockchain, repository, missingBlocksPopulated)
|
||||
go backFillAllBlocks(blockchain, repository, missingBlocksPopulated, _startingBlockNumber)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user