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.

42 lines
1.1 KiB

  1. package types
  2. import (
  3. "fmt"
  4. "io"
  5. "github.com/tendermint/go-crypto"
  6. "github.com/tendermint/go-wire"
  7. "github.com/tendermint/go-wire/data"
  8. cmn "github.com/tendermint/tmlibs/common"
  9. )
  10. type Heartbeat struct {
  11. ValidatorAddress data.Bytes `json:"validator_address"`
  12. ValidatorIndex int `json:"validator_index"`
  13. Height int `json:"height"`
  14. Round int `json:"round"`
  15. Sequence int `json:"sequence"`
  16. Signature crypto.Signature `json:"signature"`
  17. }
  18. func (heartbeat *Heartbeat) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) {
  19. wire.WriteJSON(CanonicalJSONOnceHeartbeat{
  20. chainID,
  21. CanonicalHeartbeat(heartbeat),
  22. }, w, n, err)
  23. }
  24. func (heartbeat *Heartbeat) Copy() *Heartbeat {
  25. heartbeatCopy := *heartbeat
  26. return &heartbeatCopy
  27. }
  28. func (heartbeat *Heartbeat) String() string {
  29. if heartbeat == nil {
  30. return "nil-heartbeat"
  31. }
  32. return fmt.Sprintf("Heartbeat{%v:%X %v/%02d (%v) %v}",
  33. heartbeat.ValidatorIndex, cmn.Fingerprint(heartbeat.ValidatorAddress),
  34. heartbeat.Height, heartbeat.Round, heartbeat.Sequence, heartbeat.Signature)
  35. }