Stop indexing contracts of ETH zero address

pull/105/head
Martin Boehm 2019-01-10 12:38:16 +01:00
parent 341bf331c1
commit 8c4fcf4441
3 changed files with 36 additions and 21 deletions

View File

@ -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)

View File

@ -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,

View File

@ -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)