2018-02-12 16:54:05 +00:00
|
|
|
package inmemory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
2018-02-13 16:31:57 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore"
|
2018-02-12 16:54:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
2018-02-13 16:31:57 +00:00
|
|
|
return core.Contract{}, datastore.ErrContractDoesNotExist(contractHash)
|
2018-02-12 16:54:05 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|