github.com/cosmos/cosmos-sdk@v0.50.10/x/gov/types/v1beta1/deposit.go (about)

     1  package v1beta1
     2  
     3  import (
     4  	"fmt"
     5  
     6  	sdk "github.com/cosmos/cosmos-sdk/types"
     7  )
     8  
     9  // NewDeposit creates a new Deposit instance
    10  func NewDeposit(proposalID uint64, depositor sdk.AccAddress, amount sdk.Coins) Deposit {
    11  	return Deposit{proposalID, depositor.String(), amount}
    12  }
    13  
    14  // Empty returns whether a deposit is empty.
    15  func (d Deposit) Empty() bool {
    16  	return d.String() == (&Deposit{}).String()
    17  }
    18  
    19  // Deposits is a collection of Deposit objects
    20  type Deposits []Deposit
    21  
    22  // Equal returns true if two slices (order-dependant) of deposits are equal.
    23  func (d Deposits) Equal(other Deposits) bool {
    24  	if len(d) != len(other) {
    25  		return false
    26  	}
    27  
    28  	for i, deposit := range d {
    29  		if deposit.String() != other[i].String() {
    30  			return false
    31  		}
    32  	}
    33  
    34  	return true
    35  }
    36  
    37  // String implements stringer interface
    38  func (d Deposits) String() string {
    39  	if len(d) == 0 {
    40  		return "[]"
    41  	}
    42  	out := fmt.Sprintf("Deposits for Proposal %d:", d[0].ProposalId)
    43  	for _, dep := range d {
    44  		out += fmt.Sprintf("\n  %s: %s", dep.Depositor, dep.Amount)
    45  	}
    46  	return out
    47  }