Watch contact updates (#127)
* Downcase all arguments for contact watching * ABI retrieval from test networks
This commit is contained in:
parent
14e1fc4213
commit
70cfa20c68
@ -60,14 +60,16 @@ func tasks(p *do.Project) {
|
|||||||
environment := parseEnvironment(context)
|
environment := parseEnvironment(context)
|
||||||
contractHash := context.Args.MayString("", "contract-hash", "c")
|
contractHash := context.Args.MayString("", "contract-hash", "c")
|
||||||
abiFilepath := context.Args.MayString("", "abi-filepath", "a")
|
abiFilepath := context.Args.MayString("", "abi-filepath", "a")
|
||||||
|
network := context.Args.MayString("", "network", "n")
|
||||||
if contractHash == "" {
|
if contractHash == "" {
|
||||||
log.Fatalln("--contract-hash required")
|
log.Fatalln("--contract-hash required")
|
||||||
}
|
}
|
||||||
context.Start(`go run main.go --environment={{.environment}} --contract-hash={{.contractHash}} --abi-filepath={{.abiFilepath}}`,
|
context.Start(`go run main.go --environment={{.environment}} --contract-hash={{.contractHash}} --abi-filepath={{.abiFilepath}} --network={{.network}}`,
|
||||||
do.M{
|
do.M{
|
||||||
"environment": environment,
|
"environment": environment,
|
||||||
"contractHash": contractHash,
|
"contractHash": contractHash,
|
||||||
"abiFilepath": abiFilepath,
|
"abiFilepath": abiFilepath,
|
||||||
|
"network": network,
|
||||||
"$in": "cmd/watch_contract",
|
"$in": "cmd/watch_contract",
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -86,8 +86,8 @@ vulcanizedb/
|
|||||||
<contract-address>.json
|
<contract-address>.json
|
||||||
private/
|
private/
|
||||||
```
|
```
|
||||||
The name of the JSON file should correspond the contract's address.
|
The name of the JSON file should correspond the contract's address.
|
||||||
2. Start watching the contract `godo watchContract -- --environment=<some-environment> --contract-hash=<contract-address>`
|
2. Start watching the contract `godo watchContract -- --environment=<some-environment> --contract-hash=<contract-address>`
|
||||||
3. Request summary data `godo showContractSummary -- --environment=<some-environment> --contract-hash=<contract-address>`
|
3. Request summary data `godo showContractSummary -- --environment=<some-environment> --contract-hash=<contract-address>`
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@ import (
|
|||||||
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/8thlight/vulcanizedb/cmd"
|
"github.com/8thlight/vulcanizedb/cmd"
|
||||||
"github.com/8thlight/vulcanizedb/pkg/core"
|
"github.com/8thlight/vulcanizedb/pkg/core"
|
||||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||||
@ -29,11 +31,12 @@ const (
|
|||||||
func main() {
|
func main() {
|
||||||
environment := flag.String("environment", "", "Environment name")
|
environment := flag.String("environment", "", "Environment name")
|
||||||
contractHash := flag.String("contract-hash", "", "Contract hash to show summary")
|
contractHash := flag.String("contract-hash", "", "Contract hash to show summary")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
ticker := time.NewTicker(pollingInterval)
|
ticker := time.NewTicker(pollingInterval)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
flag.Parse()
|
contractHashLowered := strings.ToLower(*contractHash)
|
||||||
|
|
||||||
config := cmd.LoadConfig(*environment)
|
config := cmd.LoadConfig(*environment)
|
||||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||||
@ -43,7 +46,7 @@ func main() {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for i := int64(0); i < lastBlockNumber; i = min(i+stepSize, lastBlockNumber) {
|
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)
|
log.Println("Backfilling Logs:", i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -61,7 +64,7 @@ func main() {
|
|||||||
z := &big.Int{}
|
z := &big.Int{}
|
||||||
z.Sub(blockchain.LastBlock(), big.NewInt(25))
|
z.Sub(blockchain.LastBlock(), big.NewInt(25))
|
||||||
log.Printf("Logs Window: %d - %d", z.Int64(), blockchain.LastBlock().Int64())
|
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)
|
repository.CreateLogs(logs)
|
||||||
done <- struct{}{}
|
done <- struct{}{}
|
||||||
}()
|
}()
|
||||||
|
@ -17,11 +17,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
environment := flag.String("environment", "", "Environment name")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
ticker := time.NewTicker(pollingInterval)
|
ticker := time.NewTicker(pollingInterval)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
environment := flag.String("environment", "", "Environment name")
|
|
||||||
flag.Parse()
|
|
||||||
config := cmd.LoadConfig(*environment)
|
config := cmd.LoadConfig(*environment)
|
||||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/8thlight/vulcanizedb/cmd"
|
"github.com/8thlight/vulcanizedb/cmd"
|
||||||
"github.com/8thlight/vulcanizedb/pkg/contract_summary"
|
"github.com/8thlight/vulcanizedb/pkg/contract_summary"
|
||||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||||
@ -17,12 +19,14 @@ func main() {
|
|||||||
contractHash := flag.String("contract-hash", "", "Contract hash to show summary")
|
contractHash := flag.String("contract-hash", "", "Contract hash to show summary")
|
||||||
_blockNumber := flag.Int64("block-number", -1, "Block number of summary")
|
_blockNumber := flag.Int64("block-number", -1, "Block number of summary")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
contractHashLowered := strings.ToLower(*contractHash)
|
||||||
config := cmd.LoadConfig(*environment)
|
config := cmd.LoadConfig(*environment)
|
||||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||||
blockNumber := cmd.RequestedBlockNumber(_blockNumber)
|
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 {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,6 @@ import (
|
|||||||
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/8thlight/vulcanizedb/pkg/config"
|
"github.com/8thlight/vulcanizedb/pkg/config"
|
||||||
@ -42,13 +40,14 @@ func ReadAbiFile(abiFilepath string) string {
|
|||||||
return abi
|
return abi
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAbi(abiFilepath string, contractHash string) string {
|
func GetAbi(abiFilepath string, contractHash string, network string) string {
|
||||||
var contractAbiString string
|
var contractAbiString string
|
||||||
if abiFilepath != "" {
|
if abiFilepath != "" {
|
||||||
contractAbiString = ReadAbiFile(abiFilepath)
|
contractAbiString = ReadAbiFile(abiFilepath)
|
||||||
} else {
|
} else {
|
||||||
etherscan := geth.NewEtherScanClient("https://api.etherscan.io")
|
url := geth.GenUrl(network)
|
||||||
fmt.Println("No ABI supplied. Retrieving ABI from Etherscan")
|
etherscan := geth.NewEtherScanClient(url)
|
||||||
|
log.Printf("No ABI supplied. Retrieving ABI from Etherscan: %s", url)
|
||||||
contractAbiString, _ = etherscan.GetAbi(contractHash)
|
contractAbiString, _ = etherscan.GetAbi(contractHash)
|
||||||
}
|
}
|
||||||
_, err := geth.ParseAbi(contractAbiString)
|
_, err := geth.ParseAbi(contractAbiString)
|
||||||
|
@ -25,11 +25,12 @@ func backFillAllBlocks(blockchain core.Blockchain, repository repositories.Postg
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
environment := flag.String("environment", "", "Environment name")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
ticker := time.NewTicker(pollingInterval)
|
ticker := time.NewTicker(pollingInterval)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
environment := flag.String("environment", "", "Environment name")
|
|
||||||
flag.Parse()
|
|
||||||
config := cmd.LoadConfig(*environment)
|
config := cmd.LoadConfig(*environment)
|
||||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||||
|
@ -3,6 +3,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/8thlight/vulcanizedb/cmd"
|
"github.com/8thlight/vulcanizedb/cmd"
|
||||||
"github.com/8thlight/vulcanizedb/pkg/core"
|
"github.com/8thlight/vulcanizedb/pkg/core"
|
||||||
"github.com/8thlight/vulcanizedb/pkg/geth"
|
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||||
@ -12,15 +14,18 @@ func main() {
|
|||||||
environment := flag.String("environment", "", "Environment name")
|
environment := flag.String("environment", "", "Environment name")
|
||||||
contractHash := flag.String("contract-hash", "", "contract-hash=x1234")
|
contractHash := flag.String("contract-hash", "", "contract-hash=x1234")
|
||||||
abiFilepath := flag.String("abi-filepath", "", "path/to/abifile.json")
|
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)
|
config := cmd.LoadConfig(*environment)
|
||||||
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
blockchain := geth.NewBlockchain(config.Client.IPCPath)
|
||||||
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
|
||||||
watchedContract := core.Contract{
|
watchedContract := core.Contract{
|
||||||
Abi: contractAbiString,
|
Abi: contractAbiString,
|
||||||
Hash: *contractHash,
|
Hash: contractHashLowered,
|
||||||
}
|
}
|
||||||
repository.CreateContract(watchedContract)
|
repository.CreateContract(watchedContract)
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,19 @@ func NewEtherScanClient(url string) *EtherScanApi {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GenUrl(network string) string {
|
||||||
|
switch network {
|
||||||
|
case "ropsten":
|
||||||
|
return "https://ropsten.etherscan.io"
|
||||||
|
case "kovan":
|
||||||
|
return "https://kovan.etherscan.io"
|
||||||
|
case "rinkeby":
|
||||||
|
return "https://rinkeby.etherscan.io"
|
||||||
|
default:
|
||||||
|
return "https://api.etherscan.io"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//https://api.etherscan.io/api?module=contract&action=getabi&address=%s
|
//https://api.etherscan.io/api?module=contract&action=getabi&address=%s
|
||||||
func (e *EtherScanApi) GetAbi(contractHash string) (string, error) {
|
func (e *EtherScanApi) GetAbi(contractHash string) (string, error) {
|
||||||
target := new(Response)
|
target := new(Response)
|
||||||
|
@ -101,5 +101,22 @@ var _ = Describe("ABI files", func() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Describe("Generating etherscan endpoints based on network", func() {
|
||||||
|
It("should return the main endpoint as the default", func() {
|
||||||
|
url := geth.GenUrl("")
|
||||||
|
Expect(url).To(Equal("https://api.etherscan.io"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("generates various test network endpoint if test network is supplied", func() {
|
||||||
|
ropstenUrl := geth.GenUrl("ropsten")
|
||||||
|
rinkebyUrl := geth.GenUrl("rinkeby")
|
||||||
|
kovanUrl := geth.GenUrl("kovan")
|
||||||
|
|
||||||
|
Expect(ropstenUrl).To(Equal("https://ropsten.etherscan.io"))
|
||||||
|
Expect(kovanUrl).To(Equal("https://kovan.etherscan.io"))
|
||||||
|
Expect(rinkebyUrl).To(Equal("https://rinkeby.etherscan.io"))
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -25,7 +25,7 @@ func ToCoreBlock(gethBlock *types.Block, client GethClient) core.Block {
|
|||||||
GasLimit: gethBlock.GasLimit().Int64(),
|
GasLimit: gethBlock.GasLimit().Int64(),
|
||||||
GasUsed: gethBlock.GasUsed().Int64(),
|
GasUsed: gethBlock.GasUsed().Int64(),
|
||||||
Hash: gethBlock.Hash().Hex(),
|
Hash: gethBlock.Hash().Hex(),
|
||||||
Miner: gethBlock.Coinbase().Hex(),
|
Miner: strings.ToLower(gethBlock.Coinbase().Hex()),
|
||||||
Nonce: hexutil.Encode(gethBlock.Header().Nonce[:]),
|
Nonce: hexutil.Encode(gethBlock.Header().Nonce[:]),
|
||||||
Number: gethBlock.Number().Int64(),
|
Number: gethBlock.Number().Int64(),
|
||||||
ParentHash: gethBlock.ParentHash().Hex(),
|
ParentHash: gethBlock.ParentHash().Hex(),
|
||||||
|
Loading…
Reference in New Issue
Block a user