Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oracle,Vaults: add query cli oraclescript by symbol,.. #101

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion proto/reserve/oracle/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ service Query {
returns (QueryBandOracleRequestResponse) {
option (google.api.http).get =
"/reserve/oracle/band_oracle_request";
}
}

rpc QueryOracleScriptIdByDenom(QueryOracleScriptIdByDenomRequest)
returns (QueryOracleScriptIdByDenomResponse) {
option (google.api.http).get =
"/reserve/oracle/band_price_states";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand Down Expand Up @@ -111,4 +117,13 @@ message QueryBandOracleRequestRequest {
// Query/QueryBandOracleRequest RPC method.
message QueryBandOracleRequestResponse {
BandOracleRequest band_oracle_request = 1;
}

message QueryOracleScriptIdByDenomRequest {
string denom = 1;
}


message QueryOracleScriptIdByDenomResponse {
repeated int64 oracle_script_ids = 1;
}
27 changes: 26 additions & 1 deletion proto/reserve/vaults/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ service Query {
option (google.api.http).get = "/reserve/vaults/params";
}

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

rpc QueryCollateralsByMintDenom(QueryCollateralsByMintDenomRequest) returns (QueryCollateralsByMintDenomResponse){
option (google.api.http).get = "/reserve/vaults/params";
}

rpc QueryCollateralsByDenomMintDenom(QueryCollateralsByDenomMintDenomRequest) returns (QueryCollateralsByDenomMintDenomResponse){
option (google.api.http).get = "/reserve/vaults/params";
}

Expand Down Expand Up @@ -76,6 +84,23 @@ message QueryCollateralsByDenomResponse{
repeated VaultMamager all_vault_mamager_by_denom = 1;
}

message QueryCollateralsByMintDenomRequest {
string mint_denom = 1;
}

message QueryCollateralsByMintDenomResponse{
repeated VaultMamager all_vault_mamager_by_mint_denom = 1;
}

message QueryCollateralsByDenomMintDenomRequest {
string denom = 1;
string mint_denom = 2;
}

message QueryCollateralsByDenomMintDenomResponse{
VaultMamager vault_mamager = 1;
}

message QueryVaultByOwnerRequest {
string address = 1;
}
Expand Down
27 changes: 26 additions & 1 deletion x/oracle/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cli

import (
"fmt"
"context"
"fmt"
"strconv"

"github.com/cosmos/gogoproto/proto"
Expand Down Expand Up @@ -31,6 +31,7 @@ func GetQueryCmd() *cobra.Command {
GetBandParams(),
GetBandOracleRequestParams(),
GetBandOracleRequest(),
GetQueryOracleScriptIdByDenomCmd(),
)
return cmd
}
Expand Down Expand Up @@ -183,3 +184,27 @@ func GetBandOracleRequest() *cobra.Command {
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

func GetQueryOracleScriptIdByDenomCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "oracle-scriptId-by-symbol [symbol]",
Short: "Get oracle-scriptId by symbol",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.QueryOracleScriptIdByDenom(context.Background(), &types.QueryOracleScriptIdByDenomRequest{Denom: args[0]})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
return cmd
}
18 changes: 18 additions & 0 deletions x/oracle/keeper/band_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ func (k Keeper) GetAllBandOracleRequests(ctx context.Context) []*types.BandOracl
return bandOracleRequests
}

func (k Keeper) IteratorOracleRequests(ctx context.Context, fn func(bandOracleRequest types.BandOracleRequest) bool) error {
kvStore := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
bandOracleRequestStore := prefix.NewStore(kvStore, types.BandOracleRequestIDKey)

iterator := bandOracleRequestStore.Iterator(nil, nil)
defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
var bandOracleRequest types.BandOracleRequest
k.cdc.MustUnmarshal(iterator.Value(), &bandOracleRequest)
if fn(bandOracleRequest) {
return nil
}
}

return nil
}

// GetBandPriceState reads the stored band ibc price state.
func (k *Keeper) GetBandPriceState(ctx context.Context, symbol string) *types.BandPriceState {
var priceState types.BandPriceState
Expand Down
21 changes: 21 additions & 0 deletions x/oracle/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"slices"
"strconv"

errors "cosmossdk.io/errors"
Expand Down Expand Up @@ -69,3 +70,23 @@ func (k Keeper) BandOracleRequest(c context.Context, q *types.QueryBandOracleReq
}
return res, nil
}

func (k Keeper) QueryOracleScriptIdByDenom(c context.Context, q *types.QueryOracleScriptIdByDenomRequest) (*types.QueryOracleScriptIdByDenomResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
allIds := []int64{}

err := k.IteratorOracleRequests(ctx, func(bandOracleRequest types.BandOracleRequest) bool {
if slices.Contains(bandOracleRequest.Symbols, q.Denom) {
allIds = append(allIds, bandOracleRequest.OracleScriptId)
}
return false
})
if err != nil {
return nil, err
}
res := &types.QueryOracleScriptIdByDenomResponse{

OracleScriptIds: allIds,
}
return res, nil
}
Loading
Loading