Watch contact updates (#127)
* Downcase all arguments for contact watching * ABI retrieval from test networks
This commit is contained in:
@@ -9,6 +9,8 @@ import (
|
||||
|
||||
"time"
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/8thlight/vulcanizedb/cmd"
|
||||
"github.com/8thlight/vulcanizedb/pkg/core"
|
||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||
@@ -29,11 +31,12 @@ const (
|
||||
func main() {
|
||||
environment := flag.String("environment", "", "Environment name")
|
||||
contractHash := flag.String("contract-hash", "", "Contract hash to show summary")
|
||||
flag.Parse()
|
||||
|
||||
ticker := time.NewTicker(pollingInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
flag.Parse()
|
||||
|
||||
contractHashLowered := strings.ToLower(*contractHash)
|
||||
config := cmd.LoadConfig(*environment)
|
||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||
@@ -43,7 +46,7 @@ func main() {
|
||||
|
||||
go func() {
|
||||
for i := int64(0); i < lastBlockNumber; i = min(i+stepSize, lastBlockNumber) {
|
||||
logs, err := blockchain.GetLogs(core.Contract{Hash: *contractHash}, big.NewInt(i), big.NewInt(i+stepSize))
|
||||
logs, err := blockchain.GetLogs(core.Contract{Hash: contractHashLowered}, big.NewInt(i), big.NewInt(i+stepSize))
|
||||
log.Println("Backfilling Logs:", i)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@@ -61,7 +64,7 @@ func main() {
|
||||
z := &big.Int{}
|
||||
z.Sub(blockchain.LastBlock(), big.NewInt(25))
|
||||
log.Printf("Logs Window: %d - %d", z.Int64(), blockchain.LastBlock().Int64())
|
||||
logs, _ := blockchain.GetLogs(core.Contract{Hash: *contractHash}, z, blockchain.LastBlock())
|
||||
logs, _ := blockchain.GetLogs(core.Contract{Hash: contractHashLowered}, z, blockchain.LastBlock())
|
||||
repository.CreateLogs(logs)
|
||||
done <- struct{}{}
|
||||
}()
|
||||
|
||||
+3
-2
@@ -17,11 +17,12 @@ const (
|
||||
)
|
||||
|
||||
func main() {
|
||||
environment := flag.String("environment", "", "Environment name")
|
||||
flag.Parse()
|
||||
|
||||
ticker := time.NewTicker(pollingInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
environment := flag.String("environment", "", "Environment name")
|
||||
flag.Parse()
|
||||
config := cmd.LoadConfig(*environment)
|
||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
|
||||
"fmt"
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/8thlight/vulcanizedb/cmd"
|
||||
"github.com/8thlight/vulcanizedb/pkg/contract_summary"
|
||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||
@@ -17,12 +19,14 @@ func main() {
|
||||
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 := cmd.LoadConfig(*environment)
|
||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||
blockNumber := cmd.RequestedBlockNumber(_blockNumber)
|
||||
|
||||
contractSummary, err := contract_summary.NewSummary(blockchain, repository, *contractHash, blockNumber)
|
||||
contractSummary, err := contract_summary.NewSummary(blockchain, repository, contractHashLowered, blockNumber)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
+4
-5
@@ -5,8 +5,6 @@ import (
|
||||
|
||||
"path/filepath"
|
||||
|
||||
"fmt"
|
||||
|
||||
"math/big"
|
||||
|
||||
"github.com/8thlight/vulcanizedb/pkg/config"
|
||||
@@ -42,13 +40,14 @@ func ReadAbiFile(abiFilepath string) string {
|
||||
return abi
|
||||
}
|
||||
|
||||
func GetAbi(abiFilepath string, contractHash string) string {
|
||||
func GetAbi(abiFilepath string, contractHash string, network string) string {
|
||||
var contractAbiString string
|
||||
if abiFilepath != "" {
|
||||
contractAbiString = ReadAbiFile(abiFilepath)
|
||||
} else {
|
||||
etherscan := geth.NewEtherScanClient("https://api.etherscan.io")
|
||||
fmt.Println("No ABI supplied. Retrieving ABI from Etherscan")
|
||||
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)
|
||||
|
||||
@@ -25,11 +25,12 @@ func backFillAllBlocks(blockchain core.Blockchain, repository repositories.Postg
|
||||
}
|
||||
|
||||
func main() {
|
||||
environment := flag.String("environment", "", "Environment name")
|
||||
flag.Parse()
|
||||
|
||||
ticker := time.NewTicker(pollingInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
environment := flag.String("environment", "", "Environment name")
|
||||
flag.Parse()
|
||||
config := cmd.LoadConfig(*environment)
|
||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||
|
||||
@@ -3,6 +3,8 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/8thlight/vulcanizedb/cmd"
|
||||
"github.com/8thlight/vulcanizedb/pkg/core"
|
||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||
@@ -12,15 +14,18 @@ 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")
|
||||
flag.Parse()
|
||||
network := flag.String("network", "", "ropsten")
|
||||
|
||||
contractAbiString := cmd.GetAbi(*abiFilepath, *contractHash)
|
||||
flag.Parse()
|
||||
contractHashLowered := strings.ToLower(*contractHash)
|
||||
|
||||
contractAbiString := cmd.GetAbi(*abiFilepath, contractHashLowered, *network)
|
||||
config := cmd.LoadConfig(*environment)
|
||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||
watchedContract := core.Contract{
|
||||
Abi: contractAbiString,
|
||||
Hash: *contractHash,
|
||||
Hash: contractHashLowered,
|
||||
}
|
||||
repository.CreateContract(watchedContract)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user