From 3c6cce0178e2ba0fd76beb6e588f3a1629809a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Thu, 26 Jan 2023 06:41:13 -0300 Subject: [PATCH] :necktie: Dont remove assets on type deletion --- transactions/deleteAssetType.go | 37 +++++---------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/transactions/deleteAssetType.go b/transactions/deleteAssetType.go index c16f291..caa9e60 100644 --- a/transactions/deleteAssetType.go +++ b/transactions/deleteAssetType.go @@ -61,7 +61,7 @@ var DeleteAssetType = Transaction{ } // Verify Asset Type usage - res["assets"], err = handleRegisteredAssets(stub, tagValue.(string), forceValue.(bool)) + err = handleRegisteredAssets(stub, tagValue.(string), forceValue.(bool)) if err != nil { return nil, errors.WrapError(err, "error checking asset type usage") } @@ -100,7 +100,7 @@ var DeleteAssetType = Transaction{ }, } -func handleRegisteredAssets(stub *sw.StubWrapper, tag string, force bool) ([]interface{}, errors.ICCError) { +func handleRegisteredAssets(stub *sw.StubWrapper, tag string, force bool) errors.ICCError { query := fmt.Sprintf( `{ "selector": { @@ -112,41 +112,14 @@ func handleRegisteredAssets(stub *sw.StubWrapper, tag string, force bool) ([]int resultsIterator, err := stub.GetQueryResult(query) if err != nil { - return nil, errors.WrapError(err, "failed to get query result") + return errors.WrapError(err, "failed to get query result") } if resultsIterator.HasNext() && !force { - return nil, errors.NewCCError(fmt.Sprintf("asset type '%s' is in use", tag), http.StatusBadRequest) + return errors.NewCCError(fmt.Sprintf("asset type '%s' is in use", tag), http.StatusBadRequest) } - res := make([]interface{}, 0) - for resultsIterator.HasNext() { - queryResponse, err := resultsIterator.Next() - if err != nil { - return nil, errors.WrapErrorWithStatus(err, "error iterating response", http.StatusInternalServerError) - } - - var data map[string]interface{} - - err = json.Unmarshal(queryResponse.Value, &data) - if err != nil { - return nil, errors.WrapErrorWithStatus(err, "failed to unmarshal queryResponse values", http.StatusInternalServerError) - } - - asset, err := assets.NewAsset(data) - if err != nil { - return nil, errors.WrapError(err, "could not assemble asset type") - } - - res = append(res, asset) - - _, err = asset.Delete(stub) - if err != nil { - return nil, errors.WrapError(err, "could not force delete AssetType assets") - } - } - - return res, nil + return nil } func checkAssetTypeReferences(tag string) errors.ICCError {