forked from cerc-io/ipld-eth-server
ed907535e3
* Separate files for InMemory * Start using separate repos for collaborating objects * Before Updating schema * Separate various repos
36 lines
1007 B
Go
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
|
|
}
|