-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
deposit.go
56 lines (45 loc) · 1.13 KB
/
deposit.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
49
50
51
52
53
54
55
56
package v1beta1
import (
"fmt"
"sigs.k8s.io/yaml"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// NewDeposit creates a new Deposit instance
//
//nolint:interfacer
func NewDeposit(proposalID uint64, depositor sdk.AccAddress, amount sdk.Coins) Deposit {
return Deposit{proposalID, depositor.String(), amount}
}
func (d Deposit) String() string {
out, _ := yaml.Marshal(d)
return string(out)
}
// Empty returns whether a deposit is empty.
func (d Deposit) Empty() bool {
return d.String() == Deposit{}.String()
}
// Deposits is a collection of Deposit objects
type Deposits []Deposit
// Equal returns true if two slices (order-dependant) of deposits are equal.
func (d Deposits) Equal(other Deposits) bool {
if len(d) != len(other) {
return false
}
for i, deposit := range d {
if deposit.String() != other[i].String() {
return false
}
}
return true
}
// String implements stringer interface
func (d Deposits) String() string {
if len(d) == 0 {
return "[]"
}
out := fmt.Sprintf("Deposits for Proposal %d:", d[0].ProposalId)
for _, dep := range d {
out += fmt.Sprintf("\n %s: %s", dep.Depositor, dep.Amount)
}
return out
}