/
withdrawal.go
41 lines (36 loc) · 1.12 KB
/
withdrawal.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
package types
import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
yaml "gopkg.in/yaml.v2"
)
// NewWithdrawal creates a new withdrawal object
//
//nolint:interfacer
func NewWithdrawal(id uint64, depositorAddr, marketUID string, participationIndex uint64, amount sdk.Int, mode WithdrawalMode) Withdrawal {
return Withdrawal{
ID: id,
DepositorAddress: depositorAddr,
MarketUID: marketUID,
ParticipationIndex: participationIndex,
Mode: mode,
Amount: amount,
}
}
// MustMarshalWithdrawal returns the withdrawal bytes. Panics if fails
func MustMarshalWithdrawal(cdc codec.BinaryCodec, withdrawal Withdrawal) []byte {
return cdc.MustMarshal(&withdrawal)
}
// return the withdrawal
func UnmarshalWithdrawal(cdc codec.BinaryCodec, value []byte) (withdrawal Withdrawal, err error) {
err = cdc.Unmarshal(value, &withdrawal)
return withdrawal, err
}
// String returns a human readable string representation of a Withdrawal.
func (w Withdrawal) String() string {
out, err := yaml.Marshal(w)
if err != nil {
panic(err)
}
return string(out)
}