-
Notifications
You must be signed in to change notification settings - Fork 5
/
common.go
62 lines (52 loc) · 1.39 KB
/
common.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
package msgs
import (
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
cdc "github.com/kaifei-bianjie/msg-parser/codec"
models "github.com/kaifei-bianjie/msg-parser/types"
"github.com/kaifei-bianjie/msg-parser/utils"
)
func CreateMsgDocInfo(msg sdk.Msg, handler func() (Msg, []string)) MsgDocInfo {
var (
docTxMsg models.TxMsg
signers []string
addrs []string
)
m, addrcollections := handler()
m.BuildMsg(msg)
docTxMsg = models.TxMsg{
Type: m.GetType(),
Msg: m,
}
_, signers = models.BuildDocSigners(msg.GetSigners())
addrs = append(addrs, signers...)
addrs = append(addrs, addrcollections...)
return MsgDocInfo{
DocTxMsg: docTxMsg,
Signers: signers,
Addrs: addrs,
}
}
// ConvertMsg
// Deprecated, use type assertion instead of this
func ConvertMsg(v interface{}, msg interface{}) {
utils.UnMarshalJsonIgnoreErr(utils.MarshalJsonIgnoreErr(v), &msg)
}
func ConvertAny(v *types.Any) string {
if v != nil {
return utils.MarshalJsonIgnoreErr(v)
}
return ""
}
func UnmarshalAcknowledgement(bytesdata []byte) string {
var result Acknowledgement
cdc.GetMarshaler().MustUnmarshalJSON(bytesdata, &result)
return result.String()
}
func UnmarshalTibcAcknowledgement(bytesdata []byte) string {
var result TIBCAcknowledgement
if err := cdc.GetMarshaler().Unmarshal(bytesdata, &result); err == nil {
return result.String()
}
return ""
}