2018-06-26 19:00:12 -07:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
2019-05-15 07:44:47 -07:00
|
|
|
"encoding/json"
|
2018-06-26 19:00:12 -07:00
|
|
|
"fmt"
|
2019-01-22 09:28:39 -08:00
|
|
|
"strings"
|
2018-08-12 00:33:48 -07:00
|
|
|
"time"
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2021-09-24 07:37:34 -07:00
|
|
|
"sigs.k8s.io/yaml"
|
2020-02-27 02:53:22 -08:00
|
|
|
|
2018-09-13 11:17:32 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2018-06-26 19:00:12 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
2019-06-04 15:06:58 -07:00
|
|
|
// Implements Delegation interface
|
2020-10-12 06:56:02 -07:00
|
|
|
var _ DelegationI = Delegation{}
|
2019-06-04 15:06:58 -07:00
|
|
|
|
2020-02-06 11:21:02 -08:00
|
|
|
// String implements the Stringer interface for a DVPair object.
|
|
|
|
func (dv DVPair) String() string {
|
|
|
|
out, _ := yaml.Marshal(dv)
|
|
|
|
return string(out)
|
2018-07-02 17:05:52 -07:00
|
|
|
}
|
|
|
|
|
2020-02-06 11:21:02 -08:00
|
|
|
// String implements the Stringer interface for a DVVTriplet object.
|
|
|
|
func (dvv DVVTriplet) String() string {
|
|
|
|
out, _ := yaml.Marshal(dvv)
|
|
|
|
return string(out)
|
|
|
|
}
|
2019-01-16 02:35:18 -08:00
|
|
|
|
2020-02-06 11:21:02 -08:00
|
|
|
// NewDelegation creates a new delegation object
|
2020-09-25 03:25:37 -07:00
|
|
|
//nolint:interfacer
|
2020-02-06 11:21:02 -08:00
|
|
|
func NewDelegation(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress, shares sdk.Dec) Delegation {
|
2019-01-16 02:35:18 -08:00
|
|
|
return Delegation{
|
2020-09-25 03:25:37 -07:00
|
|
|
DelegatorAddress: delegatorAddr.String(),
|
|
|
|
ValidatorAddress: validatorAddr.String(),
|
2019-02-25 07:16:52 -08:00
|
|
|
Shares: shares,
|
2019-01-16 02:35:18 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 10:18:00 -08:00
|
|
|
// MustMarshalDelegation returns the delegation bytes. Panics if fails
|
2021-04-29 03:46:22 -07:00
|
|
|
func MustMarshalDelegation(cdc codec.BinaryCodec, delegation Delegation) []byte {
|
|
|
|
return cdc.MustMarshal(&delegation)
|
2018-07-03 12:03:35 -07:00
|
|
|
}
|
|
|
|
|
2019-12-06 10:18:00 -08:00
|
|
|
// MustUnmarshalDelegation return the unmarshaled delegation from bytes.
|
|
|
|
// Panics if fails.
|
2021-04-29 03:46:22 -07:00
|
|
|
func MustUnmarshalDelegation(cdc codec.BinaryCodec, value []byte) Delegation {
|
2019-01-07 12:42:52 -08:00
|
|
|
delegation, err := UnmarshalDelegation(cdc, value)
|
2018-07-04 14:07:06 -07:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-05-02 12:26:59 -07:00
|
|
|
|
2018-07-04 14:07:06 -07:00
|
|
|
return delegation
|
|
|
|
}
|
|
|
|
|
2019-01-07 12:42:52 -08:00
|
|
|
// return the delegation
|
2021-04-29 03:46:22 -07:00
|
|
|
func UnmarshalDelegation(cdc codec.BinaryCodec, value []byte) (delegation Delegation, err error) {
|
|
|
|
err = cdc.Unmarshal(value, &delegation)
|
2019-01-07 12:42:52 -08:00
|
|
|
return delegation, err
|
2018-07-03 12:03:35 -07:00
|
|
|
}
|
|
|
|
|
2020-09-25 03:25:37 -07:00
|
|
|
func (d Delegation) GetDelegatorAddr() sdk.AccAddress {
|
|
|
|
delAddr, err := sdk.AccAddressFromBech32(d.DelegatorAddress)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return delAddr
|
|
|
|
}
|
|
|
|
func (d Delegation) GetValidatorAddr() sdk.ValAddress {
|
|
|
|
addr, err := sdk.ValAddressFromBech32(d.ValidatorAddress)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return addr
|
|
|
|
}
|
|
|
|
func (d Delegation) GetShares() sdk.Dec { return d.Shares }
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
// String returns a human readable string representation of a Delegation.
|
|
|
|
func (d Delegation) String() string {
|
2020-02-06 11:21:02 -08:00
|
|
|
out, _ := yaml.Marshal(d)
|
|
|
|
return string(out)
|
2019-01-22 09:28:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delegations is a collection of delegations
|
|
|
|
type Delegations []Delegation
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
func (d Delegations) String() (out string) {
|
|
|
|
for _, del := range d {
|
|
|
|
out += del.String() + "\n"
|
|
|
|
}
|
2020-05-02 12:26:59 -07:00
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
return strings.TrimSpace(out)
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
|
|
|
|
2020-02-06 11:21:02 -08:00
|
|
|
func NewUnbondingDelegationEntry(creationHeight int64, completionTime time.Time, balance sdk.Int) UnbondingDelegationEntry {
|
|
|
|
return UnbondingDelegationEntry{
|
|
|
|
CreationHeight: creationHeight,
|
|
|
|
CompletionTime: completionTime,
|
|
|
|
InitialBalance: balance,
|
|
|
|
Balance: balance,
|
|
|
|
}
|
2019-01-16 02:35:18 -08:00
|
|
|
}
|
|
|
|
|
2020-02-06 11:21:02 -08:00
|
|
|
// String implements the stringer interface for a UnbondingDelegationEntry.
|
|
|
|
func (e UnbondingDelegationEntry) String() string {
|
|
|
|
out, _ := yaml.Marshal(e)
|
|
|
|
return string(out)
|
2019-01-16 02:35:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsMature - is the current entry mature
|
|
|
|
func (e UnbondingDelegationEntry) IsMature(currentTime time.Time) bool {
|
|
|
|
return !e.CompletionTime.After(currentTime)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewUnbondingDelegation - create a new unbonding delegation object
|
2020-09-25 03:25:37 -07:00
|
|
|
//nolint:interfacer
|
2020-02-06 11:21:02 -08:00
|
|
|
func NewUnbondingDelegation(
|
|
|
|
delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress,
|
|
|
|
creationHeight int64, minTime time.Time, balance sdk.Int,
|
|
|
|
) UnbondingDelegation {
|
2019-01-16 02:35:18 -08:00
|
|
|
return UnbondingDelegation{
|
2020-09-25 03:25:37 -07:00
|
|
|
DelegatorAddress: delegatorAddr.String(),
|
|
|
|
ValidatorAddress: validatorAddr.String(),
|
2020-02-06 11:21:02 -08:00
|
|
|
Entries: []UnbondingDelegationEntry{
|
|
|
|
NewUnbondingDelegationEntry(creationHeight, minTime, balance),
|
|
|
|
},
|
2019-01-16 02:35:18 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddEntry - append entry to the unbonding delegation
|
2020-02-06 11:21:02 -08:00
|
|
|
func (ubd *UnbondingDelegation) AddEntry(creationHeight int64, minTime time.Time, balance sdk.Int) {
|
2019-01-16 02:35:18 -08:00
|
|
|
entry := NewUnbondingDelegationEntry(creationHeight, minTime, balance)
|
2020-02-06 11:21:02 -08:00
|
|
|
ubd.Entries = append(ubd.Entries, entry)
|
2019-01-16 02:35:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveEntry - remove entry at index i to the unbonding delegation
|
2020-02-06 11:21:02 -08:00
|
|
|
func (ubd *UnbondingDelegation) RemoveEntry(i int64) {
|
|
|
|
ubd.Entries = append(ubd.Entries[:i], ubd.Entries[i+1:]...)
|
2018-07-02 17:05:52 -07:00
|
|
|
}
|
|
|
|
|
2019-01-07 12:42:52 -08:00
|
|
|
// return the unbonding delegation
|
2021-04-29 03:46:22 -07:00
|
|
|
func MustMarshalUBD(cdc codec.BinaryCodec, ubd UnbondingDelegation) []byte {
|
|
|
|
return cdc.MustMarshal(&ubd)
|
2018-07-03 21:29:02 -07:00
|
|
|
}
|
|
|
|
|
2019-01-07 12:42:52 -08:00
|
|
|
// unmarshal a unbonding delegation from a store value
|
2021-04-29 03:46:22 -07:00
|
|
|
func MustUnmarshalUBD(cdc codec.BinaryCodec, value []byte) UnbondingDelegation {
|
2019-01-07 12:42:52 -08:00
|
|
|
ubd, err := UnmarshalUBD(cdc, value)
|
2018-07-04 14:07:06 -07:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-05-02 12:26:59 -07:00
|
|
|
|
2018-07-04 14:07:06 -07:00
|
|
|
return ubd
|
|
|
|
}
|
|
|
|
|
2019-01-07 12:42:52 -08:00
|
|
|
// unmarshal a unbonding delegation from a store value
|
2021-04-29 03:46:22 -07:00
|
|
|
func UnmarshalUBD(cdc codec.BinaryCodec, value []byte) (ubd UnbondingDelegation, err error) {
|
|
|
|
err = cdc.Unmarshal(value, &ubd)
|
2019-01-07 12:42:52 -08:00
|
|
|
return ubd, err
|
2018-07-03 21:29:02 -07:00
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
// String returns a human readable string representation of an UnbondingDelegation.
|
2020-02-06 11:21:02 -08:00
|
|
|
func (ubd UnbondingDelegation) String() string {
|
2019-01-22 09:28:39 -08:00
|
|
|
out := fmt.Sprintf(`Unbonding Delegations between:
|
|
|
|
Delegator: %s
|
|
|
|
Validator: %s
|
2020-02-06 11:21:02 -08:00
|
|
|
Entries:`, ubd.DelegatorAddress, ubd.ValidatorAddress)
|
|
|
|
for i, entry := range ubd.Entries {
|
2019-01-22 09:28:39 -08:00
|
|
|
out += fmt.Sprintf(` Unbonding Delegation %d:
|
|
|
|
Creation Height: %v
|
|
|
|
Min time to unbond (unix): %v
|
|
|
|
Expected balance: %s`, i, entry.CreationHeight,
|
|
|
|
entry.CompletionTime, entry.Balance)
|
2019-01-16 02:35:18 -08:00
|
|
|
}
|
2020-05-02 12:26:59 -07:00
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnbondingDelegations is a collection of UnbondingDelegation
|
|
|
|
type UnbondingDelegations []UnbondingDelegation
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
func (ubds UnbondingDelegations) String() (out string) {
|
|
|
|
for _, u := range ubds {
|
|
|
|
out += u.String() + "\n"
|
|
|
|
}
|
2020-05-02 12:26:59 -07:00
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
return strings.TrimSpace(out)
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
|
|
|
|
2020-02-06 11:21:02 -08:00
|
|
|
func NewRedelegationEntry(creationHeight int64, completionTime time.Time, balance sdk.Int, sharesDst sdk.Dec) RedelegationEntry {
|
2019-01-16 02:35:18 -08:00
|
|
|
return RedelegationEntry{
|
|
|
|
CreationHeight: creationHeight,
|
|
|
|
CompletionTime: completionTime,
|
|
|
|
InitialBalance: balance,
|
|
|
|
SharesDst: sharesDst,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-06 11:21:02 -08:00
|
|
|
// String implements the Stringer interface for a RedelegationEntry object.
|
|
|
|
func (e RedelegationEntry) String() string {
|
|
|
|
out, _ := yaml.Marshal(e)
|
|
|
|
return string(out)
|
|
|
|
}
|
|
|
|
|
2019-01-16 02:35:18 -08:00
|
|
|
// IsMature - is the current entry mature
|
|
|
|
func (e RedelegationEntry) IsMature(currentTime time.Time) bool {
|
|
|
|
return !e.CompletionTime.After(currentTime)
|
|
|
|
}
|
|
|
|
|
2020-09-25 03:25:37 -07:00
|
|
|
//nolint:interfacer
|
2020-02-06 11:21:02 -08:00
|
|
|
func NewRedelegation(
|
|
|
|
delegatorAddr sdk.AccAddress, validatorSrcAddr, validatorDstAddr sdk.ValAddress,
|
|
|
|
creationHeight int64, minTime time.Time, balance sdk.Int, sharesDst sdk.Dec,
|
|
|
|
) Redelegation {
|
|
|
|
return Redelegation{
|
2020-09-25 03:25:37 -07:00
|
|
|
DelegatorAddress: delegatorAddr.String(),
|
|
|
|
ValidatorSrcAddress: validatorSrcAddr.String(),
|
|
|
|
ValidatorDstAddress: validatorDstAddr.String(),
|
2020-02-06 11:21:02 -08:00
|
|
|
Entries: []RedelegationEntry{
|
|
|
|
NewRedelegationEntry(creationHeight, minTime, balance, sharesDst),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddEntry - append entry to the unbonding delegation
|
|
|
|
func (red *Redelegation) AddEntry(creationHeight int64, minTime time.Time, balance sdk.Int, sharesDst sdk.Dec) {
|
2019-02-07 17:41:23 -08:00
|
|
|
entry := NewRedelegationEntry(creationHeight, minTime, balance, sharesDst)
|
2020-02-06 11:21:02 -08:00
|
|
|
red.Entries = append(red.Entries, entry)
|
2019-01-16 02:35:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveEntry - remove entry at index i to the unbonding delegation
|
2020-02-06 11:21:02 -08:00
|
|
|
func (red *Redelegation) RemoveEntry(i int64) {
|
|
|
|
red.Entries = append(red.Entries[:i], red.Entries[i+1:]...)
|
2018-07-02 17:05:52 -07:00
|
|
|
}
|
|
|
|
|
2019-12-06 10:18:00 -08:00
|
|
|
// MustMarshalRED returns the Redelegation bytes. Panics if fails.
|
2021-04-29 03:46:22 -07:00
|
|
|
func MustMarshalRED(cdc codec.BinaryCodec, red Redelegation) []byte {
|
|
|
|
return cdc.MustMarshal(&red)
|
2018-07-03 21:29:02 -07:00
|
|
|
}
|
|
|
|
|
2019-12-06 10:18:00 -08:00
|
|
|
// MustUnmarshalRED unmarshals a redelegation from a store value. Panics if fails.
|
2021-04-29 03:46:22 -07:00
|
|
|
func MustUnmarshalRED(cdc codec.BinaryCodec, value []byte) Redelegation {
|
2019-01-07 12:42:52 -08:00
|
|
|
red, err := UnmarshalRED(cdc, value)
|
2018-07-04 14:07:06 -07:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-05-02 12:26:59 -07:00
|
|
|
|
2018-07-04 14:07:06 -07:00
|
|
|
return red
|
|
|
|
}
|
|
|
|
|
2019-12-06 10:18:00 -08:00
|
|
|
// UnmarshalRED unmarshals a redelegation from a store value
|
2021-04-29 03:46:22 -07:00
|
|
|
func UnmarshalRED(cdc codec.BinaryCodec, value []byte) (red Redelegation, err error) {
|
|
|
|
err = cdc.Unmarshal(value, &red)
|
2019-01-07 12:42:52 -08:00
|
|
|
return red, err
|
2018-07-03 21:29:02 -07:00
|
|
|
}
|
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
// String returns a human readable string representation of a Redelegation.
|
2020-02-06 11:21:02 -08:00
|
|
|
func (red Redelegation) String() string {
|
2019-01-22 09:28:39 -08:00
|
|
|
out := fmt.Sprintf(`Redelegations between:
|
|
|
|
Delegator: %s
|
|
|
|
Source Validator: %s
|
|
|
|
Destination Validator: %s
|
2019-05-15 07:44:47 -07:00
|
|
|
Entries:
|
|
|
|
`,
|
2020-02-06 11:21:02 -08:00
|
|
|
red.DelegatorAddress, red.ValidatorSrcAddress, red.ValidatorDstAddress,
|
2019-05-15 07:44:47 -07:00
|
|
|
)
|
|
|
|
|
2020-02-06 11:21:02 -08:00
|
|
|
for i, entry := range red.Entries {
|
2019-05-15 07:44:47 -07:00
|
|
|
out += fmt.Sprintf(` Redelegation Entry #%d:
|
2019-01-22 09:28:39 -08:00
|
|
|
Creation height: %v
|
|
|
|
Min time to unbond (unix): %v
|
2019-05-15 07:44:47 -07:00
|
|
|
Dest Shares: %s
|
|
|
|
`,
|
|
|
|
i, entry.CreationHeight, entry.CompletionTime, entry.SharesDst,
|
|
|
|
)
|
2019-01-22 09:28:39 -08:00
|
|
|
}
|
2019-05-15 07:44:47 -07:00
|
|
|
|
|
|
|
return strings.TrimRight(out, "\n")
|
2019-01-22 09:28:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Redelegations are a collection of Redelegation
|
|
|
|
type Redelegations []Redelegation
|
|
|
|
|
|
|
|
func (d Redelegations) String() (out string) {
|
|
|
|
for _, red := range d {
|
|
|
|
out += red.String() + "\n"
|
2019-01-16 02:35:18 -08:00
|
|
|
}
|
2020-05-02 12:26:59 -07:00
|
|
|
|
2019-01-22 09:28:39 -08:00
|
|
|
return strings.TrimSpace(out)
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
2019-05-15 07:44:47 -07:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Client Types
|
|
|
|
|
2019-12-06 10:18:00 -08:00
|
|
|
// NewDelegationResp creates a new DelegationResponse instance
|
|
|
|
func NewDelegationResp(
|
|
|
|
delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress, shares sdk.Dec, balance sdk.Coin,
|
|
|
|
) DelegationResponse {
|
|
|
|
return DelegationResponse{
|
|
|
|
Delegation: NewDelegation(delegatorAddr, validatorAddr, shares),
|
|
|
|
Balance: balance,
|
|
|
|
}
|
2019-05-15 07:44:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// String implements the Stringer interface for DelegationResponse.
|
|
|
|
func (d DelegationResponse) String() string {
|
|
|
|
return fmt.Sprintf("%s\n Balance: %s", d.Delegation.String(), d.Balance)
|
|
|
|
}
|
|
|
|
|
|
|
|
type delegationRespAlias DelegationResponse
|
|
|
|
|
|
|
|
// MarshalJSON implements the json.Marshaler interface. This is so we can
|
|
|
|
// achieve a flattened structure while embedding other types.
|
|
|
|
func (d DelegationResponse) MarshalJSON() ([]byte, error) {
|
|
|
|
return json.Marshal((delegationRespAlias)(d))
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON implements the json.Unmarshaler interface. This is so we can
|
|
|
|
// achieve a flattened structure while embedding other types.
|
|
|
|
func (d *DelegationResponse) UnmarshalJSON(bz []byte) error {
|
|
|
|
return json.Unmarshal(bz, (*delegationRespAlias)(d))
|
|
|
|
}
|
|
|
|
|
|
|
|
// DelegationResponses is a collection of DelegationResp
|
|
|
|
type DelegationResponses []DelegationResponse
|
|
|
|
|
|
|
|
// String implements the Stringer interface for DelegationResponses.
|
|
|
|
func (d DelegationResponses) String() (out string) {
|
|
|
|
for _, del := range d {
|
|
|
|
out += del.String() + "\n"
|
|
|
|
}
|
2020-05-02 12:26:59 -07:00
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
return strings.TrimSpace(out)
|
|
|
|
}
|
|
|
|
|
2019-12-06 10:18:00 -08:00
|
|
|
// NewRedelegationResponse crates a new RedelegationEntryResponse instance.
|
2020-09-25 03:25:37 -07:00
|
|
|
//nolint:interfacer
|
2019-12-06 10:18:00 -08:00
|
|
|
func NewRedelegationResponse(
|
|
|
|
delegatorAddr sdk.AccAddress, validatorSrc, validatorDst sdk.ValAddress, entries []RedelegationEntryResponse,
|
|
|
|
) RedelegationResponse {
|
|
|
|
return RedelegationResponse{
|
|
|
|
Redelegation: Redelegation{
|
2020-09-25 03:25:37 -07:00
|
|
|
DelegatorAddress: delegatorAddr.String(),
|
|
|
|
ValidatorSrcAddress: validatorSrc.String(),
|
|
|
|
ValidatorDstAddress: validatorDst.String(),
|
2019-12-06 10:18:00 -08:00
|
|
|
},
|
|
|
|
Entries: entries,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewRedelegationEntryResponse creates a new RedelegationEntryResponse instance.
|
|
|
|
func NewRedelegationEntryResponse(
|
|
|
|
creationHeight int64, completionTime time.Time, sharesDst sdk.Dec, initialBalance, balance sdk.Int) RedelegationEntryResponse {
|
|
|
|
return RedelegationEntryResponse{
|
|
|
|
RedelegationEntry: NewRedelegationEntry(creationHeight, completionTime, initialBalance, sharesDst),
|
|
|
|
Balance: balance,
|
2019-05-15 07:44:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type redelegationRespAlias RedelegationResponse
|
|
|
|
|
|
|
|
// MarshalJSON implements the json.Marshaler interface. This is so we can
|
|
|
|
// achieve a flattened structure while embedding other types.
|
|
|
|
func (r RedelegationResponse) MarshalJSON() ([]byte, error) {
|
|
|
|
return json.Marshal((redelegationRespAlias)(r))
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON implements the json.Unmarshaler interface. This is so we can
|
|
|
|
// achieve a flattened structure while embedding other types.
|
|
|
|
func (r *RedelegationResponse) UnmarshalJSON(bz []byte) error {
|
|
|
|
return json.Unmarshal(bz, (*redelegationRespAlias)(r))
|
|
|
|
}
|
|
|
|
|
|
|
|
// RedelegationResponses are a collection of RedelegationResp
|
|
|
|
type RedelegationResponses []RedelegationResponse
|
|
|
|
|
|
|
|
func (r RedelegationResponses) String() (out string) {
|
|
|
|
for _, red := range r {
|
|
|
|
out += red.String() + "\n"
|
|
|
|
}
|
2020-05-02 12:26:59 -07:00
|
|
|
|
2019-05-15 07:44:47 -07:00
|
|
|
return strings.TrimSpace(out)
|
|
|
|
}
|