Merge branch 'master' into pr_explorer_errors_issue

pull/1648/head^2
flicker-harmony 5 years ago committed by GitHub
commit 8a2e22fecf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 43
      api/service/explorer/service.go
  2. 13
      api/service/explorer/storage.go
  3. 4
      go.mod

@ -8,6 +8,7 @@ import (
"net"
"net/http"
"os"
"sort"
"strconv"
"strings"
@ -188,7 +189,7 @@ func (s *Service) GetExplorerBlocks(w http.ResponseWriter, r *http.Request) {
if withSignersParam == "true" {
withSigners = true
}
order := r.FormValue("order")
data := &Data{
Blocks: []*Block{},
}
@ -343,10 +344,19 @@ func (s *Service) GetExplorerBlocks(w http.ResponseWriter, r *http.Request) {
} else {
data.Blocks = data.Blocks[offset*page : offset*page+offset]
}
if order == "DESC" {
sort.Slice(data.Blocks[:], func(i, j int) bool {
return data.Blocks[i].Timestamp > data.Blocks[j].Timestamp
})
} else {
sort.Slice(data.Blocks[:], func(i, j int) bool {
return data.Blocks[i].Timestamp < data.Blocks[j].Timestamp
})
}
}
// GetExplorerBlocks rpc end-point.
func (s *ServiceAPI) GetExplorerBlocks(ctx context.Context, from, to, page, offset int, withSigners bool) ([]*Block, error) {
func (s *ServiceAPI) GetExplorerBlocks(ctx context.Context, from, to, page, offset int, withSigners bool, order string) ([]*Block, error) {
if offset == 0 {
offset = paginationOffset
}
@ -453,6 +463,15 @@ func (s *ServiceAPI) GetExplorerBlocks(ctx context.Context, from, to, page, offs
} else {
blocks = blocks[offset*page : offset*page+offset]
}
if order == "DESC" {
sort.Slice(blocks[:], func(i, j int) bool {
return blocks[i].Timestamp > blocks[j].Timestamp
})
} else {
sort.Slice(blocks[:], func(i, j int) bool {
return blocks[i].Timestamp < blocks[j].Timestamp
})
}
return blocks, nil
}
@ -656,6 +675,7 @@ func (s *Service) GetExplorerAddress(w http.ResponseWriter, r *http.Request) {
txViewParam := r.FormValue("tx_view")
pageParam := r.FormValue("page")
offsetParam := r.FormValue("offset")
order := r.FormValue("order")
txView := txViewNone
if txViewParam != "" {
txView = txViewParam
@ -750,6 +770,15 @@ func (s *Service) GetExplorerAddress(w http.ResponseWriter, r *http.Request) {
} else {
data.Address.TXs = data.Address.TXs[offset*page : offset*page+offset]
}
if order == "DESC" {
sort.Slice(data.Address.TXs[:], func(i, j int) bool {
return data.Address.TXs[i].Timestamp > data.Address.TXs[j].Timestamp
})
} else {
sort.Slice(data.Address.TXs[:], func(i, j int) bool {
return data.Address.TXs[i].Timestamp < data.Address.TXs[j].Timestamp
})
}
}
// GetExplorerAddress rpc end-point.
@ -784,7 +813,6 @@ func (s *ServiceAPI) GetExplorerAddress(ctx context.Context, id, txView string,
balance, err := s.Service.GetAccountBalance(addr)
if err == nil {
balanceAddr = balance
address.Balance = balance
}
}
@ -829,6 +857,15 @@ func (s *ServiceAPI) GetExplorerAddress(ctx context.Context, id, txView string,
} else {
address.TXs = address.TXs[offset*page : offset*page+offset]
}
if order == "DESC" {
sort.Slice(address.TXs[:], func(i, j int) bool {
return address.TXs[i].Timestamp > address.TXs[j].Timestamp
})
} else {
sort.Slice(address.TXs[:], func(i, j int) bool {
return address.TXs[i].Timestamp < address.TXs[j].Timestamp
})
}
return address, nil
}

@ -170,18 +170,9 @@ func (storage *Storage) UpdateAddressStorage(batch ethdb.Batch, addr string, exp
var address Address
if data, err := storage.db.Get([]byte(key)); err == nil {
err = rlp.DecodeBytes(data, &address)
if err == nil {
if explorerTransaction.Type == Received {
address.Balance.Add(address.Balance, tx.Value())
} else {
address.Balance.Sub(address.Balance, tx.Value())
}
} else {
utils.Logger().Error().Err(err).Msg("Failed to error")
if err = rlp.DecodeBytes(data, &address); err != nil {
utils.Logger().Error().Err(err).Msg("Failed due to error")
}
} else {
address.Balance = tx.Value()
}
address.ID = addr
address.TXs = append(address.TXs, explorerTransaction)

@ -24,7 +24,7 @@ require (
github.com/harmony-ek/gencodec v0.0.0-20190215044613-e6740dbdd846
github.com/harmony-one/bls v0.0.5
github.com/harmony-one/taggedrlp v0.1.2
github.com/harmony-one/vdf v1.0.0
github.com/harmony-one/vdf v0.0.0-20190924175951-620379da8849
github.com/hashicorp/golang-lru v0.5.1
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365
github.com/ipfs/go-ds-badger v0.0.5
@ -62,7 +62,7 @@ require (
golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443
golang.org/x/lint v0.0.0-20190409202823-959b441ac422
golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3 // indirect
golang.org/x/tools v0.0.0-20190827205025-b29f5f60c37a
golang.org/x/tools v0.0.0-20190924052046-3ac2a5bbd98a
google.golang.org/appengine v1.4.0 // indirect
google.golang.org/grpc v1.21.1
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127

Loading…
Cancel
Save