-
Notifications
You must be signed in to change notification settings - Fork 0
/
deposit.go
48 lines (39 loc) · 1.41 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
package types
import (
"fmt"
sdk "github.com/furyaxyz/fuxchain/libs/cosmos-sdk/types"
)
// Deposit defines an amount deposited by an account address to an active proposal
type Deposit struct {
ProposalID uint64 `json:"proposal_id" yaml:"proposal_id"` // proposalID of the proposal
Depositor sdk.AccAddress `json:"depositor" yaml:"depositor"` // Address of the depositor
Amount sdk.Coins `json:"amount" yaml:"amount"` // Deposit amount
}
// NewDeposit creates a new Deposit instance
func NewDeposit(proposalID uint64, depositor sdk.AccAddress, amount sdk.Coins) Deposit {
return Deposit{proposalID, depositor, amount}
}
func (d Deposit) String() string {
return fmt.Sprintf("deposit by %s on Proposal %d is for the amount %s",
d.Depositor, d.ProposalID, d.Amount)
}
// Deposits is a collection of Deposit objects
type Deposits []Deposit
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
}
// Equals returns whether two deposits are equal.
func (d Deposit) Equals(comp Deposit) bool {
return d.Depositor.Equals(comp.Depositor) && d.ProposalID == comp.ProposalID && d.Amount.IsEqual(comp.Amount)
}
// Empty returns whether a deposit is empty.
func (d Deposit) Empty() bool {
return d.Equals(Deposit{})
}