neoneo-go/pkg/consensus/prepare_request.go

56 lines
1.9 KiB
Go
Raw Normal View History

2019-11-08 15:40:21 +00:00
package consensus
import (
2019-11-15 10:32:40 +00:00
"github.com/nspcc-dev/dbft/payload"
"github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/util"
2019-11-08 15:40:21 +00:00
)
2019-11-15 10:32:40 +00:00
// prepareRequest represents dBFT prepareRequest message.
2019-11-08 15:40:21 +00:00
type prepareRequest struct {
timestamp uint64
2019-11-15 10:32:40 +00:00
nonce uint64
transactionHashes []util.Uint256
2019-11-08 15:40:21 +00:00
}
2019-11-15 10:32:40 +00:00
var _ payload.PrepareRequest = (*prepareRequest)(nil)
2019-11-08 15:40:21 +00:00
// EncodeBinary implements io.Serializable interface.
func (p *prepareRequest) EncodeBinary(w *io.BinWriter) {
w.WriteU64LE(p.timestamp)
w.WriteU64LE(p.nonce)
2019-11-15 10:32:40 +00:00
w.WriteArray(p.transactionHashes)
2019-11-08 15:40:21 +00:00
}
// DecodeBinary implements io.Serializable interface.
func (p *prepareRequest) DecodeBinary(r *io.BinReader) {
p.timestamp = r.ReadU64LE()
p.nonce = r.ReadU64LE()
r.ReadArray(&p.transactionHashes, block.MaxTransactionsPerBlock)
2019-11-08 15:40:21 +00:00
}
2019-11-15 10:32:40 +00:00
// Timestamp implements payload.PrepareRequest interface.
func (p *prepareRequest) Timestamp() uint64 { return p.timestamp * nsInMs }
2019-11-15 10:32:40 +00:00
// SetTimestamp implements payload.PrepareRequest interface.
func (p *prepareRequest) SetTimestamp(ts uint64) { p.timestamp = ts / nsInMs }
2019-11-15 10:32:40 +00:00
// Nonce implements payload.PrepareRequest interface.
func (p *prepareRequest) Nonce() uint64 { return p.nonce }
// SetNonce implements payload.PrepareRequest interface.
func (p *prepareRequest) SetNonce(nonce uint64) { p.nonce = nonce }
// TransactionHashes implements payload.PrepareRequest interface.
func (p *prepareRequest) TransactionHashes() []util.Uint256 { return p.transactionHashes }
// SetTransactionHashes implements payload.PrepareRequest interface.
func (p *prepareRequest) SetTransactionHashes(hs []util.Uint256) { p.transactionHashes = hs }
// NextConsensus implements payload.PrepareRequest interface.
func (p *prepareRequest) NextConsensus() util.Uint160 { return util.Uint160{} }
2019-11-15 10:32:40 +00:00
// SetNextConsensus implements payload.PrepareRequest interface.
func (p *prepareRequest) SetNextConsensus(_ util.Uint160) {}