From 8e28ebe8dc781f843958917cf045b39899101390 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Sat, 18 Feb 2023 01:17:56 +0100 Subject: [PATCH] Fix backward compatibility with v0.3.6 --- api/types.go | 1 + api/worker.go | 10 ++++++++-- bchain/types_ethereum_type.go | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/api/types.go b/api/types.go index c0ef1383..23d4dd1f 100644 --- a/api/types.go +++ b/api/types.go @@ -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:"-"` diff --git a/api/worker.go b/api/worker.go index e263f513..3024a5e3 100644 --- a/api/worker.go +++ b/api/worker.go @@ -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 } diff --git a/bchain/types_ethereum_type.go b/bchain/types_ethereum_type.go index a04a0810..adceec3b 100644 --- a/bchain/types_ethereum_type.go +++ b/bchain/types_ethereum_type.go @@ -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"`