-
Notifications
You must be signed in to change notification settings - Fork 67
/
hashing.go
45 lines (41 loc) · 1.16 KB
/
hashing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package types
import (
"time"
tmversion "github.com/tendermint/tendermint/proto/tendermint/version"
tmtypes "github.com/tendermint/tendermint/types"
)
// Hash returns ABCI-compatible hash of a header.
func (h *Header) Hash() [32]byte {
abciHeader := tmtypes.Header{
Version: tmversion.Consensus{
Block: h.Version.Block,
App: h.Version.App,
},
Height: int64(h.Height),
Time: time.Unix(0, int64(h.Time)),
LastBlockID: tmtypes.BlockID{
Hash: h.LastHeaderHash[:],
PartSetHeader: tmtypes.PartSetHeader{
Total: 1,
Hash: h.LastHeaderHash[:],
},
},
LastCommitHash: h.LastCommitHash[:],
DataHash: h.DataHash[:],
ValidatorsHash: h.AggregatorsHash[:],
NextValidatorsHash: h.AggregatorsHash[:],
ConsensusHash: h.ConsensusHash[:],
AppHash: h.AppHash[:],
LastResultsHash: h.LastResultsHash[:],
EvidenceHash: new(tmtypes.EvidenceData).Hash(),
ProposerAddress: h.ProposerAddress,
ChainID: h.ChainID,
}
var hash [32]byte
copy(hash[:], abciHeader.Hash())
return hash
}
// Hash returns ABCI-compatible hash of a block.
func (b *Block) Hash() [32]byte {
return b.Header.Hash()
}