forked from cerc-io/ipld-eth-server
Flop deal (#39)
*Refactor deal transformer to take in several contract addresses * Add flop address to deal transformer
This commit is contained in:
@@ -28,8 +28,8 @@ var (
|
||||
// temporary addresses from Kovan deployment
|
||||
CatContractAddress = "0x2f34f22a00ee4b7a8f8bbc4eaee1658774c624e0"
|
||||
DripContractAddress = "0x891c04639a5edcae088e546fa125b5d7fb6a2b9d"
|
||||
FlipperContractAddress = "0x32d496ad866d110060866b7125981c73642cc509" // ETH FLIP Contract
|
||||
FlopperContractAddress = "0x6191c9b0086c2ebf92300cc507009b53996fbffa" // MCD FLOP Contract
|
||||
FlipperContractAddress = "0x32D496Ad866D110060866B7125981C73642cc509" // ETH FLIP Contract
|
||||
FlopperContractAddress = "0x6191C9b0086c2eBF92300cC507009b53996FbFFa" // MCD FLOP Contract
|
||||
PepContractAddress = "0xB1997239Cfc3d15578A3a09730f7f84A90BB4975"
|
||||
PipContractAddress = "0x9FfFE440258B79c5d6604001674A4722FfC0f7Bc"
|
||||
PitContractAddress = "0xe7cf3198787c9a4daac73371a38f29aaeeced87e"
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
)
|
||||
|
||||
type LogFetcher interface {
|
||||
FetchLogs(contractAddress string, topics [][]common.Hash, blockNumber int64) ([]types.Log, error)
|
||||
FetchLogs(contractAddresses []string, topics [][]common.Hash, blockNumber int64) ([]types.Log, error)
|
||||
}
|
||||
|
||||
type Fetcher struct {
|
||||
@@ -38,14 +38,24 @@ func NewFetcher(blockchain core.BlockChain) Fetcher {
|
||||
}
|
||||
}
|
||||
|
||||
func (fetcher Fetcher) FetchLogs(contractAddress string, topics [][]common.Hash, blockNumber int64) ([]types.Log, error) {
|
||||
func (fetcher Fetcher) FetchLogs(contractAddresses []string, topics [][]common.Hash, blockNumber int64) ([]types.Log, error) {
|
||||
block := big.NewInt(blockNumber)
|
||||
address := common.HexToAddress(contractAddress)
|
||||
addresses := hexStringsToAddresses(contractAddresses)
|
||||
query := ethereum.FilterQuery{
|
||||
FromBlock: block,
|
||||
ToBlock: block,
|
||||
Addresses: []common.Address{address},
|
||||
Addresses: addresses,
|
||||
Topics: topics,
|
||||
}
|
||||
return fetcher.blockChain.GetEthLogsWithCustomQuery(query)
|
||||
}
|
||||
|
||||
func hexStringsToAddresses(hexStrings []string) []common.Address {
|
||||
var addresses []common.Address
|
||||
for _, hexString := range hexStrings {
|
||||
address := common.HexToAddress(hexString)
|
||||
addresses = append(addresses, address)
|
||||
}
|
||||
|
||||
return addresses
|
||||
}
|
||||
|
||||
@@ -28,25 +28,25 @@ import (
|
||||
|
||||
var _ = Describe("Fetcher", func() {
|
||||
Describe("FetchLogs", func() {
|
||||
|
||||
It("fetches logs based on the given query", func() {
|
||||
blockChain := fakes.NewMockBlockChain()
|
||||
fetcher := shared.NewFetcher(blockChain)
|
||||
blockNumber := int64(123)
|
||||
address := "0xfakeAddress"
|
||||
addresses := []string{"0xfakeAddress", "0xanotherFakeAddress"}
|
||||
topicZeros := [][]common.Hash{{common.BytesToHash([]byte{1, 2, 3, 4, 5})}}
|
||||
|
||||
_, err := fetcher.FetchLogs(address, topicZeros, blockNumber)
|
||||
_, err := fetcher.FetchLogs(addresses, topicZeros, blockNumber)
|
||||
|
||||
address1 := common.HexToAddress("0xfakeAddress")
|
||||
address2 := common.HexToAddress("0xanotherFakeAddress")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
expectedQuery := ethereum.FilterQuery{
|
||||
FromBlock: big.NewInt(blockNumber),
|
||||
ToBlock: big.NewInt(blockNumber),
|
||||
Addresses: []common.Address{common.HexToAddress(address)},
|
||||
Addresses: []common.Address{address1, address2},
|
||||
Topics: topicZeros,
|
||||
}
|
||||
blockChain.AssertGetEthLogsWithCustomQueryCalledWith(expectedQuery)
|
||||
|
||||
})
|
||||
|
||||
It("returns an error if fetching the logs fails", func() {
|
||||
@@ -54,7 +54,7 @@ var _ = Describe("Fetcher", func() {
|
||||
blockChain.SetGetEthLogsWithCustomQueryErr(fakes.FakeError)
|
||||
fetcher := shared.NewFetcher(blockChain)
|
||||
|
||||
_, err := fetcher.FetchLogs("", [][]common.Hash{}, int64(1))
|
||||
_, err := fetcher.FetchLogs([]string{}, [][]common.Hash{}, int64(1))
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err).To(MatchError(fakes.FakeError))
|
||||
|
||||
@@ -28,7 +28,7 @@ type Transformer interface {
|
||||
type TransformerInitializer func(db *postgres.DB, blockChain core.BlockChain) Transformer
|
||||
|
||||
type TransformerConfig struct {
|
||||
ContractAddress string
|
||||
ContractAddresses []string
|
||||
ContractAbi string
|
||||
Topics []string
|
||||
StartingBlockNumber int64
|
||||
|
||||
Reference in New Issue
Block a user