diff --git a/cmd/utils.go b/cmd/utils.go index 58df140e..2ca2d1a2 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -12,7 +12,7 @@ func LoadConfig(environment string) config.Config { if err != nil { log.Fatalf("Error loading config\n%v", err) } - return *cfg + return cfg } func LoadPostgres(database config.Database) repositories.Postgres { diff --git a/pkg/config/config.go b/pkg/config/config.go index dfbf62e9..69a0835f 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -24,12 +24,12 @@ var NewErrConfigFileNotFound = func(environment string) error { 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) absolutePath := filepath.Join(ProjectRoot(), "environments", filenameWithExtension) config, err := parseConfigFile(absolutePath) if err != nil { - return nil, NewErrConfigFileNotFound(environment) + return Config{}, NewErrConfigFileNotFound(environment) } else { if !filepath.IsAbs(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), "..", "..") } -func parseConfigFile(filePath string) (*Config, error) { +func parseConfigFile(filePath string) (Config, error) { var cfg Config _, err := os.Stat(filePath) if err != nil { - return nil, err + return Config{}, err } else { _, err := toml.DecodeFile(filePath, &cfg) if err != nil { - return nil, err + return Config{}, err } - return &cfg, err + return cfg, err } } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index f7f10e58..f5745292 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -3,7 +3,7 @@ package config_test import ( "path/filepath" - "github.com/8thlight/vulcanizedb/pkg/config" + cfg "github.com/8thlight/vulcanizedb/pkg/config" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -11,20 +11,20 @@ import ( var _ = Describe("Loading the config", 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(privateConfig.Database.Hostname).To(Equal("localhost")) Expect(privateConfig.Database.Name).To(Equal("vulcanize_private")) 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)) }) 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()) }) diff --git a/pkg/geth/contract.go b/pkg/geth/contract.go index f34e3f3c..fd6afdea 100644 --- a/pkg/geth/contract.go +++ b/pkg/geth/contract.go @@ -57,11 +57,11 @@ func (blockchain *GethBlockchain) getContractAttributes(contractHash string) (co 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())) parsed, err := ParseAbiFile(abiFilePath) 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 } diff --git a/pkg/watched_contracts/console_presenter.go b/pkg/watched_contracts/console_presenter.go index bbfd5925..badd8917 100644 --- a/pkg/watched_contracts/console_presenter.go +++ b/pkg/watched_contracts/console_presenter.go @@ -7,7 +7,7 @@ import ( "github.com/ethereum/go-ethereum/common" ) -func GenerateConsoleOutput(summary *ContractSummary) string { +func GenerateConsoleOutput(summary ContractSummary) string { return fmt.Sprintf(template(), summary.ContractHash, 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 for _, attribute := range summary.Attributes { formattedAttributes += formatAttribute(attribute.Name, summary) + "\n" + " " @@ -45,7 +45,7 @@ func attributesString(summary *ContractSummary) string { return formattedAttributes } -func formatAttribute(attributeName string, summary *ContractSummary) string { +func formatAttribute(attributeName string, summary ContractSummary) string { var stringResult string result := summary.GetStateAttribute(attributeName) switch t := result.(type) { diff --git a/pkg/watched_contracts/summary.go b/pkg/watched_contracts/summary.go index 63d8d7d8..22a2c0c2 100644 --- a/pkg/watched_contracts/summary.go +++ b/pkg/watched_contracts/summary.go @@ -21,12 +21,12 @@ var NewContractNotWatchedErr = func(contractHash string) error { 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) if watchedContract != nil { return newContractSummary(blockchain, *watchedContract), nil } else { - return nil, NewContractNotWatchedErr(contractHash) + return ContractSummary{}, NewContractNotWatchedErr(contractHash) } } @@ -35,9 +35,9 @@ func (contractSummary ContractSummary) GetStateAttribute(attributeName string) i 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) - return &ContractSummary{ + return ContractSummary{ blockChain: blockchain, Contract: contract, ContractHash: watchedContract.Hash, diff --git a/pkg/watched_contracts/summary_test.go b/pkg/watched_contracts/summary_test.go index 3a13e8f6..c9dda6ba 100644 --- a/pkg/watched_contracts/summary_test.go +++ b/pkg/watched_contracts/summary_test.go @@ -18,7 +18,7 @@ var _ bool = Describe("The watched contract summary", func() { contractSummary, err := watched_contracts.NewSummary(blockchain, repository, "123") - Expect(contractSummary).To(BeNil()) + Expect(contractSummary).To(Equal(watched_contracts.ContractSummary{})) Expect(err).NotTo(BeNil()) }) }) @@ -32,7 +32,7 @@ var _ bool = Describe("The watched contract summary", func() { contractSummary, err := watched_contracts.NewSummary(blockchain, repository, "0x123") - Expect(contractSummary).NotTo(BeNil()) + Expect(contractSummary).NotTo(Equal(watched_contracts.ContractSummary{})) Expect(err).To(BeNil()) })