Merge pull request #86 from 8thlight/remove-pointers

Update functions that return error to not return pointer
This commit is contained in:
ericmeyer 2017-12-04 10:37:50 -06:00 committed by GitHub
commit 7501fe70a7
7 changed files with 24 additions and 24 deletions

View File

@ -12,7 +12,7 @@ func LoadConfig(environment string) config.Config {
if err != nil { if err != nil {
log.Fatalf("Error loading config\n%v", err) log.Fatalf("Error loading config\n%v", err)
} }
return *cfg return cfg
} }
func LoadPostgres(database config.Database) repositories.Postgres { func LoadPostgres(database config.Database) repositories.Postgres {

View File

@ -24,12 +24,12 @@ var NewErrConfigFileNotFound = func(environment string) error {
return errors.New(fmt.Sprintf("No configuration found for environment: %v", environment)) return errors.New(fmt.Sprintf("No configuration found for environment: %v", environment))
} }
func NewConfig(environment string) (*Config, error) { func NewConfig(environment string) (Config, error) {
filenameWithExtension := fmt.Sprintf("%s.toml", environment) filenameWithExtension := fmt.Sprintf("%s.toml", environment)
absolutePath := filepath.Join(ProjectRoot(), "environments", filenameWithExtension) absolutePath := filepath.Join(ProjectRoot(), "environments", filenameWithExtension)
config, err := parseConfigFile(absolutePath) config, err := parseConfigFile(absolutePath)
if err != nil { if err != nil {
return nil, NewErrConfigFileNotFound(environment) return Config{}, NewErrConfigFileNotFound(environment)
} else { } else {
if !filepath.IsAbs(config.Client.IPCPath) { if !filepath.IsAbs(config.Client.IPCPath) {
config.Client.IPCPath = filepath.Join(ProjectRoot(), config.Client.IPCPath) config.Client.IPCPath = filepath.Join(ProjectRoot(), config.Client.IPCPath)
@ -43,16 +43,16 @@ func ProjectRoot() string {
return path.Join(path.Dir(filename), "..", "..") return path.Join(path.Dir(filename), "..", "..")
} }
func parseConfigFile(filePath string) (*Config, error) { func parseConfigFile(filePath string) (Config, error) {
var cfg Config var cfg Config
_, err := os.Stat(filePath) _, err := os.Stat(filePath)
if err != nil { if err != nil {
return nil, err return Config{}, err
} else { } else {
_, err := toml.DecodeFile(filePath, &cfg) _, err := toml.DecodeFile(filePath, &cfg)
if err != nil { if err != nil {
return nil, err return Config{}, err
} }
return &cfg, err return cfg, err
} }
} }

View File

@ -3,7 +3,7 @@ package config_test
import ( import (
"path/filepath" "path/filepath"
"github.com/8thlight/vulcanizedb/pkg/config" cfg "github.com/8thlight/vulcanizedb/pkg/config"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
@ -11,20 +11,20 @@ import (
var _ = Describe("Loading the config", func() { var _ = Describe("Loading the config", func() {
It("reads the private config using the environment", func() { It("reads the private config using the environment", func() {
privateConfig, err := config.NewConfig("private") privateConfig, err := cfg.NewConfig("private")
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(privateConfig.Database.Hostname).To(Equal("localhost")) Expect(privateConfig.Database.Hostname).To(Equal("localhost"))
Expect(privateConfig.Database.Name).To(Equal("vulcanize_private")) Expect(privateConfig.Database.Name).To(Equal("vulcanize_private"))
Expect(privateConfig.Database.Port).To(Equal(5432)) Expect(privateConfig.Database.Port).To(Equal(5432))
expandedPath := filepath.Join(config.ProjectRoot(), "test_data_dir/geth.ipc") expandedPath := filepath.Join(cfg.ProjectRoot(), "test_data_dir/geth.ipc")
Expect(privateConfig.Client.IPCPath).To(Equal(expandedPath)) Expect(privateConfig.Client.IPCPath).To(Equal(expandedPath))
}) })
It("returns an error when there is no matching config file", func() { It("returns an error when there is no matching config file", func() {
config, err := config.NewConfig("bad-config") config, err := cfg.NewConfig("bad-config")
Expect(config).To(BeNil()) Expect(config).To(Equal(cfg.Config{}))
Expect(err).NotTo(BeNil()) Expect(err).NotTo(BeNil())
}) })

View File

@ -57,11 +57,11 @@ func (blockchain *GethBlockchain) getContractAttributes(contractHash string) (co
return contractAttributes, nil return contractAttributes, nil
} }
func bindContract(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor) (*bind.BoundContract, error) { func bindContract(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor) (bind.BoundContract, error) {
abiFilePath := filepath.Join(config.ProjectRoot(), "contracts", "public", fmt.Sprintf("%s.json", address.Hex())) abiFilePath := filepath.Join(config.ProjectRoot(), "contracts", "public", fmt.Sprintf("%s.json", address.Hex()))
parsed, err := ParseAbiFile(abiFilePath) parsed, err := ParseAbiFile(abiFilePath)
if err != nil { if err != nil {
return nil, err return bind.BoundContract{}, err
} }
return bind.NewBoundContract(address, parsed, caller, transactor), nil return *bind.NewBoundContract(address, parsed, caller, transactor), nil
} }

View File

@ -7,7 +7,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
) )
func GenerateConsoleOutput(summary *ContractSummary) string { func GenerateConsoleOutput(summary ContractSummary) string {
return fmt.Sprintf(template(), return fmt.Sprintf(template(),
summary.ContractHash, summary.ContractHash,
summary.NumberOfTransactions, summary.NumberOfTransactions,
@ -37,7 +37,7 @@ func transactionToString(transaction *core.Transaction) string {
} }
} }
func attributesString(summary *ContractSummary) string { func attributesString(summary ContractSummary) string {
var formattedAttributes string var formattedAttributes string
for _, attribute := range summary.Attributes { for _, attribute := range summary.Attributes {
formattedAttributes += formatAttribute(attribute.Name, summary) + "\n" + " " formattedAttributes += formatAttribute(attribute.Name, summary) + "\n" + " "
@ -45,7 +45,7 @@ func attributesString(summary *ContractSummary) string {
return formattedAttributes return formattedAttributes
} }
func formatAttribute(attributeName string, summary *ContractSummary) string { func formatAttribute(attributeName string, summary ContractSummary) string {
var stringResult string var stringResult string
result := summary.GetStateAttribute(attributeName) result := summary.GetStateAttribute(attributeName)
switch t := result.(type) { switch t := result.(type) {

View File

@ -21,12 +21,12 @@ var NewContractNotWatchedErr = func(contractHash string) error {
return errors.New(fmt.Sprintf("Contract %v not being watched", contractHash)) return errors.New(fmt.Sprintf("Contract %v not being watched", contractHash))
} }
func NewSummary(blockchain core.Blockchain, repository repositories.Repository, contractHash string) (*ContractSummary, error) { func NewSummary(blockchain core.Blockchain, repository repositories.Repository, contractHash string) (ContractSummary, error) {
watchedContract := repository.FindWatchedContract(contractHash) watchedContract := repository.FindWatchedContract(contractHash)
if watchedContract != nil { if watchedContract != nil {
return newContractSummary(blockchain, *watchedContract), nil return newContractSummary(blockchain, *watchedContract), nil
} else { } else {
return nil, NewContractNotWatchedErr(contractHash) return ContractSummary{}, NewContractNotWatchedErr(contractHash)
} }
} }
@ -35,9 +35,9 @@ func (contractSummary ContractSummary) GetStateAttribute(attributeName string) i
return result return result
} }
func newContractSummary(blockchain core.Blockchain, watchedContract core.WatchedContract) *ContractSummary { func newContractSummary(blockchain core.Blockchain, watchedContract core.WatchedContract) ContractSummary {
contract, _ := blockchain.GetContract(watchedContract.Hash) contract, _ := blockchain.GetContract(watchedContract.Hash)
return &ContractSummary{ return ContractSummary{
blockChain: blockchain, blockChain: blockchain,
Contract: contract, Contract: contract,
ContractHash: watchedContract.Hash, ContractHash: watchedContract.Hash,

View File

@ -18,7 +18,7 @@ var _ bool = Describe("The watched contract summary", func() {
contractSummary, err := watched_contracts.NewSummary(blockchain, repository, "123") contractSummary, err := watched_contracts.NewSummary(blockchain, repository, "123")
Expect(contractSummary).To(BeNil()) Expect(contractSummary).To(Equal(watched_contracts.ContractSummary{}))
Expect(err).NotTo(BeNil()) Expect(err).NotTo(BeNil())
}) })
}) })
@ -32,7 +32,7 @@ var _ bool = Describe("The watched contract summary", func() {
contractSummary, err := watched_contracts.NewSummary(blockchain, repository, "0x123") contractSummary, err := watched_contracts.NewSummary(blockchain, repository, "0x123")
Expect(contractSummary).NotTo(BeNil()) Expect(contractSummary).NotTo(Equal(watched_contracts.ContractSummary{}))
Expect(err).To(BeNil()) Expect(err).To(BeNil())
}) })