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,
2017-12-01 22:07:17 -08:00
Height: header.Height,
Time: header.Time.Unix(),
NumTxs: int32(header.NumTxs), // XXX: overflow
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: int32(partSetHeader.Total), // XXX: overflow
2016-08-22 12:57:20 -07:00
Hash: partSetHeader.Hash,
}
}
func (tm2pb) Validator(val *Validator) *types.Validator {
return &types.Validator{
PubKey: val.PubKey.Bytes(),
2017-12-01 22:07:17 -08:00
Power: val.VotingPower,
2016-08-22 12:57:20 -07:00
}
}
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
}