@@ -9,11 +9,15 @@ import (
99 sdk "github.com/cosmos/cosmos-sdk/types"
1010 sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
1111 stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
12+ "github.com/gogo/protobuf/proto"
1213 "google.golang.org/grpc/codes"
1314 "google.golang.org/grpc/status"
1415
1516 appparams "github.com/osmosis-labs/osmosis/v15/app/params"
1617
18+ "github.com/cosmos/cosmos-sdk/store/prefix"
19+ "github.com/cosmos/cosmos-sdk/types/query"
20+
1721 lockuptypes "github.com/osmosis-labs/osmosis/v15/x/lockup/types"
1822 "github.com/osmosis-labs/osmosis/v15/x/superfluid/types"
1923)
@@ -90,22 +94,45 @@ func (q Querier) AssetMultiplier(goCtx context.Context, req *types.AssetMultipli
9094}
9195
9296// AllIntermediaryAccounts returns all superfluid intermediary accounts.
93- func (q Querier ) AllIntermediaryAccounts (goCtx context.Context , _ * types.AllIntermediaryAccountsRequest ) (* types.AllIntermediaryAccountsResponse , error ) {
94- ctx := sdk .UnwrapSDKContext (goCtx )
95- accounts := q .Keeper .GetAllIntermediaryAccounts (ctx )
97+ func (q Querier ) AllIntermediaryAccounts (goCtx context.Context , req * types.AllIntermediaryAccountsRequest ) (* types.AllIntermediaryAccountsResponse , error ) {
98+ if req == nil {
99+ return nil , status .Error (codes .InvalidArgument , "empty request" )
100+ }
101+ sdkCtx := sdk .UnwrapSDKContext (goCtx )
102+ store := sdkCtx .KVStore (q .Keeper .storeKey )
103+ accStore := prefix .NewStore (store , types .KeyPrefixIntermediaryAccount )
104+ iterator := sdk .KVStorePrefixIterator (accStore , nil )
105+ defer iterator .Close ()
106+
96107 accInfos := []types.SuperfluidIntermediaryAccountInfo {}
97108
98- for _ , acc := range accounts {
99- accInfos = append (accInfos , types.SuperfluidIntermediaryAccountInfo {
100- Denom : acc .Denom ,
101- ValAddr : acc .ValAddr ,
102- GaugeId : acc .GaugeId ,
103- Address : acc .GetAccAddress ().String (),
109+ pageRes , err := query .FilteredPaginate (accStore , req .Pagination ,
110+ func (key , value []byte , accumulate bool ) (bool , error ) {
111+ account := types.SuperfluidIntermediaryAccount {}
112+ err := proto .Unmarshal (iterator .Value (), & account )
113+ if err != nil {
114+ return false , err
115+ }
116+ iterator .Next ()
117+
118+ accountInfo := types.SuperfluidIntermediaryAccountInfo {
119+ Denom : account .Denom ,
120+ ValAddr : account .ValAddr ,
121+ GaugeId : account .GaugeId ,
122+ Address : account .GetAccAddress ().String (),
123+ }
124+ if accumulate {
125+ accInfos = append (accInfos , accountInfo )
126+ }
127+ return true , nil
104128 })
129+ if err != nil {
130+ return nil , status .Error (codes .Internal , err .Error ())
105131 }
106132
107133 return & types.AllIntermediaryAccountsResponse {
108- Accounts : accInfos ,
134+ Accounts : accInfos ,
135+ Pagination : pageRes ,
109136 }, nil
110137}
111138
0 commit comments