Skip to content

Commit

Permalink
Merge pull request #11 from GoLedgerDev/develop
Browse files Browse the repository at this point in the history
Fix getRecursive for list of references
  • Loading branch information
samuelvenzi authored Aug 8, 2022
2 parents e0e28c5 + 064ecfc commit d1e657c
Showing 1 changed file with 22 additions and 2 deletions.
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

0 comments on commit d1e657c

Please sign in to comment.