feat: attribute typing #40

Merged
0xmuralik merged 24 commits from murali/attribute-typing into main 2022-11-15 06:21:14 +00:00
2 changed files with 22 additions and 1 deletions
Showing only changes of commit e75b5eb807 - Show all commits

View File

@ -66,6 +66,7 @@ func (suite *KeeperTestSuite) TestGrpcGetRecordLists() {
{
Key: "type",
Value: &nameservicetypes.QueryListRecordsRequest_ValueInput{
Type: "string",
String_: "WebsiteRegistrationRecord",
},
},

View File

@ -135,7 +135,8 @@ func (k Keeper) ListRecords(ctx sdk.Context) []types.Record {
func (k Keeper) RecordsFromAttributes(ctx sdk.Context, attributes []*types.QueryListRecordsRequest_KeyValueInput, all bool) ([]types.Record, error) {
resultRecordIds := []string{}
for i, attr := range attributes {
attributeIndex := GetAttributesIndexKey(attr.Key, attr.Value)
val := getAttributeValue(attr.Value)
attributeIndex := GetAttributesIndexKey(attr.Key, val)
recordIds, err := k.GetAttributeMapping(ctx, attributeIndex)
if err != nil {
return nil, err
@ -161,6 +162,25 @@ func (k Keeper) RecordsFromAttributes(ctx sdk.Context, attributes []*types.Query
return records, nil
}
func getAttributeValue(input *types.QueryListRecordsRequest_ValueInput) interface{} {
if input.Type == "int" {
return input.GetInt()
}
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 {
result := []string{}
if len(a) < len(b) {