Fix backward compatibility with v0.3.6

This commit is contained in:
Martin Boehm 2023-02-18 01:17:56 +01:00
parent 026899edf1
commit 8e28ebe8dc
3 changed files with 10 additions and 3 deletions

View File

@ -339,6 +339,7 @@ type Address struct {
TotalBaseValue float64 `json:"totalBaseValue,omitempty"` // value including tokens in base currency
TotalSecondaryValue float64 `json:"totalSecondaryValue,omitempty"` // value including tokens in secondary currency
ContractInfo *bchain.ContractInfo `json:"contractInfo,omitempty"`
Erc20Contract *bchain.ContractInfo `json:"erc20Contract,omitempty"` // deprecated
AddressAliases AddressAliasesMap `json:"addressAliases,omitempty"`
// helpers for explorer
Filter string `json:"-"`

View File

@ -1007,6 +1007,7 @@ type ethereumTypeAddressData struct {
func (w *Worker) getEthereumTypeAddressBalances(addrDesc bchain.AddressDescriptor, details AccountDetails, filter *AddressFilter, secondaryCoin string) (*db.AddrBalance, *ethereumTypeAddressData, error) {
var ba *db.AddrBalance
var n uint64
// unknown number of results for paging initially
d := ethereumTypeAddressData{totalResults: -1}
ca, err := w.db.GetAddrDescContracts(addrDesc)
@ -1031,11 +1032,10 @@ func (w *Worker) getEthereumTypeAddressBalances(addrDesc bchain.AddressDescripto
if b != nil {
ba.BalanceSat = *b
}
n, err := w.chain.EthereumTypeGetNonce(addrDesc)
n, err = w.chain.EthereumTypeGetNonce(addrDesc)
if err != nil {
return nil, nil, errors.Annotatef(err, "EthereumTypeGetNonce %v", addrDesc)
}
d.nonce = strconv.Itoa(int(n))
ticker := w.is.GetCurrentTicker("", "")
if details > AccountDetailsBasic {
d.tokens = make([]Token, len(ca.Contracts))
@ -1089,6 +1089,8 @@ func (w *Worker) getEthereumTypeAddressBalances(addrDesc bchain.AddressDescripto
}
}
}
// returns 0 for unknown address
d.nonce = strconv.Itoa(int(n))
// special handling if filtering for a contract, return the contract details even though the address had no transactions with it
if len(d.tokens) == 0 && len(filterDesc) > 0 && details >= AccountDetailsTokens {
t, err := w.getEthereumContractBalanceFromBlockchain(addrDesc, filterDesc, details)
@ -1345,6 +1347,10 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option Acco
Nonce: ed.nonce,
AddressAliases: w.getAddressAliases(addresses),
}
// keep address backward compatible, set deprecated Erc20Contract value if ERC20 token
if ed.contractInfo != nil && ed.contractInfo.Type == bchain.ERC20TokenType {
r.Erc20Contract = ed.contractInfo
}
glog.Info("GetAddress ", address, ", ", time.Since(start))
return r, nil
}

View File

@ -55,7 +55,7 @@ type EthereumInternalData struct {
Error string
}
// ContractInfo contains info about ERC20 contract
// ContractInfo contains info about a contract
type ContractInfo struct {
Type TokenTypeName `json:"type"`
Contract string `json:"contract"`