github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/staking/types/shares.go (about)

     1  package types
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
     6  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     7  )
     8  
     9  // Shares is the alias of sdk.Dec to represent the amount of shares for adding shares to validators
    10  type Shares = sdk.Dec
    11  
    12  // MustUnmarshalShares unmarshals the shares bytes and return it
    13  func MustUnmarshalShares(cdc *codec.Codec, bytes []byte) Shares {
    14  	var shares Shares
    15  	cdc.MustUnmarshalBinaryLengthPrefixed(bytes, &shares)
    16  	return shares
    17  }
    18  
    19  // SharesResponse is the struct for query all the shares on a validator
    20  type SharesResponse struct {
    21  	DelAddr sdk.AccAddress `json:"delegator_address"`
    22  	Shares  sdk.Dec        `json:"shares"`
    23  }
    24  
    25  // NewSharesResponse creates a new instance of sharesResponse
    26  func NewSharesResponse(delAddr sdk.AccAddress, shares Shares) SharesResponse {
    27  	return SharesResponse{
    28  		delAddr,
    29  		shares,
    30  	}
    31  }
    32  
    33  // String returns a human readable string representation of SharesResponse
    34  func (sr SharesResponse) String() string {
    35  	return fmt.Sprintf("%s\n  Shares:   %s", sr.DelAddr.String(), sr.Shares)
    36  }
    37  
    38  // SharesResponses is the type alias of SharesResponse slice
    39  type SharesResponses []SharesResponse
    40  
    41  // String returns a human readable string representation of SharesResponses
    42  func (srs SharesResponses) String() (strFormat string) {
    43  	for _, sr := range srs {
    44  		strFormat = fmt.Sprintf("%s %s:%s", strFormat, sr.DelAddr.String(), sr.Shares.String())
    45  	}
    46  
    47  	return strFormat
    48  }