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.

47 lines
1.4 KiB

7 years ago
7 years ago
7 years ago
7 years ago
  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. // Heartbeat is a simple vote-like structure so validators can alert others that
  11. // they are alive and waiting for transactions.
  12. type Heartbeat struct {
  13. ValidatorAddress data.Bytes `json:"validator_address"`
  14. ValidatorIndex int `json:"validator_index"`
  15. Height int `json:"height"`
  16. Round int `json:"round"`
  17. Sequence int `json:"sequence"`
  18. Signature crypto.Signature `json:"signature"`
  19. }
  20. // WriteSignBytes writes the Heartbeat for signing.
  21. func (heartbeat *Heartbeat) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) {
  22. wire.WriteJSON(CanonicalJSONOnceHeartbeat{
  23. chainID,
  24. CanonicalHeartbeat(heartbeat),
  25. }, w, n, err)
  26. }
  27. // Copy makes a copy of the Heartbeat.
  28. func (heartbeat *Heartbeat) Copy() *Heartbeat {
  29. heartbeatCopy := *heartbeat
  30. return &heartbeatCopy
  31. }
  32. // String returns a string representation of the Heartbeat.
  33. func (heartbeat *Heartbeat) String() string {
  34. if heartbeat == nil {
  35. return "nil-heartbeat"
  36. }
  37. return fmt.Sprintf("Heartbeat{%v:%X %v/%02d (%v) %v}",
  38. heartbeat.ValidatorIndex, cmn.Fingerprint(heartbeat.ValidatorAddress),
  39. heartbeat.Height, heartbeat.Round, heartbeat.Sequence, heartbeat.Signature)
  40. }