forked from bnb-chain/go-sdk
/
msg-burn.go
68 lines (55 loc) · 1.55 KB
/
msg-burn.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
package msg
import (
"encoding/json"
"fmt"
"github.com/cbarraford/go-sdk/common/types"
)
// TokenBurnMsg def
type TokenBurnMsg struct {
From types.AccAddress `json:"from"`
Symbol string `json:"symbol"`
Amount int64 `json:"amount"`
}
// NewMsg for instance creation
func NewTokenBurnMsg(from types.AccAddress, symbol string, amount int64) TokenBurnMsg {
return TokenBurnMsg{From: from, Symbol: symbol, Amount: amount}
}
// Route is part of Msg interface
func (msg TokenBurnMsg) Route() string {
return "tokensBurn"
}
// Type is part of Msg interface
func (msg TokenBurnMsg) Type() string {
return "tokensBurn"
}
// String is part of Msg interface
func (msg TokenBurnMsg) String() string {
return fmt.Sprintf("BurnMsg{%v#%v%v}", msg.From, msg.Amount, msg.Symbol)
}
// GetInvolvedAddresses is part of Msg interface
func (msg TokenBurnMsg) GetInvolvedAddresses() []types.AccAddress {
return msg.GetSigners()
}
func (msg TokenBurnMsg) GetSignBytes() []byte {
b, err := json.Marshal(msg)
if err != nil {
panic(err)
}
return b
}
// GetSigners is part of Msg interface
func (msg TokenBurnMsg) GetSigners() []types.AccAddress {
return []types.AccAddress{msg.From}
}
// ValidateBasic does a simple validation check that
// doesn't require access to any other information.
func (msg TokenBurnMsg) 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
}