-
Notifications
You must be signed in to change notification settings - Fork 13
/
msg_server_router.go
142 lines (121 loc) · 4.87 KB
/
msg_server_router.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package keeper
import (
"context"
"fmt"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/functionx/fx-core/v2/x/crosschain/types"
)
type msgServer struct {
routerKeeper RouterKeeper
}
// NewMsgServerRouterImpl returns an implementation of the crosschain router MsgServer interface
// for the provided Keeper.
func NewMsgServerRouterImpl(routerKeeper RouterKeeper) types.MsgServer {
return &msgServer{routerKeeper: routerKeeper}
}
var _ types.MsgServer = msgServer{}
func (k msgServer) BondedOracle(ctx context.Context, msg *types.MsgBondedOracle) (*types.MsgBondedOracleResponse, error) {
if queryServer, err := k.getMsgServerByChainName(msg.GetChainName()); err != nil {
return nil, err
} else {
return queryServer.BondedOracle(ctx, msg)
}
}
func (k msgServer) AddDelegate(ctx context.Context, msg *types.MsgAddDelegate) (*types.MsgAddDelegateResponse, error) {
if queryServer, err := k.getMsgServerByChainName(msg.GetChainName()); err != nil {
return nil, err
} else {
return queryServer.AddDelegate(ctx, msg)
}
}
func (k msgServer) EditOracle(ctx context.Context, msg *types.MsgEditOracle) (*types.MsgEditOracleResponse, error) {
if queryServer, err := k.getMsgServerByChainName(msg.GetChainName()); err != nil {
return nil, err
} else {
return queryServer.EditOracle(ctx, msg)
}
}
func (k msgServer) WithdrawReward(ctx context.Context, msg *types.MsgWithdrawReward) (*types.MsgWithdrawRewardResponse, error) {
if queryServer, err := k.getMsgServerByChainName(msg.GetChainName()); err != nil {
return nil, err
} else {
return queryServer.WithdrawReward(ctx, msg)
}
}
func (k msgServer) UnbondedOracle(ctx context.Context, msg *types.MsgUnbondedOracle) (*types.MsgUnbondedOracleResponse, error) {
if queryServer, err := k.getMsgServerByChainName(msg.GetChainName()); err != nil {
return nil, err
} else {
return queryServer.UnbondedOracle(ctx, msg)
}
}
func (k msgServer) OracleSetConfirm(ctx context.Context, msg *types.MsgOracleSetConfirm) (*types.MsgOracleSetConfirmResponse, error) {
if queryServer, err := k.getMsgServerByChainName(msg.GetChainName()); err != nil {
return nil, err
} else {
return queryServer.OracleSetConfirm(ctx, msg)
}
}
func (k msgServer) OracleSetUpdateClaim(ctx context.Context, msg *types.MsgOracleSetUpdatedClaim) (*types.MsgOracleSetUpdatedClaimResponse, error) {
if queryServer, err := k.getMsgServerByChainName(msg.GetChainName()); err != nil {
return nil, err
} else {
return queryServer.OracleSetUpdateClaim(ctx, msg)
}
}
func (k msgServer) BridgeTokenClaim(ctx context.Context, msg *types.MsgBridgeTokenClaim) (*types.MsgBridgeTokenClaimResponse, error) {
if queryServer, err := k.getMsgServerByChainName(msg.GetChainName()); err != nil {
return nil, err
} else {
return queryServer.BridgeTokenClaim(ctx, msg)
}
}
func (k msgServer) SendToFxClaim(ctx context.Context, msg *types.MsgSendToFxClaim) (*types.MsgSendToFxClaimResponse, error) {
if queryServer, err := k.getMsgServerByChainName(msg.GetChainName()); err != nil {
return nil, err
} else {
return queryServer.SendToFxClaim(ctx, msg)
}
}
func (k msgServer) SendToExternal(ctx context.Context, msg *types.MsgSendToExternal) (*types.MsgSendToExternalResponse, error) {
if queryServer, err := k.getMsgServerByChainName(msg.GetChainName()); err != nil {
return nil, err
} else {
return queryServer.SendToExternal(ctx, msg)
}
}
func (k msgServer) CancelSendToExternal(ctx context.Context, msg *types.MsgCancelSendToExternal) (*types.MsgCancelSendToExternalResponse, error) {
if queryServer, err := k.getMsgServerByChainName(msg.GetChainName()); err != nil {
return nil, err
} else {
return queryServer.CancelSendToExternal(ctx, msg)
}
}
func (k msgServer) SendToExternalClaim(ctx context.Context, msg *types.MsgSendToExternalClaim) (*types.MsgSendToExternalClaimResponse, error) {
if queryServer, err := k.getMsgServerByChainName(msg.GetChainName()); err != nil {
return nil, err
} else {
return queryServer.SendToExternalClaim(ctx, msg)
}
}
func (k msgServer) RequestBatch(ctx context.Context, msg *types.MsgRequestBatch) (*types.MsgRequestBatchResponse, error) {
if queryServer, err := k.getMsgServerByChainName(msg.GetChainName()); err != nil {
return nil, err
} else {
return queryServer.RequestBatch(ctx, msg)
}
}
func (k msgServer) ConfirmBatch(ctx context.Context, msg *types.MsgConfirmBatch) (*types.MsgConfirmBatchResponse, error) {
if queryServer, err := k.getMsgServerByChainName(msg.GetChainName()); err != nil {
return nil, err
} else {
return queryServer.ConfirmBatch(ctx, msg)
}
}
func (k msgServer) getMsgServerByChainName(chainName string) (types.MsgServer, error) {
msgServerRouter := k.routerKeeper.Router()
if !msgServerRouter.HasRoute(chainName) {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, fmt.Sprintf("Unrecognized cross chain type:%s", chainName))
}
return msgServerRouter.GetRoute(chainName).MsgServer, nil
}