neo-go/pkg/consensus/change_view.go

34 lines
911 B
Go
Raw Normal View History

2019-11-08 15:40:21 +00:00
package consensus
2019-11-15 10:32:40 +00:00
import (
"github.com/nspcc-dev/dbft"
"github.com/nspcc-dev/neo-go/pkg/io"
2019-11-15 10:32:40 +00:00
)
2019-11-08 15:40:21 +00:00
// changeView represents dBFT ChangeView message.
type changeView struct {
2019-11-15 10:32:40 +00:00
newViewNumber byte
timestamp uint64
reason dbft.ChangeViewReason
2019-11-08 15:40:21 +00:00
}
var _ dbft.ChangeView = (*changeView)(nil)
2019-11-15 10:32:40 +00:00
// EncodeBinary implements the io.Serializable interface.
2019-11-08 15:40:21 +00:00
func (c *changeView) EncodeBinary(w *io.BinWriter) {
w.WriteU64LE(c.timestamp)
w.WriteB(byte(c.reason))
2019-11-08 15:40:21 +00:00
}
// DecodeBinary implements the io.Serializable interface.
2019-11-08 15:40:21 +00:00
func (c *changeView) DecodeBinary(r *io.BinReader) {
c.timestamp = r.ReadU64LE()
c.reason = dbft.ChangeViewReason(r.ReadB())
2019-11-08 15:40:21 +00:00
}
2019-11-15 10:32:40 +00:00
// NewViewNumber implements the payload.ChangeView interface.
2019-11-15 10:32:40 +00:00
func (c changeView) NewViewNumber() byte { return c.newViewNumber }
// Reason implements the payload.ChangeView interface.
func (c changeView) Reason() dbft.ChangeViewReason { return c.reason }