-
Notifications
You must be signed in to change notification settings - Fork 180
/
delegation.go
57 lines (49 loc) · 1.78 KB
/
delegation.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
package types
import (
"fmt"
"time"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// UndelegationInfo is the struct of the undelegation info
type UndelegationInfo struct {
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
Quantity sdk.Dec `json:"quantity" yaml:"quantity"`
CompletionTime time.Time `json:"completion_time"`
}
// NewUndelegationInfo creates a new delegation object
func NewUndelegationInfo(delegatorAddr sdk.AccAddress, votesQuantity sdk.Dec,
completionTime time.Time) UndelegationInfo {
return UndelegationInfo{
DelegatorAddress: delegatorAddr,
Quantity: votesQuantity,
CompletionTime: completionTime,
}
}
// MustUnMarshalUndelegationInfo must return the UndelegationInfo object by unmarshaling
func MustUnMarshalUndelegationInfo(cdc *codec.Codec, value []byte) UndelegationInfo {
undelegationInfo, err := UnmarshalUndelegationInfo(cdc, value)
if err != nil {
panic(err)
}
return undelegationInfo
}
// UnmarshalUndelegationInfo returns the UndelegationInfo object by unmarshaling
func UnmarshalUndelegationInfo(cdc *codec.Codec, value []byte) (undelegationInfo UndelegationInfo, err error) {
err = cdc.UnmarshalBinaryLengthPrefixed(value, &undelegationInfo)
return undelegationInfo, err
}
// String returns a human readable string representation of UndelegationInfo
func (ud UndelegationInfo) String() string {
return fmt.Sprintf(`UnDelegation:
Delegator: %s
Quantity: %s
CompletionTime: %s`,
ud.DelegatorAddress, ud.Quantity, ud.CompletionTime.Format(time.RFC3339))
}
// DefaultUndelegation returns default entity for UndelegationInfo
func DefaultUndelegation() UndelegationInfo {
return UndelegationInfo{
nil, sdk.ZeroDec(), time.Unix(0, 0).UTC(),
}
}