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

CNS-252: Added chain ID and enabled API interfaces to show-all-chains output #267

Merged
merged 6 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion proto/spec/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ message QueryShowAllChainsRequest {
}

message QueryShowAllChainsResponse {
repeated string chainNames = 1;
reserved 1;
repeated showAllChainsInfoStruct chainInfoList = 2;
}
message showAllChainsInfoStruct {
string chainName = 3;
oren-lava marked this conversation as resolved.
Show resolved Hide resolved
string chainID = 4;
repeated string enabledApiInterfaces = 5;
}

message QueryShowChainInfoRequest {
Expand Down
46 changes: 40 additions & 6 deletions x/spec/keeper/grpc_query_show_all_chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,54 @@ import (
)

func (k Keeper) ShowAllChains(goCtx context.Context, req *types.QueryShowAllChainsRequest) (*types.QueryShowAllChainsResponse, error) {
var chainInfoList []*types.ShowAllChainsInfoStruct
ctx := sdk.UnwrapSDKContext(goCtx)

if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)
var names []string

// get all spec
allSpec := k.GetAllSpec(ctx)

// iterate over specs and extract the chain's name
// iterate over specs and extract the chains' info
for _, spec := range allSpec {
names = append(names, spec.GetName())
// get the spec's APIs
apis := spec.GetApis()
var apiInterfacesNames []string

// iterate over the APIs
for _, api := range apis {
oren-lava marked this conversation as resolved.
Show resolved Hide resolved
// get the API interfaces
apiInterfaces := api.GetApiInterfaces()

// iterate over the API interfaces
for _, apiInterface := range apiInterfaces {
// get the interface's name
apiInterfaceName := apiInterface.GetInterface()

// if the name wasn't already added to the apiInterfacesNames list, add it
if !checkIfInterfaceInList(apiInterfacesNames, apiInterfaceName) {
oren-lava marked this conversation as resolved.
Show resolved Hide resolved
apiInterfacesNames = append(apiInterfacesNames, apiInterfaceName)
}
}
}

// create a chainInfoEntry which includes the chain's name, ID and enabled interfaces
chainInfoEntry := types.ShowAllChainsInfoStruct{ChainName: spec.GetName(), ChainID: spec.GetIndex(), EnabledApiInterfaces: apiInterfacesNames}

// add the chainInfoEntry to the chainInfoList
chainInfoList = append(chainInfoList, &chainInfoEntry)
}

return &types.QueryShowAllChainsResponse{ChainNames: names}, nil
return &types.QueryShowAllChainsResponse{ChainInfoList: chainInfoList}, nil
}

func checkIfInterfaceInList(apiInterfacesNames []string, apiInterfaceToCheck string) bool {
oren-lava marked this conversation as resolved.
Show resolved Hide resolved
for _, apiInterface := range apiInterfacesNames {
if apiInterfaceToCheck == apiInterface {
return true
}
}
return false
}
Loading