forked from cerc-io/ipld-eth-server
Get logs for a contract (#99)
* Add ability to fetch logs for a contract and a block * Test contract related code against Infura, so can run on Travis * Add godo task for getLogs
This commit is contained in:
+26
-5
@@ -12,6 +12,8 @@ import (
|
||||
|
||||
"errors"
|
||||
|
||||
"net/url"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
@@ -24,6 +26,10 @@ var NewErrConfigFileNotFound = func(environment string) error {
|
||||
return errors.New(fmt.Sprintf("No configuration found for environment: %v", environment))
|
||||
}
|
||||
|
||||
var NewErrBadConnectionString = func(connectionString string) error {
|
||||
return errors.New(fmt.Sprintf("connection string is invalid: %v", connectionString))
|
||||
}
|
||||
|
||||
func NewConfig(environment string) (Config, error) {
|
||||
filenameWithExtension := fmt.Sprintf("%s.toml", environment)
|
||||
absolutePath := filepath.Join(ProjectRoot(), "environments", filenameWithExtension)
|
||||
@@ -31,7 +37,7 @@ func NewConfig(environment string) (Config, error) {
|
||||
if err != nil {
|
||||
return Config{}, NewErrConfigFileNotFound(environment)
|
||||
} else {
|
||||
if !filepath.IsAbs(config.Client.IPCPath) {
|
||||
if !filepath.IsAbs(config.Client.IPCPath) && !isUrl(config.Client.IPCPath) {
|
||||
config.Client.IPCPath = filepath.Join(ProjectRoot(), config.Client.IPCPath)
|
||||
}
|
||||
return config, nil
|
||||
@@ -43,16 +49,31 @@ func ProjectRoot() string {
|
||||
return path.Join(path.Dir(filename), "..", "..")
|
||||
}
|
||||
|
||||
func isUrl(s string) bool {
|
||||
_, err := url.ParseRequestURI(s)
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func fileExists(s string) bool {
|
||||
_, err := os.Stat(s)
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func parseConfigFile(filePath string) (Config, error) {
|
||||
var cfg Config
|
||||
_, err := os.Stat(filePath)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
if !isUrl(filePath) && !fileExists(filePath) {
|
||||
return Config{}, NewErrBadConnectionString(filePath)
|
||||
} else {
|
||||
_, err := toml.DecodeFile(filePath, &cfg)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
return cfg, err
|
||||
return cfg, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user