make Block Header and Data non-pointers

make BlockMeta Header a non-pointer

Refs #693
This commit is contained in:
Anton Kaliaev
2018-07-13 12:05:54 +04:00
parent bbf2bd1d81
commit 270659f03f
13 changed files with 59 additions and 72 deletions

View File

@ -17,8 +17,8 @@ import (
// TODO: add Version byte
type Block struct {
mtx sync.Mutex
*Header `json:"header"`
*Data `json:"data"`
Header `json:"header"`
Data `json:"data"`
Evidence EvidenceData `json:"evidence"`
LastCommit *Commit `json:"last_commit"`
}
@ -27,15 +27,15 @@ type Block struct {
// It populates the same set of fields validated by ValidateBasic
func MakeBlock(height int64, txs []Tx, commit *Commit) *Block {
block := &Block{
Header: &Header{
Header: Header{
Height: height,
Time: time.Now(),
NumTxs: int64(len(txs)),
},
LastCommit: commit,
Data: &Data{
Data: Data{
Txs: txs,
},
LastCommit: commit,
}
block.fillHeader()
return block
@ -43,6 +43,9 @@ func MakeBlock(height int64, txs []Tx, commit *Commit) *Block {
// AddEvidence appends the given evidence to the block
func (b *Block) AddEvidence(evidence []Evidence) {
if b == nil {
return
}
b.Evidence.Evidence = append(b.Evidence.Evidence, evidence...)
}
@ -98,7 +101,7 @@ func (b *Block) Hash() cmn.HexBytes {
b.mtx.Lock()
defer b.mtx.Unlock()
if b == nil || b.Header == nil || b.Data == nil || b.LastCommit == nil {
if b == nil || b.LastCommit == nil {
return nil
}
b.fillHeader()