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

     1  package types
     2  
     3  import (
     4  	"fmt"
     5  
     6  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     7  )
     8  
     9  // Deposit
    10  type Deposit struct {
    11  	ProposalID uint64         `json:"proposal_id" yaml:"proposal_id"` //  proposalID of the proposal
    12  	Depositor  sdk.AccAddress `json:"depositor" yaml:"depositor"`     //  Address of the depositor
    13  	Amount     sdk.SysCoins   `json:"amount" yaml:"amount"`           //  Deposit amount
    14  }
    15  
    16  // NewDeposit creates a new Deposit instance
    17  func NewDeposit(proposalID uint64, depositor sdk.AccAddress, amount sdk.SysCoins) Deposit {
    18  	return Deposit{proposalID, depositor, amount}
    19  }
    20  
    21  func (d Deposit) String() string {
    22  	return fmt.Sprintf("deposit by %s on Proposal %d is for the amount %s",
    23  		d.Depositor, d.ProposalID, d.Amount)
    24  }
    25  
    26  // Deposits is a collection of Deposit objects
    27  type Deposits []Deposit
    28  
    29  func (d Deposits) String() string {
    30  	if len(d) == 0 {
    31  		return "[]"
    32  	}
    33  	out := fmt.Sprintf("Deposits for Proposal %d:", d[0].ProposalID)
    34  	for _, dep := range d {
    35  		out += fmt.Sprintf("\n  %s: %s", dep.Depositor, dep.Amount)
    36  	}
    37  	return out
    38  }
    39  
    40  // Equals returns whether two deposits are equal.
    41  func (d Deposit) Equals(comp Deposit) bool {
    42  	return d.Depositor.Equals(comp.Depositor) && d.ProposalID == comp.ProposalID && d.Amount.IsEqual(comp.Amount)
    43  }
    44  
    45  // Empty returns whether a deposit is empty.
    46  func (d Deposit) Empty() bool {
    47  	return d.Equals(Deposit{})
    48  }