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