Updated to use contracts derived Attributes

This commit is contained in:
Matt Krump 2017-11-28 10:45:21 -06:00
parent 60bef69113
commit aa3318451b
6 changed files with 64 additions and 10 deletions

30
Gopkg.lock generated
View File

@ -13,6 +13,12 @@
packages = ["."]
revision = "4748e29d5718c2df4028a6543edf86fd8cc0f881"
[[projects]]
branch = "master"
name = "github.com/aristanetworks/goarista"
packages = ["monotime"]
revision = "54fadd0c513d502544edf098480238dc9da50f9e"
[[projects]]
branch = "master"
name = "github.com/btcsuite/btcd"
@ -21,7 +27,7 @@
[[projects]]
name = "github.com/ethereum/go-ethereum"
packages = [".","common","common/hexutil","common/math","core/types","crypto","crypto/secp256k1","crypto/sha3","ethclient","log","params","rlp","rpc","trie"]
packages = [".","accounts","accounts/abi","accounts/abi/bind","accounts/keystore","common","common/hexutil","common/math","common/mclock","core/types","crypto","crypto/randentropy","crypto/secp256k1","crypto/sha3","ethclient","event","log","params","rlp","rpc","trie"]
revision = "1db4ecdc0b9e828ff65777fb466fc7c1d04e0de9"
version = "v1.7.2"
@ -103,12 +109,24 @@
revision = "c893efa28eb45626cdaa76c9f653b62488858837"
version = "v1.2.0"
[[projects]]
name = "github.com/pborman/uuid"
packages = ["."]
revision = "e790cca94e6cc75c7064b1332e63811d4aae1a53"
version = "v1.1"
[[projects]]
branch = "master"
name = "github.com/rcrowley/go-metrics"
packages = ["."]
revision = "1f30fe9094a513ce4c700b9a54458bbb0c96996c"
[[projects]]
branch = "master"
name = "github.com/rjeczalik/notify"
packages = ["."]
revision = "767eb674ef14b09119b2fff3601e64558d530c47"
[[projects]]
name = "github.com/rs/cors"
packages = ["."]
@ -118,7 +136,7 @@
[[projects]]
branch = "master"
name = "golang.org/x/crypto"
packages = ["ssh/terminal"]
packages = ["pbkdf2","scrypt","ssh/terminal"]
revision = "bd6f299fb381e4c3393d1c4b1f0b94f5e77650c8"
[[projects]]
@ -139,6 +157,12 @@
packages = ["encoding","encoding/charmap","encoding/htmlindex","encoding/internal","encoding/internal/identifier","encoding/japanese","encoding/korean","encoding/simplifiedchinese","encoding/traditionalchinese","encoding/unicode","internal/gen","internal/tag","internal/utf8internal","language","runes","transform","unicode/cldr"]
revision = "c01e4764d870b77f8abe5096ee19ad20d80e8075"
[[projects]]
branch = "master"
name = "golang.org/x/tools"
packages = ["go/ast/astutil","imports"]
revision = "6d70fb2e85323e81c89374331d3d2b93304faa36"
[[projects]]
name = "gopkg.in/fatih/set.v0"
packages = ["."]
@ -172,6 +196,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "f9569275c3b9863e5209029135f13d3d9df9a697b49e75b5cbd37942b23e4f3b"
inputs-digest = "d2aa2bdc1442319cde6fe38b39e0ff8e25b1a0b0c120a7e2fab8065324c98693"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -2,7 +2,7 @@
-- PostgreSQL database dump
--
-- Dumped from database version 10.0
-- Dumped from database version 10.1
-- Dumped by pg_dump version 10.1
SET statement_timeout = 0;

View File

@ -1,6 +1,8 @@
package fakes
import "github.com/8thlight/vulcanizedb/pkg/core"
import (
"github.com/8thlight/vulcanizedb/pkg/core"
)
type Blockchain struct {
blocks map[int64]core.Block
@ -10,7 +12,14 @@ type Blockchain struct {
}
func (blockchain *Blockchain) GetContractAttributes(contractHash string) ([]core.ContractAttribute, error) {
panic("implement me")
var contractAttribute []core.ContractAttribute
attributes, ok := blockchain.contractAttributes[contractHash]
if ok {
for key, _ := range attributes {
contractAttribute = append(contractAttribute, core.ContractAttribute{Name: key, Type: "string"})
}
}
return contractAttribute, nil
}
func (blockchain *Blockchain) GetContractStateAttribute(contractHash string, attributeName string) (*string, error) {

View File

@ -14,6 +14,7 @@ func GenerateConsoleOutput(summary *ContractSummary) string {
attributesString(summary),
)
}
func template() string {
return `********************Contract Summary***********************
HASH: %v
@ -36,10 +37,9 @@ func transactionToString(transaction *core.Transaction) string {
}
func attributesString(summary *ContractSummary) string {
attributes := []string{"name", "symbol"}
var formattedAttributes string
for _, attribute := range attributes {
formattedAttributes += formatAttribute(attribute, summary) + "\n" + " "
for _, attribute := range summary.Attributes {
formattedAttributes += formatAttribute(attribute.Name, summary) + "\n" + " "
}
return formattedAttributes
}

View File

@ -13,6 +13,7 @@ type ContractSummary struct {
NumberOfTransactions int
LastTransaction *core.Transaction
blockChain core.Blockchain
Attributes []core.ContractAttribute
}
var NewContractNotWatchedErr = func(contractHash string) error {
@ -34,11 +35,13 @@ func (contractSummary ContractSummary) GetStateAttribute(attributeName string) s
}
func newContractSummary(blockchain core.Blockchain, watchedContract core.WatchedContract) *ContractSummary {
attributes, _ := blockchain.GetContractAttributes(watchedContract.Hash)
return &ContractSummary{
blockChain: blockchain,
ContractHash: watchedContract.Hash,
NumberOfTransactions: len(watchedContract.Transactions),
LastTransaction: lastTransaction(watchedContract),
Attributes: attributes,
}
}

View File

@ -83,7 +83,7 @@ var _ bool = Describe("The watched contract summary", func() {
Expect(contractSummary.LastTransaction.Hash).To(Equal("TRANSACTION2"))
})
It("gets a state attribute for the contract from the blockchain", func() {
It("gets contract state attribute for the contract from the blockchain", func() {
repository := repositories.NewInMemory()
watchedContract := core.WatchedContract{Hash: "0x123"}
repository.CreateWatchedContract(watchedContract)
@ -94,6 +94,24 @@ var _ bool = Describe("The watched contract summary", func() {
Expect(contractSummary.GetStateAttribute("foo")).To(Equal("bar"))
})
It("gets a attributes for the contract from the blockchain", func() {
repository := repositories.NewInMemory()
watchedContract := core.WatchedContract{Hash: "0x123"}
repository.CreateWatchedContract(watchedContract)
blockchain := fakes.NewBlockchain()
blockchain.SetContractStateAttribute("0x123", "foo", "bar")
blockchain.SetContractStateAttribute("0x123", "baz", "bar")
contractSummary, _ := watched_contracts.NewSummary(blockchain, repository, "0x123")
Expect(contractSummary.Attributes).To(Equal(
[]core.ContractAttribute{
{Name: "foo", Type: "string"},
{Name: "baz", Type: "string"},
},
))
})
})
})