From 8c4fcf444136ced0baad0612493aa01278aef566 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Thu, 10 Jan 2019 12:38:16 +0100 Subject: [PATCH] Stop indexing contracts of ETH zero address --- api/worker.go | 4 +++- bchain/coins/eth/erc20.go | 11 +++++----- db/rocksdb_ethereumtype.go | 42 ++++++++++++++++++++++++-------------- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/api/worker.go b/api/worker.go index a6db0a1f..a7683230 100644 --- a/api/worker.go +++ b/api/worker.go @@ -513,6 +513,7 @@ func (w *Worker) getEthereumTypeAddressBalances(addrDesc bchain.AddressDescripto // filter only transactions of this contract filter.Vout = i + 1 } + validContract := true ci, err := w.chain.EthereumTypeGetErc20ContractInfo(c.Contract) if err != nil { return nil, nil, nil, 0, 0, 0, errors.Annotatef(err, "EthereumTypeGetErc20ContractInfo %v", c.Contract) @@ -524,9 +525,10 @@ func (w *Worker) getEthereumTypeAddressBalances(addrDesc bchain.AddressDescripto ci.Contract = addresses[0] ci.Name = addresses[0] } + validContract = false } // do not read contract balances etc in case of Basic option - if option != Basic { + if option != Basic && validContract { b, err = w.chain.EthereumTypeGetErc20ContractBalance(addrDesc, c.Contract) if err != nil { // return nil, nil, nil, errors.Annotatef(err, "EthereumTypeGetErc20ContractBalance %v %v", addrDesc, c.Contract) diff --git a/bchain/coins/eth/erc20.go b/bchain/coins/eth/erc20.go index 217a0d60..8da5b818 100644 --- a/bchain/coins/eth/erc20.go +++ b/bchain/coins/eth/erc20.go @@ -130,7 +130,9 @@ func parseErc20NumericProperty(contractDesc bchain.AddressDescriptor, data strin return &n } } - glog.Warning("Cannot parse '", data, "' for contract ", contractDesc) + if glog.V(1) { + glog.Warning("Cannot parse '", data, "' for contract ", contractDesc) + } return nil } @@ -150,7 +152,9 @@ func parseErc20StringProperty(contractDesc bchain.AddressDescriptor, data string } } } - glog.Warning("Cannot parse '", data, "' for contract ", contractDesc) + if glog.V(1) { + glog.Warning("Cannot parse '", data, "' for contract ", contractDesc) + } return "" } @@ -177,9 +181,6 @@ func (b *EthereumRPC) EthereumTypeGetErc20ContractInfo(contractDesc bchain.Addre if err != nil { return nil, err } - if name == "" { - name = address - } contract = &bchain.Erc20Contract{ Contract: address, Name: name, diff --git a/db/rocksdb_ethereumtype.go b/db/rocksdb_ethereumtype.go index 22595dd8..2ce35924 100644 --- a/db/rocksdb_ethereumtype.go +++ b/db/rocksdb_ethereumtype.go @@ -6,7 +6,7 @@ import ( "bytes" "encoding/hex" - "github.com/bsm/go-vlq" + vlq "github.com/bsm/go-vlq" "github.com/golang/glog" "github.com/juju/errors" "github.com/tecbot/gorocksdb" @@ -93,6 +93,15 @@ func findContractInAddressContracts(contract bchain.AddressDescriptor, contracts return 0, false } +func isZeroAddress(addrDesc bchain.AddressDescriptor) bool { + for _, b := range addrDesc { + if b != 0 { + return false + } + } + return true +} + func (d *RocksDB) addToAddressesAndContractsEthereumType(addrDesc bchain.AddressDescriptor, btxID []byte, index int32, contract bchain.AddressDescriptor, addresses addressesMap, addressContracts map[string]*AddrContracts, addTxCount bool) error { var err error strAddrDesc := string(addrDesc) @@ -115,20 +124,23 @@ func (d *RocksDB) addToAddressesAndContractsEthereumType(addrDesc bchain.Address ac.NonContractTxs++ } } else { - // locate the contract and set i to the index in the array of contracts - i, found := findContractInAddressContracts(contract, ac.Contracts) - if !found { - i = len(ac.Contracts) - ac.Contracts = append(ac.Contracts, AddrContract{Contract: contract}) - } - // index 0 is for ETH transfers, contract indexes start with 1 - if index < 0 { - index = ^int32(i + 1) - } else { - index = int32(i + 1) - } - if addTxCount { - ac.Contracts[i].Txs++ + // do not store contracts for 0x0000000000000000000000000000000000000000 address + if !isZeroAddress(addrDesc) { + // locate the contract and set i to the index in the array of contracts + i, found := findContractInAddressContracts(contract, ac.Contracts) + if !found { + i = len(ac.Contracts) + ac.Contracts = append(ac.Contracts, AddrContract{Contract: contract}) + } + // index 0 is for ETH transfers, contract indexes start with 1 + if index < 0 { + index = ^int32(i + 1) + } else { + index = int32(i + 1) + } + if addTxCount { + ac.Contracts[i].Txs++ + } } } counted := addToAddressesMap(addresses, strAddrDesc, btxID, index)