forked from bnb-chain/go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg-freeze.go
114 lines (90 loc) · 2.79 KB
/
msg-freeze.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package msg
import (
"encoding/json"
"fmt"
"github.com/go-chain/go-sdk/common/types"
)
// TokenFreezeMsg def
type TokenFreezeMsg struct {
From types.AccAddress `json:"from"`
Symbol string `json:"symbol"`
Amount int64 `json:"amount"`
}
// NewFreezeMsg for instance creation
func NewFreezeMsg(from types.AccAddress, symbol string, amount int64) TokenFreezeMsg {
return TokenFreezeMsg{From: from, Symbol: symbol, Amount: amount}
}
// Route is part of Msg interface
func (msg TokenFreezeMsg) Route() string { return "tokensFreeze" }
// Type is part of Msg interface
func (msg TokenFreezeMsg) Type() string { return "tokensFreeze" }
// String is part of Msg interface
func (msg TokenFreezeMsg) String() string {
return fmt.Sprintf("Freeze{%v#%v}", msg.From, msg.Symbol)
}
// GetInvolvedAddresses is part of Msg interface
func (msg TokenFreezeMsg) GetInvolvedAddresses() []types.AccAddress {
return msg.GetSigners()
}
func (msg TokenFreezeMsg) GetSigners() []types.AccAddress {
return []types.AccAddress{msg.From}
}
func (msg TokenFreezeMsg) GetSignBytes() []byte {
b, err := json.Marshal(msg)
if err != nil {
panic(err)
}
return b
}
func (msg TokenFreezeMsg) ValidateBasic() error {
err := ValidateSymbol(msg.Symbol)
if err != nil {
return fmt.Errorf("ErrInvalidCoins %s", msg.Symbol)
}
if msg.Amount <= 0 {
return fmt.Errorf("ErrInsufficientFunds, amount should be more than 0")
}
return nil
}
// TokenUnfreezeMsg def
type TokenUnfreezeMsg struct {
From types.AccAddress `json:"from"`
Symbol string `json:"symbol"`
Amount int64 `json:"amount"`
}
// NewUnfreezeMsg for instance creation
func NewUnfreezeMsg(from types.AccAddress, symbol string, amount int64) TokenUnfreezeMsg {
return TokenUnfreezeMsg{From: from, Symbol: symbol, Amount: amount}
}
// Route is part of Msg interface
func (msg TokenUnfreezeMsg) Route() string { return "tokensFreeze" }
// Type is part of Msg interface
func (msg TokenUnfreezeMsg) Type() string { return "tokensFreeze" }
// String is part of Msg interface
func (msg TokenUnfreezeMsg) String() string {
return fmt.Sprintf("Unfreeze{%v#%v%v}", msg.From, msg.Amount, msg.Symbol)
}
// GetInvolvedAddresses is part of Msg interface
func (msg TokenUnfreezeMsg) GetInvolvedAddresses() []types.AccAddress {
return msg.GetSigners()
}
func (msg TokenUnfreezeMsg) GetSigners() []types.AccAddress {
return []types.AccAddress{msg.From}
}
func (msg TokenUnfreezeMsg) GetSignBytes() []byte {
b, err := json.Marshal(msg)
if err != nil {
panic(err)
}
return b
}
func (msg TokenUnfreezeMsg) ValidateBasic() error {
err := ValidateSymbol(msg.Symbol)
if err != nil {
return fmt.Errorf("ErrInvalidCoins %s", msg.Symbol)
}
if msg.Amount <= 0 {
return fmt.Errorf("ErrInsufficientFunds, amount should be more than 0")
}
return nil
}