3535 AccountByNumber = collections .NewPrefix (2 )
3636)
3737
38- // QueryRouter represents a router which can be used to route queries to the correct module.
39- // It returns the handler given the message name, if multiple handlers are returned, then
40- // it is up to the caller to choose which one to call.
41- type QueryRouter interface {
42- HybridHandlerByRequestName (name string ) []func (ctx context.Context , req , resp implementation.ProtoMsg ) error
43- }
44-
45- // MsgRouter represents a router which can be used to route messages to the correct module.
46- type MsgRouter interface {
47- HybridHandlerByMsgName (msgName string ) func (ctx context.Context , req , resp implementation.ProtoMsg ) error
48- ResponseNameByMsgName (name string ) string
49- }
50-
5138type InterfaceRegistry interface {
5239 RegisterInterface (name string , iface any , impls ... protoiface.MessageV1 )
5340 RegisterImplementations (iface any , impls ... protoiface.MessageV1 )
@@ -57,18 +44,14 @@ func NewKeeper(
5744 cdc codec.Codec ,
5845 env appmodule.Environment ,
5946 addressCodec address.Codec ,
60- execRouter MsgRouter ,
61- queryRouter QueryRouter ,
6247 ir InterfaceRegistry ,
6348 accounts ... accountstd.AccountCreatorFunc ,
6449) (Keeper , error ) {
6550 sb := collections .NewSchemaBuilder (env .KVStoreService )
6651 keeper := Keeper {
6752 environment : env ,
68- addressCodec : addressCodec ,
69- msgRouter : execRouter ,
7053 codec : cdc ,
71- queryRouter : queryRouter ,
54+ addressCodec : addressCodec ,
7255 makeSendCoinsMsg : defaultCoinsTransferMsgFunc (addressCodec ),
7356 Schema : collections.Schema {},
7457 AccountNumber : collections .NewSequence (sb , AccountNumberKey , "account_number" ),
@@ -95,8 +78,6 @@ type Keeper struct {
9578 environment appmodule.Environment
9679 addressCodec address.Codec
9780 codec codec.Codec
98- msgRouter MsgRouter // todo use env
99- queryRouter QueryRouter // todo use env
10081 makeSendCoinsMsg coinsTransferMsgFunc
10182
10283 accounts map [string ]implementation.Implementation
@@ -343,17 +324,11 @@ func (k Keeper) sendAnyMessages(ctx context.Context, sender []byte, anyMessages
343324// SendModuleMessageUntyped can be used to send a message towards a module.
344325// It should be used when the response type is not known by the caller.
345326func (k Keeper ) SendModuleMessageUntyped (ctx context.Context , sender []byte , msg implementation.ProtoMsg ) (implementation.ProtoMsg , error ) {
346- // we need to fetch the response type from the request message type.
347- // this is because the response type is not known.
348- respName := k .msgRouter .ResponseNameByMsgName (implementation .MessageName (msg ))
349- if respName == "" {
350- return nil , fmt .Errorf ("could not find response type for message %T" , msg )
351- }
352- // get response type
353- resp , err := implementation .FindMessageByName (respName )
327+ resp , err := k .environment .RouterService .MessageRouterService ().InvokeUntyped (ctx , msg )
354328 if err != nil {
355329 return nil , err
356330 }
331+
357332 // send the message
358333 return resp , k .sendModuleMessage (ctx , sender , msg , resp )
359334}
@@ -373,27 +348,14 @@ func (k Keeper) sendModuleMessage(ctx context.Context, sender []byte, msg, msgRe
373348 if ! bytes .Equal (sender , wantSenders [0 ]) {
374349 return fmt .Errorf ("%w: sender does not match expected sender" , ErrUnauthorized )
375350 }
376- messageName := implementation .MessageName (msg )
377- handler := k .msgRouter .HybridHandlerByMsgName (messageName )
378- if handler == nil {
379- return fmt .Errorf ("unknown message: %s" , messageName )
380- }
381- return handler (ctx , msg , msgResp )
351+ return k .environment .RouterService .MessageRouterService ().InvokeTyped (ctx , msg , msgResp )
382352}
383353
384354// queryModule is the entrypoint for an account to query a module.
385355// It will try to find the query handler for the given query and execute it.
386356// If multiple query handlers are found, it will return an error.
387357func (k Keeper ) queryModule (ctx context.Context , queryReq , queryResp implementation.ProtoMsg ) error {
388- queryName := implementation .MessageName (queryReq )
389- handlers := k .queryRouter .HybridHandlerByRequestName (queryName )
390- if len (handlers ) == 0 {
391- return fmt .Errorf ("unknown query: %s" , queryName )
392- }
393- if len (handlers ) > 1 {
394- return fmt .Errorf ("multiple handlers for query: %s" , queryName )
395- }
396- return handlers [0 ](ctx , queryReq , queryResp )
358+ return k .environment .RouterService .QueryRouterService ().InvokeTyped (ctx , queryReq , queryResp )
397359}
398360
399361// maybeSendFunds will send the provided coins between the provided addresses, if amt
0 commit comments