-
Notifications
You must be signed in to change notification settings - Fork 175
/
proposal.go
54 lines (44 loc) · 1.27 KB
/
proposal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package model
import (
"github.com/onflow/flow-go/model/flow"
)
// Proposal represent a new proposed block within HotStuff (and thus a
// a header in the bigger picture), signed by the proposer.
type Proposal struct {
Block *Block
SigData []byte
}
// ProposerVote extracts the proposer vote from the proposal
func (p *Proposal) ProposerVote() *Vote {
vote := Vote{
View: p.Block.View,
BlockID: p.Block.BlockID,
SignerID: p.Block.ProposerID,
SigData: p.SigData,
}
return &vote
}
// ProposalFromFlow turns a flow header into a hotstuff block type.
func ProposalFromFlow(header *flow.Header, parentView uint64) *Proposal {
block := BlockFromFlow(header, parentView)
proposal := Proposal{
Block: block,
SigData: header.ProposerSigData,
}
return &proposal
}
// ProposalToFlow turns a block proposal into a flow header.
func ProposalToFlow(proposal *Proposal) *flow.Header {
block := proposal.Block
header := flow.Header{
ParentID: block.QC.BlockID,
PayloadHash: block.PayloadHash,
Timestamp: block.Timestamp,
View: block.View,
ParentVoterIDs: block.QC.SignerIDs,
ParentVoterSigData: block.QC.SigData,
ProposerID: block.ProposerID,
ProposerSigData: proposal.SigData,
}
return &header
}