/
payout.go
67 lines (55 loc) · 1.09 KB
/
payout.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
package types
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
hubtypes "github.com/sentinel-official/hub/types"
)
func (p *Payout) GetAddress() sdk.AccAddress {
if p.Address == "" {
return nil
}
addr, err := sdk.AccAddressFromBech32(p.Address)
if err != nil {
panic(err)
}
return addr
}
func (p *Payout) GetNodeAddress() hubtypes.NodeAddress {
if p.NodeAddress == "" {
return nil
}
addr, err := hubtypes.NodeAddressFromBech32(p.NodeAddress)
if err != nil {
panic(err)
}
return addr
}
func (p *Payout) Validate() error {
if p.ID == 0 {
return fmt.Errorf("id cannot be zero")
}
if p.Hours < 0 {
return fmt.Errorf("hours cannot be negative")
}
if p.Hours == 0 {
if !p.NextAt.IsZero() {
return fmt.Errorf("hours cannot be zero")
}
}
if p.Price.IsNil() {
return fmt.Errorf("price cannot be nil")
}
if p.Price.IsNegative() {
return fmt.Errorf("price cannot be negative")
}
if p.Price.IsZero() {
return fmt.Errorf("price cannot be zero")
}
if !p.Price.IsValid() {
return fmt.Errorf("price must be valid")
}
return nil
}
type (
Payouts []Payout
)