forked from cerc-io/ipld-eth-server
finish method polling with hash or address type argument values
collected from watched events; 'MissingMethodsCheckedEventsIntersection' method to find headers which have been checked for each event of interest but methods have not yet been polled at that header; tests for new features; travis ci go version 1.9 -> 1.11 ; consolidate omniWatcher and lightOmniWatcher into single command with light as default
This commit is contained in:
@@ -31,6 +31,7 @@ const (
|
||||
ApprovalEvent Event = 1
|
||||
BurnEvent Event = 2
|
||||
MintEvent Event = 3
|
||||
NewOwnerEvent Event = 4
|
||||
)
|
||||
|
||||
func (e Event) String() string {
|
||||
@@ -39,9 +40,10 @@ func (e Event) String() string {
|
||||
"Approval",
|
||||
"Burn",
|
||||
"Mint",
|
||||
"NewOwner",
|
||||
}
|
||||
|
||||
if e < TransferEvent || e > MintEvent {
|
||||
if e < TransferEvent || e > NewOwnerEvent {
|
||||
return "Unknown"
|
||||
}
|
||||
|
||||
@@ -54,9 +56,10 @@ func (e Event) Signature() string {
|
||||
helpers.GenerateSignature("Approval(address,address,uint256)"),
|
||||
helpers.GenerateSignature("Burn(address,uint256)"),
|
||||
helpers.GenerateSignature("Mint(address,uint256)"),
|
||||
helpers.GenerateSignature("NewOwner(bytes32,bytes32,address)"),
|
||||
}
|
||||
|
||||
if e < TransferEvent || e > MintEvent {
|
||||
if e < TransferEvent || e > NewOwnerEvent {
|
||||
return "Unknown"
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package contract
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
@@ -44,23 +43,22 @@ type Contract struct {
|
||||
FilterArgs map[string]bool // User-input list of values to filter event logs for
|
||||
MethodArgs map[string]bool // User-input list of values to limit method polling to
|
||||
EmittedAddrs map[interface{}]bool // List of all unique addresses collected from converted event logs
|
||||
EmittedBytes map[interface{}]bool // List of all unique bytes collected from converted event logs
|
||||
EmittedHashes map[interface{}]bool // List of all unique hashes collected from converted event logs
|
||||
CreateAddrList bool // Whether or not to persist address list to postgres
|
||||
CreateHashList bool // Whether or not to persist hash list to postgres
|
||||
Piping bool // Whether or not to pipe method results forward as arguments to subsequent methods
|
||||
}
|
||||
|
||||
// If we will be calling methods that use addr, hash, or byte arrays
|
||||
// as arguments then we initialize map to hold these types of values
|
||||
// as arguments then we initialize maps to hold these types of values
|
||||
func (c Contract) Init() *Contract {
|
||||
for _, method := range c.Methods {
|
||||
for _, arg := range method.Args {
|
||||
switch arg.Type.T {
|
||||
case abi.AddressTy:
|
||||
c.EmittedAddrs = map[interface{}]bool{}
|
||||
case abi.HashTy:
|
||||
case abi.HashTy, abi.BytesTy, abi.FixedBytesTy:
|
||||
c.EmittedHashes = map[interface{}]bool{}
|
||||
case abi.BytesTy, abi.FixedBytesTy:
|
||||
c.EmittedBytes = map[interface{}]bool{}
|
||||
default:
|
||||
}
|
||||
}
|
||||
@@ -160,15 +158,6 @@ func (c *Contract) AddEmittedHash(hashes ...interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
// Add event emitted bytes to our list if it passes filter and method polling is on
|
||||
func (c *Contract) AddEmittedBytes(byteArrays ...interface{}) {
|
||||
for _, bytes := range byteArrays {
|
||||
if c.WantedMethodArg(bytes) && c.Methods != nil {
|
||||
c.EmittedBytes[bytes] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func StringifyArg(arg interface{}) (str string) {
|
||||
switch arg.(type) {
|
||||
case string:
|
||||
|
||||
@@ -47,6 +47,17 @@ type TransferLog struct {
|
||||
Value string `db:"value_"`
|
||||
}
|
||||
|
||||
type NewOwnerLog struct {
|
||||
Id int64 `db:"id"`
|
||||
VulvanizeLogId int64 `db:"vulcanize_log_id"`
|
||||
TokenName string `db:"token_name"`
|
||||
Block int64 `db:"block"`
|
||||
Tx string `db:"tx"`
|
||||
Node string `db:"node_"`
|
||||
Label string `db:"label_"`
|
||||
Owner string `db:"owner_"`
|
||||
}
|
||||
|
||||
type LightTransferLog struct {
|
||||
Id int64 `db:"id"`
|
||||
HeaderID int64 `db:"header_id"`
|
||||
@@ -59,6 +70,18 @@ type LightTransferLog struct {
|
||||
RawLog []byte `db:"raw_log"`
|
||||
}
|
||||
|
||||
type LightNewOwnerLog struct {
|
||||
Id int64 `db:"id"`
|
||||
HeaderID int64 `db:"header_id"`
|
||||
TokenName string `db:"token_name"`
|
||||
LogIndex int64 `db:"log_idx"`
|
||||
TxIndex int64 `db:"tx_idx"`
|
||||
Node string `db:"node_"`
|
||||
Label string `db:"label_"`
|
||||
Owner string `db:"owner_"`
|
||||
RawLog []byte `db:"raw_log"`
|
||||
}
|
||||
|
||||
type BalanceOf struct {
|
||||
Id int64 `db:"id"`
|
||||
TokenName string `db:"token_name"`
|
||||
@@ -67,6 +90,14 @@ type BalanceOf struct {
|
||||
Balance string `db:"returned"`
|
||||
}
|
||||
|
||||
type Owner struct {
|
||||
Id int64 `db:"id"`
|
||||
TokenName string `db:"token_name"`
|
||||
Block int64 `db:"block"`
|
||||
Node string `db:"node_"`
|
||||
Address string `db:"returned"`
|
||||
}
|
||||
|
||||
func SetupBC() core.BlockChain {
|
||||
infuraIPC := "https://mainnet.infura.io/v3/b09888c1113640cc9ab42750ce750c05"
|
||||
rawRpcClient, err := rpc.Dial(infuraIPC)
|
||||
@@ -135,7 +166,7 @@ func SetupTusdContract(wantedEvents, wantedMethods []string) *contract.Contract
|
||||
err := p.Parse()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
return &contract.Contract{
|
||||
return contract.Contract{
|
||||
Name: "TrueUSD",
|
||||
Address: constants.TusdContractAddress,
|
||||
Abi: p.Abi(),
|
||||
@@ -143,13 +174,57 @@ func SetupTusdContract(wantedEvents, wantedMethods []string) *contract.Contract
|
||||
StartingBlock: 6194634,
|
||||
LastBlock: 6507323,
|
||||
Events: p.GetEvents(wantedEvents),
|
||||
Methods: p.GetMethods(wantedMethods),
|
||||
Methods: p.GetSelectMethods(wantedMethods),
|
||||
MethodArgs: map[string]bool{},
|
||||
FilterArgs: map[string]bool{},
|
||||
EmittedAddrs: map[interface{}]bool{},
|
||||
EmittedBytes: map[interface{}]bool{},
|
||||
EmittedHashes: map[interface{}]bool{},
|
||||
}
|
||||
}.Init()
|
||||
}
|
||||
|
||||
func SetupENSRepo(vulcanizeLogId *int64, wantedEvents, wantedMethods []string) (*postgres.DB, *contract.Contract) {
|
||||
db, err := postgres.NewDB(config.Database{
|
||||
Hostname: "localhost",
|
||||
Name: "vulcanize_private",
|
||||
Port: 5432,
|
||||
}, core.Node{})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
receiptRepository := repositories.ReceiptRepository{DB: db}
|
||||
logRepository := repositories.LogRepository{DB: db}
|
||||
blockRepository := *repositories.NewBlockRepository(db)
|
||||
|
||||
blockNumber := rand.Int63()
|
||||
blockId := CreateBlock(blockNumber, blockRepository)
|
||||
|
||||
receipts := []core.Receipt{{Logs: []core.Log{{}}}}
|
||||
|
||||
err = receiptRepository.CreateReceiptsAndLogs(blockId, receipts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = logRepository.Get(vulcanizeLogId, `SELECT id FROM logs`)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
info := SetupENSContract(wantedEvents, wantedMethods)
|
||||
|
||||
return db, info
|
||||
}
|
||||
|
||||
func SetupENSContract(wantedEvents, wantedMethods []string) *contract.Contract {
|
||||
p := mocks.NewParser(constants.ENSAbiString)
|
||||
err := p.Parse()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
return contract.Contract{
|
||||
Name: "ENS-Registry",
|
||||
Address: constants.EnsContractAddress,
|
||||
Abi: p.Abi(),
|
||||
ParsedAbi: p.ParsedAbi(),
|
||||
StartingBlock: 6194634,
|
||||
LastBlock: 6507323,
|
||||
Events: p.GetEvents(wantedEvents),
|
||||
Methods: p.GetSelectMethods(wantedMethods),
|
||||
MethodArgs: map[string]bool{},
|
||||
FilterArgs: map[string]bool{},
|
||||
}.Init()
|
||||
}
|
||||
|
||||
func TearDown(db *postgres.DB) {
|
||||
@@ -168,6 +243,9 @@ func TearDown(db *postgres.DB) {
|
||||
_, err = tx.Exec(`DELETE FROM logs`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
_, err = tx.Exec(`DELETE FROM log_filters`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
_, err = tx.Exec(`DELETE FROM transactions`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
@@ -186,6 +264,12 @@ func TearDown(db *postgres.DB) {
|
||||
_, err = tx.Exec(`DROP SCHEMA IF EXISTS light_0x8dd5fbce2f6a956c3022ba3663759011dd51e73e CASCADE`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
_, err = tx.Exec(`DROP SCHEMA IF EXISTS full_0x314159265dd8dbb310642f98f50c066173c1259b CASCADE`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
_, err = tx.Exec(`DROP SCHEMA IF EXISTS light_0x314159265dd8dbb310642f98f50c066173c1259b CASCADE`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = tx.Commit()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
@@ -78,6 +78,56 @@ var TransferBlock2 = core.Block{
|
||||
}},
|
||||
}
|
||||
|
||||
var NewOwnerBlock1 = core.Block{
|
||||
Hash: "0x135391a0962a63944e5908e6fedfff90fb4be3e3290a21017861099bad123ppp",
|
||||
Number: 6194635,
|
||||
Transactions: []core.Transaction{{
|
||||
Hash: "0x135391a0962a63944e5908e6fedfff90fb4be3e3290a21017861099bad654bbb",
|
||||
Receipt: core.Receipt{
|
||||
TxHash: "0x135391a0962a63944e5908e6fedfff90fb4be3e3290a21017861099bad654bbb",
|
||||
ContractAddress: "",
|
||||
Logs: []core.Log{{
|
||||
BlockNumber: 6194635,
|
||||
TxHash: "0x135391a0962a63944e5908e6fedfff90fb4be3e3290a21017861099bad654bbb",
|
||||
Address: constants.EnsContractAddress,
|
||||
Topics: core.Topics{
|
||||
constants.NewOwnerEvent.Signature(),
|
||||
"0x0000000000000000000000000000000000000000000000000000c02aaa39b223",
|
||||
"0x9dd48110dcc444fdc242510c09bbbbe21a5975cac061d82f7b843bce061ba391",
|
||||
"",
|
||||
},
|
||||
Index: 1,
|
||||
Data: "0x000000000000000000000000000000000000000000000000000000000000af21",
|
||||
}},
|
||||
},
|
||||
}},
|
||||
}
|
||||
|
||||
var NewOwnerBlock2 = core.Block{
|
||||
Hash: "0x135391a0962a63944e5908e6fedfff90fb4be3e3290a21017861099bad123ggg",
|
||||
Number: 6194636,
|
||||
Transactions: []core.Transaction{{
|
||||
Hash: "0x135391a0962a63944e5908e6fedfff90fb4be3e3290a21017861099bad654lll",
|
||||
Receipt: core.Receipt{
|
||||
TxHash: "0x135391a0962a63944e5908e6fedfff90fb4be3e3290a21017861099bad654lll",
|
||||
ContractAddress: "",
|
||||
Logs: []core.Log{{
|
||||
BlockNumber: 6194636,
|
||||
TxHash: "0x135391a0962a63944e5908e6fedfff90fb4be3e3290a21017861099bad654lll",
|
||||
Address: constants.EnsContractAddress,
|
||||
Topics: core.Topics{
|
||||
constants.NewOwnerEvent.Signature(),
|
||||
"0x0000000000000000000000000000000000000000000000000000c02aaa39b223",
|
||||
"0x9dd48110dcc444fdc242510c09bbbbe21a5975cac061d82f7b843bce061ba400",
|
||||
"",
|
||||
},
|
||||
Index: 1,
|
||||
Data: "0x000000000000000000000000000000000000000000000000000000000000af21",
|
||||
}},
|
||||
},
|
||||
}},
|
||||
}
|
||||
|
||||
var ExpectedTransferFilter = filters.LogFilter{
|
||||
Name: "Transfer",
|
||||
Address: constants.TusdContractAddress,
|
||||
@@ -150,7 +200,7 @@ var MockTransferLog2 = types.Log{
|
||||
Address: common.HexToAddress(constants.TusdContractAddress),
|
||||
BlockNumber: 5488077,
|
||||
TxIndex: 2,
|
||||
TxHash: common.HexToHash("0x135391a0962a63944e5908e6fedfff90fb4be3e3290a21017861099bad6546ae"),
|
||||
TxHash: common.HexToHash("0x135391a0962a63944e5908e6fedfff90fb4be3e3290a21017861099bad6546df"),
|
||||
Topics: []common.Hash{
|
||||
common.HexToHash(constants.TransferEvent.Signature()),
|
||||
common.HexToHash("0x9dd48110dcc444fdc242510c09bbbbe21a5975cac061d82f7b843bce061ba391"),
|
||||
@@ -162,7 +212,7 @@ var MockTransferLog2 = types.Log{
|
||||
var MockMintLog = types.Log{
|
||||
Index: 10,
|
||||
Address: common.HexToAddress(constants.TusdContractAddress),
|
||||
BlockNumber: 548808,
|
||||
BlockNumber: 5488080,
|
||||
TxIndex: 50,
|
||||
TxHash: common.HexToHash("0x135391a0962a63944e5908e6fedfff90fb4be3e3290a21017861099bad6minty"),
|
||||
Topics: []common.Hash{
|
||||
@@ -171,3 +221,31 @@ var MockMintLog = types.Log{
|
||||
},
|
||||
Data: hexutil.MustDecode("0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000089d24a6b4ccb1b6faa2625fe562bdd9a23260359000000000000000000000000000000000000000000000000392d2e2bda9c00000000000000000000000000000000000000000000000000927f41fa0a4a418000000000000000000000000000000000000000000000000000000000005adcfebe"),
|
||||
}
|
||||
|
||||
var MockNewOwnerLog1 = types.Log{
|
||||
Index: 1,
|
||||
Address: common.HexToAddress(constants.EnsContractAddress),
|
||||
BlockNumber: 5488076,
|
||||
TxIndex: 110,
|
||||
TxHash: common.HexToHash("0x135391a0962a63944e5908e6fedfff90fb4be3e3290a21017861099bad6546ae"),
|
||||
Topics: []common.Hash{
|
||||
common.HexToHash(constants.NewOwnerEvent.Signature()),
|
||||
common.HexToHash("0x000000000000000000000000c02aaa39b223helloa0e5c4f27ead9083c752553"),
|
||||
common.HexToHash("0x9dd48110dcc444fdc242510c09bbbbe21a5975cac061d82f7b843bce061ba391"),
|
||||
},
|
||||
Data: hexutil.MustDecode("0x000000000000000000000000000000000000000000000000000000000000af21"),
|
||||
}
|
||||
|
||||
var MockNewOwnerLog2 = types.Log{
|
||||
Index: 3,
|
||||
Address: common.HexToAddress(constants.EnsContractAddress),
|
||||
BlockNumber: 5488077,
|
||||
TxIndex: 2,
|
||||
TxHash: common.HexToHash("0x135391a0962a63944e5908e6fedfff90fb4be3e3290a21017861099bad6546df"),
|
||||
Topics: []common.Hash{
|
||||
common.HexToHash(constants.NewOwnerEvent.Signature()),
|
||||
common.HexToHash("0x000000000000000000000000c02aaa39b223helloa0e5c4f27ead9083c752553"),
|
||||
common.HexToHash("0x9dd48110dcc444fdc242510c09bbbbe21a5975cac061d82f7b843bce061ba400"),
|
||||
},
|
||||
Data: hexutil.MustDecode("0x000000000000000000000000000000000000000000000000000000000000af21"),
|
||||
}
|
||||
|
||||
@@ -56,25 +56,18 @@ func (p *parser) Parse() error {
|
||||
}
|
||||
|
||||
// Returns wanted methods, if they meet the criteria, as map of types.Methods
|
||||
// Only returns specified methods
|
||||
func (p *parser) GetMethods(wanted []string) map[string]types.Method {
|
||||
// Empty wanted array => all methods that fit are returned
|
||||
// Nil wanted array => no events are returned
|
||||
func (p *parser) GetSelectMethods(wanted []string) map[string]types.Method {
|
||||
addrMethods := map[string]types.Method{}
|
||||
if wanted == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, m := range p.parsedAbi.Methods {
|
||||
// Only return methods that have less than 3 inputs, 1 output, and wanted
|
||||
if len(m.Inputs) < 3 && len(m.Outputs) == 1 && stringInSlice(wanted, m.Name) {
|
||||
addrsOnly := true
|
||||
for _, input := range m.Inputs {
|
||||
if input.Type.T != abi.AddressTy {
|
||||
addrsOnly = false
|
||||
}
|
||||
}
|
||||
|
||||
// Only return methods if inputs are all of type address and output is of the accepted types
|
||||
if addrsOnly && wantType(m.Outputs[0]) {
|
||||
method := types.NewMethod(m)
|
||||
addrMethods[method.Name] = method
|
||||
}
|
||||
if okInputTypes(m, wanted) {
|
||||
wantedMethod := types.NewMethod(m)
|
||||
addrMethods[wantedMethod.Name] = wantedMethod
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,3 +109,46 @@ func stringInSlice(list []string, s string) bool {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func okInputTypes(m abi.Method, wanted []string) bool {
|
||||
// Only return method if it has less than 3 arguments, a single output value, and it is a method we want or we want all methods (empty 'wanted' slice)
|
||||
if len(m.Inputs) < 3 && len(m.Outputs) == 1 && (len(wanted) == 0 || stringInSlice(wanted, m.Name)) {
|
||||
// Only return methods if inputs are all of accepted types and output is of the accepted types
|
||||
if !okReturnType(m.Outputs[0]) {
|
||||
return false
|
||||
}
|
||||
for _, input := range m.Inputs {
|
||||
switch input.Type.T {
|
||||
case abi.AddressTy, abi.HashTy, abi.BytesTy, abi.FixedBytesTy:
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func okReturnType(arg abi.Argument) bool {
|
||||
wantedTypes := []byte{
|
||||
abi.UintTy,
|
||||
abi.IntTy,
|
||||
abi.BoolTy,
|
||||
abi.StringTy,
|
||||
abi.AddressTy,
|
||||
abi.HashTy,
|
||||
abi.BytesTy,
|
||||
abi.FixedBytesTy,
|
||||
abi.FixedPointTy,
|
||||
}
|
||||
|
||||
for _, ty := range wantedTypes {
|
||||
if arg.Type.T == ty {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ var _ = Describe("Parser", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(parsedAbi).To(Equal(expectedAbi))
|
||||
|
||||
methods := mp.GetMethods([]string{"balanceOf"})
|
||||
methods := mp.GetSelectMethods([]string{"balanceOf"})
|
||||
_, ok := methods["totalSupply"]
|
||||
Expect(ok).To(Equal(false))
|
||||
m, ok := methods["balanceOf"]
|
||||
|
||||
@@ -129,9 +129,7 @@ func (p *poller) pollSingleArgAt(m types.Method, bn int64) error {
|
||||
// the correct argument set to iterate over
|
||||
var args map[interface{}]bool
|
||||
switch m.Args[0].Type.T {
|
||||
case abi.FixedBytesTy, abi.BytesTy:
|
||||
args = p.contract.EmittedBytes
|
||||
case abi.HashTy:
|
||||
case abi.HashTy, abi.FixedBytesTy, abi.BytesTy:
|
||||
args = p.contract.EmittedHashes
|
||||
case abi.AddressTy:
|
||||
args = p.contract.EmittedAddrs
|
||||
@@ -182,9 +180,7 @@ func (p *poller) pollDoubleArgAt(m types.Method, bn int64) error {
|
||||
// the correct argument sets to iterate over
|
||||
var firstArgs map[interface{}]bool
|
||||
switch m.Args[0].Type.T {
|
||||
case abi.FixedBytesTy, abi.BytesTy:
|
||||
firstArgs = p.contract.EmittedBytes
|
||||
case abi.HashTy:
|
||||
case abi.HashTy, abi.FixedBytesTy, abi.BytesTy:
|
||||
firstArgs = p.contract.EmittedHashes
|
||||
case abi.AddressTy:
|
||||
firstArgs = p.contract.EmittedAddrs
|
||||
@@ -195,9 +191,7 @@ func (p *poller) pollDoubleArgAt(m types.Method, bn int64) error {
|
||||
|
||||
var secondArgs map[interface{}]bool
|
||||
switch m.Args[1].Type.T {
|
||||
case abi.FixedBytesTy, abi.BytesTy:
|
||||
secondArgs = p.contract.EmittedBytes
|
||||
case abi.HashTy:
|
||||
case abi.HashTy, abi.FixedBytesTy, abi.BytesTy:
|
||||
secondArgs = p.contract.EmittedHashes
|
||||
case abi.AddressTy:
|
||||
secondArgs = p.contract.EmittedAddrs
|
||||
|
||||
@@ -83,6 +83,28 @@ var _ = Describe("Poller", func() {
|
||||
Expect(scanStruct.TokenName).To(Equal("TrueUSD"))
|
||||
})
|
||||
|
||||
It("Polls specified contract methods using contract's hash list", func() {
|
||||
con = test_helpers.SetupENSContract(nil, []string{"owner"})
|
||||
Expect(con.Abi).To(Equal(constants.ENSAbiString))
|
||||
Expect(len(con.Methods)).To(Equal(1))
|
||||
con.AddEmittedHash(common.HexToHash("0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae"), common.HexToHash("0x7e74a86b6e146964fb965db04dc2590516da77f720bb6759337bf5632415fd86"))
|
||||
|
||||
err := p.PollContractAt(*con, 6885877)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
scanStruct := test_helpers.Owner{}
|
||||
|
||||
err = db.QueryRowx(fmt.Sprintf("SELECT * FROM full_%s.owner_method WHERE node_ = '0x7e74a86b6e146964fb965db04dc2590516da77f720bb6759337bf5632415fd86' AND block = '6885877'", constants.EnsContractAddress)).StructScan(&scanStruct)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(scanStruct.Address).To(Equal("0x546aA2EaE2514494EeaDb7bbb35243348983C59d"))
|
||||
Expect(scanStruct.TokenName).To(Equal("ENS-Registry"))
|
||||
|
||||
err = db.QueryRowx(fmt.Sprintf("SELECT * FROM full_%s.owner_method WHERE node_ = '0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae' AND block = '6885877'", constants.EnsContractAddress)).StructScan(&scanStruct)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(scanStruct.Address).To(Equal("0x6090A6e47849629b7245Dfa1Ca21D94cd15878Ef"))
|
||||
Expect(scanStruct.TokenName).To(Equal("ENS-Registry"))
|
||||
})
|
||||
|
||||
It("Does not poll and persist any methods if none are specified", func() {
|
||||
con = test_helpers.SetupTusdContract(nil, nil)
|
||||
Expect(con.Abi).To(Equal(constants.TusdAbiString))
|
||||
@@ -109,4 +131,93 @@ var _ = Describe("Poller", func() {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Describe("Light sync mode", func() {
|
||||
BeforeEach(func() {
|
||||
db, bc = test_helpers.SetupDBandBC()
|
||||
p = poller.NewPoller(bc, db, types.LightSync)
|
||||
})
|
||||
|
||||
Describe("PollContract", func() {
|
||||
It("Polls specified contract methods using contract's token holder address list", func() {
|
||||
con = test_helpers.SetupTusdContract(nil, []string{"balanceOf"})
|
||||
Expect(con.Abi).To(Equal(constants.TusdAbiString))
|
||||
con.StartingBlock = 6707322
|
||||
con.LastBlock = 6707323
|
||||
con.AddEmittedAddr(common.HexToAddress("0xfE9e8709d3215310075d67E3ed32A380CCf451C8"), common.HexToAddress("0x3f5CE5FBFe3E9af3971dD833D26bA9b5C936f0bE"))
|
||||
|
||||
err := p.PollContract(*con)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
scanStruct := test_helpers.BalanceOf{}
|
||||
|
||||
err = db.QueryRowx(fmt.Sprintf("SELECT * FROM light_%s.balanceof_method WHERE who_ = '0xfE9e8709d3215310075d67E3ed32A380CCf451C8' AND block = '6707322'", constants.TusdContractAddress)).StructScan(&scanStruct)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(scanStruct.Balance).To(Equal("66386309548896882859581786"))
|
||||
Expect(scanStruct.TokenName).To(Equal("TrueUSD"))
|
||||
|
||||
err = db.QueryRowx(fmt.Sprintf("SELECT * FROM light_%s.balanceof_method WHERE who_ = '0xfE9e8709d3215310075d67E3ed32A380CCf451C8' AND block = '6707323'", constants.TusdContractAddress)).StructScan(&scanStruct)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(scanStruct.Balance).To(Equal("66386309548896882859581786"))
|
||||
Expect(scanStruct.TokenName).To(Equal("TrueUSD"))
|
||||
|
||||
err = db.QueryRowx(fmt.Sprintf("SELECT * FROM light_%s.balanceof_method WHERE who_ = '0x3f5CE5FBFe3E9af3971dD833D26bA9b5C936f0bE' AND block = '6707322'", constants.TusdContractAddress)).StructScan(&scanStruct)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(scanStruct.Balance).To(Equal("17982350181394112023885864"))
|
||||
Expect(scanStruct.TokenName).To(Equal("TrueUSD"))
|
||||
|
||||
err = db.QueryRowx(fmt.Sprintf("SELECT * FROM light_%s.balanceof_method WHERE who_ = '0x3f5CE5FBFe3E9af3971dD833D26bA9b5C936f0bE' AND block = '6707323'", constants.TusdContractAddress)).StructScan(&scanStruct)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(scanStruct.Balance).To(Equal("17982350181394112023885864"))
|
||||
Expect(scanStruct.TokenName).To(Equal("TrueUSD"))
|
||||
})
|
||||
|
||||
It("Polls specified contract methods using contract's hash list", func() {
|
||||
con = test_helpers.SetupENSContract(nil, []string{"owner"})
|
||||
Expect(con.Abi).To(Equal(constants.ENSAbiString))
|
||||
Expect(len(con.Methods)).To(Equal(1))
|
||||
con.AddEmittedHash(common.HexToHash("0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae"), common.HexToHash("0x7e74a86b6e146964fb965db04dc2590516da77f720bb6759337bf5632415fd86"))
|
||||
|
||||
err := p.PollContractAt(*con, 6885877)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
scanStruct := test_helpers.Owner{}
|
||||
|
||||
err = db.QueryRowx(fmt.Sprintf("SELECT * FROM light_%s.owner_method WHERE node_ = '0x7e74a86b6e146964fb965db04dc2590516da77f720bb6759337bf5632415fd86' AND block = '6885877'", constants.EnsContractAddress)).StructScan(&scanStruct)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(scanStruct.Address).To(Equal("0x546aA2EaE2514494EeaDb7bbb35243348983C59d"))
|
||||
Expect(scanStruct.TokenName).To(Equal("ENS-Registry"))
|
||||
|
||||
err = db.QueryRowx(fmt.Sprintf("SELECT * FROM light_%s.owner_method WHERE node_ = '0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae' AND block = '6885877'", constants.EnsContractAddress)).StructScan(&scanStruct)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(scanStruct.Address).To(Equal("0x6090A6e47849629b7245Dfa1Ca21D94cd15878Ef"))
|
||||
Expect(scanStruct.TokenName).To(Equal("ENS-Registry"))
|
||||
})
|
||||
|
||||
It("Does not poll and persist any methods if none are specified", func() {
|
||||
con = test_helpers.SetupTusdContract(nil, nil)
|
||||
Expect(con.Abi).To(Equal(constants.TusdAbiString))
|
||||
con.StartingBlock = 6707322
|
||||
con.LastBlock = 6707323
|
||||
con.AddEmittedAddr(common.HexToAddress("0xfE9e8709d3215310075d67E3ed32A380CCf451C8"), common.HexToAddress("0x3f5CE5FBFe3E9af3971dD833D26bA9b5C936f0bE"))
|
||||
|
||||
err := p.PollContract(*con)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
scanStruct := test_helpers.BalanceOf{}
|
||||
|
||||
err = db.QueryRowx(fmt.Sprintf("SELECT * FROM light_%s.balanceof_method WHERE who_ = '0xfE9e8709d3215310075d67E3ed32A380CCf451C8' AND block = '6707322'", constants.TusdContractAddress)).StructScan(&scanStruct)
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
Describe("PollMethod", func() {
|
||||
It("Polls a single contract method", func() {
|
||||
var name = new(string)
|
||||
err := p.FetchContractData(constants.TusdAbiString, constants.TusdContractAddress, "name", nil, &name, 6197514)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(*name).To(Equal("TrueUSD"))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -112,7 +112,6 @@ func (r *methodRepository) persistResults(results []types.Result, methodInfo typ
|
||||
// Add this query to the transaction
|
||||
_, err = tx.Exec(pgStr, data...)
|
||||
if err != nil {
|
||||
println("howdy")
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -20,10 +20,13 @@ package transformer
|
||||
// data for any contract and persists it to custom postgres tables in vDB
|
||||
type Transformer interface {
|
||||
SetEvents(contractAddr string, filterSet []string)
|
||||
SetEventAddrs(contractAddr string, filterSet []string)
|
||||
SetEventArgs(contractAddr string, filterSet []string)
|
||||
SetMethods(contractAddr string, filterSet []string)
|
||||
SetMethodAddrs(contractAddr string, filterSet []string)
|
||||
SetRange(contractAddr string, rng []int64)
|
||||
SetMethodArgs(contractAddr string, filterSet []string)
|
||||
SetRange(contractAddr string, rng [2]int64)
|
||||
SetCreateAddrList(contractAddr string, on bool)
|
||||
SetCreateHashList(contractAddr string, on bool)
|
||||
SetPiping(contractAddr string, on bool)
|
||||
Init() error
|
||||
Execute() error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user