c00b8a5a98
* 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
119 lines
4.0 KiB
Go
119 lines
4.0 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"fmt"
|
|
|
|
"github.com/8thlight/vulcanizedb/cmd"
|
|
"github.com/8thlight/vulcanizedb/pkg/config"
|
|
do "gopkg.in/godo.v2"
|
|
)
|
|
|
|
func parseEnvironment(context *do.Context) string {
|
|
environment := context.Args.MayString("", "environment", "env", "e")
|
|
if environment == "" {
|
|
log.Fatalln("--environment required")
|
|
}
|
|
return environment
|
|
}
|
|
|
|
func tasks(p *do.Project) {
|
|
|
|
p.Task("run", nil, func(context *do.Context) {
|
|
environment := parseEnvironment(context)
|
|
context.Start(`go run main.go --environment={{.environment}}`,
|
|
do.M{"environment": environment, "$in": "cmd/run"})
|
|
})
|
|
|
|
p.Task("vulcanizeDb", nil, func(context *do.Context) {
|
|
environment := parseEnvironment(context)
|
|
startingNumber := context.Args.MayInt(0, "starting-number", "s")
|
|
context.Start(`go run main.go --environment={{.environment}} --starting-number={{.startingNumber}}`,
|
|
do.M{"environment": environment,
|
|
"startingNumber": startingNumber,
|
|
"$in": "cmd/vulcanize_db"})
|
|
})
|
|
|
|
p.Task("populateBlocks", nil, func(context *do.Context) {
|
|
environment := parseEnvironment(context)
|
|
startingNumber := context.Args.MayInt(-1, "starting-number", "s")
|
|
if startingNumber < 0 {
|
|
log.Fatalln("--starting-number required")
|
|
}
|
|
context.Start(`go run main.go --environment={{.environment}} --starting-number={{.startingNumber}}`,
|
|
do.M{"environment": environment, "startingNumber": startingNumber, "$in": "cmd/populate_blocks"})
|
|
})
|
|
|
|
p.Task("watchEvent", nil, func(context *do.Context) {
|
|
environment := parseEnvironment(context)
|
|
filterFilePath := context.Args.MayString("", "filter-filepath", "f")
|
|
if filterFilePath == "" {
|
|
log.Fatalln("--filter-filepath required")
|
|
}
|
|
context.Start(`go run main.go --environment={{.environment}} --filter-filepath={{.filterFilePath}}`,
|
|
do.M{
|
|
"environment": environment,
|
|
"filterFilePath": filterFilePath,
|
|
"$in": "cmd/add_filter",
|
|
})
|
|
})
|
|
|
|
p.Task("watchContract", nil, func(context *do.Context) {
|
|
environment := parseEnvironment(context)
|
|
contractHash := context.Args.MayString("", "contract-hash", "c")
|
|
abiFilepath := context.Args.MayString("", "abi-filepath", "a")
|
|
network := context.Args.MayString("", "network", "n")
|
|
if contractHash == "" {
|
|
log.Fatalln("--contract-hash required")
|
|
}
|
|
context.Start(`go run main.go --environment={{.environment}} --contract-hash={{.contractHash}} --abi-filepath={{.abiFilepath}} --network={{.network}}`,
|
|
do.M{
|
|
"environment": environment,
|
|
"contractHash": contractHash,
|
|
"abiFilepath": abiFilepath,
|
|
"network": network,
|
|
"$in": "cmd/watch_contract",
|
|
})
|
|
})
|
|
|
|
p.Task("migrate", nil, func(context *do.Context) {
|
|
environment := parseEnvironment(context)
|
|
cfg := cmd.LoadConfig(environment)
|
|
connectString := config.DbConnectionString(cfg.Database)
|
|
migrate := fmt.Sprintf("migrate -database '%s' -path ./db/migrations up", connectString)
|
|
dumpSchema := fmt.Sprintf("pg_dump -O -s %s > db/schema.sql", cfg.Database.Name)
|
|
context.Bash(migrate)
|
|
context.Bash(dumpSchema)
|
|
})
|
|
|
|
p.Task("rollback", nil, func(context *do.Context) {
|
|
environment := parseEnvironment(context)
|
|
cfg := cmd.LoadConfig(environment)
|
|
connectString := config.DbConnectionString(cfg.Database)
|
|
migrate := fmt.Sprintf("migrate -database '%s' -path ./db/migrations down 1", connectString)
|
|
dumpSchema := fmt.Sprintf("pg_dump -O -s %s > db/schema.sql", cfg.Database.Name)
|
|
context.Bash(migrate)
|
|
context.Bash(dumpSchema)
|
|
})
|
|
|
|
p.Task("showContractSummary", nil, func(context *do.Context) {
|
|
environment := parseEnvironment(context)
|
|
contractHash := context.Args.MayString("", "contract-hash", "c")
|
|
blockNumber := context.Args.MayInt(-1, "block-number", "b")
|
|
if contractHash == "" {
|
|
log.Fatalln("--contract-hash required")
|
|
}
|
|
context.Start(`go run main.go --environment={{.environment}} --contract-hash={{.contractHash}} --block-number={{.blockNumber}}`,
|
|
do.M{"environment": environment,
|
|
"contractHash": contractHash,
|
|
"blockNumber": blockNumber,
|
|
"$in": "cmd/show_contract_summary"})
|
|
})
|
|
|
|
}
|
|
|
|
func main() {
|
|
do.Godo(tasks)
|
|
}
|