use sum type in protobuf query

This commit is contained in:
Roy Crihfield 2023-10-18 19:29:37 -05:00 committed by Nabarun
parent 62d2d1598a
commit 8d7e26515b
3 changed files with 1052 additions and 385 deletions

View File

@ -67,17 +67,25 @@ message QueryParamsResponse {
// QueryListRecordsRequest is request type for registry records list
message QueryListRecordsRequest {
message ReferenceInput {
message LinkInput {
string id = 1;
}
message ArrayInput {
repeated ValueInput values = 1;
}
message MapInput {
map<string, ValueInput> values = 1;
}
message ValueInput {
string type = 1;
string string = 2;
int64 int = 3;
double float = 4;
bool boolean = 5;
ReferenceInput reference = 6;
repeated ValueInput values = 7;
oneof value {
string string = 1;
int64 int = 2;
double float = 3;
bool boolean = 4;
string link = 5;
ArrayInput array = 6;
MapInput map = 7;
}
}
message KeyValueInput {
string key = 1;

View File

@ -179,22 +179,26 @@ func (k Keeper) RecordsFromAttributes(ctx sdk.Context, attributes []*types.Query
}
func GetAttributeValue(input *types.QueryListRecordsRequest_ValueInput) interface{} {
if input.Type == "int" {
return input.GetInt()
switch value := input.GetValue().(type) {
case *types.QueryListRecordsRequest_ValueInput_String_:
return value.String_
case *types.QueryListRecordsRequest_ValueInput_Int:
return value.Int
case *types.QueryListRecordsRequest_ValueInput_Float:
return value.Float
case *types.QueryListRecordsRequest_ValueInput_Boolean:
return value.Boolean
case *types.QueryListRecordsRequest_ValueInput_Link:
return value.Link
case *types.QueryListRecordsRequest_ValueInput_Array:
return value.Array
case *types.QueryListRecordsRequest_ValueInput_Map:
return value.Map
case nil:
return nil
default:
return fmt.Errorf("Value has unepxpected type %T", value)
}
if input.Type == "float" {
return input.GetFloat()
}
if input.Type == "string" {
return input.GetString_()
}
if input.Type == "boolean" {
return input.GetBoolean()
}
if input.Type == "reference" {
return input.GetReference().GetId()
}
return nil
}
func getIntersection(a []string, b []string) []string {

File diff suppressed because it is too large Load Diff