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

Fix getRecursive when 2+ references of the same asset are subassets #10

Merged
merged 3 commits into from
Aug 8, 2022
Merged
Changes from all 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
24 changes: 22 additions & 2 deletions assets/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [
return nil, errors.WrapErrorWithStatus(err, "failed to unmarshal asset from ledger", 500)
}

keysCheckedInScope := make([]string, 0)

for k, v := range response {
switch prop := v.(type) {
case map[string]interface{}:
Expand All @@ -167,17 +169,26 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [
return nil, errors.WrapErrorWithStatus(err, "failed to resolve asset references", 500)
}

keyIsFetchedInScope := false
for _, key := range keysCheckedInScope {
if key == propKey.Key() {
keyIsFetchedInScope = true
break
}
}

keyIsFetched := false
for _, key := range keysChecked {
if key == propKey.Key() {
keyIsFetched = true
break
}
}
if keyIsFetched {
if keyIsFetched && !keyIsFetchedInScope {
continue
}
keysChecked = append(keysChecked, propKey.Key())
keysCheckedInScope = append(keysCheckedInScope, propKey.Key())

var subAsset map[string]interface{}
if propKey.IsPrivate() {
Expand All @@ -199,17 +210,26 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [
return nil, errors.WrapErrorWithStatus(err, "failed to resolve asset references", 500)
}

keyIsFetchedInScope := false
for _, key := range keysCheckedInScope {
if key == elemKey.Key() {
keyIsFetchedInScope = true
break
}
}

keyIsFetched := false
for _, key := range keysChecked {
if key == elemKey.Key() {
keyIsFetched = true
break
}
}
if keyIsFetched {
if keyIsFetched && !keyIsFetchedInScope {
continue
}
keysChecked = append(keysChecked, elemKey.Key())
keysCheckedInScope = append(keysCheckedInScope, elemKey.Key())

var subAsset map[string]interface{}
if elemKey.IsPrivate() {
Expand Down