forked from bnb-chain/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtx.go
81 lines (71 loc) · 2.14 KB
/
tx.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
package admin
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/bnb-chain/node/common/runtime"
"github.com/bnb-chain/node/plugins/account"
"github.com/bnb-chain/node/plugins/bridge"
"github.com/bnb-chain/node/plugins/dex/order"
list "github.com/bnb-chain/node/plugins/dex/types"
"github.com/bnb-chain/node/plugins/tokens/burn"
"github.com/bnb-chain/node/plugins/tokens/freeze"
"github.com/bnb-chain/node/plugins/tokens/issue"
"github.com/bnb-chain/node/plugins/tokens/ownership"
"github.com/bnb-chain/node/plugins/tokens/seturi"
"github.com/bnb-chain/node/plugins/tokens/swap"
"github.com/bnb-chain/node/plugins/tokens/timelock"
)
var transferOnlyModeBlackList = []string{
burn.BurnMsg{}.Type(),
freeze.FreezeMsg{}.Type(),
freeze.UnfreezeMsg{}.Type(),
issue.IssueMsg{}.Type(),
issue.MintMsg{}.Type(),
order.NewOrderMsg{}.Type(),
order.CancelOrderMsg{}.Type(),
timelock.TimeLockMsg{}.Type(),
timelock.TimeUnlockMsg{}.Type(),
timelock.TimeRelockMsg{}.Type(),
issue.IssueMiniMsg{}.Type(),
issue.IssueTinyMsg{}.Type(),
seturi.SetURIMsg{}.Type(),
list.ListMsg{}.Type(),
list.ListMiniMsg{}.Type(),
ownership.TransferOwnershipMsg{}.Type(),
swap.HTLTMsg{}.Type(),
swap.DepositHTLTMsg{}.Type(),
swap.ClaimHTLTMsg{}.Type(),
swap.RefundHTLTMsg{}.Type(),
account.SetAccountFlagsMsg{}.Type(),
bridge.BindMsg{}.Type(),
bridge.UnbindMsg{}.Type(),
bridge.TransferOutMsg{}.Type(),
}
var TxBlackList = map[runtime.Mode][]string{
runtime.TransferOnlyMode: transferOnlyModeBlackList,
runtime.RecoverOnlyMode: append(transferOnlyModeBlackList, bank.MsgSend{}.Type()),
}
func TxNotAllowedError() sdk.Error {
return sdk.ErrInternal(fmt.Sprintf("The tx is not allowed, RunningMode: %v", runtime.GetRunningMode()))
}
func IsTxAllowed(tx sdk.Tx) bool {
mode := runtime.GetRunningMode()
if mode == runtime.NormalMode {
return true
}
for _, msg := range tx.GetMsgs() {
if !isMsgAllowed(msg, mode) {
return false
}
}
return true
}
func isMsgAllowed(msg sdk.Msg, mode runtime.Mode) bool {
for _, msgType := range TxBlackList[mode] {
if msgType == msg.Type() {
return false
}
}
return true
}