-
Notifications
You must be signed in to change notification settings - Fork 199
/
rewardTx.go
134 lines (107 loc) · 3.26 KB
/
rewardTx.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package rewardTx
import (
"io"
"math/big"
"github.com/ElrondNetwork/elrond-go/data/rewardTx/capnp"
capn "github.com/glycerine/go-capnproto"
)
// RewardTx holds the data for a reward transaction
type RewardTx struct {
Round uint64 `capid:"1" json:"round"`
Epoch uint32 `capid:"2" json:"epoch"`
Value *big.Int `capid:"3" json:"value"`
RcvAddr []byte `capid:"4" json:"receiver"`
ShardId uint32 `capid:"5" json:"shardId"`
}
// Save saves the serialized data of a RewardTx into a stream through Capnp protocol
func (rtx *RewardTx) Save(w io.Writer) error {
seg := capn.NewBuffer(nil)
RewardTxGoToCapn(seg, rtx)
_, err := seg.WriteTo(w)
return err
}
// Load loads the data from the stream into a RewardTx object through Capnp protocol
func (rtx *RewardTx) Load(r io.Reader) error {
capMsg, err := capn.ReadFromStream(r, nil)
if err != nil {
return err
}
z := capnp.ReadRootRewardTxCapn(capMsg)
RewardTxCapnToGo(z, rtx)
return nil
}
// RewardTxCapnToGo is a helper function to copy fields from a RewardTxCapn object to a RewardTx object
func RewardTxCapnToGo(src capnp.RewardTxCapn, dest *RewardTx) *RewardTx {
if dest == nil {
dest = &RewardTx{}
}
if dest.Value == nil {
dest.Value = big.NewInt(0)
}
dest.Epoch = src.Epoch()
dest.Round = src.Round()
err := dest.Value.GobDecode(src.Value())
if err != nil {
return nil
}
dest.RcvAddr = src.RcvAddr()
dest.ShardId = src.ShardId()
return dest
}
// RewardTxGoToCapn is a helper function to copy fields from a RewardTx object to a RewardTxCapn object
func RewardTxGoToCapn(seg *capn.Segment, src *RewardTx) capnp.RewardTxCapn {
dest := capnp.AutoNewRewardTxCapn(seg)
value, _ := src.Value.GobEncode()
dest.SetEpoch(src.Epoch)
dest.SetRound(src.Round)
dest.SetValue(value)
dest.SetRcvAddr(src.RcvAddr)
dest.SetShardId(src.ShardId)
return dest
}
// IsInterfaceNil verifies if underlying object is nil
func (rtx *RewardTx) IsInterfaceNil() bool {
return rtx == nil
}
// GetValue returns the value of the reward transaction
func (rtx *RewardTx) GetValue() *big.Int {
return rtx.Value
}
// GetNonce returns 0 as reward transactions do not have a nonce
func (scr *RewardTx) GetNonce() uint64 {
return 0
}
// GetData returns the data of the reward transaction
func (rtx *RewardTx) GetData() string {
return ""
}
// GetRecvAddress returns the receiver address from the reward transaction
func (rtx *RewardTx) GetRecvAddress() []byte {
return rtx.RcvAddr
}
// GetSndAddress returns the sender address from the reward transaction
func (rtx *RewardTx) GetSndAddress() []byte {
return nil
}
// GetGasLimit returns the gas limit of the smart reward transaction
func (scr *RewardTx) GetGasLimit() uint64 {
return 0
}
// GetGasPrice returns the gas price of the smart reward transaction
func (scr *RewardTx) GetGasPrice() uint64 {
return 0
}
// SetValue sets the value of the reward transaction
func (rtx *RewardTx) SetValue(value *big.Int) {
rtx.Value = value
}
// SetData sets the data of the reward transaction
func (rtx *RewardTx) SetData(data string) {
}
// SetRecvAddress sets the receiver address of the reward transaction
func (rtx *RewardTx) SetRecvAddress(addr []byte) {
rtx.RcvAddr = addr
}
// SetSndAddress sets the sender address of the reward transaction
func (rtx *RewardTx) SetSndAddress(addr []byte) {
}