github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/staking/typesadapter/msgs.go (about) 1 package typesadapter 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec" 8 "sigs.k8s.io/yaml" 9 ) 10 11 // TODO,change yaml import 12 func (c CommissionRates) String() string { 13 out, _ := yaml.Marshal(c) 14 return string(out) 15 } 16 17 // String implements the Stringer interface for a Description object. 18 func (d Description) String() string { 19 out, _ := yaml.Marshal(d) 20 return string(out) 21 } 22 23 // String implements the Stringer interface for a Validator object. 24 func (v Validator) String() string { 25 bz, err := codec.ProtoMarshalJSON(&v, nil) 26 if err != nil { 27 panic(err) 28 } 29 30 out, err := yaml.JSONToYAML(bz) 31 if err != nil { 32 panic(err) 33 } 34 35 return string(out) 36 } 37 38 // String implements the Stringer interface for a DVPair object. 39 func (dv DVPair) String() string { 40 out, _ := yaml.Marshal(dv) 41 return string(out) 42 } 43 44 // String implements the Stringer interface for a DVVTriplet object. 45 func (dvv DVVTriplet) String() string { 46 out, _ := yaml.Marshal(dvv) 47 return string(out) 48 } 49 50 // String returns a human readable string representation of a Delegation. 51 func (d Delegation) String() string { 52 out, _ := yaml.Marshal(d) 53 return string(out) 54 } 55 56 // Delegations is a collection of delegations 57 type Delegations []Delegation 58 59 func (d Delegations) String() (out string) { 60 for _, del := range d { 61 out += del.String() + "\n" 62 } 63 64 return strings.TrimSpace(out) 65 } 66 67 // String returns a human readable string representation of an UnbondingDelegation. 68 func (ubd UnbondingDelegation) String() string { 69 out := fmt.Sprintf(`Unbonding Delegations between: 70 Delegator: %s 71 Validator: %s 72 Entries:`, ubd.DelegatorAddress, ubd.ValidatorAddress) 73 for i, entry := range ubd.Entries { 74 out += fmt.Sprintf(` Unbonding Delegation %d: 75 Creation Height: %v 76 Min time to unbond (unix): %v 77 Expected balance: %s`, i, entry.CreationHeight, 78 entry.CompletionTime, entry.Balance) 79 } 80 81 return out 82 } 83 84 // UnbondingDelegations is a collection of UnbondingDelegation 85 type UnbondingDelegations []UnbondingDelegation 86 87 func (ubds UnbondingDelegations) String() (out string) { 88 for _, u := range ubds { 89 out += u.String() + "\n" 90 } 91 92 return strings.TrimSpace(out) 93 } 94 95 // String implements the stringer interface for a UnbondingDelegationEntry. 96 func (e UnbondingDelegationEntry) String() string { 97 out, _ := yaml.Marshal(e) 98 return string(out) 99 } 100 101 // String implements the Stringer interface for a RedelegationEntry object. 102 func (e RedelegationEntry) String() string { 103 out, _ := yaml.Marshal(e) 104 return string(out) 105 } 106 107 // String returns a human readable string representation of a Redelegation. 108 func (red Redelegation) String() string { 109 out := fmt.Sprintf(`Redelegations between: 110 Delegator: %s 111 Source Validator: %s 112 Destination Validator: %s 113 Entries: 114 `, 115 red.DelegatorAddress, red.ValidatorSrcAddress, red.ValidatorDstAddress, 116 ) 117 118 for i, entry := range red.Entries { 119 out += fmt.Sprintf(` Redelegation Entry #%d: 120 Creation height: %v 121 Min time to unbond (unix): %v 122 Dest Shares: %s 123 `, 124 i, entry.CreationHeight, entry.CompletionTime, entry.SharesDst, 125 ) 126 } 127 128 return strings.TrimRight(out, "\n") 129 } 130 131 // String returns a human readable string representation of the parameters. 132 func (p Params) String() string { 133 out, _ := yaml.Marshal(p) 134 return string(out) 135 } 136 137 // String implements the Stringer interface for DelegationResponse. 138 func (d DelegationResponse) String() string { 139 return fmt.Sprintf("%s\n Balance: %s", d.Delegation.String(), d.Balance) 140 }