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{
|
2017-12-21 09:52:26 -08:00
|
|
|
ChainID: header.ChainID,
|
2017-12-01 22:07:17 -08:00
|
|
|
Height: header.Height,
|
|
|
|
Time: header.Time.Unix(),
|
2017-12-02 08:52:10 -08:00
|
|
|
NumTxs: int32(header.NumTxs), // XXX: overflow
|
2017-12-21 09:52:26 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 13:13:17 -08: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{
|
2017-12-02 08:52:10 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2017-04-27 10:39:06 -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
|
|
|
|
}
|