You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.8 KiB

8 years ago
8 years ago
8 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
  1. package types
  2. import (
  3. "github.com/tendermint/abci/types"
  4. )
  5. // TM2PB is used for converting Tendermint types to protobuf types.
  6. // UNSTABLE
  7. var TM2PB = tm2pb{}
  8. type tm2pb struct{}
  9. func (tm2pb) Header(header *Header) types.Header {
  10. return types.Header{
  11. ChainID: header.ChainID,
  12. Height: header.Height,
  13. Time: header.Time.Unix(),
  14. NumTxs: int32(header.NumTxs), // XXX: overflow
  15. LastBlockID: TM2PB.BlockID(header.LastBlockID),
  16. LastCommitHash: header.LastCommitHash,
  17. DataHash: header.DataHash,
  18. AppHash: header.AppHash,
  19. }
  20. }
  21. func (tm2pb) BlockID(blockID BlockID) types.BlockID {
  22. return types.BlockID{
  23. Hash: blockID.Hash,
  24. Parts: TM2PB.PartSetHeader(blockID.PartsHeader),
  25. }
  26. }
  27. func (tm2pb) PartSetHeader(partSetHeader PartSetHeader) types.PartSetHeader {
  28. return types.PartSetHeader{
  29. Total: int32(partSetHeader.Total), // XXX: overflow
  30. Hash: partSetHeader.Hash,
  31. }
  32. }
  33. func (tm2pb) Validator(val *Validator) types.Validator {
  34. return types.Validator{
  35. PubKey: val.PubKey.Bytes(),
  36. Power: val.VotingPower,
  37. }
  38. }
  39. func (tm2pb) Validators(vals *ValidatorSet) []types.Validator {
  40. validators := make([]types.Validator, len(vals.Validators))
  41. for i, val := range vals.Validators {
  42. validators[i] = TM2PB.Validator(val)
  43. }
  44. return validators
  45. }
  46. func (tm2pb) ConsensusParams(params *ConsensusParams) *types.ConsensusParams {
  47. return &types.ConsensusParams{
  48. BlockSize: &types.BlockSize{
  49. MaxBytes: int32(params.BlockSize.MaxBytes),
  50. MaxTxs: int32(params.BlockSize.MaxTxs),
  51. MaxGas: params.BlockSize.MaxGas,
  52. },
  53. TxSize: &types.TxSize{
  54. MaxBytes: int32(params.TxSize.MaxBytes),
  55. MaxGas: params.TxSize.MaxGas,
  56. },
  57. BlockGossip: &types.BlockGossip{
  58. BlockPartSizeBytes: int32(params.BlockGossip.BlockPartSizeBytes),
  59. },
  60. }
  61. }