Move WatchedContract back to core
This commit is contained in:
parent
e4a05858f8
commit
5aa0bcd6ce
@ -8,5 +8,6 @@ type Blockchain interface {
|
|||||||
StartListening()
|
StartListening()
|
||||||
StopListening()
|
StopListening()
|
||||||
GetContract(contractHash string) (Contract, error)
|
GetContract(contractHash string) (Contract, error)
|
||||||
|
GetContractAttributes(contractHash string) (ContractAttributes, error)
|
||||||
GetAttribute(contract Contract, attributeName string, blockNumber *big.Int) (interface{}, error)
|
GetAttribute(contract Contract, attributeName string, blockNumber *big.Int) (interface{}, error)
|
||||||
}
|
}
|
||||||
|
7
pkg/core/watched_contract.go
Normal file
7
pkg/core/watched_contract.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
type WatchedContract struct {
|
||||||
|
Abi string
|
||||||
|
Hash string
|
||||||
|
Transactions []Transaction
|
||||||
|
}
|
@ -16,7 +16,7 @@ type Blockchain struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (blockchain *Blockchain) GetContract(contractHash string) (core.Contract, error) {
|
func (blockchain *Blockchain) GetContract(contractHash string) (core.Contract, error) {
|
||||||
contractAttributes, err := blockchain.getContractAttributes(contractHash)
|
contractAttributes, err := blockchain.GetContractAttributes(contractHash)
|
||||||
contract := core.Contract{
|
contract := core.Contract{
|
||||||
Attributes: contractAttributes,
|
Attributes: contractAttributes,
|
||||||
Hash: contractHash,
|
Hash: contractHash,
|
||||||
@ -84,7 +84,7 @@ func (blockchain *Blockchain) SetContractStateAttribute(contractHash string, blo
|
|||||||
blockchain.contractAttributes[key][attributeName] = attributeValue
|
blockchain.contractAttributes[key][attributeName] = attributeValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (blockchain *Blockchain) getContractAttributes(contractHash string) (core.ContractAttributes, error) {
|
func (blockchain *Blockchain) GetContractAttributes(contractHash string) (core.ContractAttributes, error) {
|
||||||
var contractAttributes core.ContractAttributes
|
var contractAttributes core.ContractAttributes
|
||||||
attributes, ok := blockchain.contractAttributes[contractHash+"-1"]
|
attributes, ok := blockchain.contractAttributes[contractHash+"-1"]
|
||||||
if ok {
|
if ok {
|
||||||
|
@ -22,7 +22,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (blockchain *GethBlockchain) GetContract(contractHash string) (core.Contract, error) {
|
func (blockchain *GethBlockchain) GetContract(contractHash string) (core.Contract, error) {
|
||||||
attributes, err := blockchain.getContractAttributes(contractHash)
|
attributes, err := blockchain.GetContractAttributes(contractHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return core.Contract{}, err
|
return core.Contract{}, err
|
||||||
} else {
|
} else {
|
||||||
@ -69,7 +69,7 @@ func callContract(contract core.Contract, input []byte, err error, blockchain *G
|
|||||||
return blockchain.client.CallContract(context.Background(), msg, blockNumber)
|
return blockchain.client.CallContract(context.Background(), msg, blockNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (blockchain *GethBlockchain) getContractAttributes(contractHash string) (core.ContractAttributes, error) {
|
func (blockchain *GethBlockchain) GetContractAttributes(contractHash string) (core.ContractAttributes, error) {
|
||||||
abiFilePath := filepath.Join(config.ProjectRoot(), "contracts", "public", fmt.Sprintf("%s.json", contractHash))
|
abiFilePath := filepath.Join(config.ProjectRoot(), "contracts", "public", fmt.Sprintf("%s.json", contractHash))
|
||||||
parsed, _ := ParseAbiFile(abiFilePath)
|
parsed, _ := ParseAbiFile(abiFilePath)
|
||||||
var contractAttributes core.ContractAttributes
|
var contractAttributes core.ContractAttributes
|
||||||
|
@ -1,117 +1,118 @@
|
|||||||
package geth_test
|
package geth_test
|
||||||
|
|
||||||
//import (
|
import (
|
||||||
// "math/big"
|
"math/big"
|
||||||
//
|
|
||||||
// cfg "github.com/8thlight/vulcanizedb/pkg/config"
|
cfg "github.com/8thlight/vulcanizedb/pkg/config"
|
||||||
// "github.com/8thlight/vulcanizedb/pkg/geth"
|
"github.com/8thlight/vulcanizedb/pkg/geth"
|
||||||
// "github.com/8thlight/vulcanizedb/pkg/geth/testing"
|
"github.com/8thlight/vulcanizedb/pkg/geth/testing"
|
||||||
// . "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
// . "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
//)
|
)
|
||||||
//
|
|
||||||
//var _ = Describe("Reading contracts", func() {
|
var _ = Describe("Reading contracts", func() {
|
||||||
//
|
|
||||||
// Describe("Reading the list of attributes", func() {
|
Describe("Reading the list of attributes", func() {
|
||||||
// It("returns a string attribute for a real contract", func() {
|
It("returns a string attribute for a real contract", func() {
|
||||||
// config, _ := cfg.NewConfig("public")
|
config, _ := cfg.NewConfig("public")
|
||||||
// blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
||||||
// contractHash := "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
|
contractHash := "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
|
||||||
//
|
|
||||||
// contract, err := blockchain.GetContract(contractHash)
|
contract, err := blockchain.GetContract(contractHash)
|
||||||
//
|
//contractAttributes, _ := blockchain.GetContractAttributes(contractHash)
|
||||||
// Expect(err).To(BeNil())
|
|
||||||
// Expect(len(contract.Attributes)).NotTo(Equal(0))
|
Expect(err).To(BeNil())
|
||||||
// symbolAttribute := *testing.FindAttribute(contract.Attributes, "symbol")
|
Expect(len(contract.Attributes)).NotTo(Equal(0))
|
||||||
// Expect(symbolAttribute.Name).To(Equal("symbol"))
|
symbolAttribute := *testing.FindAttribute(contract.Attributes, "symbol")
|
||||||
// Expect(symbolAttribute.Type).To(Equal("string"))
|
Expect(symbolAttribute.Name).To(Equal("symbol"))
|
||||||
// })
|
Expect(symbolAttribute.Type).To(Equal("string"))
|
||||||
//
|
})
|
||||||
// It("does not return an attribute that takes an input", func() {
|
|
||||||
// config, _ := cfg.NewConfig("public")
|
It("does not return an attribute that takes an input", func() {
|
||||||
// blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
config, _ := cfg.NewConfig("public")
|
||||||
// contractHash := "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
|
blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
||||||
//
|
contractHash := "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
|
||||||
// contract, err := blockchain.GetContract(contractHash)
|
|
||||||
//
|
contract, err := blockchain.GetContract(contractHash)
|
||||||
// Expect(err).To(BeNil())
|
|
||||||
// attribute := testing.FindAttribute(contract.Attributes, "balanceOf")
|
Expect(err).To(BeNil())
|
||||||
// Expect(attribute).To(BeNil())
|
attribute := testing.FindAttribute(contract.Attributes, "balanceOf")
|
||||||
// })
|
Expect(attribute).To(BeNil())
|
||||||
//
|
})
|
||||||
// It("does not return an attribute that is not constant", func() {
|
|
||||||
// config, _ := cfg.NewConfig("public")
|
It("does not return an attribute that is not constant", func() {
|
||||||
// blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
config, _ := cfg.NewConfig("public")
|
||||||
// contractHash := "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
|
blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
||||||
//
|
contractHash := "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
|
||||||
// contract, err := blockchain.GetContract(contractHash)
|
|
||||||
//
|
contract, err := blockchain.GetContract(contractHash)
|
||||||
// Expect(err).To(BeNil())
|
|
||||||
// attribute := testing.FindAttribute(contract.Attributes, "unpause")
|
Expect(err).To(BeNil())
|
||||||
// Expect(attribute).To(BeNil())
|
attribute := testing.FindAttribute(contract.Attributes, "unpause")
|
||||||
// })
|
Expect(attribute).To(BeNil())
|
||||||
// })
|
})
|
||||||
//
|
})
|
||||||
// Describe("Getting a contract attribute", func() {
|
|
||||||
// It("returns the correct attribute for a real contract", func() {
|
Describe("Getting a contract attribute", func() {
|
||||||
// config, _ := cfg.NewConfig("public")
|
It("returns the correct attribute for a real contract", func() {
|
||||||
// blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
config, _ := cfg.NewConfig("public")
|
||||||
// contractHash := "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
|
blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
||||||
//
|
contractHash := "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
|
||||||
// contract, _ := blockchain.GetContract(contractHash)
|
|
||||||
// name, err := blockchain.GetAttribute(contract, "name", nil)
|
contract, _ := blockchain.GetContract(contractHash)
|
||||||
//
|
name, err := blockchain.GetAttribute(contract, "name", nil)
|
||||||
// Expect(err).To(BeNil())
|
|
||||||
// Expect(name).To(Equal("OMGToken"))
|
Expect(err).To(BeNil())
|
||||||
// })
|
Expect(name).To(Equal("OMGToken"))
|
||||||
//
|
})
|
||||||
// It("returns the correct attribute for a real contract", func() {
|
|
||||||
// config, _ := cfg.NewConfig("public")
|
It("returns the correct attribute for a real contract", func() {
|
||||||
// blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
config, _ := cfg.NewConfig("public")
|
||||||
// contractHash := "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
|
blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
||||||
//
|
contractHash := "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
|
||||||
// contract, _ := blockchain.GetContract(contractHash)
|
|
||||||
// name, err := blockchain.GetAttribute(contract, "name", nil)
|
contract, _ := blockchain.GetContract(contractHash)
|
||||||
//
|
name, err := blockchain.GetAttribute(contract, "name", nil)
|
||||||
// Expect(err).To(BeNil())
|
|
||||||
// Expect(name).To(Equal("OMGToken"))
|
Expect(err).To(BeNil())
|
||||||
// })
|
Expect(name).To(Equal("OMGToken"))
|
||||||
//
|
})
|
||||||
// It("returns the correct attribute for a real contract at a specific block height", func() {
|
|
||||||
// config, _ := cfg.NewConfig("public")
|
It("returns the correct attribute for a real contract at a specific block height", func() {
|
||||||
// blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
config, _ := cfg.NewConfig("public")
|
||||||
// contractHash := "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
|
blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
||||||
//
|
contractHash := "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
|
||||||
// contract, _ := blockchain.GetContract(contractHash)
|
|
||||||
// name, err := blockchain.GetAttribute(contract, "name", big.NewInt(4652791))
|
contract, _ := blockchain.GetContract(contractHash)
|
||||||
//
|
name, err := blockchain.GetAttribute(contract, "name", big.NewInt(4652791))
|
||||||
// Expect(name).To(Equal("OMGToken"))
|
|
||||||
// Expect(err).To(BeNil())
|
Expect(name).To(Equal("OMGToken"))
|
||||||
// })
|
Expect(err).To(BeNil())
|
||||||
//
|
})
|
||||||
// It("returns an error when there is no ABI for the given contract", func() {
|
|
||||||
// config, _ := cfg.NewConfig("public")
|
It("returns an error when there is no ABI for the given contract", func() {
|
||||||
// blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
config, _ := cfg.NewConfig("public")
|
||||||
// contractHash := "MISSINGHASH"
|
blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
||||||
//
|
contractHash := "MISSINGHASH"
|
||||||
// contract, _ := blockchain.GetContract(contractHash)
|
|
||||||
// name, err := blockchain.GetAttribute(contract, "name", nil)
|
contract, _ := blockchain.GetContract(contractHash)
|
||||||
//
|
name, err := blockchain.GetAttribute(contract, "name", nil)
|
||||||
// Expect(err).To(Equal(geth.ErrMissingAbiFile))
|
|
||||||
// Expect(name).To(BeNil())
|
Expect(err).To(Equal(geth.ErrMissingAbiFile))
|
||||||
// })
|
Expect(name).To(BeNil())
|
||||||
//
|
})
|
||||||
// It("returns an error when asking for an attribute that does not exist", func() {
|
|
||||||
// config, _ := cfg.NewConfig("public")
|
It("returns an error when asking for an attribute that does not exist", func() {
|
||||||
// blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
config, _ := cfg.NewConfig("public")
|
||||||
// contractHash := "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
|
blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
|
||||||
//
|
contractHash := "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
|
||||||
// contract, _ := blockchain.GetContract(contractHash)
|
|
||||||
// name, err := blockchain.GetAttribute(contract, "missing_attribute", nil)
|
contract, _ := blockchain.GetContract(contractHash)
|
||||||
//
|
name, err := blockchain.GetAttribute(contract, "missing_attribute", nil)
|
||||||
// Expect(err).To(Equal(geth.ErrInvalidStateAttribute))
|
|
||||||
// Expect(name).To(BeNil())
|
Expect(err).To(Equal(geth.ErrInvalidStateAttribute))
|
||||||
// })
|
Expect(name).To(BeNil())
|
||||||
// })
|
})
|
||||||
//
|
})
|
||||||
//})
|
|
||||||
|
})
|
||||||
|
@ -6,10 +6,10 @@ import (
|
|||||||
|
|
||||||
type InMemory struct {
|
type InMemory struct {
|
||||||
blocks map[int64]*core.Block
|
blocks map[int64]*core.Block
|
||||||
watchedContracts map[string]*WatchedContract
|
watchedContracts map[string]*core.WatchedContract
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *InMemory) CreateWatchedContract(watchedContract WatchedContract) error {
|
func (repository *InMemory) CreateWatchedContract(watchedContract core.WatchedContract) error {
|
||||||
repository.watchedContracts[watchedContract.Hash] = &watchedContract
|
repository.watchedContracts[watchedContract.Hash] = &watchedContract
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -19,7 +19,7 @@ func (repository *InMemory) IsWatchedContract(contractHash string) bool {
|
|||||||
return present
|
return present
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *InMemory) FindWatchedContract(contractHash string) *WatchedContract {
|
func (repository *InMemory) FindWatchedContract(contractHash string) *core.WatchedContract {
|
||||||
watchedContract, ok := repository.watchedContracts[contractHash]
|
watchedContract, ok := repository.watchedContracts[contractHash]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
@ -47,7 +47,7 @@ func (repository *InMemory) MissingBlockNumbers(startingBlockNumber int64, endin
|
|||||||
func NewInMemory() *InMemory {
|
func NewInMemory() *InMemory {
|
||||||
return &InMemory{
|
return &InMemory{
|
||||||
blocks: make(map[int64]*core.Block),
|
blocks: make(map[int64]*core.Block),
|
||||||
watchedContracts: make(map[string]*WatchedContract),
|
watchedContracts: make(map[string]*core.WatchedContract),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ func NewPostgres(databaseConfig config.Database) (Postgres, error) {
|
|||||||
return Postgres{Db: db}, nil
|
return Postgres{Db: db}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository Postgres) CreateWatchedContract(contract WatchedContract) error {
|
func (repository Postgres) CreateWatchedContract(contract core.WatchedContract) error {
|
||||||
abi := contract.Abi
|
abi := contract.Abi
|
||||||
var abiToInsert *string
|
var abiToInsert *string
|
||||||
if abi != "" {
|
if abi != "" {
|
||||||
@ -52,8 +52,8 @@ func (repository Postgres) IsWatchedContract(contractHash string) bool {
|
|||||||
return exists
|
return exists
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository Postgres) FindWatchedContract(contractHash string) *WatchedContract {
|
func (repository Postgres) FindWatchedContract(contractHash string) *core.WatchedContract {
|
||||||
var savedContracts []WatchedContract
|
var savedContracts []core.WatchedContract
|
||||||
contractRows, _ := repository.Db.Query(
|
contractRows, _ := repository.Db.Query(
|
||||||
`SELECT contract_hash, contract_abi FROM watched_contracts WHERE contract_hash=$1`, contractHash)
|
`SELECT contract_hash, contract_abi FROM watched_contracts WHERE contract_hash=$1`, contractHash)
|
||||||
savedContracts = repository.loadContract(contractRows)
|
savedContracts = repository.loadContract(contractRows)
|
||||||
@ -197,15 +197,15 @@ func (repository Postgres) loadTransactions(transactionRows *sql.Rows) []core.Tr
|
|||||||
return transactions
|
return transactions
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository Postgres) loadContract(contractRows *sql.Rows) []WatchedContract {
|
func (repository Postgres) loadContract(contractRows *sql.Rows) []core.WatchedContract {
|
||||||
var savedContracts []WatchedContract
|
var savedContracts []core.WatchedContract
|
||||||
for contractRows.Next() {
|
for contractRows.Next() {
|
||||||
var savedContractHash string
|
var savedContractHash string
|
||||||
var savedContractAbi string
|
var savedContractAbi string
|
||||||
contractRows.Scan(&savedContractHash, &savedContractAbi)
|
contractRows.Scan(&savedContractHash, &savedContractAbi)
|
||||||
transactionRows, _ := repository.Db.Query(`SELECT tx_hash, tx_nonce, tx_to, tx_from, tx_gaslimit, tx_gasprice, tx_value FROM transactions WHERE tx_to = $1 ORDER BY block_id desc`, savedContractHash)
|
transactionRows, _ := repository.Db.Query(`SELECT tx_hash, tx_nonce, tx_to, tx_from, tx_gaslimit, tx_gasprice, tx_value FROM transactions WHERE tx_to = $1 ORDER BY block_id desc`, savedContractHash)
|
||||||
transactions := repository.loadTransactions(transactionRows)
|
transactions := repository.loadTransactions(transactionRows)
|
||||||
savedContract := WatchedContract{Hash: savedContractHash, Transactions: transactions, Abi: savedContractAbi}
|
savedContract := core.WatchedContract{Hash: savedContractHash, Transactions: transactions, Abi: savedContractAbi}
|
||||||
savedContracts = append(savedContracts, savedContract)
|
savedContracts = append(savedContracts, savedContract)
|
||||||
}
|
}
|
||||||
return savedContracts
|
return savedContracts
|
||||||
|
@ -8,7 +8,7 @@ type Repository interface {
|
|||||||
FindBlockByNumber(blockNumber int64) *core.Block
|
FindBlockByNumber(blockNumber int64) *core.Block
|
||||||
MaxBlockNumber() int64
|
MaxBlockNumber() int64
|
||||||
MissingBlockNumbers(startingBlockNumber int64, endingBlockNumber int64) []int64
|
MissingBlockNumbers(startingBlockNumber int64, endingBlockNumber int64) []int64
|
||||||
CreateWatchedContract(contract WatchedContract) error
|
CreateWatchedContract(contract core.WatchedContract) error
|
||||||
IsWatchedContract(contractHash string) bool
|
IsWatchedContract(contractHash string) bool
|
||||||
FindWatchedContract(contractHash string) *WatchedContract
|
FindWatchedContract(contractHash string) *core.WatchedContract
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ func AssertRepositoryBehavior(buildRepository func() repositories.Repository) {
|
|||||||
|
|
||||||
Describe("Creating watched contracts", func() {
|
Describe("Creating watched contracts", func() {
|
||||||
It("returns the watched contract when it exists", func() {
|
It("returns the watched contract when it exists", func() {
|
||||||
repository.CreateWatchedContract(repositories.WatchedContract{Hash: "x123"})
|
repository.CreateWatchedContract(core.WatchedContract{Hash: "x123"})
|
||||||
|
|
||||||
watchedContract := repository.FindWatchedContract("x123")
|
watchedContract := repository.FindWatchedContract("x123")
|
||||||
Expect(watchedContract).NotTo(BeNil())
|
Expect(watchedContract).NotTo(BeNil())
|
||||||
@ -226,7 +226,7 @@ func AssertRepositoryBehavior(buildRepository func() repositories.Repository) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("returns empty array when no transactions 'To' a watched contract", func() {
|
It("returns empty array when no transactions 'To' a watched contract", func() {
|
||||||
repository.CreateWatchedContract(repositories.WatchedContract{Hash: "x123"})
|
repository.CreateWatchedContract(core.WatchedContract{Hash: "x123"})
|
||||||
watchedContract := repository.FindWatchedContract("x123")
|
watchedContract := repository.FindWatchedContract("x123")
|
||||||
Expect(watchedContract).ToNot(BeNil())
|
Expect(watchedContract).ToNot(BeNil())
|
||||||
Expect(watchedContract.Transactions).To(BeEmpty())
|
Expect(watchedContract.Transactions).To(BeEmpty())
|
||||||
@ -243,7 +243,7 @@ func AssertRepositoryBehavior(buildRepository func() repositories.Repository) {
|
|||||||
}
|
}
|
||||||
repository.CreateBlock(block)
|
repository.CreateBlock(block)
|
||||||
|
|
||||||
repository.CreateWatchedContract(repositories.WatchedContract{Hash: "x123"})
|
repository.CreateWatchedContract(core.WatchedContract{Hash: "x123"})
|
||||||
watchedContract := repository.FindWatchedContract("x123")
|
watchedContract := repository.FindWatchedContract("x123")
|
||||||
Expect(watchedContract).ToNot(BeNil())
|
Expect(watchedContract).ToNot(BeNil())
|
||||||
Expect(watchedContract.Transactions).To(
|
Expect(watchedContract.Transactions).To(
|
||||||
@ -254,7 +254,7 @@ func AssertRepositoryBehavior(buildRepository func() repositories.Repository) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("stores the ABI of the contract", func() {
|
It("stores the ABI of the contract", func() {
|
||||||
repository.CreateWatchedContract(repositories.WatchedContract{
|
repository.CreateWatchedContract(core.WatchedContract{
|
||||||
Abi: "{\"some\": \"json\"}",
|
Abi: "{\"some\": \"json\"}",
|
||||||
Hash: "x123",
|
Hash: "x123",
|
||||||
})
|
})
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
package repositories
|
|
||||||
|
|
||||||
import "github.com/8thlight/vulcanizedb/pkg/core"
|
|
||||||
|
|
||||||
type WatchedContract struct {
|
|
||||||
Abi string
|
|
||||||
Hash string
|
|
||||||
Transactions []core.Transaction
|
|
||||||
}
|
|
@ -39,7 +39,7 @@ func (contractSummary ContractSummary) GetStateAttribute(attributeName string) i
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func newContractSummary(blockchain core.Blockchain, watchedContract repositories.WatchedContract, blockNumber *big.Int) ContractSummary {
|
func newContractSummary(blockchain core.Blockchain, watchedContract core.WatchedContract, blockNumber *big.Int) ContractSummary {
|
||||||
contract, _ := blockchain.GetContract(watchedContract.Hash)
|
contract, _ := blockchain.GetContract(watchedContract.Hash)
|
||||||
return ContractSummary{
|
return ContractSummary{
|
||||||
blockChain: blockchain,
|
blockChain: blockchain,
|
||||||
@ -52,7 +52,7 @@ func newContractSummary(blockchain core.Blockchain, watchedContract repositories
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func lastTransaction(watchedContract repositories.WatchedContract) *core.Transaction {
|
func lastTransaction(watchedContract core.WatchedContract) *core.Transaction {
|
||||||
if len(watchedContract.Transactions) > 0 {
|
if len(watchedContract.Transactions) > 0 {
|
||||||
return &watchedContract.Transactions[0]
|
return &watchedContract.Transactions[0]
|
||||||
} else {
|
} else {
|
||||||
|
@ -32,7 +32,7 @@ var _ = Describe("The watched contract summary", func() {
|
|||||||
Context("when the given contract is being watched", func() {
|
Context("when the given contract is being watched", func() {
|
||||||
It("returns the summary", func() {
|
It("returns the summary", func() {
|
||||||
repository := repositories.NewInMemory()
|
repository := repositories.NewInMemory()
|
||||||
watchedContract := repositories.WatchedContract{Hash: "0x123"}
|
watchedContract := core.WatchedContract{Hash: "0x123"}
|
||||||
repository.CreateWatchedContract(watchedContract)
|
repository.CreateWatchedContract(watchedContract)
|
||||||
blockchain := fakes.NewBlockchain()
|
blockchain := fakes.NewBlockchain()
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ var _ = Describe("The watched contract summary", func() {
|
|||||||
|
|
||||||
It("includes the contract hash in the summary", func() {
|
It("includes the contract hash in the summary", func() {
|
||||||
repository := repositories.NewInMemory()
|
repository := repositories.NewInMemory()
|
||||||
watchedContract := repositories.WatchedContract{Hash: "0x123"}
|
watchedContract := core.WatchedContract{Hash: "0x123"}
|
||||||
repository.CreateWatchedContract(watchedContract)
|
repository.CreateWatchedContract(watchedContract)
|
||||||
blockchain := fakes.NewBlockchain()
|
blockchain := fakes.NewBlockchain()
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ var _ = Describe("The watched contract summary", func() {
|
|||||||
|
|
||||||
It("sets the number of transactions", func() {
|
It("sets the number of transactions", func() {
|
||||||
repository := repositories.NewInMemory()
|
repository := repositories.NewInMemory()
|
||||||
watchedContract := repositories.WatchedContract{Hash: "0x123"}
|
watchedContract := core.WatchedContract{Hash: "0x123"}
|
||||||
repository.CreateWatchedContract(watchedContract)
|
repository.CreateWatchedContract(watchedContract)
|
||||||
block := core.Block{
|
block := core.Block{
|
||||||
Transactions: []core.Transaction{
|
Transactions: []core.Transaction{
|
||||||
@ -73,7 +73,7 @@ var _ = Describe("The watched contract summary", func() {
|
|||||||
|
|
||||||
It("sets the last transaction", func() {
|
It("sets the last transaction", func() {
|
||||||
repository := repositories.NewInMemory()
|
repository := repositories.NewInMemory()
|
||||||
watchedContract := repositories.WatchedContract{Hash: "0x123"}
|
watchedContract := core.WatchedContract{Hash: "0x123"}
|
||||||
repository.CreateWatchedContract(watchedContract)
|
repository.CreateWatchedContract(watchedContract)
|
||||||
block := core.Block{
|
block := core.Block{
|
||||||
Transactions: []core.Transaction{
|
Transactions: []core.Transaction{
|
||||||
@ -91,7 +91,7 @@ var _ = Describe("The watched contract summary", func() {
|
|||||||
|
|
||||||
It("gets contract state attribute for the contract from the blockchain", func() {
|
It("gets contract state attribute for the contract from the blockchain", func() {
|
||||||
repository := repositories.NewInMemory()
|
repository := repositories.NewInMemory()
|
||||||
watchedContract := repositories.WatchedContract{Hash: "0x123"}
|
watchedContract := core.WatchedContract{Hash: "0x123"}
|
||||||
repository.CreateWatchedContract(watchedContract)
|
repository.CreateWatchedContract(watchedContract)
|
||||||
blockchain := fakes.NewBlockchain()
|
blockchain := fakes.NewBlockchain()
|
||||||
blockchain.SetContractStateAttribute("0x123", nil, "foo", "bar")
|
blockchain.SetContractStateAttribute("0x123", nil, "foo", "bar")
|
||||||
@ -104,7 +104,7 @@ var _ = Describe("The watched contract summary", func() {
|
|||||||
|
|
||||||
It("gets contract state attribute for the contract from the blockchain at specific block height", func() {
|
It("gets contract state attribute for the contract from the blockchain at specific block height", func() {
|
||||||
repository := repositories.NewInMemory()
|
repository := repositories.NewInMemory()
|
||||||
watchedContract := repositories.WatchedContract{Hash: "0x123"}
|
watchedContract := core.WatchedContract{Hash: "0x123"}
|
||||||
repository.CreateWatchedContract(watchedContract)
|
repository.CreateWatchedContract(watchedContract)
|
||||||
blockchain := fakes.NewBlockchain()
|
blockchain := fakes.NewBlockchain()
|
||||||
blockNumber := big.NewInt(1000)
|
blockNumber := big.NewInt(1000)
|
||||||
@ -119,7 +119,7 @@ var _ = Describe("The watched contract summary", func() {
|
|||||||
|
|
||||||
It("gets attributes for the contract from the blockchain", func() {
|
It("gets attributes for the contract from the blockchain", func() {
|
||||||
repository := repositories.NewInMemory()
|
repository := repositories.NewInMemory()
|
||||||
watchedContract := repositories.WatchedContract{Hash: "0x123"}
|
watchedContract := core.WatchedContract{Hash: "0x123"}
|
||||||
repository.CreateWatchedContract(watchedContract)
|
repository.CreateWatchedContract(watchedContract)
|
||||||
blockchain := fakes.NewBlockchain()
|
blockchain := fakes.NewBlockchain()
|
||||||
blockchain.SetContractStateAttribute("0x123", nil, "foo", "bar")
|
blockchain.SetContractStateAttribute("0x123", nil, "foo", "bar")
|
||||||
|
Loading…
Reference in New Issue
Block a user