OSDN Git Service

Peer add announces new block message num limit
[bytom/vapor.git] / api / block_retrieve.go
index 4b85fde..10b9fb0 100644 (file)
@@ -1,7 +1,7 @@
 package api
 
 import (
-       "gopkg.in/fatih/set.v0"
+       set "gopkg.in/fatih/set.v0"
 
        "github.com/vapor/blockchain/query"
        chainjson "github.com/vapor/encoding/json"
@@ -41,15 +41,17 @@ type BlockReq struct {
 
 // GetBlockResp is the resp for getBlock api
 type GetBlockResp struct {
-       Hash                   *bc.Hash   `json:"hash"`
-       Size                   uint64     `json:"size"`
-       Version                uint64     `json:"version"`
-       Height                 uint64     `json:"height"`
-       PreviousBlockHash      *bc.Hash   `json:"previous_block_hash"`
-       Timestamp              uint64     `json:"timestamp"`
-       TransactionsMerkleRoot *bc.Hash   `json:"transaction_merkle_root"`
-       TransactionStatusHash  *bc.Hash   `json:"transaction_status_hash"`
-       Transactions           []*BlockTx `json:"transactions"`
+       Hash                   *bc.Hash             `json:"hash"`
+       Size                   uint64               `json:"size"`
+       Version                uint64               `json:"version"`
+       Height                 uint64               `json:"height"`
+       PreviousBlockHash      *bc.Hash             `json:"previous_block_hash"`
+       Timestamp              uint64               `json:"timestamp"`
+       Witness                []chainjson.HexBytes `json:"witness"`
+       Blocker                string               `json:"blocker"`
+       TransactionsMerkleRoot *bc.Hash             `json:"transaction_merkle_root"`
+       TransactionStatusHash  *bc.Hash             `json:"transaction_status_hash"`
+       Transactions           []*BlockTx           `json:"transactions"`
 }
 
 // return block by hash/height
@@ -66,6 +68,17 @@ func (a *API) getBlock(ins BlockReq) Response {
                return NewErrorResponse(err)
        }
 
+       witness := make([]chainjson.HexBytes, len(block.Witness))
+       for i, w := range block.Witness {
+               witness[i] = w
+       }
+       var blocker string
+       if block.Height > 0 {
+               if blocker, err = a.chain.GetBlocker(&block.PreviousBlockHash, block.Timestamp); err != nil {
+                       return NewErrorResponse(err)
+               }
+       }
+
        resp := &GetBlockResp{
                Hash:                   &blockHash,
                Size:                   uint64(len(rawBlock)),
@@ -73,6 +86,8 @@ func (a *API) getBlock(ins BlockReq) Response {
                Height:                 block.Height,
                PreviousBlockHash:      &block.PreviousBlockHash,
                Timestamp:              block.Timestamp,
+               Witness:                witness,
+               Blocker:                blocker,
                TransactionsMerkleRoot: &block.TransactionsMerkleRoot,
                TransactionStatusHash:  &block.TransactionStatusHash,
                Transactions:           []*BlockTx{},
@@ -93,10 +108,14 @@ func (a *API) getBlock(ins BlockReq) Response {
                }
 
                resOutID := orig.ResultIds[0]
-               resOut, ok := orig.Entries[*resOutID].(*bc.IntraChainOutput)
-               if ok {
+               switch resOut := orig.Entries[*resOutID].(type) {
+               case *bc.IntraChainOutput:
+                       tx.MuxID = *resOut.Source.Ref
+               case *bc.CrossChainOutput:
+                       tx.MuxID = *resOut.Source.Ref
+               case *bc.VoteOutput:
                        tx.MuxID = *resOut.Source.Ref
-               } else {
+               case *bc.Retirement:
                        resRetire, _ := orig.Entries[*resOutID].(*bc.Retirement)
                        tx.MuxID = *resRetire.Source.Ref
                }