Fix explorer balance checking problem

pull/1621/head
Rongjian Lan 5 years ago
parent e74a2f1bdf
commit 396fd319b4
  1. 23
      api/service/explorer/service.go
  2. 5
      api/service/explorer/storage.go

@ -641,7 +641,6 @@ 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")
@ -698,17 +697,6 @@ func (s *Service) GetExplorerAddress(w http.ResponseWriter, r *http.Request) {
}
}
db := s.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
}
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
}
if balanceAddr.Cmp(big.NewInt(0)) != 0 {
data.Address.Balance = balanceAddr
}
@ -766,17 +754,6 @@ func (s *ServiceAPI) GetExplorerAddress(ctx context.Context, id, txView string,
}
}
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
}
if balanceAddr.Cmp(big.NewInt(0)) != 0 {
address.Balance = balanceAddr
}

@ -118,7 +118,8 @@ func (storage *Storage) Dump(block *types.Block, height uint64) {
explorerTransaction := GetTransaction(tx, block)
storage.UpdateTXStorage(batch, explorerTransaction, tx)
storage.UpdateAddress(batch, explorerTransaction, tx)
//storage.UpdateAddress(batch, explorerTransaction, tx)
}
if err := batch.Write(); err != nil {
ctxerror.Warn(utils.GetLogger(), err, "cannot write batch")
@ -155,6 +156,7 @@ func (storage *Storage) UpdateTXStorage(batch ethdb.Batch, explorerTransaction *
}
// UpdateAddress ...
// TODO: deprecate this logic
func (storage *Storage) UpdateAddress(batch ethdb.Batch, explorerTransaction *Transaction, tx *types.Transaction) {
explorerTransaction.Type = Received
storage.UpdateAddressStorage(batch, explorerTransaction.To, explorerTransaction, tx)
@ -163,6 +165,7 @@ func (storage *Storage) UpdateAddress(batch ethdb.Batch, explorerTransaction *Tr
}
// UpdateAddressStorage updates specific addr Address.
// TODO: deprecate this logic
func (storage *Storage) UpdateAddressStorage(batch ethdb.Batch, addr string, explorerTransaction *Transaction, tx *types.Transaction) {
key := GetAddressKey(addr)

Loading…
Cancel
Save