add signers field

pull/688/head
Richard Liu 6 years ago
parent 7e2bcf6413
commit b9c627d9b5
  1. 15
      api/service/explorer/service.go
  2. 15
      api/service/explorer/structs.go

@ -107,8 +107,8 @@ func (s *Service) Run() *http.Server {
return server return server
} }
// GetAccountBlocks returns a list of types.Block to server blocks end-point. // ReadBlocksFromDB returns a list of types.Block to server blocks end-point.
func (s *Service) GetAccountBlocks(from, to int) []*types.Block { func (s *Service) ReadBlocksFromDB(from, to int) []*types.Block {
blocks := []*types.Block{} blocks := []*types.Block{}
for i := from - 1; i <= to+1; i++ { for i := from - 1; i <= to+1; i++ {
if i < 0 { if i < 0 {
@ -160,19 +160,12 @@ func (s *Service) GetExplorerBlocks(w http.ResponseWriter, r *http.Request) {
return return
} }
accountBlocks := s.GetAccountBlocks(fromInt, toInt) accountBlocks := s.ReadBlocksFromDB(fromInt, toInt)
for id, accountBlock := range accountBlocks { for id, accountBlock := range accountBlocks {
if id == 0 || id == len(accountBlocks)-1 || accountBlock == nil { if id == 0 || id == len(accountBlocks)-1 || accountBlock == nil {
continue continue
} }
block := &Block{ block := NewBlock(accountBlock, id+fromInt-1)
Height: strconv.Itoa(id + fromInt - 1),
ID: accountBlock.Hash().Hex(),
TXCount: strconv.Itoa(accountBlock.Transactions().Len()),
Timestamp: strconv.Itoa(int(accountBlock.Time().Int64() * 1000)),
MerkleRoot: accountBlock.Hash().Hex(),
Bytes: strconv.Itoa(int(accountBlock.Size())),
}
// Populate transactions // Populate transactions
for _, tx := range accountBlock.Transactions() { for _, tx := range accountBlock.Transactions() {
transaction := GetTransaction(tx, accountBlock) transaction := GetTransaction(tx, accountBlock)

@ -49,6 +49,7 @@ type Block struct {
Bytes string `json:"bytes"` Bytes string `json:"bytes"`
NextBlock RefBlock `json:"nextBlock"` NextBlock RefBlock `json:"nextBlock"`
TXs []*Transaction `json:"txs"` TXs []*Transaction `json:"txs"`
Signers []string `json:"signers"`
} }
// RefBlock ... // RefBlock ...
@ -67,6 +68,20 @@ type Shard struct {
Nodes []Node `json:"nodes"` Nodes []Node `json:"nodes"`
} }
// NewBlock ...
func NewBlock(block *types.Block, height int) *Block {
// TODO(ricl): use block.Header().CommitBitmap and GetPubKeyFromMask
return &Block{
Height: strconv.Itoa(height),
ID: block.Hash().Hex(),
TXCount: strconv.Itoa(block.Transactions().Len()),
Timestamp: strconv.Itoa(int(block.Time().Int64() * 1000)),
MerkleRoot: block.Hash().Hex(),
Bytes: strconv.Itoa(int(block.Size())),
Signers: []string{},
}
}
// GetTransaction ... // GetTransaction ...
func GetTransaction(tx *types.Transaction, accountBlock *types.Block) *Transaction { func GetTransaction(tx *types.Transaction, accountBlock *types.Block) *Transaction {
if tx.To() == nil { if tx.To() == nil {

Loading…
Cancel
Save