github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/staking/types/delegation.go (about) 1 package types 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec" 8 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 9 ) 10 11 // UndelegationInfo is the struct of the undelegation info 12 type UndelegationInfo struct { 13 DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"` 14 Quantity sdk.Dec `json:"quantity" yaml:"quantity"` 15 CompletionTime time.Time `json:"completion_time"` 16 } 17 18 // NewUndelegationInfo creates a new delegation object 19 func NewUndelegationInfo(delegatorAddr sdk.AccAddress, sharesQuantity Shares, completionTime time.Time) UndelegationInfo { 20 return UndelegationInfo{ 21 DelegatorAddress: delegatorAddr, 22 Quantity: sharesQuantity, 23 CompletionTime: completionTime, 24 } 25 } 26 27 // MustUnMarshalUndelegationInfo must return the UndelegationInfo object by unmarshaling 28 func MustUnMarshalUndelegationInfo(cdc *codec.Codec, value []byte) UndelegationInfo { 29 undelegationInfo, err := UnmarshalUndelegationInfo(cdc, value) 30 if err != nil { 31 panic(err) 32 } 33 return undelegationInfo 34 } 35 36 // UnmarshalUndelegationInfo returns the UndelegationInfo object by unmarshaling 37 func UnmarshalUndelegationInfo(cdc *codec.Codec, value []byte) (undelegationInfo UndelegationInfo, err error) { 38 err = cdc.UnmarshalBinaryLengthPrefixed(value, &undelegationInfo) 39 return undelegationInfo, err 40 } 41 42 // String returns a human readable string representation of UndelegationInfo 43 func (ud UndelegationInfo) String() string { 44 return fmt.Sprintf(`UnDelegation: 45 Delegator: %s 46 Quantity: %s 47 CompletionTime: %s`, 48 ud.DelegatorAddress, ud.Quantity, ud.CompletionTime.Format(time.RFC3339)) 49 } 50 51 // DefaultUndelegation returns default entity for UndelegationInfo 52 func DefaultUndelegation() UndelegationInfo { 53 return UndelegationInfo{ 54 nil, sdk.ZeroDec(), time.Unix(0, 0).UTC(), 55 } 56 }