Store unknown contracts in DB
This commit is contained in:
parent
91c4675a53
commit
845d7e231a
@ -548,13 +548,19 @@ func (w *Worker) getEthereumTokensTransfers(transfers bchain.TokenTransfers, add
|
||||
glog.Errorf("GetContractInfo error %v, contract %v", err, t.Contract)
|
||||
}
|
||||
if contractInfo == nil {
|
||||
glog.Warningf("Contract %v %v not found in DB", t.Contract, typeName)
|
||||
// log warning only if the contract should have been known from processing of the internal data
|
||||
if eth.ProcessInternalTransactions {
|
||||
glog.Warningf("Contract %v %v not found in DB", t.Contract, typeName)
|
||||
}
|
||||
contractInfo, err = w.chain.GetContractInfo(cd)
|
||||
if err != nil {
|
||||
glog.Errorf("GetContractInfo from chain error %v, contract %v", err, t.Contract)
|
||||
}
|
||||
if contractInfo == nil {
|
||||
contractInfo = &bchain.ContractInfo{Name: t.Contract, Type: bchain.UnknownTokenType}
|
||||
contractInfo = &bchain.ContractInfo{Name: t.Contract, Type: bchain.UnknownTokenType, Decimals: w.chainParser.AmountDecimals()}
|
||||
}
|
||||
if err = w.db.StoreContractInfo(contractInfo); err != nil {
|
||||
glog.Errorf("StoreContractInfo error %v, contract %v", err, t.Contract)
|
||||
}
|
||||
}
|
||||
var value *Amount
|
||||
|
||||
@ -749,7 +749,7 @@ func (d *RocksDB) GetContractInfoForAddress(address string) (*bchain.ContractInf
|
||||
}
|
||||
|
||||
// GetContractInfo gets contract from cache or DB and possibly updates the type from typeFromContext
|
||||
// this is because it is hard to guess the type of the contract using API, it is easier to set it the first time its usage is detected in tx
|
||||
// it is hard to guess the type of the contract using API, it is easier to set it the first time the contract is processed in a tx
|
||||
func (d *RocksDB) GetContractInfo(contract bchain.AddressDescriptor, typeFromContext bchain.TokenTypeName) (*bchain.ContractInfo, error) {
|
||||
cacheKey := string(contract)
|
||||
cachedContractsMux.Lock()
|
||||
@ -783,9 +783,18 @@ func (d *RocksDB) GetContractInfo(contract bchain.AddressDescriptor, typeFromCon
|
||||
}
|
||||
|
||||
// StoreContractInfo stores contractInfo in DB
|
||||
// if CreatedInBlock==0 and DestructedInBlock!=0, it is evaluated as a desctruction of a contract, the contract info is updated
|
||||
// if CreatedInBlock==0 and DestructedInBlock!=0, it is evaluated as a destruction of a contract, the contract info is updated
|
||||
// in all other cases the contractInfo overwrites previously stored data in DB (however it should not really happen as contract is created only once)
|
||||
func (d *RocksDB) StoreContractInfo(wb *grocksdb.WriteBatch, contractInfo *bchain.ContractInfo) error {
|
||||
func (d *RocksDB) StoreContractInfo(contractInfo *bchain.ContractInfo) error {
|
||||
wb := grocksdb.NewWriteBatch()
|
||||
defer wb.Destroy()
|
||||
if err := d.storeContractInfo(wb, contractInfo); err != nil {
|
||||
return err
|
||||
}
|
||||
return d.WriteBatch(wb)
|
||||
}
|
||||
|
||||
func (d *RocksDB) storeContractInfo(wb *grocksdb.WriteBatch, contractInfo *bchain.ContractInfo) error {
|
||||
if contractInfo.Contract != "" {
|
||||
key, err := d.chainParser.GetAddrDescFromAddress(contractInfo.Contract)
|
||||
if err != nil {
|
||||
@ -882,7 +891,7 @@ func (d *RocksDB) storeBlockSpecificDataEthereumType(wb *grocksdb.WriteBatch, bl
|
||||
}
|
||||
}
|
||||
for i := range blockSpecificData.Contracts {
|
||||
if err := d.StoreContractInfo(wb, &blockSpecificData.Contracts[i]); err != nil {
|
||||
if err := d.storeContractInfo(wb, &blockSpecificData.Contracts[i]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user