ipld-eth-server/pkg/repositories/inmemory/contract_repository.go
Matt K ed907535e3 Separate DB access into several repos (#28)
* Separate files for InMemory

* Start using separate repos for collaborating objects

* Before Updating schema

* Separate various repos
2018-02-12 10:54:05 -06:00

36 lines
1007 B
Go

package inmemory
import (
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/repositories"
)
type ContractRepostiory struct {
*InMemory
}
func (contractRepository *ContractRepostiory) ContractExists(contractHash string) bool {
_, present := contractRepository.contracts[contractHash]
return present
}
func (contractRepository *ContractRepostiory) GetContract(contractHash string) (core.Contract, error) {
contract, ok := contractRepository.contracts[contractHash]
if !ok {
return core.Contract{}, repositories.ErrContractDoesNotExist(contractHash)
}
for _, block := range contractRepository.blocks {
for _, transaction := range block.Transactions {
if transaction.To == contractHash {
contract.Transactions = append(contract.Transactions, transaction)
}
}
}
return contract, nil
}
func (contractRepository *ContractRepostiory) CreateContract(contract core.Contract) error {
contractRepository.contracts[contract.Hash] = contract
return nil
}