-
Notifications
You must be signed in to change notification settings - Fork 8
/
delegate.go
54 lines (45 loc) · 1.06 KB
/
delegate.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 transaction
import (
"github.com/MinterTeam/minter-go-sdk/wallet"
"github.com/ethereum/go-ethereum/rlp"
"math/big"
)
// Transaction for delegating funds to validator.
// PubKey - Public key of a validator. Coin - Symbol of coin to stake. Value - Amount of coins to stake.
type DelegateData struct {
PubKey []byte
Coin Coin
Value *big.Int
}
func NewDelegateData() *DelegateData {
return &DelegateData{}
}
func (d *DelegateData) SetPubKey(key string) (*DelegateData, error) {
var err error
d.PubKey, err = wallet.PublicKeyToHex(key)
if err != nil {
return d, err
}
return d, nil
}
func (d *DelegateData) MustSetPubKey(key string) *DelegateData {
_, err := d.SetPubKey(key)
if err != nil {
panic(err)
}
return d
}
func (d *DelegateData) SetCoin(symbol string) *DelegateData {
copy(d.Coin[:], symbol)
return d
}
func (d *DelegateData) SetValue(value *big.Int) *DelegateData {
d.Value = value
return d
}
func (d *DelegateData) encode() ([]byte, error) {
return rlp.EncodeToBytes(d)
}
func (d *DelegateData) fee() fee {
return feeTypeDelegate
}