Update Blockchain interface to use WatchedContract instead of Contract

This commit is contained in:
Eric Meyer
2017-12-04 17:04:06 -06:00
parent e432219e20
commit 3a2e7e0cc1
9 changed files with 86 additions and 100 deletions
+5 -14
View File
@@ -15,21 +15,12 @@ type Blockchain struct {
WasToldToStop bool
}
func (blockchain *Blockchain) GetContract(contractHash string) (core.Contract, error) {
contractAttributes, err := blockchain.GetContractAttributes(contractHash)
contract := core.Contract{
Attributes: contractAttributes,
Hash: contractHash,
}
return contract, err
}
func (blockchain *Blockchain) GetAttribute(contract core.Contract, attributeName string, blockNumber *big.Int) (interface{}, error) {
func (blockchain *Blockchain) GetAttribute(watchedContract core.WatchedContract, attributeName string, blockNumber *big.Int) (interface{}, error) {
var result interface{}
if blockNumber == nil {
result = blockchain.contractAttributes[contract.Hash+"-1"][attributeName]
result = blockchain.contractAttributes[watchedContract.Hash+"-1"][attributeName]
} else {
result = blockchain.contractAttributes[contract.Hash+blockNumber.String()][attributeName]
result = blockchain.contractAttributes[watchedContract.Hash+blockNumber.String()][attributeName]
}
return result, nil
}
@@ -84,9 +75,9 @@ func (blockchain *Blockchain) SetContractStateAttribute(contractHash string, blo
blockchain.contractAttributes[key][attributeName] = attributeValue
}
func (blockchain *Blockchain) GetContractAttributes(contractHash string) (core.ContractAttributes, error) {
func (blockchain *Blockchain) GetAttributes(watchedContract core.WatchedContract) (core.ContractAttributes, error) {
var contractAttributes core.ContractAttributes
attributes, ok := blockchain.contractAttributes[contractHash+"-1"]
attributes, ok := blockchain.contractAttributes[watchedContract.Hash+"-1"]
if ok {
for key, _ := range attributes {
contractAttributes = append(contractAttributes, core.ContractAttribute{Name: key, Type: "string"})