revert txns list in address query

pull/1626/head
Rongjian Lan 5 years ago
parent 81729f6b72
commit df1fd71a33
  1. 28
      api/service/explorer/service.go

@ -641,6 +641,7 @@ func (s *ServiceAPI) GetExplorerCommittee(ctx context.Context, shardID uint32, e
func (s *Service) GetExplorerAddress(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
id := r.FormValue("id")
key := GetAddressKey(id)
txViewParam := r.FormValue("tx_view")
pageParam := r.FormValue("page")
offsetParam := r.FormValue("offset")
@ -697,9 +698,17 @@ func (s *Service) GetExplorerAddress(w http.ResponseWriter, r *http.Request) {
}
}
if balanceAddr.Cmp(big.NewInt(0)) != 0 {
data.Address.Balance = balanceAddr
db := s.Storage.GetDB()
bytes, err := db.Get([]byte(key))
if err = rlp.DecodeBytes(bytes, &data.Address); err != nil {
utils.Logger().Warn().Str("id", id).Msg("cannot convert data from DB")
w.WriteHeader(http.StatusInternalServerError)
return
}
data.Address.Balance = balanceAddr
switch txView {
case txViewNone:
data.Address.TXs = nil
@ -754,9 +763,20 @@ func (s *ServiceAPI) GetExplorerAddress(ctx context.Context, id, txView string,
}
}
if balanceAddr.Cmp(big.NewInt(0)) != 0 {
address.Balance = balanceAddr
key := GetAddressKey(id)
db := s.Service.Storage.GetDB()
bytes, err := db.Get([]byte(key))
if err != nil {
utils.Logger().Warn().Err(err).Str("id", id).Msg("cannot read address from db")
return address, nil
}
if err = rlp.DecodeBytes(bytes, &address); err != nil {
utils.Logger().Warn().Str("id", id).Msg("cannot convert data from DB")
return nil, err
}
address.Balance = balanceAddr
switch txView {
case txViewNone:
address.TXs = nil

Loading…
Cancel
Save