diff --git a/assets/get.go b/assets/get.go index c88ef2d..a82f8f6 100644 --- a/assets/get.go +++ b/assets/get.go @@ -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{}: @@ -167,6 +169,14 @@ 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() { @@ -174,10 +184,11 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [ 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() { @@ -199,6 +210,14 @@ 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() { @@ -206,10 +225,11 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [ 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() {