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.

53 lines
1.3 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
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: uint64(header.Height),
  13. Time: uint64(header.Time.Unix()),
  14. NumTxs: uint64(header.NumTxs),
  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: uint64(partSetHeader.Total),
  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: uint64(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. }