forked from forbole/callisto
-
Notifications
You must be signed in to change notification settings - Fork 1
/
staking_delegations.go
97 lines (85 loc) · 2.86 KB
/
staking_delegations.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
package types
import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Delegation represents a single delegation made from a delegator
// to a specific validator at a specific height (and timestamp)
// containing a given amount of tokens
type Delegation struct {
DelegatorAddress string
ValidatorOperAddr string
Amount sdk.Coin
Height int64
}
// NewDelegation creates a new Delegation instance containing
// the given data
func NewDelegation(delegator string, validatorOperAddr string, amount sdk.Coin, height int64) Delegation {
return Delegation{
DelegatorAddress: delegator,
ValidatorOperAddr: validatorOperAddr,
Amount: amount,
Height: height,
}
}
// -----------------------------------------------------------------------------------------------------------------
// UnbondingDelegation represents a single unbonding delegation
type UnbondingDelegation struct {
DelegatorAddress string
ValidatorOperAddr string
Amount sdk.Coin
CompletionTimestamp time.Time
Height int64
}
// NewUnbondingDelegation allows to create a new UnbondingDelegation instance
func NewUnbondingDelegation(
delegator string, validatorOperAddr string, amount sdk.Coin, completionTimestamp time.Time, height int64,
) UnbondingDelegation {
return UnbondingDelegation{
DelegatorAddress: delegator,
ValidatorOperAddr: validatorOperAddr,
Amount: amount,
CompletionTimestamp: completionTimestamp,
Height: height,
}
}
// Equal returns true iff u and v contain the same data
func (u UnbondingDelegation) Equal(v UnbondingDelegation) bool {
return u.DelegatorAddress == v.DelegatorAddress &&
u.ValidatorOperAddr == v.ValidatorOperAddr &&
u.Amount.IsEqual(v.Amount) &&
u.CompletionTimestamp.Equal(v.CompletionTimestamp) &&
u.Height == v.Height
}
// _________________________________________________________
// Redelegation represents a single re-delegations
type Redelegation struct {
DelegatorAddress string
SrcValidator string
DstValidator string
Amount sdk.Coin
CompletionTime time.Time
Height int64
}
// NewRedelegation build a new Redelegation object
func NewRedelegation(
delegator string, srcValidator, dstValidator string, amount sdk.Coin, completionTime time.Time, height int64,
) Redelegation {
return Redelegation{
DelegatorAddress: delegator,
SrcValidator: srcValidator,
DstValidator: dstValidator,
Amount: amount,
CompletionTime: completionTime,
Height: height,
}
}
// Equal returns true iff r and s contain the same data
func (r Redelegation) Equal(s Redelegation) bool {
return r.DelegatorAddress == s.DelegatorAddress &&
r.SrcValidator == s.SrcValidator &&
r.DstValidator == s.DstValidator &&
r.Amount.IsEqual(s.Amount) &&
r.CompletionTime.Equal(s.CompletionTime) &&
r.Height == s.Height
}