Refactoring (#101)

* Make naming consistent for watched_contracts

* Update FindContract and FindBlockByNumber to return errors rather than nil
This commit is contained in:
Matt K
2017-12-13 10:51:11 -06:00
committed by GitHub
parent a68f277066
commit 0e837e2d03
10 changed files with 98 additions and 84 deletions
+4 -11
View File
@@ -1,9 +1,6 @@
package contract_summary
import (
"errors"
"fmt"
"math/big"
"github.com/8thlight/vulcanizedb/pkg/core"
@@ -20,16 +17,12 @@ type ContractSummary struct {
blockChain core.Blockchain
}
var ErrContractDoesNotExist = func(contractHash string) error {
return errors.New(fmt.Sprintf("Contract %v does not exist", contractHash))
}
func NewSummary(blockchain core.Blockchain, repository repositories.Repository, contractHash string, blockNumber *big.Int) (ContractSummary, error) {
contract := repository.FindContract(contractHash)
if contract != nil {
return newContractSummary(blockchain, *contract, blockNumber), nil
contract, err := repository.FindContract(contractHash)
if err != nil {
return ContractSummary{}, err
} else {
return ContractSummary{}, ErrContractDoesNotExist(contractHash)
return newContractSummary(blockchain, contract, blockNumber), nil
}
}