tendermint/types/protobuf.go

54 lines
1.3 KiB
Go
Raw Normal View History

2016-08-22 12:57:20 -07:00
package types
import (
2017-01-12 12:53:32 -08:00
"github.com/tendermint/abci/types"
2016-08-22 12:57:20 -07:00
)
2017-09-22 09:00:37 -07:00
// TM2PB is used for converting Tendermint types to protobuf types.
// UNSTABLE
2016-08-22 12:57:20 -07:00
var TM2PB = tm2pb{}
type tm2pb struct{}
func (tm2pb) Header(header *Header) *types.Header {
return &types.Header{
ChainId: header.ChainID,
2016-11-22 15:55:42 -08:00
Height: uint64(header.Height),
2016-08-22 12:57:20 -07:00
Time: uint64(header.Time.Unix()),
NumTxs: uint64(header.NumTxs),
LastBlockId: TM2PB.BlockID(header.LastBlockID),
2016-08-22 12:57:20 -07:00
LastCommitHash: header.LastCommitHash,
DataHash: header.DataHash,
2016-08-23 22:44:20 -07:00
AppHash: header.AppHash,
2016-08-22 12:57:20 -07:00
}
}
func (tm2pb) BlockID(blockID BlockID) *types.BlockID {
return &types.BlockID{
Hash: blockID.Hash,
Parts: TM2PB.PartSetHeader(blockID.PartsHeader),
}
}
2016-08-22 12:57:20 -07:00
func (tm2pb) PartSetHeader(partSetHeader PartSetHeader) *types.PartSetHeader {
return &types.PartSetHeader{
Total: uint64(partSetHeader.Total),
Hash: partSetHeader.Hash,
}
}
func (tm2pb) Validator(val *Validator) *types.Validator {
return &types.Validator{
PubKey: val.PubKey.Bytes(),
Power: uint64(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
}