Skip to content

Commit

Permalink
Merge pull request #98 from onomyprotocol/dong/query-collaterals-by-d…
Browse files Browse the repository at this point in the history
…enom

vaults: add query Collaterals by denom
  • Loading branch information
DongLieu authored Nov 12, 2024
2 parents 3cb3dcc + 0dc129e commit ebdf6f1
Show file tree
Hide file tree
Showing 4 changed files with 542 additions and 40 deletions.
12 changes: 12 additions & 0 deletions proto/reserve/vaults/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ service Query {
option (google.api.http).get = "/reserve/vaults/params";
}

rpc QueryCollateralsByDenom(QueryCollateralsByDenomRequest) returns (QueryCollateralsByDenomResponse){
option (google.api.http).get = "/reserve/vaults/params";
}

rpc QueryAllVaults(QueryAllVaultsRequest) returns (QueryAllVaultsResponse){
option (google.api.http).get = "/reserve/vaults/params";
}
Expand Down Expand Up @@ -64,6 +68,14 @@ message QueryAllCollateralResponse{
repeated VaultMamager all_vault_mamager = 1;
}

message QueryCollateralsByDenomRequest {
string denom = 1;
}

message QueryCollateralsByDenomResponse{
repeated VaultMamager all_vault_mamager_by_denom = 1;
}

message QueryVaultByOwnerRequest {
string address = 1;
}
Expand Down
16 changes: 16 additions & 0 deletions x/vaults/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ func (q queryServer) QueryAllCollateral(ctx context.Context, req *types.QueryAll
}, err
}

func (q queryServer) QueryCollateralsByDenom(ctx context.Context, req *types.QueryCollateralsByDenomRequest) (*types.QueryCollateralsByDenomResponse, error) {
allCollateral := []*types.VaultMamager{}

err := q.keeper.VaultsManager.Walk(ctx, nil, func(key string, value types.VaultMamager) (stop bool, err error) {
if value.Denom == req.Denom {
allCollateral = append(allCollateral, &value)
}

return false, nil
})

return &types.QueryCollateralsByDenomResponse{
AllVaultMamagerByDenom: allCollateral,
}, err
}

func (q queryServer) QueryAllVaults(ctx context.Context, req *types.QueryAllVaultsRequest) (*types.QueryAllVaultsResponse, error) {
allVaults := []*types.Vault{}

Expand Down
Loading

0 comments on commit ebdf6f1

Please sign in to comment.