2019-11-08 15:40:21 +00:00
|
|
|
package consensus
|
|
|
|
|
2019-11-15 10:32:40 +00:00
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/dbft/payload"
|
2020-03-03 14:21:42 +00:00
|
|
|
"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 uint32
|
2019-11-08 15:40:21 +00:00
|
|
|
}
|
|
|
|
|
2019-11-15 10:32:40 +00:00
|
|
|
var _ payload.ChangeView = (*changeView)(nil)
|
|
|
|
|
2019-11-08 15:40:21 +00:00
|
|
|
// EncodeBinary implements io.Serializable interface.
|
|
|
|
func (c *changeView) EncodeBinary(w *io.BinWriter) {
|
2019-12-12 15:52:23 +00:00
|
|
|
w.WriteU32LE(c.timestamp)
|
2019-11-08 15:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeBinary implements io.Serializable interface.
|
|
|
|
func (c *changeView) DecodeBinary(r *io.BinReader) {
|
2019-12-12 15:52:23 +00:00
|
|
|
c.timestamp = r.ReadU32LE()
|
2019-11-08 15:40:21 +00:00
|
|
|
}
|
2019-11-15 10:32:40 +00:00
|
|
|
|
|
|
|
// NewViewNumber implements payload.ChangeView interface.
|
|
|
|
func (c changeView) NewViewNumber() byte { return c.newViewNumber }
|
|
|
|
|
|
|
|
// SetNewViewNumber implements payload.ChangeView interface.
|
|
|
|
func (c *changeView) SetNewViewNumber(view byte) { c.newViewNumber = view }
|
|
|
|
|
|
|
|
// Timestamp implements payload.ChangeView interface.
|
2020-08-09 20:31:34 +00:00
|
|
|
func (c changeView) Timestamp() uint64 { return uint64(c.timestamp) * nanoInSec }
|
2019-11-15 10:32:40 +00:00
|
|
|
|
|
|
|
// SetTimestamp implements payload.ChangeView interface.
|
2020-08-09 20:31:34 +00:00
|
|
|
func (c *changeView) SetTimestamp(ts uint64) { c.timestamp = uint32(ts / nanoInSec) }
|
|
|
|
|
|
|
|
// Reason implements payload.ChangeView interface.
|
|
|
|
func (c changeView) Reason() payload.ChangeViewReason { return payload.CVUnknown }
|
|
|
|
|
|
|
|
// SetReason implements payload.ChangeView interface.
|
|
|
|
func (c *changeView) SetReason(_ payload.ChangeViewReason) {}
|