clean up
Some checks failed
Build / cleanup-runs (pull_request) Successful in 12s
Build / build (pull_request) Successful in 1m21s
Protobuf / lint (pull_request) Failing after 32s
Protobuf / break-check (pull_request) Failing after 32s
Tests / cleanup-runs (pull_request) Successful in 5s
Tests / test-unit-cover (pull_request) Successful in 1m9s
Tests / test-importer (pull_request) Successful in 54s
Tests / test-rpc (pull_request) Successful in 1m0s
Tests / sdk_tests (pull_request) Failing after 2m51s
CodeQL / Analyze (go) (pull_request) Successful in 1m11s
Dependency Review / dependency-review (pull_request) Successful in 1m13s
Run Gosec / Gosec (pull_request) Successful in 26s
Deploy Contract / cleanup-runs (pull_request) Successful in 9s
Deploy Contract / deploy (pull_request) Failing after 1m11s
Lint / Run golangci-lint (pull_request) Successful in 1m15s
Lint / Run flake8 on python integration tests (pull_request) Failing after 25s
Pull Request Labeler / triage (pull_request) Failing after 27s
Semgrep / Scan (pull_request) Failing after 12s

This commit is contained in:
Roy Crihfield 2023-10-19 09:13:47 -05:00
parent 7d43cd3ee4
commit 21aa925758

View File

@ -150,20 +150,13 @@ func (k Keeper) ListRecords(ctx sdk.Context) []types.Record {
// RecordsFromAttributes gets a list of records whose attributes match all provided values
func (k Keeper) RecordsFromAttributes(ctx sdk.Context, attributes []*types.QueryListRecordsRequest_KeyValueInput, all bool) ([]types.Record, error) {
log := logger(ctx).With("function", "RecordsFromAttributes")
resultRecordIds := []string{}
for i, attr := range attributes {
val, err := EncodeAttributeValue2(attr.Value)
suffix, err := EncodeQueryValue(attr.Value)
if err != nil {
return nil, err
}
attributeIndex := GetAttributesIndexKey(attr.Key, val)
log.Debug("attribute index",
"key", attr.Key,
"value", val,
"value_type", fmt.Sprintf("%T", val),
"index", attributeIndex)
attributeIndex := GetAttributesIndexKey(attr.Key, suffix)
recordIds, err := k.GetAttributeMapping(ctx, attributeIndex)
if err != nil {
return nil, err
@ -191,8 +184,8 @@ func (k Keeper) RecordsFromAttributes(ctx sdk.Context, attributes []*types.Query
return records, nil
}
// TODO non recursive
func EncodeAttributeValue2(input *types.QueryListRecordsRequest_ValueInput) ([]byte, error) {
// TODO not recursive, and only should be if we want to support querying with whole sub-objects
func EncodeQueryValue(input *types.QueryListRecordsRequest_ValueInput) ([]byte, error) {
np := basicnode.Prototype.Any
nb := np.NewBuilder()
@ -344,7 +337,7 @@ func (k Keeper) processRecord(ctx sdk.Context, record *types.RecordEncodable, is
return err
}
expiryTimeKey := GetAttributesIndexKey(ExpiryTimeAttributeName, record.ExpiryTime)
expiryTimeKey := GetAttributesIndexKey(ExpiryTimeAttributeName, []byte(record.ExpiryTime))
if err := k.SetAttributeMapping(ctx, expiryTimeKey, record.ID); err != nil {
return err
}
@ -391,7 +384,6 @@ func (k Keeper) processAttributeMap(ctx sdk.Context, n ipld.Node, id string, pre
return err
}
// for key, value := range attrs {
if valuenode.Kind() == ipld.Kind_Map {
k.processAttributeMap(ctx, valuenode, id, key)
} else {
@ -409,9 +401,10 @@ func (k Keeper) processAttributeMap(ctx sdk.Context, n ipld.Node, id string, pre
return nil
}
func GetAttributesIndexKey(key string, value interface{}) []byte {
keyString := fmt.Sprintf("%s%s", key, value)
func GetAttributesIndexKey(key string, suffix []byte) []byte {
keyString := fmt.Sprintf("%s%s", key, suffix)
return append(PrefixAttributesIndex, []byte(keyString)...)
// return append(append(PrefixAttributesIndex, key...), suffix...)
}
func (k Keeper) SetAttributeMapping(ctx sdk.Context, key []byte, recordID string) error {