Skip to content

Commit

Permalink
updating query responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratik authored and Pratik committed Jul 1, 2022
1 parent a630a1f commit 337008d
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions x/lend/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (q queryServer) QueryLend(c context.Context, req *types.QueryLendRequest) (

item, found := q.GetLend(ctx, req.Id)
if !found {
return nil, status.Errorf(codes.NotFound, "lend position does not exist for id %d", req.Id)
return &types.QueryLendResponse{}, nil
}

return &types.QueryLendResponse{
Expand All @@ -94,7 +94,10 @@ func (q queryServer) QueryAllLendByOwner(c context.Context, req *types.QueryAllL
return nil, status.Errorf(codes.NotFound, "Address is not correct")
}

userVaultAssetData, _ := q.UserLends(ctx, req.Owner)
userVaultAssetData, found := q.UserLends(ctx, req.Owner)
if !found {
return &types.QueryAllLendByOwnerResponse{}, nil
}

for _, data := range userVaultAssetData {
lends = append(lends, data)
Expand All @@ -120,7 +123,10 @@ func (q queryServer) QueryAllLendByOwnerAndPool(c context.Context, req *types.Qu
return nil, status.Errorf(codes.NotFound, "Address is not correct")
}

userVaultAssetData, _ := q.LendIdByOwnerAndPool(ctx, req.Owner, req.PoolId)
userVaultAssetData, found := q.LendIdByOwnerAndPool(ctx, req.Owner, req.PoolId)
if !found {
return &types.QueryAllLendByOwnerAndPoolResponse{}, nil
}

for _, data := range userVaultAssetData {
lends = append(lends, data)
Expand All @@ -146,7 +152,10 @@ func (q queryServer) QueryAllBorrowByOwnerAndPool(c context.Context, req *types.
return nil, status.Errorf(codes.NotFound, "Address is not correct")
}

userVaultAssetData, _ := q.BorrowIdByOwnerAndPool(ctx, req.Owner, req.PoolId)
userVaultAssetData, found := q.BorrowIdByOwnerAndPool(ctx, req.Owner, req.PoolId)
if !found {
return &types.QueryAllBorrowByOwnerAndPoolResponse{}, nil
}

for _, data := range userVaultAssetData {
borrows = append(borrows, data)
Expand Down Expand Up @@ -206,7 +215,7 @@ func (q queryServer) QueryPair(c context.Context, req *types.QueryPairRequest) (

item, found := q.GetLendPair(ctx, req.Id)
if !found {
return nil, status.Errorf(codes.NotFound, "pair does not exist for id %d", req.Id)
return &types.QueryPairResponse{}, nil
}

return &types.QueryPairResponse{
Expand Down Expand Up @@ -262,7 +271,7 @@ func (q queryServer) QueryPool(c context.Context, req *types.QueryPoolRequest) (

item, found := q.GetPool(ctx, req.Id)
if !found {
return nil, status.Errorf(codes.NotFound, "pool does not exist for id %d", req.Id)
return &types.QueryPoolResponse{}, nil
}

return &types.QueryPoolResponse{
Expand Down Expand Up @@ -318,7 +327,7 @@ func (q queryServer) QueryAssetToPairMapping(c context.Context, req *types.Query

item, found := q.GetAssetToPair(ctx, req.AssetId, req.PoolId)
if !found {
return nil, status.Errorf(codes.NotFound, "pairs does not exist for assetId and poolId %d", req.AssetId, req.PoolId)
return &types.QueryAssetToPairMappingResponse{}, nil
}

return &types.QueryAssetToPairMappingResponse{
Expand Down Expand Up @@ -374,7 +383,7 @@ func (q queryServer) QueryBorrow(c context.Context, req *types.QueryBorrowReques

item, found := q.GetBorrow(ctx, req.Id)
if !found {
return nil, status.Errorf(codes.NotFound, "borrow does not exist for id %d", req.Id)
return &types.QueryBorrowResponse{}, nil
}

return &types.QueryBorrowResponse{
Expand All @@ -396,7 +405,10 @@ func (q queryServer) QueryAllBorrowByOwner(c context.Context, req *types.QueryAl
return nil, status.Errorf(codes.NotFound, "Address is not correct")
}

userVaultAssetData, _ := q.UserBorrows(ctx, req.Owner)
userVaultAssetData, found := q.UserBorrows(ctx, req.Owner)
if !found {
return &types.QueryAllBorrowByOwnerResponse{}, nil
}

for _, data := range userVaultAssetData {
borrows = append(borrows, data)
Expand Down Expand Up @@ -456,7 +468,7 @@ func (q queryServer) QueryAssetRatesStat(c context.Context, req *types.QueryAsse

item, found := q.GetAssetRatesStats(ctx, req.Id)
if !found {
return nil, status.Errorf(codes.NotFound, "asset-rates-stat does not exist for id %d", req.Id)
return &types.QueryAssetRatesStatResponse{}, nil
}

return &types.QueryAssetRatesStatResponse{
Expand All @@ -472,7 +484,7 @@ func (q queryServer) QueryAssetStats(c context.Context, req *types.QueryAssetSta

assetStatsData, found := q.AssetStatsByPoolIdAndAssetId(ctx, req.AssetId, req.PoolId)
if !found {
return nil, status.Errorf(codes.NotFound, "assetStatsData does not exist for assetId %d and poolId %d ", req.AssetId, req.PoolId)
return &types.QueryAssetStatsResponse{}, nil
}

return &types.QueryAssetStatsResponse{
Expand All @@ -488,7 +500,7 @@ func (q queryServer) QueryModuleBalance(c context.Context, req *types.QueryModul

modBal, found := q.GetModuleBalanceByPoolId(ctx, req.PoolId)
if !found {
return nil, status.Errorf(codes.NotFound, "module Balance does not exist for poolId %d ", req.PoolId)
return &types.QueryModuleBalanceResponse{}, nil
}

return &types.QueryModuleBalanceResponse{
Expand Down

0 comments on commit 337008d

Please sign in to comment.