forked from tendermint/tendermint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protobuf.go
71 lines (61 loc) · 1.77 KB
/
protobuf.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package types
import (
"github.com/tendermint/abci/types"
)
// TM2PB is used for converting Tendermint types to protobuf types.
// UNSTABLE
var TM2PB = tm2pb{}
type tm2pb struct{}
func (tm2pb) Header(header *Header) types.Header {
return types.Header{
ChainID: header.ChainID,
Height: header.Height,
Time: header.Time.Unix(),
NumTxs: int32(header.NumTxs), // XXX: overflow
LastBlockID: TM2PB.BlockID(header.LastBlockID),
LastCommitHash: header.LastCommitHash,
DataHash: header.DataHash,
AppHash: header.AppHash,
}
}
func (tm2pb) BlockID(blockID BlockID) types.BlockID {
return types.BlockID{
Hash: blockID.Hash,
Parts: TM2PB.PartSetHeader(blockID.PartsHeader),
}
}
func (tm2pb) PartSetHeader(partSetHeader PartSetHeader) types.PartSetHeader {
return types.PartSetHeader{
Total: int32(partSetHeader.Total), // XXX: overflow
Hash: partSetHeader.Hash,
}
}
func (tm2pb) Validator(val *Validator) types.Validator {
return types.Validator{
PubKey: val.PubKey.Bytes(),
Power: val.VotingPower,
}
}
func (tm2pb) Validators(vals *ValidatorSet) []types.Validator {
validators := make([]types.Validator, len(vals.Validators))
for i, val := range vals.Validators {
validators[i] = TM2PB.Validator(val)
}
return validators
}
func (tm2pb) ConsensusParams(params *ConsensusParams) *types.ConsensusParams {
return &types.ConsensusParams{
BlockSize: &types.BlockSize{
MaxBytes: int32(params.BlockSize.MaxBytes),
MaxTxs: int32(params.BlockSize.MaxTxs),
MaxGas: params.BlockSize.MaxGas,
},
TxSize: &types.TxSize{
MaxBytes: int32(params.TxSize.MaxBytes),
MaxGas: params.TxSize.MaxGas,
},
BlockGossip: &types.BlockGossip{
BlockPartSizeBytes: int32(params.BlockGossip.BlockPartSizeBytes),
},
}
}