consensus: refactor payloads structure
1. `Version` and `PrevHash` are now in `PrepareRequest`. 2. Serialization is done via `Extensible` payload. 3. Update dbft version.
This commit is contained in:
parent
59a193c7c7
commit
b918ec3abc
10 changed files with 287 additions and 309 deletions
|
@ -9,6 +9,8 @@ import (
|
|||
|
||||
// prepareRequest represents dBFT prepareRequest message.
|
||||
type prepareRequest struct {
|
||||
version uint32
|
||||
prevHash util.Uint256
|
||||
timestamp uint64
|
||||
nonce uint64
|
||||
transactionHashes []util.Uint256
|
||||
|
@ -20,6 +22,8 @@ var _ payload.PrepareRequest = (*prepareRequest)(nil)
|
|||
|
||||
// EncodeBinary implements io.Serializable interface.
|
||||
func (p *prepareRequest) EncodeBinary(w *io.BinWriter) {
|
||||
w.WriteU32LE(p.version)
|
||||
w.WriteBytes(p.prevHash[:])
|
||||
w.WriteU64LE(p.timestamp)
|
||||
w.WriteU64LE(p.nonce)
|
||||
w.WriteArray(p.transactionHashes)
|
||||
|
@ -30,6 +34,8 @@ func (p *prepareRequest) EncodeBinary(w *io.BinWriter) {
|
|||
|
||||
// DecodeBinary implements io.Serializable interface.
|
||||
func (p *prepareRequest) DecodeBinary(r *io.BinReader) {
|
||||
p.version = r.ReadU32LE()
|
||||
r.ReadBytes(p.prevHash[:])
|
||||
p.timestamp = r.ReadU64LE()
|
||||
p.nonce = r.ReadU64LE()
|
||||
r.ReadArray(&p.transactionHashes, block.MaxTransactionsPerBlock)
|
||||
|
@ -38,6 +44,26 @@ func (p *prepareRequest) DecodeBinary(r *io.BinReader) {
|
|||
}
|
||||
}
|
||||
|
||||
// Version implements payload.PrepareRequest interface.
|
||||
func (p prepareRequest) Version() uint32 {
|
||||
return p.version
|
||||
}
|
||||
|
||||
// SetVersion implements payload.PrepareRequest interface.
|
||||
func (p *prepareRequest) SetVersion(v uint32) {
|
||||
p.version = v
|
||||
}
|
||||
|
||||
// PrevHash implements payload.PrepareRequest interface.
|
||||
func (p prepareRequest) PrevHash() util.Uint256 {
|
||||
return p.prevHash
|
||||
}
|
||||
|
||||
// SetPrevHash implements payload.PrepareRequest interface.
|
||||
func (p *prepareRequest) SetPrevHash(h util.Uint256) {
|
||||
p.prevHash = h
|
||||
}
|
||||
|
||||
// Timestamp implements payload.PrepareRequest interface.
|
||||
func (p *prepareRequest) Timestamp() uint64 { return p.timestamp * nsInMs }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue