-
Notifications
You must be signed in to change notification settings - Fork 2
/
prop_send_fee.go
110 lines (95 loc) · 3.1 KB
/
prop_send_fee.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package txns
import (
"github.com/make-os/kit/util"
"github.com/make-os/kit/util/errors"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/vmihailenco/msgpack"
)
// TxRepoProposalSendFee implements BaseTx, it describes a transaction for
// contributing to a proposal's deposit fee
type TxRepoProposalSendFee struct {
*TxCommon `json:",flatten" msgpack:"-" mapstructure:"-"`
*TxType `json:",flatten" msgpack:"-" mapstructure:"-"`
*TxProposalCommon `json:",flatten" msgpack:"-" mapstructure:"-"`
}
// NewBareRepoProposalFeeSend returns an instance of TxRepoProposalSendFee with zero values
func NewBareRepoProposalFeeSend() *TxRepoProposalSendFee {
return &TxRepoProposalSendFee{
TxCommon: NewBareTxCommon(),
TxType: &TxType{Type: TxTypeRepoProposalSendFee},
TxProposalCommon: &TxProposalCommon{Value: "0"},
}
}
// EncodeMsgpack implements msgpack.CustomEncoder
func (tx *TxRepoProposalSendFee) EncodeMsgpack(enc *msgpack.Encoder) error {
return tx.EncodeMulti(enc,
tx.Type,
tx.Nonce,
tx.Value,
tx.Fee,
tx.Sig,
tx.Timestamp,
tx.SenderPubKey,
tx.RepoName,
tx.ID)
}
// DecodeMsgpack implements msgpack.CustomDecoder
func (tx *TxRepoProposalSendFee) DecodeMsgpack(dec *msgpack.Decoder) error {
return tx.DecodeMulti(dec,
&tx.Type,
&tx.Nonce,
&tx.Value,
&tx.Fee,
&tx.Sig,
&tx.Timestamp,
&tx.SenderPubKey,
&tx.RepoName,
&tx.ID)
}
// Bytes returns the serialized transaction
func (tx *TxRepoProposalSendFee) Bytes() []byte {
return util.ToBytes(tx)
}
// GetBytesNoSig returns the serialized the transaction excluding the signature
func (tx *TxRepoProposalSendFee) GetBytesNoSig() []byte {
sig := tx.Sig
tx.Sig = nil
bz := tx.Bytes()
tx.Sig = sig
return bz
}
// ComputeHash computes the hash of the transaction
func (tx *TxRepoProposalSendFee) ComputeHash() util.Bytes32 {
return util.BytesToBytes32(tmhash.Sum(tx.Bytes()))
}
// GetHash returns the hash of the transaction
func (tx *TxRepoProposalSendFee) GetHash() util.HexBytes {
return tx.ComputeHash().ToHexBytes()
}
// GetID returns the id of the transaction (also the hash)
func (tx *TxRepoProposalSendFee) GetID() string {
return tx.ComputeHash().HexStr()
}
// GetEcoSize returns the size of the transaction for use in protocol economics
func (tx *TxRepoProposalSendFee) GetEcoSize() int64 {
return tx.GetSize()
}
// GetSize returns the size of the tx object (excluding nothing)
func (tx *TxRepoProposalSendFee) GetSize() int64 {
return int64(len(tx.Bytes()))
}
// Sign signs the transaction
func (tx *TxRepoProposalSendFee) Sign(privKey string) ([]byte, error) {
return SignTransaction(tx, privKey)
}
// ToMap returns a map equivalent of the transaction
func (tx *TxRepoProposalSendFee) ToMap() map[string]interface{} {
return util.ToJSONMap(tx)
}
// FromMap populates tx with a map generated by tx.ToMap.
func (tx *TxRepoProposalSendFee) FromMap(data map[string]interface{}) error {
err := tx.TxCommon.FromMap(data)
err = errors.CallIfNil(err, func() error { return tx.TxType.FromMap(data) })
err = errors.CallIfNil(err, func() error { return tx.TxProposalCommon.FromMap(data) })
return err
}