forked from hyperledger-archives/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proposal_tx.go
79 lines (62 loc) · 1.34 KB
/
proposal_tx.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package payload
import (
"crypto/sha256"
"fmt"
amino "github.com/tendermint/go-amino"
)
var cdc = amino.NewCodec()
func NewProposalTx(propsal *Proposal) *ProposalTx {
return &ProposalTx{
Proposal: propsal,
}
}
func (tx *ProposalTx) Type() Type {
return TypeProposal
}
func (tx *ProposalTx) GetInputs() []*TxInput {
return []*TxInput{tx.Input}
}
func (tx *ProposalTx) String() string {
return fmt.Sprintf("ProposalTx{%v}", tx.Proposal)
}
func (tx *ProposalTx) Any() *Any {
return &Any{
ProposalTx: tx,
}
}
func DecodeProposal(proposalBytes []byte) (*Proposal, error) {
proposal := new(Proposal)
err := cdc.UnmarshalBinaryBare(proposalBytes, proposal)
if err != nil {
return nil, err
}
return proposal, nil
}
func (p *Proposal) Encode() ([]byte, error) {
return cdc.MarshalBinaryBare(p)
}
func (p *Proposal) Hash() []byte {
bs, err := p.Encode()
if err != nil {
panic("failed to encode Proposal")
}
hash := sha256.Sum256(bs)
return hash[:]
}
func (p *Proposal) String() string {
return ""
}
func (v *Vote) String() string {
return v.Address.String()
}
func DecodeBallot(ballotBytes []byte) (*Ballot, error) {
ballot := new(Ballot)
err := cdc.UnmarshalBinaryBare(ballotBytes, ballot)
if err != nil {
return nil, err
}
return ballot, nil
}
func (p *Ballot) Encode() ([]byte, error) {
return cdc.MarshalBinaryBare(p)
}