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 2 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
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 = 1;
string chainID = 2;
repeated string enabledApiInterfaces = 3;
}

message QueryShowChainInfoRequest {
Expand Down
48 changes: 42 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,56 @@ 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()

// create API interface names map to efficiently check if an interface already exists in it
apiInterfacesNamesMap := make(map[string]int)

// 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()

// check if the interface exists in the map
_, found := apiInterfacesNamesMap[apiInterfaceName]

// if the interface name wasn't found, add it to the map (put dummy value 0)
if !found {
apiInterfacesNamesMap[apiInterfaceName] = 0
}
}
}

// copy the apiInterfacesNamesMap's keys (which are the interface names) to a string list
var apiInterfacesNames []string
for apiInterfacesName := range apiInterfacesNamesMap {
apiInterfacesNames = append(apiInterfacesNames, apiInterfacesName)
oren-lava marked this conversation as resolved.
Show resolved Hide resolved
}

// 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
}
Loading