github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/consensus/prepare_request.go (about) 1 package consensus 2 3 import ( 4 "github.com/nspcc-dev/dbft" 5 "github.com/nspcc-dev/neo-go/pkg/core/block" 6 "github.com/nspcc-dev/neo-go/pkg/io" 7 "github.com/nspcc-dev/neo-go/pkg/util" 8 ) 9 10 // prepareRequest represents dBFT prepareRequest message. 11 type prepareRequest struct { 12 version uint32 13 prevHash util.Uint256 14 timestamp uint64 15 nonce uint64 16 transactionHashes []util.Uint256 17 stateRootEnabled bool 18 stateRoot util.Uint256 19 } 20 21 var _ dbft.PrepareRequest[util.Uint256] = (*prepareRequest)(nil) 22 23 // EncodeBinary implements the io.Serializable interface. 24 func (p *prepareRequest) EncodeBinary(w *io.BinWriter) { 25 w.WriteU32LE(p.version) 26 w.WriteBytes(p.prevHash[:]) 27 w.WriteU64LE(p.timestamp) 28 w.WriteU64LE(p.nonce) 29 w.WriteVarUint(uint64(len(p.transactionHashes))) 30 for i := range p.transactionHashes { 31 w.WriteBytes(p.transactionHashes[i][:]) 32 } 33 if p.stateRootEnabled { 34 w.WriteBytes(p.stateRoot[:]) 35 } 36 } 37 38 // DecodeBinary implements the io.Serializable interface. 39 func (p *prepareRequest) DecodeBinary(r *io.BinReader) { 40 p.version = r.ReadU32LE() 41 r.ReadBytes(p.prevHash[:]) 42 p.timestamp = r.ReadU64LE() 43 p.nonce = r.ReadU64LE() 44 r.ReadArray(&p.transactionHashes, block.MaxTransactionsPerBlock) 45 if p.stateRootEnabled { 46 r.ReadBytes(p.stateRoot[:]) 47 } 48 } 49 50 // Timestamp implements the payload.PrepareRequest interface. 51 func (p *prepareRequest) Timestamp() uint64 { return p.timestamp * nsInMs } 52 53 // Nonce implements the payload.PrepareRequest interface. 54 func (p *prepareRequest) Nonce() uint64 { return p.nonce } 55 56 // TransactionHashes implements the payload.PrepareRequest interface. 57 func (p *prepareRequest) TransactionHashes() []util.Uint256 { return p.transactionHashes }