From 4096d359034db73bb8700db747eb54b638eee147 Mon Sep 17 00:00:00 2001 From: Samuel Date: Tue, 2 Aug 2022 19:04:01 -0300 Subject: [PATCH 1/3] Fix getRecursive when 2+ references of the same asset are subassets --- assets/get.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/assets/get.go b/assets/get.go index c88ef2d..7f9af7d 100644 --- a/assets/get.go +++ b/assets/get.go @@ -2,6 +2,7 @@ package assets import ( "encoding/json" + "log" "github.com/goledgerdev/cc-tools/errors" sw "github.com/goledgerdev/cc-tools/stubwrapper" @@ -159,6 +160,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 +170,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 +185,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() { @@ -228,6 +240,10 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [ } } + log.Println("\n\n") + log.Println(response) + log.Println("\n\n") + return response, nil } From 093c5af780d151911cfca0cf02a00b661c0e78cf Mon Sep 17 00:00:00 2001 From: Samuel Date: Tue, 2 Aug 2022 19:08:33 -0300 Subject: [PATCH 2/3] Fix getRecursive for list of references --- assets/get.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/assets/get.go b/assets/get.go index 7f9af7d..f1b158d 100644 --- a/assets/get.go +++ b/assets/get.go @@ -211,6 +211,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() { @@ -218,10 +226,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() { From f6ba4fde95274c923729eb8bb2532b0fe77555a3 Mon Sep 17 00:00:00 2001 From: Samuel Date: Tue, 2 Aug 2022 21:15:30 -0300 Subject: [PATCH 3/3] Remove unwanted logs --- assets/get.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/assets/get.go b/assets/get.go index f1b158d..a82f8f6 100644 --- a/assets/get.go +++ b/assets/get.go @@ -2,7 +2,6 @@ package assets import ( "encoding/json" - "log" "github.com/goledgerdev/cc-tools/errors" sw "github.com/goledgerdev/cc-tools/stubwrapper" @@ -249,10 +248,6 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [ } } - log.Println("\n\n") - log.Println(response) - log.Println("\n\n") - return response, nil }