-
Notifications
You must be signed in to change notification settings - Fork 206
/
delegate.go
60 lines (50 loc) · 1.53 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
55
56
57
58
59
60
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/lavanet/lava/utils/slices"
epochstoragetypes "github.com/lavanet/lava/x/epochstorage/types"
)
func NewDelegation(delegator, provider, chainID string) Delegation {
return Delegation{
Delegator: delegator,
Provider: provider,
ChainID: chainID,
Amount: sdk.NewCoin(epochstoragetypes.TokenDenom, sdk.ZeroInt()),
}
}
func (delegation *Delegation) AddAmount(amount sdk.Coin) {
delegation.Amount = delegation.Amount.Add(amount)
}
func (delegation *Delegation) SubAmount(amount sdk.Coin) {
delegation.Amount = delegation.Amount.Sub(amount)
}
func (delegation *Delegation) IsZero() bool {
return delegation.Amount.IsZero()
}
func (delegation *Delegation) Equal(other *Delegation) bool {
if delegation.Delegator != other.Delegator ||
delegation.Provider != other.Provider ||
delegation.ChainID != other.ChainID ||
!delegation.Amount.IsEqual(other.Amount) {
return false
}
return true
}
func NewDelegator(delegator, provider string) Delegator {
return Delegator{
Providers: []string{provider},
}
}
func (delegator *Delegator) AddProvider(provider string) {
if !slices.Contains(delegator.Providers, provider) {
delegator.Providers = append(delegator.Providers, provider)
}
}
func (delegator *Delegator) DelProvider(provider string) {
if slices.Contains(delegator.Providers, provider) {
delegator.Providers, _ = slices.Remove(delegator.Providers, provider)
}
}
func (delegator *Delegator) IsEmpty() bool {
return len(delegator.Providers) == 0
}