1
0
mirror of https://github.com/fluencelabs/tendermint synced 2025-07-26 01:31:56 +00:00
Files
.circleci
.github
DOCKER
benchmarks
blockchain
cmd
config
consensus
docs
evidence
libs
lite
mempool
networks
node
p2p
privval
proxy
rpc
scripts
state
test
types
block.go
block_meta.go
block_test.go
canonical_json.go
event_buffer.go
event_buffer_test.go
event_bus.go
event_bus_test.go
events.go
evidence.go
evidence_test.go
genesis.go
genesis_test.go
heartbeat.go
heartbeat_test.go
keys.go
nop_event_bus.go
params.go
params_test.go
part_set.go
part_set_test.go
priv_validator.go
proposal.go
proposal_test.go
protobuf.go
results.go
results_test.go
signable.go
test_util.go
tx.go
tx_test.go
validator.go
validator_set.go
validator_set_test.go
vote.go
vote_set.go
vote_set_test.go
vote_test.go
wire.go
version
.editorconfig
.gitignore
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Gopkg.lock
Gopkg.toml
LICENSE
Makefile
README.md
ROADMAP.md
SECURITY.md
Vagrantfile
appveyor.yml
codecov.yml
docker-compose.yml
tendermint/types/heartbeat.go

53 lines
1.5 KiB
Go
Raw Normal View History

2017-08-03 13:58:17 -04:00
package types
import (
"fmt"
"github.com/tendermint/go-crypto"
cmn "github.com/tendermint/tmlibs/common"
)
// Heartbeat is a simple vote-like structure so validators can
// alert others that they are alive and waiting for transactions.
// Note: We aren't adding ",omitempty" to Heartbeat's
// json field tags because we always want the JSON
// representation to be in its canonical form.
2017-08-03 13:58:17 -04:00
type Heartbeat struct {
ValidatorAddress Address `json:"validator_address"`
2017-08-03 13:58:17 -04:00
ValidatorIndex int `json:"validator_index"`
Height int64 `json:"height"`
2017-08-03 13:58:17 -04:00
Round int `json:"round"`
Sequence int `json:"sequence"`
Signature crypto.Signature `json:"signature"`
}
// SignBytes returns the Heartbeat bytes for signing.
// It panics if the Heartbeat is nil.
func (heartbeat *Heartbeat) SignBytes(chainID string) []byte {
bz, err := cdc.MarshalJSON(CanonicalHeartbeat(chainID, heartbeat))
if err != nil {
panic(err)
}
return bz
2017-08-03 13:58:17 -04:00
}
2017-09-22 12:00:37 -04:00
// Copy makes a copy of the Heartbeat.
2017-08-03 13:58:17 -04:00
func (heartbeat *Heartbeat) Copy() *Heartbeat {
if heartbeat == nil {
return nil
}
2017-08-03 13:58:17 -04:00
heartbeatCopy := *heartbeat
return &heartbeatCopy
}
2017-09-22 12:00:37 -04:00
// String returns a string representation of the Heartbeat.
2017-08-03 13:58:17 -04:00
func (heartbeat *Heartbeat) String() string {
if heartbeat == nil {
return "nil-heartbeat"
}
return fmt.Sprintf("Heartbeat{%v:%X %v/%02d (%v) %v}",
heartbeat.ValidatorIndex, cmn.Fingerprint(heartbeat.ValidatorAddress),
heartbeat.Height, heartbeat.Round, heartbeat.Sequence, heartbeat.Signature)
}