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 // QueryListRecordsRequest is request type for registry records list
message QueryListRecordsRequest { message QueryListRecordsRequest {
message ReferenceInput { message LinkInput {
string id = 1; string id = 1;
} }
message ArrayInput {
repeated ValueInput values = 1;
}
message MapInput {
map<string, ValueInput> values = 1;
}
message ValueInput { message ValueInput {
string type = 1; oneof value {
string string = 2; string string = 1;
int64 int = 3; int64 int = 2;
double float = 4; double float = 3;
bool boolean = 5; bool boolean = 4;
ReferenceInput reference = 6; string link = 5;
repeated ValueInput values = 7; ArrayInput array = 6;
MapInput map = 7;
}
} }
message KeyValueInput { message KeyValueInput {
string key = 1; 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{} { func GetAttributeValue(input *types.QueryListRecordsRequest_ValueInput) interface{} {
if input.Type == "int" { switch value := input.GetValue().(type) {
return input.GetInt() 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 { func getIntersection(a []string, b []string) []string {

File diff suppressed because it is too large Load Diff