-
Notifications
You must be signed in to change notification settings - Fork 23
/
filter.go
40 lines (34 loc) · 914 Bytes
/
filter.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
package ante
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz"
)
type SSIMsg sdk.Msg
type NonSSIMsg sdk.Msg
// filterMsgsIntoSSIAndNonSSI filters transaction messages into SSI and non-SSI messages
func filterMsgsIntoSSIAndNonSSI(msgs []sdk.Msg) ([]SSIMsg, []NonSSIMsg) {
msgList := []sdk.Msg{}
for _, msg := range msgs {
// Append every sub-message of Authz's MsgExec to msgList
if isAuthzExecMsg(msg) {
subMsgs, err := msg.(*authz.MsgExec).GetMessages()
if err != nil {
panic(err)
}
msgList = append(msgList, subMsgs...)
} else {
msgList = append(msgList, msg)
}
}
// Categorize messages into SSI and non-SSI
ssiMsgs := []SSIMsg{}
nonSsiMsgs := []NonSSIMsg{}
for _, msg := range msgList {
if isSSIMsg(msg) {
ssiMsgs = append(ssiMsgs, msg)
} else {
nonSsiMsgs = append(nonSsiMsgs, msg)
}
}
return ssiMsgs, nonSsiMsgs
}