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"
// 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
return NewErrorResponse(err)
}
+ witness := make([]chainjson.HexBytes, len(block.Witness))
+ for i, w := range block.Witness {
+ witness[i] = w
+ }
+
+ blocker, err := a.chain.GetBlocker(&block.PreviousBlockHash, block.Timestamp)
+ if err != nil {
+ return NewErrorResponse(err)
+ }
+
resp := &GetBlockResp{
Hash: &blockHash,
Size: uint64(len(rawBlock)),
Height: block.Height,
PreviousBlockHash: &block.PreviousBlockHash,
Timestamp: block.Timestamp,
+ Witness: witness,
+ Blocker: blocker,
TransactionsMerkleRoot: &block.TransactionsMerkleRoot,
TransactionStatusHash: &block.TransactionStatusHash,
Transactions: []*BlockTx{},
}
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
}