-
Notifications
You must be signed in to change notification settings - Fork 181
/
shares.go
48 lines (39 loc) · 1.38 KB
/
shares.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
package types
import (
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Shares is the alias of sdk.Dec to represent the amount of shares for adding shares to validators
type Shares = sdk.Dec
// MustUnmarshalShares unmarshals the shares bytes and return it
func MustUnmarshalShares(cdc *codec.Codec, bytes []byte) Shares {
var shares Shares
cdc.MustUnmarshalBinaryLengthPrefixed(bytes, &shares)
return shares
}
// SharesResponse is the struct for query all the shares on a validator
type SharesResponse struct {
DelAddr sdk.AccAddress `json:"delegator_address"`
Shares sdk.Dec `json:"shares"`
}
// NewSharesResponse creates a new instance of sharesResponse
func NewSharesResponse(delAddr sdk.AccAddress, shares Shares) SharesResponse {
return SharesResponse{
delAddr,
shares,
}
}
// String returns a human readable string representation of SharesResponse
func (sr SharesResponse) String() string {
return fmt.Sprintf("%s\n Shares: %s", sr.DelAddr.String(), sr.Shares)
}
// SharesResponses is the type alias of SharesResponse slice
type SharesResponses []SharesResponse
// String returns a human readable string representation of SharesResponses
func (srs SharesResponses) String() (strFormat string) {
for _, sr := range srs {
strFormat = fmt.Sprintf("%s %s:%s", strFormat, sr.DelAddr.String(), sr.Shares.String())
}
return strFormat
}