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"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
|
|
"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 {
|
2019-11-15 10:32:40 +00:00
|
|
|
timestamp uint32
|
|
|
|
nonce uint64
|
|
|
|
transactionHashes []util.Uint256
|
|
|
|
minerTx transaction.Transaction
|
|
|
|
nextConsensus util.Uint160
|
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) {
|
2019-12-12 15:52:23 +00:00
|
|
|
w.WriteU32LE(p.timestamp)
|
|
|
|
w.WriteU64LE(p.nonce)
|
2019-12-06 15:22:21 +00:00
|
|
|
w.WriteBytes(p.nextConsensus[:])
|
2019-11-15 10:32:40 +00:00
|
|
|
w.WriteArray(p.transactionHashes)
|
|
|
|
p.minerTx.EncodeBinary(w)
|
2019-11-08 15:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeBinary implements io.Serializable interface.
|
|
|
|
func (p *prepareRequest) DecodeBinary(r *io.BinReader) {
|
2019-12-12 15:52:23 +00:00
|
|
|
p.timestamp = r.ReadU32LE()
|
|
|
|
p.nonce = r.ReadU64LE()
|
2019-12-06 15:37:46 +00:00
|
|
|
r.ReadBytes(p.nextConsensus[:])
|
2019-11-15 10:32:40 +00:00
|
|
|
r.ReadArray(&p.transactionHashes)
|
|
|
|
p.minerTx.DecodeBinary(r)
|
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() uint32 { return p.timestamp }
|
|
|
|
|
|
|
|
// SetTimestamp implements payload.PrepareRequest interface.
|
|
|
|
func (p *prepareRequest) SetTimestamp(ts uint32) { p.timestamp = ts }
|
|
|
|
|
|
|
|
// 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 p.nextConsensus }
|
|
|
|
|
|
|
|
// SetNextConsensus implements payload.PrepareRequest interface.
|
|
|
|
func (p *prepareRequest) SetNextConsensus(nc util.Uint160) { p.nextConsensus = nc }
|