@@ -19,9 +19,15 @@ import (
1919 "github.com/cosmos/cosmos-sdk/x/auth/types"
2020)
2121
22- var _ types.QueryServer = AccountKeeper {}
22+ var _ types.QueryServer = queryServer {}
2323
24- func (ak AccountKeeper ) AccountAddressByID (c context.Context , req * types.QueryAccountAddressByIDRequest ) (* types.QueryAccountAddressByIDResponse , error ) {
24+ func NewQueryServer (k AccountKeeper ) types.QueryServer {
25+ return queryServer {k : k }
26+ }
27+
28+ type queryServer struct { k AccountKeeper }
29+
30+ func (s queryServer ) AccountAddressByID (c context.Context , req * types.QueryAccountAddressByIDRequest ) (* types.QueryAccountAddressByIDResponse , error ) {
2531 if req == nil {
2632 return nil , status .Errorf (codes .InvalidArgument , "empty request" )
2733 }
@@ -33,25 +39,25 @@ func (ak AccountKeeper) AccountAddressByID(c context.Context, req *types.QueryAc
3339 accID := req .AccountId
3440
3541 ctx := sdk .UnwrapSDKContext (c )
36- address := ak .GetAccountAddressByID (ctx , accID )
42+ address := s . k .GetAccountAddressByID (ctx , accID )
3743 if len (address ) == 0 {
3844 return nil , status .Errorf (codes .NotFound , "account address not found with account number %d" , req .Id )
3945 }
4046
4147 return & types.QueryAccountAddressByIDResponse {AccountAddress : address }, nil
4248}
4349
44- func (ak AccountKeeper ) Accounts (ctx context.Context , req * types.QueryAccountsRequest ) (* types.QueryAccountsResponse , error ) {
50+ func (s queryServer ) Accounts (ctx context.Context , req * types.QueryAccountsRequest ) (* types.QueryAccountsResponse , error ) {
4551 if req == nil {
4652 return nil , status .Error (codes .InvalidArgument , "empty request" )
4753 }
4854
49- store := ak .storeService .OpenKVStore (ctx )
55+ store := s . k .storeService .OpenKVStore (ctx )
5056 accountsStore := prefix .NewStore (runtime .KVStoreAdapter (store ), types .AddressStoreKeyPrefix )
5157
5258 var accounts []* codectypes.Any
5359 pageRes , err := query .Paginate (accountsStore , req .Pagination , func (key , value []byte ) error {
54- account := ak .decodeAccount (value )
60+ account := s . k .decodeAccount (value )
5561 any , err := codectypes .NewAnyWithValue (account )
5662 if err != nil {
5763 return err
@@ -68,7 +74,7 @@ func (ak AccountKeeper) Accounts(ctx context.Context, req *types.QueryAccountsRe
6874}
6975
7076// Account returns account details based on address
71- func (ak AccountKeeper ) Account (c context.Context , req * types.QueryAccountRequest ) (* types.QueryAccountResponse , error ) {
77+ func (s queryServer ) Account (c context.Context , req * types.QueryAccountRequest ) (* types.QueryAccountResponse , error ) {
7278 if req == nil {
7379 return nil , status .Errorf (codes .InvalidArgument , "empty request" )
7480 }
@@ -78,11 +84,11 @@ func (ak AccountKeeper) Account(c context.Context, req *types.QueryAccountReques
7884 }
7985
8086 ctx := sdk .UnwrapSDKContext (c )
81- addr , err := ak .StringToBytes (req .Address )
87+ addr , err := s . k .StringToBytes (req .Address )
8288 if err != nil {
8389 return nil , err
8490 }
85- account := ak .GetAccount (ctx , addr )
91+ account := s . k .GetAccount (ctx , addr )
8692 if account == nil {
8793 return nil , status .Errorf (codes .NotFound , "account %s not found" , req .Address )
8894 }
@@ -96,35 +102,35 @@ func (ak AccountKeeper) Account(c context.Context, req *types.QueryAccountReques
96102}
97103
98104// Params returns parameters of auth module
99- func (ak AccountKeeper ) Params (c context.Context , req * types.QueryParamsRequest ) (* types.QueryParamsResponse , error ) {
105+ func (s queryServer ) Params (c context.Context , req * types.QueryParamsRequest ) (* types.QueryParamsResponse , error ) {
100106 if req == nil {
101107 return nil , status .Error (codes .InvalidArgument , "empty request" )
102108 }
103109 ctx := sdk .UnwrapSDKContext (c )
104- params := ak .GetParams (ctx )
110+ params := s . k .GetParams (ctx )
105111
106112 return & types.QueryParamsResponse {Params : params }, nil
107113}
108114
109115// ModuleAccounts returns all the existing Module Accounts
110- func (ak AccountKeeper ) ModuleAccounts (c context.Context , req * types.QueryModuleAccountsRequest ) (* types.QueryModuleAccountsResponse , error ) {
116+ func (s queryServer ) ModuleAccounts (c context.Context , req * types.QueryModuleAccountsRequest ) (* types.QueryModuleAccountsResponse , error ) {
111117 if req == nil {
112118 return nil , status .Error (codes .InvalidArgument , "empty request" )
113119 }
114120
115121 ctx := sdk .UnwrapSDKContext (c )
116122
117123 // For deterministic output, sort the permAddrs by module name.
118- sortedPermAddrs := make ([]string , 0 , len (ak .permAddrs ))
119- for moduleName := range ak .permAddrs {
124+ sortedPermAddrs := make ([]string , 0 , len (s . k .permAddrs ))
125+ for moduleName := range s . k .permAddrs {
120126 sortedPermAddrs = append (sortedPermAddrs , moduleName )
121127 }
122128 sort .Strings (sortedPermAddrs )
123129
124- modAccounts := make ([]* codectypes.Any , 0 , len (ak .permAddrs ))
130+ modAccounts := make ([]* codectypes.Any , 0 , len (s . k .permAddrs ))
125131
126132 for _ , moduleName := range sortedPermAddrs {
127- account := ak .GetModuleAccount (ctx , moduleName )
133+ account := s . k .GetModuleAccount (ctx , moduleName )
128134 if account == nil {
129135 return nil , status .Errorf (codes .NotFound , "account %s not found" , moduleName )
130136 }
@@ -139,7 +145,7 @@ func (ak AccountKeeper) ModuleAccounts(c context.Context, req *types.QueryModule
139145}
140146
141147// ModuleAccountByName returns module account by module name
142- func (ak AccountKeeper ) ModuleAccountByName (c context.Context , req * types.QueryModuleAccountByNameRequest ) (* types.QueryModuleAccountByNameResponse , error ) {
148+ func (s queryServer ) ModuleAccountByName (c context.Context , req * types.QueryModuleAccountByNameRequest ) (* types.QueryModuleAccountByNameResponse , error ) {
143149 if req == nil {
144150 return nil , status .Errorf (codes .InvalidArgument , "empty request" )
145151 }
@@ -151,7 +157,7 @@ func (ak AccountKeeper) ModuleAccountByName(c context.Context, req *types.QueryM
151157 ctx := sdk .UnwrapSDKContext (c )
152158 moduleName := req .Name
153159
154- account := ak .GetModuleAccount (ctx , moduleName )
160+ account := s . k .GetModuleAccount (ctx , moduleName )
155161 if account == nil {
156162 return nil , status .Errorf (codes .NotFound , "account %s not found" , moduleName )
157163 }
@@ -164,8 +170,8 @@ func (ak AccountKeeper) ModuleAccountByName(c context.Context, req *types.QueryM
164170}
165171
166172// Bech32Prefix returns the keeper internally stored bech32 prefix.
167- func (ak AccountKeeper ) Bech32Prefix (ctx context.Context , req * types.Bech32PrefixRequest ) (* types.Bech32PrefixResponse , error ) {
168- bech32Prefix , err := ak .getBech32Prefix ()
173+ func (s queryServer ) Bech32Prefix (ctx context.Context , req * types.Bech32PrefixRequest ) (* types.Bech32PrefixResponse , error ) {
174+ bech32Prefix , err := s . k .getBech32Prefix ()
169175 if err != nil {
170176 return nil , err
171177 }
@@ -175,7 +181,7 @@ func (ak AccountKeeper) Bech32Prefix(ctx context.Context, req *types.Bech32Prefi
175181
176182// AddressBytesToString converts an address from bytes to string, using the
177183// keeper's bech32 prefix.
178- func (ak AccountKeeper ) AddressBytesToString (ctx context.Context , req * types.AddressBytesToStringRequest ) (* types.AddressBytesToStringResponse , error ) {
184+ func (s queryServer ) AddressBytesToString (ctx context.Context , req * types.AddressBytesToStringRequest ) (* types.AddressBytesToStringResponse , error ) {
179185 if req == nil {
180186 return nil , status .Error (codes .InvalidArgument , "empty request" )
181187 }
@@ -184,7 +190,7 @@ func (ak AccountKeeper) AddressBytesToString(ctx context.Context, req *types.Add
184190 return nil , errors .New ("empty address bytes is not allowed" )
185191 }
186192
187- text , err := ak .BytesToString (req .AddressBytes )
193+ text , err := s . k .BytesToString (req .AddressBytes )
188194 if err != nil {
189195 return nil , err
190196 }
@@ -194,7 +200,7 @@ func (ak AccountKeeper) AddressBytesToString(ctx context.Context, req *types.Add
194200
195201// AddressStringToBytes converts an address from string to bytes, using the
196202// keeper's bech32 prefix.
197- func (ak AccountKeeper ) AddressStringToBytes (ctx context.Context , req * types.AddressStringToBytesRequest ) (* types.AddressStringToBytesResponse , error ) {
203+ func (s queryServer ) AddressStringToBytes (ctx context.Context , req * types.AddressStringToBytesRequest ) (* types.AddressStringToBytesResponse , error ) {
198204 if req == nil {
199205 return nil , status .Error (codes .InvalidArgument , "empty request" )
200206 }
@@ -203,7 +209,7 @@ func (ak AccountKeeper) AddressStringToBytes(ctx context.Context, req *types.Add
203209 return nil , errors .New ("empty address string is not allowed" )
204210 }
205211
206- bz , err := ak .StringToBytes (req .AddressString )
212+ bz , err := s . k .StringToBytes (req .AddressString )
207213 if err != nil {
208214 return nil , err
209215 }
@@ -212,7 +218,7 @@ func (ak AccountKeeper) AddressStringToBytes(ctx context.Context, req *types.Add
212218}
213219
214220// AccountInfo implements the AccountInfo query.
215- func (ak AccountKeeper ) AccountInfo (goCtx context.Context , req * types.QueryAccountInfoRequest ) (* types.QueryAccountInfoResponse , error ) {
221+ func (s queryServer ) AccountInfo (goCtx context.Context , req * types.QueryAccountInfoRequest ) (* types.QueryAccountInfoResponse , error ) {
216222 if req == nil {
217223 return nil , status .Errorf (codes .InvalidArgument , "empty request" )
218224 }
@@ -222,12 +228,12 @@ func (ak AccountKeeper) AccountInfo(goCtx context.Context, req *types.QueryAccou
222228 }
223229
224230 ctx := sdk .UnwrapSDKContext (goCtx )
225- addr , err := ak .StringToBytes (req .Address )
231+ addr , err := s . k .StringToBytes (req .Address )
226232 if err != nil {
227233 return nil , err
228234 }
229235
230- account := ak .GetAccount (ctx , addr )
236+ account := s . k .GetAccount (ctx , addr )
231237 if account == nil {
232238 return nil , status .Errorf (codes .NotFound , "account %s not found" , req .Address )
233239 }
0 commit comments