forked from cerc-io/ipld-eth-server
Update NewSummary to take the blockchain
This commit is contained in:
parent
90edd15ead
commit
9c1051bfce
@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/8thlight/vulcanizedb/cmd"
|
"github.com/8thlight/vulcanizedb/cmd"
|
||||||
|
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||||
"github.com/8thlight/vulcanizedb/pkg/repositories"
|
"github.com/8thlight/vulcanizedb/pkg/repositories"
|
||||||
"github.com/8thlight/vulcanizedb/pkg/watched_contracts"
|
"github.com/8thlight/vulcanizedb/pkg/watched_contracts"
|
||||||
)
|
)
|
||||||
@ -18,8 +19,9 @@ func main() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
config := cmd.LoadConfig(*environment)
|
config := cmd.LoadConfig(*environment)
|
||||||
|
|
||||||
|
blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
||||||
repository := repositories.NewPostgres(config.Database)
|
repository := repositories.NewPostgres(config.Database)
|
||||||
contractSummary, err := watched_contracts.NewSummary(repository, *contractHash)
|
contractSummary, err := watched_contracts.NewSummary(blockchain, repository, *contractHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
func GenerateConsoleOutput(summary *ContractSummary) string {
|
func GenerateConsoleOutput(summary *ContractSummary) string {
|
||||||
return fmt.Sprintf(template(),
|
return fmt.Sprintf(template(),
|
||||||
summary.ContractHash,
|
summary.ContractHash,
|
||||||
|
summary.GetStateAttribute("name"),
|
||||||
summary.NumberOfTransactions,
|
summary.NumberOfTransactions,
|
||||||
transactionToString(summary.LastTransaction),
|
transactionToString(summary.LastTransaction),
|
||||||
)
|
)
|
||||||
@ -17,6 +18,7 @@ func GenerateConsoleOutput(summary *ContractSummary) string {
|
|||||||
func template() string {
|
func template() string {
|
||||||
return `********************Contract Summary***********************
|
return `********************Contract Summary***********************
|
||||||
HASH: %v
|
HASH: %v
|
||||||
|
NAME: %s
|
||||||
NUMBER OF TRANSACTIONS: %d
|
NUMBER OF TRANSACTIONS: %d
|
||||||
LAST TRANSACTION:
|
LAST TRANSACTION:
|
||||||
%s
|
%s
|
||||||
|
@ -18,7 +18,7 @@ var NewContractNotWatchedErr = func(contractHash string) error {
|
|||||||
return errors.New(fmt.Sprintf("Contract %v not being watched", contractHash))
|
return errors.New(fmt.Sprintf("Contract %v not being watched", contractHash))
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSummary(repository repositories.Repository, contractHash string) (*ContractSummary, error) {
|
func NewSummary(_ core.Blockchain, repository repositories.Repository, contractHash string) (*ContractSummary, error) {
|
||||||
contract := repository.FindWatchedContract(contractHash)
|
contract := repository.FindWatchedContract(contractHash)
|
||||||
if contract != nil {
|
if contract != nil {
|
||||||
return newContractSummary(*contract), nil
|
return newContractSummary(*contract), nil
|
||||||
@ -27,6 +27,10 @@ func NewSummary(repository repositories.Repository, contractHash string) (*Contr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ContractSummary) GetStateAttribute(attributeName string) string {
|
||||||
|
return "Hello world"
|
||||||
|
}
|
||||||
|
|
||||||
func newContractSummary(contract core.WatchedContract) *ContractSummary {
|
func newContractSummary(contract core.WatchedContract) *ContractSummary {
|
||||||
return &ContractSummary{
|
return &ContractSummary{
|
||||||
ContractHash: contract.Hash,
|
ContractHash: contract.Hash,
|
||||||
|
@ -2,6 +2,7 @@ package watched_contracts_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/8thlight/vulcanizedb/pkg/core"
|
"github.com/8thlight/vulcanizedb/pkg/core"
|
||||||
|
"github.com/8thlight/vulcanizedb/pkg/fakes"
|
||||||
"github.com/8thlight/vulcanizedb/pkg/repositories"
|
"github.com/8thlight/vulcanizedb/pkg/repositories"
|
||||||
"github.com/8thlight/vulcanizedb/pkg/watched_contracts"
|
"github.com/8thlight/vulcanizedb/pkg/watched_contracts"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
@ -13,8 +14,9 @@ var _ bool = Describe("The watched contract summary", func() {
|
|||||||
Context("when the given contract is not being watched", func() {
|
Context("when the given contract is not being watched", func() {
|
||||||
It("returns an error", func() {
|
It("returns an error", func() {
|
||||||
repository := repositories.NewInMemory()
|
repository := repositories.NewInMemory()
|
||||||
|
blockchain := fakes.NewBlockchain()
|
||||||
|
|
||||||
contractSummary, err := watched_contracts.NewSummary(repository, "123")
|
contractSummary, err := watched_contracts.NewSummary(blockchain, repository, "123")
|
||||||
|
|
||||||
Expect(contractSummary).To(BeNil())
|
Expect(contractSummary).To(BeNil())
|
||||||
Expect(err).NotTo(BeNil())
|
Expect(err).NotTo(BeNil())
|
||||||
@ -26,8 +28,9 @@ var _ bool = Describe("The watched contract summary", func() {
|
|||||||
repository := repositories.NewInMemory()
|
repository := repositories.NewInMemory()
|
||||||
watchedContract := core.WatchedContract{Hash: "0x123"}
|
watchedContract := core.WatchedContract{Hash: "0x123"}
|
||||||
repository.CreateWatchedContract(watchedContract)
|
repository.CreateWatchedContract(watchedContract)
|
||||||
|
blockchain := fakes.NewBlockchain()
|
||||||
|
|
||||||
contractSummary, err := watched_contracts.NewSummary(repository, "0x123")
|
contractSummary, err := watched_contracts.NewSummary(blockchain, repository, "0x123")
|
||||||
|
|
||||||
Expect(contractSummary).NotTo(BeNil())
|
Expect(contractSummary).NotTo(BeNil())
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
@ -37,8 +40,9 @@ var _ bool = Describe("The watched contract summary", func() {
|
|||||||
repository := repositories.NewInMemory()
|
repository := repositories.NewInMemory()
|
||||||
watchedContract := core.WatchedContract{Hash: "0x123"}
|
watchedContract := core.WatchedContract{Hash: "0x123"}
|
||||||
repository.CreateWatchedContract(watchedContract)
|
repository.CreateWatchedContract(watchedContract)
|
||||||
|
blockchain := fakes.NewBlockchain()
|
||||||
|
|
||||||
contractSummary, _ := watched_contracts.NewSummary(repository, "0x123")
|
contractSummary, _ := watched_contracts.NewSummary(blockchain, repository, "0x123")
|
||||||
|
|
||||||
Expect(contractSummary.ContractHash).To(Equal("0x123"))
|
Expect(contractSummary.ContractHash).To(Equal("0x123"))
|
||||||
})
|
})
|
||||||
@ -54,8 +58,9 @@ var _ bool = Describe("The watched contract summary", func() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
repository.CreateBlock(block)
|
repository.CreateBlock(block)
|
||||||
|
blockchain := fakes.NewBlockchain()
|
||||||
|
|
||||||
contractSummary, _ := watched_contracts.NewSummary(repository, "0x123")
|
contractSummary, _ := watched_contracts.NewSummary(blockchain, repository, "0x123")
|
||||||
|
|
||||||
Expect(contractSummary.NumberOfTransactions).To(Equal(2))
|
Expect(contractSummary.NumberOfTransactions).To(Equal(2))
|
||||||
})
|
})
|
||||||
@ -71,8 +76,9 @@ var _ bool = Describe("The watched contract summary", func() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
repository.CreateBlock(block)
|
repository.CreateBlock(block)
|
||||||
|
blockchain := fakes.NewBlockchain()
|
||||||
|
|
||||||
contractSummary, _ := watched_contracts.NewSummary(repository, "0x123")
|
contractSummary, _ := watched_contracts.NewSummary(blockchain, repository, "0x123")
|
||||||
|
|
||||||
Expect(contractSummary.LastTransaction.Hash).To(Equal("TRANSACTION2"))
|
Expect(contractSummary.LastTransaction.Hash).To(Equal("TRANSACTION2"))
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user