06f78e0083
- Adds interfaces for developers to build handlers that update data in response to log events - Resolves #29
36 lines
1001 B
Go
36 lines
1001 B
Go
package inmemory
|
|
|
|
import (
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore"
|
|
)
|
|
|
|
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{}, datastore.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
|
|
}
|