Browse Source

Optimize blockchain overview

now.sh
garritfra 5 years ago
parent
commit
8a5a3c4983
  1. 2
      core/Blockchain.go
  2. 2
      server/webserver.go

2
core/Blockchain.go

@ -76,6 +76,7 @@ func (bc *Blockchain) IsValid() bool {
// JSONBlockchain is needed, because the hash of each block is calculated dynamically, and therefore is not stored in the `Block` struct
type JSONBlockchain struct {
Blocks []JSONBlock
Blockcount int
PendingTransactions []Transaction
}
@ -86,6 +87,7 @@ func (bc *Blockchain) AsJSON() JSONBlockchain {
for _, block := range bc.Blocks {
jsonChain.Blocks = append(jsonChain.Blocks, block.AsJSON())
}
jsonChain.Blockcount = len(jsonChain.Blocks)
return jsonChain
}

2
server/webserver.go

@ -41,7 +41,7 @@ func handleError(err error, w http.ResponseWriter, r *http.Request) {
}
func handleListBlocks(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(blockchain.AsJSON().Blocks)
json.NewEncoder(w).Encode(blockchain.AsJSON())
}
func handleAddTransaction(w http.ResponseWriter, r *http.Request) {

Loading…
Cancel
Save