From 517373b0e0b91db6089b8c8c30d20d8f7cc63698 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 30 Aug 2023 14:03:08 +0000 Subject: [PATCH 01/31] :arrow_up: Bump gopkg.in/yaml.v3 Bumps gopkg.in/yaml.v3 from 3.0.0-20200615113413-eeeca48fe776 to 3.0.0. --- updated-dependencies: - dependency-name: gopkg.in/yaml.v3 dependency-type: indirect ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 243e3d5..c650a7d 100644 --- a/go.mod +++ b/go.mod @@ -26,5 +26,5 @@ require ( google.golang.org/grpc v1.35.0 // indirect gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect + gopkg.in/yaml.v3 v3.0.0 // indirect ) diff --git a/go.sum b/go.sum index 666cb16..43a706f 100644 --- a/go.sum +++ b/go.sum @@ -397,8 +397,8 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= -gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= +gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 9869b5bd80289ca2db41cffc97d60dea558c0219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Wed, 6 Sep 2023 07:13:38 -0300 Subject: [PATCH 02/31] Initial '@asset' datatype implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Macedo --- assets/dataType.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/assets/dataType.go b/assets/dataType.go index a5c8241..1f741a1 100644 --- a/assets/dataType.go +++ b/assets/dataType.go @@ -188,6 +188,46 @@ var dataTypeMap = map[string]*DataType{ return "", nil, errors.WrapErrorWithStatus(err, "failed to marshal return value", http.StatusInternalServerError) } + return string(retVal), dataVal, nil + }, + }, + "@asset": { + AcceptedFormats: []string{"@asset"}, + Parse: func(data interface{}) (string, interface{}, errors.ICCError) { + dataVal, ok := data.(map[string]interface{}) + if !ok { + switch v := data.(type) { + case []byte: + err := json.Unmarshal(v, &dataVal) + if err != nil { + return "", nil, errors.WrapErrorWithStatus(err, "failed to unmarshal []byte into map[string]interface{}", http.StatusBadRequest) + } + case string: + err := json.Unmarshal([]byte(v), &dataVal) + if err != nil { + return "", nil, errors.WrapErrorWithStatus(err, "failed to unmarshal string into map[string]interface{}", http.StatusBadRequest) + } + default: + return "", nil, errors.NewCCError(fmt.Sprintf("asset property must be either a byte array or a string, but received type is: %T", data), http.StatusBadRequest) + } + } + + // Check if assetType is defined + assetType, ok := dataVal["@assetType"].(string) + if !ok { + return "", nil, errors.NewCCError("asset property must have an '@assetType' property", http.StatusBadRequest) + } + + // Check if assetType is valid + if FetchAssetType(assetType) == nil { + return "", nil, errors.NewCCError(fmt.Sprintf("asset property '@assetType' must be an existing asset type, but received '%s'", assetType), http.StatusBadRequest) + } + + retVal, err := json.Marshal(dataVal) + if err != nil { + return "", nil, errors.WrapErrorWithStatus(err, "failed to marshal return value", http.StatusInternalServerError) + } + return string(retVal), dataVal, nil }, }, From 16c57ccf7066c6a602cbbb28073bef9227b5e69f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Wed, 6 Sep 2023 14:27:16 -0300 Subject: [PATCH 03/31] Key generation for @asset datatype MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Macedo --- assets/dataType.go | 69 +++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/assets/dataType.go b/assets/dataType.go index 1f741a1..2c71164 100644 --- a/assets/dataType.go +++ b/assets/dataType.go @@ -29,6 +29,11 @@ type DataType struct { // CustomDataTypes allows cc developer to inject custom primitive data types func CustomDataTypes(m map[string]DataType) error { + // Avoid initialization cycle + if FetchAssetType("@asset") != nil { + dataTypeMap["@asset"] = &assetDatatype + } + for k, v := range m { if v.Parse == nil { return errors.NewCCError(fmt.Sprintf("invalid custom data type '%s': nil Parse function", k), 500) @@ -191,44 +196,40 @@ var dataTypeMap = map[string]*DataType{ return string(retVal), dataVal, nil }, }, - "@asset": { - AcceptedFormats: []string{"@asset"}, - Parse: func(data interface{}) (string, interface{}, errors.ICCError) { - dataVal, ok := data.(map[string]interface{}) - if !ok { - switch v := data.(type) { - case []byte: - err := json.Unmarshal(v, &dataVal) - if err != nil { - return "", nil, errors.WrapErrorWithStatus(err, "failed to unmarshal []byte into map[string]interface{}", http.StatusBadRequest) - } - case string: - err := json.Unmarshal([]byte(v), &dataVal) - if err != nil { - return "", nil, errors.WrapErrorWithStatus(err, "failed to unmarshal string into map[string]interface{}", http.StatusBadRequest) - } - default: - return "", nil, errors.NewCCError(fmt.Sprintf("asset property must be either a byte array or a string, but received type is: %T", data), http.StatusBadRequest) - } - } +} - // Check if assetType is defined - assetType, ok := dataVal["@assetType"].(string) - if !ok { - return "", nil, errors.NewCCError("asset property must have an '@assetType' property", http.StatusBadRequest) +var assetDatatype = DataType{ + AcceptedFormats: []string{"@asset"}, + Parse: func(data interface{}) (string, interface{}, errors.ICCError) { + dataVal, ok := data.(map[string]interface{}) + if !ok { + switch v := data.(type) { + case []byte: + err := json.Unmarshal(v, &dataVal) + if err != nil { + return "", nil, errors.WrapErrorWithStatus(err, "failed to unmarshal []byte into map[string]interface{}", http.StatusBadRequest) + } + case string: + err := json.Unmarshal([]byte(v), &dataVal) + if err != nil { + return "", nil, errors.WrapErrorWithStatus(err, "failed to unmarshal string into map[string]interface{}", http.StatusBadRequest) + } + default: + return "", nil, errors.NewCCError(fmt.Sprintf("asset property must be either a byte array or a string, but received type is: %T", data), http.StatusBadRequest) } + } - // Check if assetType is valid - if FetchAssetType(assetType) == nil { - return "", nil, errors.NewCCError(fmt.Sprintf("asset property '@assetType' must be an existing asset type, but received '%s'", assetType), http.StatusBadRequest) - } + key, er := GenerateKey(dataVal) + if er != nil { + return "", nil, errors.WrapError(er, "failed to generate key") + } + dataVal["@key"] = key - retVal, err := json.Marshal(dataVal) - if err != nil { - return "", nil, errors.WrapErrorWithStatus(err, "failed to marshal return value", http.StatusInternalServerError) - } + retVal, err := json.Marshal(dataVal) + if err != nil { + return "", nil, errors.WrapErrorWithStatus(err, "failed to marshal return value", http.StatusInternalServerError) + } - return string(retVal), dataVal, nil - }, + return string(retVal), dataVal, nil }, } From a1e8d2318252ec6f8e716489e6f99187d88c3d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Wed, 6 Sep 2023 15:01:59 -0300 Subject: [PATCH 04/31] Add '@asset' datatype tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Macedo --- assets/dataType.go | 2 +- test/assets_dataType_test.go | 71 +++++++++++++++++++++++++++++++++++- test/tx_getDataTypes_test.go | 6 +++ 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/assets/dataType.go b/assets/dataType.go index 2c71164..e390239 100644 --- a/assets/dataType.go +++ b/assets/dataType.go @@ -30,7 +30,7 @@ type DataType struct { // CustomDataTypes allows cc developer to inject custom primitive data types func CustomDataTypes(m map[string]DataType) error { // Avoid initialization cycle - if FetchAssetType("@asset") != nil { + if FetchAssetType("@asset") == nil { dataTypeMap["@asset"] = &assetDatatype } diff --git a/test/assets_dataType_test.go b/test/assets_dataType_test.go index 1c134b6..2446852 100644 --- a/test/assets_dataType_test.go +++ b/test/assets_dataType_test.go @@ -1,7 +1,9 @@ package test import ( + "encoding/json" "log" + "net/http" "reflect" "testing" @@ -21,7 +23,7 @@ func testParseValid(t *testing.T, dtype assets.DataType, inputVal interface{}, e log.Printf("parsing %v expected key: %q but got %q\n", inputVal, expectedKey, key) t.FailNow() } - if val != expectedVal { + if !reflect.DeepEqual(val, expectedVal) { log.Printf("parsing %v expected parsed val: \"%v\" of type %s but got \"%v\" of type %s\n", inputVal, expectedVal, reflect.TypeOf(expectedVal), val, reflect.TypeOf(val)) t.FailNow() } @@ -92,3 +94,70 @@ func TestDataTypeBoolean(t *testing.T) { testParseInvalid(t, dtype, "True", 400) testParseInvalid(t, dtype, 37.3, 400) } + +func TestDataTypeObject(t *testing.T) { + dtypeName := "@object" + dtype, exists := assets.DataTypeMap()[dtypeName] + if !exists { + log.Printf("%s datatype not declared in DataTypeMap\n", dtypeName) + t.FailNow() + } + + testCase1 := map[string]interface{}{ + "key1": "value1", + "key2": "value2", + } + testCaseByte1, _ := json.Marshal(testCase1) + testCaseExpected1 := map[string]interface{}{ + "@assetType": "@object", + "key1": "value1", + "key2": "value2", + } + testCaseExpectedByte1, _ := json.Marshal(testCaseExpected1) + + testParseValid(t, dtype, testCase1, string(testCaseExpectedByte1), testCase1) + testParseValid(t, dtype, testCaseByte1, string(testCaseExpectedByte1), testCase1) + testParseValid(t, dtype, string(testCaseByte1), string(testCaseExpectedByte1), testCase1) + testParseInvalid(t, dtype, "{'key': 'value'}", http.StatusBadRequest) +} +func TestDataTypeAsset(t *testing.T) { + dtypeName := "@asset" + dtype, exists := assets.DataTypeMap()[dtypeName] + if !exists { + log.Printf("%s datatype not declared in DataTypeMap\n", dtypeName) + t.FailNow() + } + + testCase1 := map[string]interface{}{ + "@assetType": "person", + "id": "42186475006", + } + testCaseExpected1 := map[string]interface{}{ + "@assetType": "person", + "id": "42186475006", + "@key": "person:a11e54a8-7e23-5d16-9fed-45523dd96bfa", + } + testCaseExpectedByte1, _ := json.Marshal(testCaseExpected1) + testParseValid(t, dtype, testCase1, string(testCaseExpectedByte1), testCaseExpected1) + + testCase2 := map[string]interface{}{ + "@assetType": "book", + "title": "Book Name", + "author": "Author Name", + "@key": "book:983a78df-9f0e-5ecb-baf2-4a8698590c81", + } + testCaseExpectedByte2, _ := json.Marshal(testCase2) + testParseValid(t, dtype, testCase2, string(testCaseExpectedByte2), testCase2) + testParseValid(t, dtype, testCaseExpectedByte2, string(testCaseExpectedByte2), testCase2) + testParseValid(t, dtype, string(testCaseExpectedByte2), string(testCaseExpectedByte2), testCase2) + + testCase3 := map[string]interface{}{ + "@assetType": "library", + } + testParseInvalid(t, dtype, testCase3, http.StatusBadRequest) + + testCase4 := map[string]interface{}{ + "@assetType": "inexistant", + } + testParseInvalid(t, dtype, testCase4, http.StatusBadRequest) +} diff --git a/test/tx_getDataTypes_test.go b/test/tx_getDataTypes_test.go index 8921dd2..36aa946 100644 --- a/test/tx_getDataTypes_test.go +++ b/test/tx_getDataTypes_test.go @@ -51,6 +51,12 @@ func TestGetDataTypes(t *testing.T) { }, "DropDownValues": nil, }, + "@asset": map[string]interface{}{ + "acceptedFormats": []interface{}{ + "@asset", + }, + "DropDownValues": nil, + }, } err := invokeAndVerify(stub, "getDataTypes", nil, expectedResponse, 200) if err != nil { From 12928907d51181ebd3a2bdc890cdce92acdd2b36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Wed, 6 Sep 2023 16:10:16 -0300 Subject: [PATCH 05/31] Modify '@asset' type to '->@asset' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Macedo --- assets/assetProp.go | 1 + assets/assetType.go | 3 +++ assets/dataType.go | 4 ++-- assets/dynamicAssetTypeFuncs.go | 3 +++ assets/generateKey.go | 13 ++++++++----- assets/put.go | 9 ++++++++- assets/references.go | 16 +++++++++++----- assets/startupCheck.go | 9 ++++++--- assets/update.go | 4 +++- assets/validateProp.go | 23 +++++++++++++++-------- test/assets_dataType_test.go | 2 +- test/tx_getDataTypes_test.go | 4 ++-- transactions/getArgs.go | 17 ++++++++++++----- transactions/startupCheck.go | 2 +- 14 files changed, 76 insertions(+), 34 deletions(-) diff --git a/assets/assetProp.go b/assets/assetProp.go index a5b77f6..674e6c6 100644 --- a/assets/assetProp.go +++ b/assets/assetProp.go @@ -29,6 +29,7 @@ type AssetProp struct { // Primary types: "string", "number", "integer", "boolean", "datetime" // Special types: // ->: the specific asset type key (reference) as defined by in the assets packages + // ->@asset: an arbitrary asset type key (reference) // []: an array of elements specified by as any of the above valid types DataType string `json:"dataType"` diff --git a/assets/assetType.go b/assets/assetType.go index e73a8dc..d1d970a 100644 --- a/assets/assetType.go +++ b/assets/assetType.go @@ -48,6 +48,9 @@ func (t AssetType) SubAssets() (subAssets []AssetProp) { dataType := prop.DataType dataType = strings.TrimPrefix(dataType, "[]") dataType = strings.TrimPrefix(dataType, "->") + if dataType == "@asset" { + subAssets = append(subAssets, prop) + } subAssetType := FetchAssetType(dataType) if subAssetType != nil { subAssets = append(subAssets, prop) diff --git a/assets/dataType.go b/assets/dataType.go index e390239..cc3de10 100644 --- a/assets/dataType.go +++ b/assets/dataType.go @@ -31,7 +31,7 @@ type DataType struct { func CustomDataTypes(m map[string]DataType) error { // Avoid initialization cycle if FetchAssetType("@asset") == nil { - dataTypeMap["@asset"] = &assetDatatype + dataTypeMap["->@asset"] = &assetDatatype } for k, v := range m { @@ -199,7 +199,7 @@ var dataTypeMap = map[string]*DataType{ } var assetDatatype = DataType{ - AcceptedFormats: []string{"@asset"}, + AcceptedFormats: []string{"->@asset"}, Parse: func(data interface{}) (string, interface{}, errors.ICCError) { dataVal, ok := data.(map[string]interface{}) if !ok { diff --git a/assets/dynamicAssetTypeFuncs.go b/assets/dynamicAssetTypeFuncs.go index 4419fbd..b51ae35 100644 --- a/assets/dynamicAssetTypeFuncs.go +++ b/assets/dynamicAssetTypeFuncs.go @@ -163,6 +163,9 @@ func CheckDataType(dataType string, newTypesList []interface{}) errors.ICCError if strings.HasPrefix(trimDataType, "->") { trimDataType = strings.TrimPrefix(trimDataType, "->") + if trimDataType == "@asset" { + return nil + } assetType := FetchAssetType(trimDataType) if assetType == nil { diff --git a/assets/generateKey.go b/assets/generateKey.go index 7911cce..968d153 100644 --- a/assets/generateKey.go +++ b/assets/generateKey.go @@ -90,11 +90,6 @@ func GenerateKey(asset map[string]interface{}) (string, errors.ICCError) { keySeed += seed } else { // If key is a subAsset, generate subAsset's key to append to seed - assetTypeDef := FetchAssetType(dataTypeName) - if assetTypeDef == nil { - return "", errors.NewCCError(fmt.Sprintf("internal error: invalid sub asset type %s", prop.DataType), 500) - } - var propMap map[string]interface{} switch t := propInterface.(type) { case map[string]interface{}: @@ -108,6 +103,14 @@ func GenerateKey(asset map[string]interface{}) (string, errors.ICCError) { return "", errors.NewCCError(errMsg, 400) } + if dataTypeName == "@asset" { + dataTypeName = propMap["@assetType"].(string) + } + assetTypeDef := FetchAssetType(dataTypeName) + if assetTypeDef == nil { + return "", errors.NewCCError(fmt.Sprintf("internal error: invalid sub asset type %s", prop.DataType), 500) + } + propMap["@assetType"] = dataTypeName subAssetKey, err := GenerateKey(propMap) if err != nil { diff --git a/assets/put.go b/assets/put.go index 15bf91b..e401c73 100644 --- a/assets/put.go +++ b/assets/put.go @@ -167,7 +167,14 @@ func putRecursive(stub *sw.StubWrapper, object map[string]interface{}, root bool // If subAsset is badly formatted, this method shouldn't have been called return nil, errors.NewCCError(fmt.Sprintf("asset reference property '%s' must be an object", subAsset.Tag), 400) } - obj["@assetType"] = dType + if dType != "@asset" { + obj["@assetType"] = dType + } else { + _, ok := obj["@assetType"].(string) + if !ok { + return nil, errors.NewCCError(fmt.Sprintf("asset reference property '%s' must have an '@assetType' property", subAsset.Tag), 400) + } + } putSubAsset, err := putRecursive(stub, obj, false) if err != nil { return nil, errors.WrapError(err, fmt.Sprintf("failed to put sub-asset %s recursively", subAsset.Tag)) diff --git a/assets/references.go b/assets/references.go index 77a6597..2d2041c 100644 --- a/assets/references.go +++ b/assets/references.go @@ -67,11 +67,17 @@ func (a Asset) Refs() ([]Key, errors.ICCError) { } subAssetTypeName, ok := subAssetRefMap["@assetType"] - if ok && subAssetTypeName != subAssetDataType { - return nil, errors.NewCCError("sub-asset reference of wrong asset type", 400) - } - if !ok { - subAssetRefMap["@assetType"] = subAssetDataType + if subAssetDataType != "@asset" { + if ok && subAssetTypeName != subAssetDataType { + return nil, errors.NewCCError("sub-asset reference of wrong asset type", 400) + } + if !ok { + subAssetRefMap["@assetType"] = subAssetDataType + } + } else { + if !ok { + return nil, errors.NewCCError("sub-asset reference must have an '@assetType' property", 400) + } } // Generate key for subAsset diff --git a/assets/startupCheck.go b/assets/startupCheck.go index bc7be2a..c94bdd2 100644 --- a/assets/startupCheck.go +++ b/assets/startupCheck.go @@ -69,10 +69,13 @@ func StartupCheck() errors.ICCError { // Check if there are references to undefined types if isSubAsset { // Checks if the prop's datatype exists on assetMap - propTypeDef := FetchAssetType(dataTypeName) - if propTypeDef == nil { - return errors.NewCCError(fmt.Sprintf("reference for undefined asset type '%s'", propDef.DataType), 500) + if dataTypeName != "@asset" { + propTypeDef := FetchAssetType(dataTypeName) + if propTypeDef == nil { + return errors.NewCCError(fmt.Sprintf("reference for undefined asset type '%s'", propDef.DataType), 500) + } } + if propDef.DefaultValue != nil { return errors.NewCCError(fmt.Sprintf("reference cannot have a default value in prop '%s' of asset '%s'", propDef.Label, assetType.Label), 500) } diff --git a/assets/update.go b/assets/update.go index 255dc54..6af1e21 100644 --- a/assets/update.go +++ b/assets/update.go @@ -296,7 +296,9 @@ func checkUpdateRecursive(stub *sw.StubWrapper, object map[string]interface{}, r // If subAsset is badly formatted, this method shouldn't have been called return errors.NewCCError(fmt.Sprintf("asset reference property '%s' must be an object", subAsset.Tag), 400) } - obj["@assetType"] = dType + if dType != "@asset" { + obj["@assetType"] = dType + } err := checkUpdateRecursive(stub, obj, false) if err != nil { return errors.WrapError(err, fmt.Sprintf("failed to check sub-asset %s recursively", subAsset.Tag)) diff --git a/assets/validateProp.go b/assets/validateProp.go index 2aaf4c6..9fd9565 100644 --- a/assets/validateProp.go +++ b/assets/validateProp.go @@ -61,12 +61,6 @@ func validateProp(prop interface{}, propDef AssetProp) (interface{}, error) { return nil, errors.WrapError(err, fmt.Sprintf("invalid '%s' (%s) asset property", propDef.Tag, propDef.Label)) } } else { - // Check if type is defined in assetList - subAssetType := FetchAssetType(dataTypeName) - if subAssetType == nil { - return nil, errors.NewCCError(fmt.Sprintf("invalid asset type named '%s'", propDef.DataType), 400) - } - // Check if received subAsset is a map var recvMap map[string]interface{} switch t := prop.(type) { @@ -80,8 +74,21 @@ func validateProp(prop interface{}, propDef AssetProp) (interface{}, error) { return nil, errors.NewCCError("asset reference must be an object", 400) } - // Add assetType to received object - recvMap["@assetType"] = dataTypeName + if dataTypeName != "@asset" { + // Check if type is defined in assetList + subAssetType := FetchAssetType(dataTypeName) + if subAssetType == nil { + return nil, errors.NewCCError(fmt.Sprintf("invalid asset type named '%s'", propDef.DataType), 400) + } + + // Add assetType to received object + recvMap["@assetType"] = dataTypeName + } else { + _, ok := recvMap["@assetType"].(string) + if !ok { + return nil, errors.NewCCError("invalid asset reference: missing '@assetType' property", 400) + } + } // Check if all key props are included key, err := NewKey(recvMap) diff --git a/test/assets_dataType_test.go b/test/assets_dataType_test.go index 2446852..d264e4f 100644 --- a/test/assets_dataType_test.go +++ b/test/assets_dataType_test.go @@ -121,7 +121,7 @@ func TestDataTypeObject(t *testing.T) { testParseInvalid(t, dtype, "{'key': 'value'}", http.StatusBadRequest) } func TestDataTypeAsset(t *testing.T) { - dtypeName := "@asset" + dtypeName := "->@asset" dtype, exists := assets.DataTypeMap()[dtypeName] if !exists { log.Printf("%s datatype not declared in DataTypeMap\n", dtypeName) diff --git a/test/tx_getDataTypes_test.go b/test/tx_getDataTypes_test.go index 36aa946..b24e376 100644 --- a/test/tx_getDataTypes_test.go +++ b/test/tx_getDataTypes_test.go @@ -51,9 +51,9 @@ func TestGetDataTypes(t *testing.T) { }, "DropDownValues": nil, }, - "@asset": map[string]interface{}{ + "->@asset": map[string]interface{}{ "acceptedFormats": []interface{}{ - "@asset", + "->@asset", }, "DropDownValues": nil, }, diff --git a/transactions/getArgs.go b/transactions/getArgs.go index f493721..ee4b080 100644 --- a/transactions/getArgs.go +++ b/transactions/getArgs.go @@ -3,6 +3,7 @@ package transactions import ( "encoding/json" "fmt" + "net/http" "strings" "github.com/goledgerdev/cc-tools/assets" @@ -122,11 +123,17 @@ func validateTxArg(argType string, arg interface{}) (interface{}, errors.ICCErro return nil, errors.NewCCError("invalid argument format", 400) } assetTypeName, ok := argMap["@assetType"] - if ok && assetTypeName != argType { // in case an @assetType is specified, check if it is correct - return nil, errors.NewCCError(fmt.Sprintf("invalid @assetType '%s' (expecting '%s')", assetTypeName, argType), 400) - } - if !ok { // if @assetType is not specified, inject it - argMap["@assetType"] = argType + if argType != "@asset" { + if ok && assetTypeName != argType { // in case an @assetType is specified, check if it is correct + return nil, errors.NewCCError(fmt.Sprintf("invalid @assetType '%s' (expecting '%s')", assetTypeName, argType), 400) + } + if !ok { // if @assetType is not specified, inject it + argMap["@assetType"] = argType + } + } else { + if !ok { + return nil, errors.NewCCError("missing @assetType", http.StatusBadRequest) + } } key, err := assets.NewKey(argMap) if err != nil { diff --git a/transactions/startupCheck.go b/transactions/startupCheck.go index 0cc6390..f96bf37 100644 --- a/transactions/startupCheck.go +++ b/transactions/startupCheck.go @@ -41,7 +41,7 @@ func StartupCheck() errors.ICCError { dtype != "@object" { if strings.HasPrefix(dtype, "->") { dtype = strings.TrimPrefix(dtype, "->") - if assets.FetchAssetType(dtype) == nil { + if assets.FetchAssetType(dtype) == nil && dtype != "@asset" { return errors.NewCCError(fmt.Sprintf("invalid arg type %s in tx %s", arg.DataType, txName), 500) } } else { From 87866c36e0e982f1186300bdc929e50939c32b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Wed, 6 Sep 2023 16:40:23 -0300 Subject: [PATCH 06/31] Improve tests and validation for '->@asset' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Macedo --- assets/dataType.go | 12 +++++++++++- test/assets_dataType_test.go | 22 +++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/assets/dataType.go b/assets/dataType.go index cc3de10..0e52c01 100644 --- a/assets/dataType.go +++ b/assets/dataType.go @@ -6,6 +6,7 @@ import ( "math" "net/http" "strconv" + "strings" "time" "github.com/goledgerdev/cc-tools/errors" @@ -30,7 +31,7 @@ type DataType struct { // CustomDataTypes allows cc developer to inject custom primitive data types func CustomDataTypes(m map[string]DataType) error { // Avoid initialization cycle - if FetchAssetType("@asset") == nil { + if FetchAssetType("->@asset") == nil { dataTypeMap["->@asset"] = &assetDatatype } @@ -225,6 +226,15 @@ var assetDatatype = DataType{ } dataVal["@key"] = key + assetType, ok := dataVal["@assetType"].(string) + if ok { + if !strings.Contains(key, assetType) { + return "", nil, errors.NewCCError(fmt.Sprintf("asset type '%s' doesnt match key '%s'", assetType, key), http.StatusBadRequest) + } + } else { + dataVal["@assetType"] = key[:strings.IndexByte(key, ':')] + } + retVal, err := json.Marshal(dataVal) if err != nil { return "", nil, errors.WrapErrorWithStatus(err, "failed to marshal return value", http.StatusInternalServerError) diff --git a/test/assets_dataType_test.go b/test/assets_dataType_test.go index d264e4f..ed0134d 100644 --- a/test/assets_dataType_test.go +++ b/test/assets_dataType_test.go @@ -152,12 +152,28 @@ func TestDataTypeAsset(t *testing.T) { testParseValid(t, dtype, string(testCaseExpectedByte2), string(testCaseExpectedByte2), testCase2) testCase3 := map[string]interface{}{ + "@key": "library:ca683ce5-05bf-5799-a359-b28a1f981f96", + } + testCaseExpected3 := map[string]interface{}{ + "@assetType": "library", + "@key": "library:ca683ce5-05bf-5799-a359-b28a1f981f96", + } + testCaseExpectedByte3, _ := json.Marshal(testCaseExpected3) + testParseValid(t, dtype, testCase3, string(testCaseExpectedByte3), testCase3) + + invalidCase1 := map[string]interface{}{ "@assetType": "library", } - testParseInvalid(t, dtype, testCase3, http.StatusBadRequest) + testParseInvalid(t, dtype, invalidCase1, http.StatusBadRequest) - testCase4 := map[string]interface{}{ + invalidCase2 := map[string]interface{}{ "@assetType": "inexistant", } - testParseInvalid(t, dtype, testCase4, http.StatusBadRequest) + testParseInvalid(t, dtype, invalidCase2, http.StatusBadRequest) + + invalidCase3 := map[string]interface{}{ + "@assetType": "person", + "@key": "library:ca683ce5-05bf-5799-a359-b28a1f981f96", + } + testParseInvalid(t, dtype, invalidCase3, http.StatusBadRequest) } From 337337b6ec4db3a1a9ebf21ea8d72f45c5a1760c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Wed, 6 Sep 2023 17:09:59 -0300 Subject: [PATCH 07/31] Improve tx tests with generic associations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Macedo --- test/assets_assetType_test.go | 22 +++++++ test/chaincode_test.go | 6 ++ test/tx_createAsset_test.go | 106 ++++++++++++++++++++++++++++++++++ test/tx_getSchema_test.go | 10 ++++ 4 files changed, 144 insertions(+) diff --git a/test/assets_assetType_test.go b/test/assets_assetType_test.go index 321a8ba..e23eead 100644 --- a/test/assets_assetType_test.go +++ b/test/assets_assetType_test.go @@ -83,6 +83,17 @@ func TestAssetTypeToMap(t *testing.T) { "dataType": "@object", "writers": emptySlice, }, + { + "tag": "association", + "label": "Association", + "description": "", + "isKey": false, + "required": false, + "readOnly": false, + "defaultValue": nil, + "dataType": "[]->@asset", + "writers": emptySlice, + }, }, "readers": emptySlice, "dynamic": false, @@ -198,6 +209,17 @@ func TestAssetTypeListToMap(t *testing.T) { "dataType": "@object", "writers": emptySlice, }, + { + "tag": "association", + "label": "Association", + "description": "", + "isKey": false, + "required": false, + "readOnly": false, + "defaultValue": nil, + "dataType": "[]->@asset", + "writers": emptySlice, + }, }, "readers": emptySlice, "dynamic": false, diff --git a/test/chaincode_test.go b/test/chaincode_test.go index a7e075e..b224eab 100644 --- a/test/chaincode_test.go +++ b/test/chaincode_test.go @@ -76,6 +76,12 @@ var testAssetList = []assets.AssetType{ Label: "Other Info", DataType: "@object", }, + { + // Generic JSON object + Tag: "association", + Label: "Association", + DataType: "[]->@asset", + }, }, }, { diff --git a/test/tx_createAsset_test.go b/test/tx_createAsset_test.go index 00b0d6a..c05e0be 100644 --- a/test/tx_createAsset_test.go +++ b/test/tx_createAsset_test.go @@ -88,6 +88,112 @@ func TestCreateAsset(t *testing.T) { } } +func TestCreateAssetGenericAssociation(t *testing.T) { + stub := mock.NewMockStub("org1MSP", new(testCC)) + book := map[string]interface{}{ + "@assetType": "book", + "title": "Book Title", + "author": "Author", + } + + library := map[string]interface{}{ + "@assetType": "library", + "name": "Library Name", + } + + req := map[string]interface{}{ + "asset": []map[string]interface{}{book, library}, + } + reqBytes, err := json.Marshal(req) + if err != nil { + t.FailNow() + } + + res := stub.MockInvoke("createAsset", [][]byte{ + []byte("createAsset"), + reqBytes, + }) + + person := map[string]interface{}{ + "@assetType": "person", + "name": "Maria", + "id": "318.207.920-48", + "association": []map[string]interface{}{book, library}, + } + req = map[string]interface{}{ + "asset": []map[string]interface{}{person}, + } + reqBytes, err = json.Marshal(req) + if err != nil { + t.FailNow() + } + + res = stub.MockInvoke("createAsset", [][]byte{ + []byte("createAsset"), + reqBytes, + }) + lastUpdated, _ := stub.GetTxTimestamp() + expectedResponse := map[string]interface{}{ + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", + "@lastTx": "createAsset", + "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 0.0, + "association": []interface{}{ + map[string]interface{}{ + "@assetType": "book", + "@key": "book:46179ee0-5503-54e1-aa51-bbaad559638b", + }, + map[string]interface{}{ + "@assetType": "library", + "@key": "library:9aeaddc4-d1cb-5b03-9ad0-1d9af7416c2e", + }, + }, + } + + if res.GetStatus() != 200 { + log.Println(res) + t.FailNow() + } + + var resPayload []map[string]interface{} + err = json.Unmarshal(res.GetPayload(), &resPayload) + if err != nil { + log.Println(err) + t.FailNow() + } + + if len(resPayload) != 1 { + log.Println("response length should be 1") + t.FailNow() + } + + if !reflect.DeepEqual(resPayload[0], expectedResponse) { + log.Println("these should be equal") + log.Printf("%#v\n", resPayload[0]) + log.Printf("%#v\n", expectedResponse) + t.FailNow() + } + + var state map[string]interface{} + stateBytes := stub.State["person:47061146-c642-51a1-844a-bf0b17cb5e19"] + err = json.Unmarshal(stateBytes, &state) + if err != nil { + log.Println(err) + t.FailNow() + } + + if !reflect.DeepEqual(state, expectedResponse) { + log.Println("these should be equal") + log.Printf("%#v\n", state) + log.Printf("%#v\n", expectedResponse) + t.FailNow() + } +} + func TestCreateAssetEmptyList(t *testing.T) { stub := mock.NewMockStub("org1MSP", new(testCC)) diff --git a/test/tx_getSchema_test.go b/test/tx_getSchema_test.go index 620eb4c..a1badde 100644 --- a/test/tx_getSchema_test.go +++ b/test/tx_getSchema_test.go @@ -120,6 +120,16 @@ func TestGetSchema(t *testing.T) { "tag": "info", "writers": nil, }, + map[string]interface{}{ + "dataType": "[]->@asset", + "description": "", + "isKey": false, + "label": "Association", + "readOnly": false, + "required": false, + "tag": "association", + "writers": nil, + }, }, } err = invokeAndVerify(stub, "getSchema", req, expectedPersonSchema, 200) From c5815fd6c7150548a491c6c63bdc89bb4884787f Mon Sep 17 00:00:00 2001 From: mikaellafs Date: Mon, 11 Sep 2023 16:41:27 -0300 Subject: [PATCH 08/31] Create permissioning by msp, org unit and attributes Signed-off-by: mikaellafs --- accesscontrol/allowCaller.go | 89 ++++++++++++++++++++++++++++++++++++ accesscontrol/caller.go | 7 +++ 2 files changed, 96 insertions(+) create mode 100644 accesscontrol/allowCaller.go create mode 100644 accesscontrol/caller.go diff --git a/accesscontrol/allowCaller.go b/accesscontrol/allowCaller.go new file mode 100644 index 0000000..3ab2ecb --- /dev/null +++ b/accesscontrol/allowCaller.go @@ -0,0 +1,89 @@ +package accesscontrol + +import ( + "regexp" + + "github.com/goledgerdev/cc-tools/errors" + "github.com/hyperledger/fabric-chaincode-go/pkg/cid" + "github.com/hyperledger/fabric-chaincode-go/shim" +) + +func AllowCaller(stub shim.ChaincodeStubInterface, allowedCallers []Caller) (bool, error) { + if allowedCallers == nil { + return true, nil + } + + callerMSP, err := cid.GetMSPID(stub) + if err != nil { + return false, errors.WrapError(err, "could not get MSP id") + } + + var grantedPermission bool + for i := 0; i < len(allowedCallers) && !grantedPermission; i++ { + allowed := allowedCallers[i] + isAllowedMSP, err := checkMSP(callerMSP, allowed.MSP) + if err != nil { + return false, errors.WrapError(err, "failed to check MSP") + } + + isAllowedOU, err := checkOU(stub, allowed.OU) + if err != nil { + return false, errors.WrapError(err, "failed to check OU") + } + + isAllowedAttrs, err := checkAttributes(stub, allowed.Attributes) + if err != nil { + return false, errors.WrapError(err, "failed to check attributes") + } + + grantedPermission = isAllowedMSP && isAllowedOU && isAllowedAttrs + } + + return grantedPermission, nil +} + +func checkMSP(callerMsp, allowedMSP string) (bool, error) { + if len(allowedMSP) <= 1 { + return true, nil + } + + // if caller is regexp + if allowedMSP[0] == '$' { + match, err := regexp.MatchString(allowedMSP[1:], callerMsp) + if err != nil { + return false, errors.NewCCError("failed to check if caller matches regexp", 500) + } + + return match, nil + } + + // if caller is not regexss + return callerMsp == allowedMSP, nil +} + +func checkOU(stub shim.ChaincodeStubInterface, allowedOU string) (bool, error) { + if allowedOU == "" { + return true, nil + } + + return cid.HasOUValue(stub, allowedOU) +} + +func checkAttributes(stub shim.ChaincodeStubInterface, allowedAttrs map[string]string) (bool, error) { + if allowedAttrs == nil { + return true, nil + } + + for key, value := range allowedAttrs { + callerValue, _, err := cid.GetAttributeValue(stub, key) + if err != nil { + return false, err + } + + if callerValue != value { + return false, nil + } + } + + return true, nil +} diff --git a/accesscontrol/caller.go b/accesscontrol/caller.go new file mode 100644 index 0000000..746f6c6 --- /dev/null +++ b/accesscontrol/caller.go @@ -0,0 +1,7 @@ +package accesscontrol + +type Caller struct { + MSP string `json:"msp"` + OU string `json:"ou"` + Attributes map[string]string `json:"attributes"` +} From b54edd627bfadd9f0df6319edd13503d0aee9656 Mon Sep 17 00:00:00 2001 From: mikaellafs Date: Mon, 11 Sep 2023 16:42:19 -0300 Subject: [PATCH 09/31] Refactor tx permissioning check to use new model Signed-off-by: mikaellafs --- transactions/getTx.go | 9 +++++---- transactions/run.go | 39 +++++++----------------------------- transactions/startupCheck.go | 8 ++++---- transactions/transaction.go | 3 ++- transactions/txList.go | 14 +++++++++++-- 5 files changed, 30 insertions(+), 43 deletions(-) diff --git a/transactions/getTx.go b/transactions/getTx.go index d7dbeb4..1a4a11f 100644 --- a/transactions/getTx.go +++ b/transactions/getTx.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" + "github.com/goledgerdev/cc-tools/accesscontrol" "github.com/goledgerdev/cc-tools/errors" sw "github.com/goledgerdev/cc-tools/stubwrapper" ) @@ -50,10 +51,10 @@ var getTx = Transaction{ // If user requested asset list type txListElem struct { - Tag string `json:"tag"` - Label string `json:"label"` - Description string `json:"description"` - Callers []string `json:"callers,omitempty"` + Tag string `json:"tag"` + Label string `json:"label"` + Description string `json:"description"` + Callers []accesscontrol.Caller `json:"callers,omitempty"` } var txRetList []txListElem for _, tx := range txList { diff --git a/transactions/run.go b/transactions/run.go index c6f114a..11e486d 100644 --- a/transactions/run.go +++ b/transactions/run.go @@ -2,8 +2,8 @@ package transactions import ( "fmt" - "regexp" + "github.com/goledgerdev/cc-tools/accesscontrol" "github.com/goledgerdev/cc-tools/assets" "github.com/goledgerdev/cc-tools/errors" sw "github.com/goledgerdev/cc-tools/stubwrapper" @@ -40,38 +40,13 @@ func Run(stub shim.ChaincodeStubInterface) ([]byte, errors.ICCError) { } // Verify callers permissions - if tx.Callers != nil { - // Get tx caller MSP ID - txCaller, err := sw.GetMSPID() - if err != nil { - return nil, errors.WrapErrorWithStatus(err, "error getting tx caller", 500) - } + callPermission, err := accesscontrol.AllowCaller(stub, tx.Callers) + if err != nil { + return nil, errors.WrapError(err, "failed to check permissions") + } - // Check if caller is allowed - callPermission := false - for _, c := range tx.Callers { - if len(c) <= 1 { - continue - } - if c[0] == '$' { // if caller is regexp - match, err := regexp.MatchString(c[1:], txCaller) - if err != nil { - return nil, errors.NewCCError("failed to check if caller matches regexp", 500) - } - if match { - callPermission = true - break - } - } else { // if caller is not regexp - if c == txCaller { - callPermission = true - break - } - } - } - if !callPermission { - return nil, errors.NewCCError(fmt.Sprintf("%s cannot call this transaction", txCaller), 403) - } + if !callPermission { + return nil, errors.NewCCError("current caller not allowed", 403) } return tx.Routine(sw, reqMap) diff --git a/transactions/startupCheck.go b/transactions/startupCheck.go index 0cc6390..3d8f4e9 100644 --- a/transactions/startupCheck.go +++ b/transactions/startupCheck.go @@ -15,13 +15,13 @@ func StartupCheck() errors.ICCError { for _, tx := range txList { txName := tx.Tag for _, c := range tx.Callers { - if len(c) <= 1 { + if len(c.MSP) <= 1 { continue } - if c[0] == '$' { - _, err := regexp.Compile(c[1:]) + if c.MSP[0] == '$' { + _, err := regexp.Compile(c.MSP[1:]) if err != nil { - return errors.WrapErrorWithStatus(err, fmt.Sprintf("invalid caller regular expression %s for tx %s", c, txName), 500) + return errors.WrapErrorWithStatus(err, fmt.Sprintf("invalid caller msp regular expression %s for tx %s", c, txName), 500) } } } diff --git a/transactions/transaction.go b/transactions/transaction.go index aedd0a9..149381c 100644 --- a/transactions/transaction.go +++ b/transactions/transaction.go @@ -1,6 +1,7 @@ package transactions import ( + "github.com/goledgerdev/cc-tools/accesscontrol" "github.com/goledgerdev/cc-tools/errors" sw "github.com/goledgerdev/cc-tools/stubwrapper" ) @@ -11,7 +12,7 @@ type Transaction struct { // Regexp is supported by putting '$' before the MSP regexp e.g. []string{`$org\dMSP`}. // Please note this restriction DOES NOT protect ledger data from being // read by unauthorized organizations, this should be done with Private Data. - Callers []string `json:"callers,omitempty"` + Callers []accesscontrol.Caller `json:"callers,omitempty"` // Tag is how the tx will be called. Tag string `json:"tag"` diff --git a/transactions/txList.go b/transactions/txList.go index 68cfdac..f4ffb15 100644 --- a/transactions/txList.go +++ b/transactions/txList.go @@ -1,6 +1,9 @@ package transactions -import "github.com/goledgerdev/cc-tools/assets" +import ( + "github.com/goledgerdev/cc-tools/accesscontrol" + "github.com/goledgerdev/cc-tools/assets" +) var txList = []Transaction{} @@ -45,7 +48,14 @@ func FetchTx(txName string) *Transaction { func InitTxList(l []Transaction) { txList = append(l, basicTxs...) if assets.GetEnabledDynamicAssetType() { - callers := assets.GetAssetAdminsDynamicAssetType() + callersMSP := assets.GetAssetAdminsDynamicAssetType() + var callers []accesscontrol.Caller + for _, msp := range callersMSP { + callers = append(callers, accesscontrol.Caller{ + MSP: msp, + }) + } + for i := range dynamicAssetTypesTxs { if dynamicAssetTypesTxs[i].Tag != "loadAssetTypeList" { dynamicAssetTypesTxs[i].Callers = callers From fa60f83cadeaf9fe2b93b6775820a6c8a839756f Mon Sep 17 00:00:00 2001 From: mikaellafs Date: Tue, 12 Sep 2023 18:31:23 -0300 Subject: [PATCH 10/31] Initialize creator in mock stub Signed-off-by: mikaellafs --- mock/mockstub.go | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/mock/mockstub.go b/mock/mockstub.go index 718fdbd..2a498c7 100644 --- a/mock/mockstub.go +++ b/mock/mockstub.go @@ -17,6 +17,7 @@ import ( "github.com/golang/protobuf/ptypes/timestamp" "github.com/hyperledger/fabric-chaincode-go/shim" "github.com/hyperledger/fabric-protos-go/ledger/queryresult" + "github.com/hyperledger/fabric-protos-go/msp" pb "github.com/hyperledger/fabric-protos-go/peer" ) @@ -291,10 +292,10 @@ func (stub *MockStub) GetStateByRange(startKey, endKey string) (shim.StateQueryI return NewMockStateRangeQueryIterator(stub, startKey, endKey), nil } -//To ensure that simple keys do not go into composite key namespace, -//we validate simplekey to check whether the key starts with 0x00 (which -//is the namespace for compositeKey). This helps in avoding simple/composite -//key collisions. +// To ensure that simple keys do not go into composite key namespace, +// we validate simplekey to check whether the key starts with 0x00 (which +// is the namespace for compositeKey). This helps in avoding simple/composite +// key collisions. func validateSimpleKeys(simpleKeys ...string) error { for _, key := range simpleKeys { if len(key) > 0 && key[0] == compositeKeyNamespace[0] { @@ -508,10 +509,25 @@ func NewMockStub(name string, cc shim.Chaincode) *MockStub { s.Keys = list.New() s.ChaincodeEventsChannel = make(chan *pb.ChaincodeEvent, 100) //define large capacity for non-blocking setEvent calls. s.Decorations = make(map[string][]byte) - + s.Creator, _ = newCreator(name, []byte{}) return s } +// NewMockStubWithCert Constructor to initialize mock stub with a certificate. Useful for transactions with robust permissioning. +func NewMockStubWithCert(name string, cc shim.Chaincode, cert []byte) (*MockStub, error) { + s := NewMockStub(name, cc) + var err error + s.Creator, err = newCreator(name, cert) + + return s, err +} + +func newCreator(orgMSP string, cert []byte) ([]byte, error) { + sid := &msp.SerializedIdentity{Mspid: orgMSP, + IdBytes: cert} + return proto.Marshal(sid) +} + /***************************** Range Query Iterator *****************************/ From 4570f75fb0709ac77ea6a94a7a5f1ba4dc6a2c58 Mon Sep 17 00:00:00 2001 From: mikaellafs Date: Wed, 13 Sep 2023 17:55:37 -0300 Subject: [PATCH 11/31] Remove @lastTouchBy from everything but history queries Signed-off-by: mikaellafs --- assets/get.go | 3 ++ assets/put.go | 3 ++ assets/search.go | 2 ++ test/assets_get_test.go | 62 ++++++++++++++++----------------- test/assets_put_test.go | 5 +-- test/tryout_test.go | 37 +++++++++----------- test/tx_createAssetType_test.go | 2 +- test/tx_createAsset_test.go | 2 +- test/tx_deleteAsset_test.go | 1 + test/tx_readAsset_test.go | 25 +++++++------ test/tx_updateAsset_test.go | 4 +-- transactions/readAsset.go | 10 +++++- 12 files changed, 83 insertions(+), 73 deletions(-) diff --git a/assets/get.go b/assets/get.go index ce84f0a..e6de77e 100644 --- a/assets/get.go +++ b/assets/get.go @@ -41,6 +41,8 @@ func get(stub *sw.StubWrapper, pvtCollection, key string, committed bool) (*Asse return nil, errors.WrapErrorWithStatus(err, "failed to unmarshal asset from ledger", 500) } + delete(response, "@lastTouchBy") + return &response, nil } @@ -179,6 +181,7 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [ return nil, errors.WrapErrorWithStatus(err, "failed to unmarshal asset from ledger", 500) } + delete(response, "@lastTouchBy") keysCheckedInScope := make([]string, 0) for k, v := range response { diff --git a/assets/put.go b/assets/put.go index 15bf91b..4d988f8 100644 --- a/assets/put.go +++ b/assets/put.go @@ -46,6 +46,9 @@ func (a *Asset) put(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCErr if err != nil { return nil, errors.WrapError(err, "failed to write asset to ledger") } + + delete(*a, "@lastTouchBy") + return *a, nil } diff --git a/assets/search.go b/assets/search.go index cb40bd9..0ba2ec0 100644 --- a/assets/search.go +++ b/assets/search.go @@ -99,6 +99,8 @@ func Search(stub *sw.StubWrapper, request map[string]interface{}, privateCollect data = asset } + delete(data, "@lastTouchBy") + searchResult = append(searchResult, data) } diff --git a/test/assets_get_test.go b/test/assets_get_test.go index a237edd..ee33ce5 100644 --- a/test/assets_get_test.go +++ b/test/assets_get_test.go @@ -16,13 +16,12 @@ func TestGetAsset(t *testing.T) { // State setup expectedResponse := assets.Asset{ - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTouchBy": "org1MSP", - "@lastTx": "createAsset", - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 0.0, + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTx": "createAsset", + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 0.0, } stub.MockTransactionStart("setupGetAsset") setupState, _ := json.Marshal(expectedResponse) @@ -93,6 +92,9 @@ func TestGetManyAssets(t *testing.T) { stub.PutState("person:916c708a-1d6c-5c4f-8f12-d9d36f2aad27", setupState) stub.MockTransactionEnd("setupGetManyAssets") + delete(asset1, "@lastTouchBy") + delete(asset2, "@lastTouchBy") + delete(asset3, "@lastTouchBy") expectedResponse := []*assets.Asset{&asset1, &asset2, &asset3} assetKeys := []assets.Key{ @@ -160,6 +162,8 @@ func TestGetCommittedAsset(t *testing.T) { log.Println(err) t.FailNow() } + + delete(expectedResponse, "@lastTouchBy") if !reflect.DeepEqual(*gotAsset, expectedResponse) { log.Println("these should be deeply equal") log.Println(expectedResponse) @@ -215,20 +219,18 @@ func TestGetRecursive(t *testing.T) { "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", } expectedResponse := map[string]interface{}{ - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTouchBy": "org2MSP", - "@lastTx": "createAsset", - "@assetType": "book", - "title": "Meu Nome é Maria", - "author": "Maria Viana", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTx": "createAsset", + "@assetType": "book", + "title": "Meu Nome é Maria", + "author": "Maria Viana", "currentTenant": map[string]interface{}{ - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTouchBy": "org1MSP", - "@lastTx": "createAsset", - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 0.0, + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTx": "createAsset", + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 0.0, }, "genres": []interface{}{"biography", "non-fiction"}, "published": "2019-05-06T22:12:41Z", @@ -294,18 +296,16 @@ func TestGetRecursiveWithPvtData(t *testing.T) { "@key": "library:37262f3f-5f08-5649-b488-e5abaad266e1", } expectedResponse := map[string]interface{}{ - "@assetType": "library", - "@key": "library:37262f3f-5f08-5649-b488-e5abaad266e1", - "@lastTouchBy": "org3MSP", - "@lastTx": "createAsset", - "name": "Biblioteca Maria da Silva", + "@assetType": "library", + "@key": "library:37262f3f-5f08-5649-b488-e5abaad266e1", + "@lastTx": "createAsset", + "name": "Biblioteca Maria da Silva", "entranceCode": map[string]interface{}{ - "@assetType": "secret", - "@key": "secret:73a3f9a7-eb91-5f4d-b1bb-c0487e90f40b", - "@lastTouchBy": "org2MSP", - "@lastTx": "createAsset", - "secretName": "testSecret", - "secret": "this is very secret", + "@assetType": "secret", + "@key": "secret:73a3f9a7-eb91-5f4d-b1bb-c0487e90f40b", + "@lastTx": "createAsset", + "secretName": "testSecret", + "secret": "this is very secret", }, } diff --git a/test/assets_put_test.go b/test/assets_put_test.go index f9391a8..fc5cb57 100644 --- a/test/assets_put_test.go +++ b/test/assets_put_test.go @@ -117,6 +117,7 @@ func TestPutAssetWithSubAsset(t *testing.T) { t.FailNow() } + expectedState["@lastTouchBy"] = "org1MSP" if !reflect.DeepEqual(expectedState, state) { log.Println("these should be deeply equal") log.Println(expectedState) @@ -158,7 +159,6 @@ func TestPutNewAssetRecursive(t *testing.T) { expectedBook := map[string]interface{}{ "@assetType": "book", "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTouchBy": "org1MSP", "@lastTx": "", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "title": "Meu Nome é Maria", @@ -166,7 +166,6 @@ func TestPutNewAssetRecursive(t *testing.T) { "currentTenant": map[string]interface{}{ "@assetType": "person", "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTouchBy": "org1MSP", "@lastTx": "", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "name": "Maria", @@ -267,7 +266,6 @@ func TestUpdateRecursive(t *testing.T) { expectedBook := map[string]interface{}{ "@assetType": "book", "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTouchBy": "org1MSP", "@lastTx": "", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "title": "Meu Nome é Maria", @@ -275,7 +273,6 @@ func TestUpdateRecursive(t *testing.T) { "currentTenant": map[string]interface{}{ "@assetType": "person", "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTouchBy": "org1MSP", "@lastTx": "", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "name": "Maria", diff --git a/test/tryout_test.go b/test/tryout_test.go index 99b5573..e0510f6 100644 --- a/test/tryout_test.go +++ b/test/tryout_test.go @@ -23,13 +23,12 @@ func TestTryout(t *testing.T) { } expectedPerson := []interface{}{ map[string]interface{}{ - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTouchBy": "org1MSP", - "@lastTx": "createAsset", - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 0.0, + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTx": "createAsset", + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 0.0, }, } @@ -59,12 +58,11 @@ func TestTryout(t *testing.T) { expectedBook := []interface{}{ map[string]interface{}{ - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTouchBy": "org2MSP", - "@lastTx": "createAsset", - "@assetType": "book", - "title": "Meu Nome é Maria", - "author": "Maria Viana", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTx": "createAsset", + "@assetType": "book", + "title": "Meu Nome é Maria", + "author": "Maria Viana", "currentTenant": map[string]interface{}{ "@assetType": "person", "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", @@ -112,13 +110,12 @@ func TestTryout(t *testing.T) { } expectedUpdatePerson := map[string]interface{}{ - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTouchBy": "org2MSP", - "@lastTx": "updateAsset", - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 1.67, + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTx": "updateAsset", + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 1.67, } err = invokeAndVerify(stub, "updateAsset", reqUpdatePerson, expectedUpdatePerson, 200) diff --git a/test/tx_createAssetType_test.go b/test/tx_createAssetType_test.go index 6a72ec5..80d6e7b 100644 --- a/test/tx_createAssetType_test.go +++ b/test/tx_createAssetType_test.go @@ -118,7 +118,6 @@ func TestCreateAssetType(t *testing.T) { lastUpdated, _ := stub.GetTxTimestamp() expectedResponse = map[string]interface{}{ "@key": "magazine:236a29db-f53c-59e1-ac6d-a4f264dbc477", - "@lastTouchBy": "org1MSP", "@lastTx": "createAsset", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "@assetType": "magazine", @@ -161,6 +160,7 @@ func TestCreateAssetType(t *testing.T) { t.FailNow() } + expectedResponse["@lastTouchBy"] = "org1MSP" if !reflect.DeepEqual(state, expectedResponse) { log.Println("these should be equal") log.Printf("%#v\n", state) diff --git a/test/tx_createAsset_test.go b/test/tx_createAsset_test.go index 00b0d6a..6a7e59e 100644 --- a/test/tx_createAsset_test.go +++ b/test/tx_createAsset_test.go @@ -35,7 +35,6 @@ func TestCreateAsset(t *testing.T) { lastUpdated, _ := stub.GetTxTimestamp() expectedResponse := map[string]interface{}{ "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTouchBy": "org1MSP", "@lastTx": "createAsset", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "@assetType": "person", @@ -80,6 +79,7 @@ func TestCreateAsset(t *testing.T) { t.FailNow() } + expectedResponse["@lastTouchBy"] = "org1MSP" if !reflect.DeepEqual(state, expectedResponse) { log.Println("these should be equal") log.Printf("%#v\n", state) diff --git a/test/tx_deleteAsset_test.go b/test/tx_deleteAsset_test.go index 313a46c..e4736d0 100644 --- a/test/tx_deleteAsset_test.go +++ b/test/tx_deleteAsset_test.go @@ -62,6 +62,7 @@ func TestDeleteAsset(t *testing.T) { t.FailNow() } + delete(expectedResponse, "@lastTouchBy") if !reflect.DeepEqual(resPayload, expectedResponse) { log.Println("these should be equal") log.Printf("%#v\n", resPayload) diff --git a/test/tx_readAsset_test.go b/test/tx_readAsset_test.go index 32d7f10..baa4985 100644 --- a/test/tx_readAsset_test.go +++ b/test/tx_readAsset_test.go @@ -55,6 +55,7 @@ func TestReadAsset(t *testing.T) { t.FailNow() } + delete(expectedResponse, "@lastTouchBy") if !reflect.DeepEqual(resPayload, expectedResponse) { log.Println("these should be equal") log.Printf("%#v\n", resPayload) @@ -109,20 +110,18 @@ func TestReadRecursive(t *testing.T) { "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", } expectedResponse := map[string]interface{}{ - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTouchBy": "org2MSP", - "@lastTx": "createAsset", - "@assetType": "book", - "title": "Meu Nome é Maria", - "author": "Maria Viana", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTx": "createAsset", + "@assetType": "book", + "title": "Meu Nome é Maria", + "author": "Maria Viana", "currentTenant": map[string]interface{}{ - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTouchBy": "org1MSP", - "@lastTx": "createAsset", - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 0.0, + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTx": "createAsset", + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 0.0, }, "genres": []interface{}{"biography", "non-fiction"}, "published": "2019-05-06T22:12:41Z", diff --git a/test/tx_updateAsset_test.go b/test/tx_updateAsset_test.go index d2edb8d..84393d9 100644 --- a/test/tx_updateAsset_test.go +++ b/test/tx_updateAsset_test.go @@ -69,7 +69,6 @@ func TestUpdateAsset(t *testing.T) { expectedPerson := map[string]interface{}{ "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTouchBy": "org1MSP", "@lastTx": "updateAsset", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "@assetType": "person", @@ -93,9 +92,10 @@ func TestUpdateAsset(t *testing.T) { t.FailNow() } + expectedPerson["@lastTouchBy"] = "org1MSP" if !reflect.DeepEqual(state, expectedPerson) { log.Println("these should be equal") - log.Printf("%#v\n", resPayload) + log.Printf("%#v\n", state) log.Printf("%#v\n", expectedPerson) t.FailNow() } diff --git a/transactions/readAsset.go b/transactions/readAsset.go index d03a0bc..ece11c4 100644 --- a/transactions/readAsset.go +++ b/transactions/readAsset.go @@ -51,7 +51,15 @@ var ReadAsset = Transaction{ return nil, errors.WrapErrorWithStatus(err, "failed to serialize asset", 500) } } else { - assetJSON, err = key.GetBytes(stub) + var asset *assets.Asset + asset, err = key.Get(stub) + if err != nil { + return nil, errors.WrapError(err, "failed to get asset state") + } + + delete(*asset, "@lastTouchBy") + + assetJSON, err = json.Marshal(asset) if err != nil { return nil, errors.WrapError(err, "failed to get asset state") } From ba0b37f030cd450fd4562f5ba5680efd39b59b16 Mon Sep 17 00:00:00 2001 From: mikaellafs Date: Fri, 15 Sep 2023 11:25:27 -0300 Subject: [PATCH 12/31] Add collection name property to assetType Signed-off-by: mikaellafs --- assets/asset.go | 10 ++++++++++ assets/assetType.go | 13 +++++++++++++ assets/delete.go | 2 +- assets/existsInLedger.go | 20 ++++++++++---------- assets/get.go | 20 ++++++++++---------- assets/key.go | 10 ++++++++++ assets/put.go | 2 +- 7 files changed, 55 insertions(+), 22 deletions(-) diff --git a/assets/asset.go b/assets/asset.go index aaf93e6..266235f 100644 --- a/assets/asset.go +++ b/assets/asset.go @@ -106,6 +106,16 @@ func (a Asset) IsPrivate() bool { return assetTypeDef.IsPrivate() } +func (a Asset) CollectionName() string { + // Fetch asset properties + assetTypeDef := a.Type() + if assetTypeDef == nil { + return "" + } + + return assetTypeDef.CollectionName() +} + // TypeTag returns the @assetType attribute. func (a Asset) TypeTag() string { assetType, _ := a["@assetType"].(string) diff --git a/assets/assetType.go b/assets/assetType.go index e73a8dc..d98793c 100644 --- a/assets/assetType.go +++ b/assets/assetType.go @@ -30,6 +30,10 @@ type AssetType struct { // Dynamic is a flag that indicates if the asset type is dynamic. Dynamic bool `json:"dynamic,omitempty"` + + // Private collection name it belongs to. When empty and len(readers) > 0, + // Tag is considered instead + Collection string `json:"collection,omitempty"` } // Keys returns a list of asset properties which are defined as primary keys. (IsKey == true) @@ -81,6 +85,15 @@ func (t AssetType) IsPrivate() bool { return len(t.Readers) > 0 } +// CollectionName returns the private collection name. Default is tag. +func (t AssetType) CollectionName() string { + if t.Collection == "" { + return t.Tag + } + + return t.Collection +} + // ToMap returns a map representation of the asset type. func (t AssetType) ToMap() map[string]interface{} { return map[string]interface{}{ diff --git a/assets/delete.go b/assets/delete.go index 79b07b3..7200a23 100644 --- a/assets/delete.go +++ b/assets/delete.go @@ -34,7 +34,7 @@ func (a *Asset) delete(stub *sw.StubWrapper) ([]byte, errors.ICCError) { return nil, errors.WrapError(err, "failed to marshal asset") } } else { - err = stub.DelPrivateData(a.TypeTag(), a.Key()) + err = stub.DelPrivateData(a.CollectionName(), a.Key()) if err != nil { return nil, errors.WrapError(err, "failed to delete state from private collection") } diff --git a/assets/existsInLedger.go b/assets/existsInLedger.go index 1a729da..c1174f1 100644 --- a/assets/existsInLedger.go +++ b/assets/existsInLedger.go @@ -6,15 +6,15 @@ import ( sw "github.com/goledgerdev/cc-tools/stubwrapper" ) -func existsInLedger(stub *sw.StubWrapper, isPrivate bool, typeTag, key string) (bool, errors.ICCError) { +func existsInLedger(stub *sw.StubWrapper, isPrivate bool, collection, key string) (bool, errors.ICCError) { var assetBytes []byte var err error if isPrivate { _, isMock := stub.Stub.(*mock.MockStub) if isMock { - assetBytes, err = stub.GetPrivateData(typeTag, key) + assetBytes, err = stub.GetPrivateData(collection, key) } else { - assetBytes, err = stub.GetPrivateDataHash(typeTag, key) + assetBytes, err = stub.GetPrivateDataHash(collection, key) } } else { assetBytes, err = stub.GetState(key) @@ -34,7 +34,7 @@ func (a *Asset) ExistsInLedger(stub *sw.StubWrapper) (bool, errors.ICCError) { if a.Key() == "" { return false, errors.NewCCError("asset key is empty", 500) } - return existsInLedger(stub, a.IsPrivate(), a.TypeTag(), a.Key()) + return existsInLedger(stub, a.IsPrivate(), a.CollectionName(), a.Key()) } // ExistsInLedger checks if asset referenced by a key object currently has a state. @@ -42,20 +42,20 @@ func (k *Key) ExistsInLedger(stub *sw.StubWrapper) (bool, errors.ICCError) { if k.Key() == "" { return false, errors.NewCCError("key is empty", 500) } - return existsInLedger(stub, k.IsPrivate(), k.TypeTag(), k.Key()) + return existsInLedger(stub, k.IsPrivate(), k.CollectionName(), k.Key()) } // ---------------------------------------- -func committedInLedger(stub *sw.StubWrapper, isPrivate bool, typeTag, key string) (bool, errors.ICCError) { +func committedInLedger(stub *sw.StubWrapper, isPrivate bool, collection, key string) (bool, errors.ICCError) { var assetBytes []byte var err error if isPrivate { _, isMock := stub.Stub.(*mock.MockStub) if isMock { - assetBytes, err = stub.Stub.GetPrivateData(typeTag, key) + assetBytes, err = stub.Stub.GetPrivateData(collection, key) } else { - assetBytes, err = stub.Stub.GetPrivateDataHash(typeTag, key) + assetBytes, err = stub.Stub.GetPrivateDataHash(collection, key) } } else { assetBytes, err = stub.Stub.GetState(key) @@ -75,7 +75,7 @@ func (a *Asset) CommittedInLedger(stub *sw.StubWrapper) (bool, errors.ICCError) if a.Key() == "" { return false, errors.NewCCError("asset key is empty", 500) } - return committedInLedger(stub, a.IsPrivate(), a.TypeTag(), a.Key()) + return committedInLedger(stub, a.IsPrivate(), a.CollectionName(), a.Key()) } // CommittedInLedger checks if asset referenced by a key object currently has a state committed in ledger. @@ -83,5 +83,5 @@ func (k *Key) CommittedInLedger(stub *sw.StubWrapper) (bool, errors.ICCError) { if k.Key() == "" { return false, errors.NewCCError("key is empty", 500) } - return committedInLedger(stub, k.IsPrivate(), k.TypeTag(), k.Key()) + return committedInLedger(stub, k.IsPrivate(), k.CollectionName(), k.Key()) } diff --git a/assets/get.go b/assets/get.go index ce84f0a..816743f 100644 --- a/assets/get.go +++ b/assets/get.go @@ -48,7 +48,7 @@ func get(stub *sw.StubWrapper, pvtCollection, key string, committed bool) (*Asse func (a *Asset) Get(stub *sw.StubWrapper) (*Asset, errors.ICCError) { var pvtCollection string if a.IsPrivate() { - pvtCollection = a.TypeTag() + pvtCollection = a.CollectionName() } return get(stub, pvtCollection, a.Key(), false) @@ -58,7 +58,7 @@ func (a *Asset) Get(stub *sw.StubWrapper) (*Asset, errors.ICCError) { func (k *Key) Get(stub *sw.StubWrapper) (*Asset, errors.ICCError) { var pvtCollection string if k.IsPrivate() { - pvtCollection = k.TypeTag() + pvtCollection = k.CollectionName() } return get(stub, pvtCollection, k.Key(), false) @@ -71,7 +71,7 @@ func GetMany(stub *sw.StubWrapper, keys []Key) ([]*Asset, errors.ICCError) { for _, k := range keys { var pvtCollection string if k.IsPrivate() { - pvtCollection = k.TypeTag() + pvtCollection = k.CollectionName() } asset, err := get(stub, pvtCollection, k.Key(), false) @@ -88,7 +88,7 @@ func GetMany(stub *sw.StubWrapper, keys []Key) ([]*Asset, errors.ICCError) { func (a *Asset) GetCommitted(stub *sw.StubWrapper) (*Asset, errors.ICCError) { var pvtCollection string if a.IsPrivate() { - pvtCollection = a.TypeTag() + pvtCollection = a.CollectionName() } return get(stub, pvtCollection, a.Key(), true) @@ -98,7 +98,7 @@ func (a *Asset) GetCommitted(stub *sw.StubWrapper) (*Asset, errors.ICCError) { func (k *Key) GetCommitted(stub *sw.StubWrapper) (*Asset, errors.ICCError) { var pvtCollection string if k.IsPrivate() { - pvtCollection = k.TypeTag() + pvtCollection = k.CollectionName() } return get(stub, pvtCollection, k.Key(), true) @@ -109,7 +109,7 @@ func (k *Key) GetBytes(stub *sw.StubWrapper) ([]byte, errors.ICCError) { var assetBytes []byte var err error if k.IsPrivate() { - assetBytes, err = stub.GetPrivateData(k.TypeTag(), k.Key()) + assetBytes, err = stub.GetPrivateData(k.CollectionName(), k.Key()) } else { assetBytes, err = stub.GetState(k.Key()) } @@ -218,7 +218,7 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [ var subAsset map[string]interface{} if propKey.IsPrivate() { - subAsset, err = getRecursive(stub, propKey.TypeTag(), propKey.Key(), keysChecked) + subAsset, err = getRecursive(stub, propKey.CollectionName(), propKey.Key(), keysChecked) } else { subAsset, err = getRecursive(stub, "", propKey.Key(), keysChecked) } @@ -265,7 +265,7 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [ var subAsset map[string]interface{} if elemKey.IsPrivate() { - subAsset, err = getRecursive(stub, elemKey.TypeTag(), elemKey.Key(), keysChecked) + subAsset, err = getRecursive(stub, elemKey.CollectionName(), elemKey.Key(), keysChecked) } else { subAsset, err = getRecursive(stub, "", elemKey.Key(), keysChecked) } @@ -287,7 +287,7 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [ func (a *Asset) GetRecursive(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCError) { var pvtCollection string if a.IsPrivate() { - pvtCollection = a.TypeTag() + pvtCollection = a.CollectionName() } return getRecursive(stub, pvtCollection, a.Key(), []string{}) @@ -297,7 +297,7 @@ func (a *Asset) GetRecursive(stub *sw.StubWrapper) (map[string]interface{}, erro func (k *Key) GetRecursive(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCError) { var pvtCollection string if k.IsPrivate() { - pvtCollection = k.TypeTag() + pvtCollection = k.CollectionName() } return getRecursive(stub, pvtCollection, k.Key(), []string{}) diff --git a/assets/key.go b/assets/key.go index 5e4e646..7c41eac 100644 --- a/assets/key.go +++ b/assets/key.go @@ -99,6 +99,16 @@ func (k Key) IsPrivate() bool { return assetTypeDef.IsPrivate() } +func (k Key) CollectionName() string { + // Fetch asset properties + assetTypeDef := k.Type() + if assetTypeDef == nil { + return "" + } + + return assetTypeDef.CollectionName() +} + // TypeTag returns @assetType attribute func (k Key) TypeTag() string { assetType, _ := k["@assetType"].(string) diff --git a/assets/put.go b/assets/put.go index 15bf91b..f9f445d 100644 --- a/assets/put.go +++ b/assets/put.go @@ -31,7 +31,7 @@ func (a *Asset) put(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCErr // Write asset to blockchain if a.IsPrivate() { - err = stub.PutPrivateData(a.TypeTag(), a.Key(), assetJSON) + err = stub.PutPrivateData(a.CollectionName(), a.Key(), assetJSON) if err != nil { return nil, errors.WrapError(err, "failed to write asset to ledger") } From aa76fb643f5f0c5437570a30a74c5bb8a492a8d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Fri, 15 Sep 2023 15:47:56 -0300 Subject: [PATCH 13/31] Fix ->@asset prop validation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Macedo --- assets/validateProp.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/assets/validateProp.go b/assets/validateProp.go index 9fd9565..a65c2fe 100644 --- a/assets/validateProp.go +++ b/assets/validateProp.go @@ -2,6 +2,7 @@ package assets import ( "fmt" + "net/http" "reflect" "strings" @@ -84,10 +85,12 @@ func validateProp(prop interface{}, propDef AssetProp) (interface{}, error) { // Add assetType to received object recvMap["@assetType"] = dataTypeName } else { - _, ok := recvMap["@assetType"].(string) - if !ok { - return nil, errors.NewCCError("invalid asset reference: missing '@assetType' property", 400) + keyStr, keyExists := recvMap["@key"].(string) + if !keyExists { + return nil, errors.NewCCError("invalid asset reference: missing '@key' property", http.StatusBadRequest) } + assetTypeName := keyStr[:strings.IndexByte(keyStr, ':')] + recvMap["@assetType"] = assetTypeName } // Check if all key props are included From c8e1362bf7f5439757e54374a3a7724bc84409b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Fri, 15 Sep 2023 16:03:32 -0300 Subject: [PATCH 14/31] Improve ->@asset prop validation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Macedo --- assets/validateProp.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/assets/validateProp.go b/assets/validateProp.go index a65c2fe..de45adc 100644 --- a/assets/validateProp.go +++ b/assets/validateProp.go @@ -86,11 +86,20 @@ func validateProp(prop interface{}, propDef AssetProp) (interface{}, error) { recvMap["@assetType"] = dataTypeName } else { keyStr, keyExists := recvMap["@key"].(string) - if !keyExists { - return nil, errors.NewCCError("invalid asset reference: missing '@key' property", http.StatusBadRequest) + assetTypeStr, typeExists := recvMap["@assetType"].(string) + if !keyExists && !typeExists { + return nil, errors.NewCCError("invalid asset reference: missing '@key' or '@assetType' property", http.StatusBadRequest) + } + if keyExists { + assetTypeName := keyStr[:strings.IndexByte(keyStr, ':')] + if !typeExists { + recvMap["@assetType"] = assetTypeName + } else { + if assetTypeName != assetTypeStr { + return nil, errors.NewCCError("invalid asset reference: '@key' and '@assetType' properties do not match", http.StatusBadRequest) + } + } } - assetTypeName := keyStr[:strings.IndexByte(keyStr, ':')] - recvMap["@assetType"] = assetTypeName } // Check if all key props are included From 0a240ac1fd49d844a104676d4d4d0334fd141177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Mon, 18 Sep 2023 15:53:30 -0300 Subject: [PATCH 15/31] Add collection to getSchema MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Macedo --- transactions/getSchema.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/transactions/getSchema.go b/transactions/getSchema.go index 2157b8c..8943e9e 100644 --- a/transactions/getSchema.go +++ b/transactions/getSchema.go @@ -59,6 +59,7 @@ var GetSchema = Transaction{ Readers []string `json:"readers,omitempty"` Writers []string `json:"writers"` Dynamic bool `json:"dynamic"` + Collection string `json:"collection,omitempty"` } var assetList []assetListElem for _, assetTypeDef := range assetTypeList { @@ -68,6 +69,7 @@ var GetSchema = Transaction{ Description: assetTypeDef.Description, Readers: assetTypeDef.Readers, Dynamic: assetTypeDef.Dynamic, + Collection: assetTypeDef.Collection, }) } From 191214fdbbf685ed9a826443597bb7ae85c625b2 Mon Sep 17 00:00:00 2001 From: mikaellafs Date: Tue, 19 Sep 2023 16:06:02 -0300 Subject: [PATCH 16/31] Check if asset need to be updated in updateRecursive Signed-off-by: mikaellafs --- assets/put.go | 50 +++++++++++++++++++++++++++++++----------------- assets/update.go | 8 +++----- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/assets/put.go b/assets/put.go index 15bf91b..061baad 100644 --- a/assets/put.go +++ b/assets/put.go @@ -3,6 +3,7 @@ package assets import ( "encoding/json" "fmt" + "reflect" "strings" "github.com/goledgerdev/cc-tools/errors" @@ -97,30 +98,43 @@ func putRecursive(stub *sw.StubWrapper, object map[string]interface{}, root bool return nil, errors.WrapError(err, "unable to create asset object") } - if !root { - exists, err := objAsKey.ExistsInLedger(stub) + exists, err := objAsKey.ExistsInLedger(stub) + if err != nil { + return nil, errors.WrapError(err, "failed checking if asset exists") + } + + asset := map[string]interface{}{} + if exists && !root { + asset, err = objAsKey.GetRecursive(stub) if err != nil { - return nil, errors.WrapError(err, "failed checking if asset exists") + return nil, errors.WrapError(err, "failed fetching sub-asset that already exists") } - if exists { - asset, err := objAsKey.GetRecursive(stub) - if err != nil { - return nil, errors.WrapError(err, "failed fetching sub-asset that already exists") - } - if asset == nil { - return nil, errors.NewCCError("existing sub-asset could not be fetched", 404) - } + if asset == nil { + return nil, errors.NewCCError("existing sub-asset could not be fetched", 404) + } + } else if exists { + asset, err = objAsKey.GetMap(stub) + if err != nil { + return nil, errors.WrapError(err, "failed fetching asset that already exists") + } + } - // If asset key is not in object, add asset value to object (so that properties are not erased) - for k := range asset { - if _, ok := object[k]; !ok { - object[k] = asset[k] - } - } + // If asset key is not in object, add asset value to object (so that properties are not erased) + for k := range asset { + if _, ok := object[k]; !ok { + object[k] = asset[k] + } + } - // TODO: check property by property if asset must be updated + var shouldUpdate bool + for k, v := range object { + if !reflect.DeepEqual(v, asset[k]) { + shouldUpdate = true } } + if !shouldUpdate { + return asset, nil + } objAsAsset, err := NewAsset(object) if err != nil { diff --git a/assets/update.go b/assets/update.go index 255dc54..da7236a 100644 --- a/assets/update.go +++ b/assets/update.go @@ -159,11 +159,9 @@ func (k *Key) Update(stub *sw.StubWrapper, update map[string]interface{}) (map[s writePermission = true break } - } else { // if writer is not regexp - if w == txCreator { - writePermission = true - break - } + } else if w == txCreator { // if writer is not regexp + writePermission = true + break } } if !writePermission { From fd6c110da1e0f5c8d6507e4e96f69aa478614903 Mon Sep 17 00:00:00 2001 From: mikaellafs Date: Tue, 19 Sep 2023 16:06:26 -0300 Subject: [PATCH 17/31] Add test case to updateRecursive test Signed-off-by: mikaellafs --- test/assets_put_test.go | 362 +++++++++++++++++++++++++++++----------- 1 file changed, 264 insertions(+), 98 deletions(-) diff --git a/test/assets_put_test.go b/test/assets_put_test.go index f9391a8..36b371f 100644 --- a/test/assets_put_test.go +++ b/test/assets_put_test.go @@ -218,110 +218,276 @@ func TestPutNewAssetRecursive(t *testing.T) { func TestUpdateRecursive(t *testing.T) { stub := mock.NewMockStub("org1MSP", new(testCC)) - - // Create a book - stub.MockTransactionStart("TestPutAsset") sw := &sw.StubWrapper{ Stub: stub, } - book := map[string]interface{}{ - "@assetType": "book", - "title": "Meu Nome é Maria", - "author": "Maria Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 1.66, - }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": "2019-05-06T22:12:41Z", - } - - var err error - _, err = assets.PutNewRecursive(sw, book) - if err != nil { - log.Println(err) - t.FailNow() - } - stub.MockTransactionEnd("TestPutAsset") - // Update the book and the tenant - stub.MockTransactionStart("TestUpdateAsset") - book["published"] = "2022-05-06T22:12:41Z" - book["currentTenant"] = map[string]interface{}{ - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 1.88, - } - - putBook, err := assets.UpdateRecursive(sw, book) - if err != nil { - log.Println(err) - t.FailNow() - } - - publishedTime, _ := time.Parse(time.RFC3339, "2022-05-06T22:12:41Z") - lastUpdated, _ := stub.GetTxTimestamp() - expectedBook := map[string]interface{}{ - "@assetType": "book", - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTouchBy": "org1MSP", - "@lastTx": "", - "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), - "title": "Meu Nome é Maria", - "author": "Maria Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTouchBy": "org1MSP", - "@lastTx": "", - "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), - "name": "Maria", - "id": "31820792048", - "height": 1.88, + tests := []struct { + description string + + assetkey string + asset map[string]interface{} + updateReq map[string]interface{} + expectedResponse func(lastUpdated string) map[string]interface{} + expectedState func(lastUpdated string) map[string]interface{} + }{ + { + description: "update recursive book", + + assetkey: "book:a36a2920-c405-51c3-b584-dcd758338cb5", + asset: map[string]interface{}{ + "@assetType": "book", + "title": "Meu Nome é Maria", + "author": "Maria Viana", + "currentTenant": map[string]interface{}{ + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 1.66, + }, + "genres": []interface{}{"biography", "non-fiction"}, + "published": "2019-05-06T22:12:41Z", + }, + updateReq: map[string]interface{}{ + "@assetType": "book", + "author": "Maria Viana", + "title": "Meu Nome é Maria", + "published": "2022-05-06T22:12:41Z", + "currentTenant": map[string]interface{}{ + "@assetType": "person", + "id": "31820792048", + "height": 1.88, + }, + }, + expectedResponse: func(lastUpdated string) map[string]interface{} { + publishedTime, _ := time.Parse(time.RFC3339, "2022-05-06T22:12:41Z") + return map[string]interface{}{ + "@assetType": "book", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTouchBy": "org1MSP", + "@lastTx": "", + "@lastUpdated": lastUpdated, + "title": "Meu Nome é Maria", + "author": "Maria Viana", + "currentTenant": map[string]interface{}{ + "@assetType": "person", + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", + "@lastTx": "", + "@lastUpdated": lastUpdated, + "name": "Maria", + "id": "31820792048", + "height": 1.88, + }, + "genres": []interface{}{"biography", "non-fiction"}, + "published": publishedTime, + } + }, + expectedState: func(lastUpdated string) map[string]interface{} { + return map[string]interface{}{ + "@assetType": "book", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTouchBy": "org1MSP", + "@lastTx": "", + "@lastUpdated": lastUpdated, + "title": "Meu Nome é Maria", + "author": "Maria Viana", + "currentTenant": map[string]interface{}{ + "@assetType": "person", + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + }, + "genres": []interface{}{"biography", "non-fiction"}, + "published": "2022-05-06T22:12:41Z", + } + }, }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": publishedTime, - } - - // Check if the book is updated - if !reflect.DeepEqual(expectedBook, putBook) { - log.Println("these should be deeply equal") - log.Println(expectedBook) - log.Println(putBook) - t.FailNow() - } - - expectedState := map[string]interface{}{ - "@assetType": "book", - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTouchBy": "org1MSP", - "@lastTx": "", - "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), - "title": "Meu Nome é Maria", - "author": "Maria Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + { + description: "update books in library", + + assetkey: "library:9c5ffeb3-2491-5a88-858c-653b1ea8dbc5", + asset: map[string]interface{}{ + "@assetType": "library", + "name": "biographies", + "books": []interface{}{ + map[string]interface{}{ + "@assetType": "book", + "title": "Meu Nome é Maria", + "author": "Maria Viana", + "currentTenant": map[string]interface{}{ + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 1.66, + }, + "genres": []interface{}{"biography", "non-fiction"}, + "published": "2019-05-06T22:12:41Z", + }, + map[string]interface{}{ + "@assetType": "book", + "title": "Meu Nome é João", + "author": "João Viana", + "currentTenant": map[string]interface{}{ + "@assetType": "person", + "name": "João", + "id": "42931801159", + "height": 1.90, + }, + "genres": []interface{}{"biography", "non-fiction"}, + "published": "2020-06-06T22:12:41Z", + }, + }, + }, + updateReq: map[string]interface{}{ + "@assetType": "library", + "name": "biographies", + "books": []interface{}{ + map[string]interface{}{ // This book will not be updated + "@assetType": "book", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "title": "Meu Nome é Maria", + "author": "Maria Viana", + "currentTenant": map[string]interface{}{ // This person will not be updated + "@assetType": "person", + "id": "31820792048", + }, + }, + map[string]interface{}{ // This book will be updated + "@assetType": "book", + "title": "Meu Nome é João", + "author": "João Viana", + "currentTenant": map[string]interface{}{ // This person will be updated + "@assetType": "person", + "id": "42931801159", + "height": 1.92, + }, + "published": "2020-06-10T22:12:41Z", + }, + }, + }, + expectedResponse: func(lastUpdated string) map[string]interface{} { + publishedTimeBook1, _ := time.Parse(time.RFC3339, "2019-05-06T22:12:41Z") + publishedTimeBook2, _ := time.Parse(time.RFC3339, "2020-06-10T22:12:41Z") + + return map[string]interface{}{ + "@assetType": "library", + "@key": "library:9c5ffeb3-2491-5a88-858c-653b1ea8dbc5", + "@lastTouchBy": "org1MSP", + "@lastTx": "", + "@lastUpdated": lastUpdated, + "name": "biographies", + "books": []interface{}{ + map[string]interface{}{ + "@assetType": "book", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTouchBy": "org1MSP", + "@lastTx": "", + "@lastUpdated": lastUpdated, + "title": "Meu Nome é Maria", + "author": "Maria Viana", + "currentTenant": map[string]interface{}{ + "@assetType": "person", + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", + "@lastTx": "", + "@lastUpdated": lastUpdated, + "name": "Maria", + "id": "31820792048", + "height": 1.66, + }, + "genres": []interface{}{"biography", "non-fiction"}, + "published": publishedTimeBook1, + }, + map[string]interface{}{ + "@assetType": "book", + "@key": "book:679f58a4-578f-563c-9c22-3f51b9fab6d5", + "@lastTouchBy": "org1MSP", + "@lastTx": "", + "@lastUpdated": lastUpdated, + "title": "Meu Nome é João", + "author": "João Viana", + "currentTenant": map[string]interface{}{ + "@assetType": "person", + "@key": "person:09c4f266-3bac-5d2f-813b-db3c41ab3375", + "@lastTouchBy": "org1MSP", + "@lastTx": "", + "@lastUpdated": lastUpdated, + "name": "João", + "id": "42931801159", + "height": 1.92, + }, + "genres": []interface{}{"biography", "non-fiction"}, + "published": publishedTimeBook2, + }, + }, + } + }, + expectedState: func(lastUpdated string) map[string]interface{} { + return map[string]interface{}{ + "@assetType": "library", + "@key": "library:9c5ffeb3-2491-5a88-858c-653b1ea8dbc5", + "@lastTouchBy": "org1MSP", + "@lastTx": "", + "@lastUpdated": lastUpdated, + "name": "biographies", + "books": []interface{}{ + map[string]interface{}{ + "@assetType": "book", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + }, + map[string]interface{}{ + "@assetType": "book", + "@key": "book:679f58a4-578f-563c-9c22-3f51b9fab6d5", + }, + }, + } + }, }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": "2022-05-06T22:12:41Z", } - - stateJSON := stub.State["book:a36a2920-c405-51c3-b584-dcd758338cb5"] - var state map[string]interface{} - err = json.Unmarshal(stateJSON, &state) - if err != nil { - log.Println(err) - t.FailNow() - } - - if !reflect.DeepEqual(expectedState, state) { - log.Println("these should be deeply equal") - log.Println(expectedState) - log.Println(state) - t.FailNow() + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + // Put asset + stub.MockTransactionStart("TestPutAsset") + var err error + _, err = assets.PutNewRecursive(sw, tt.asset) + if err != nil { + log.Println(err) + t.FailNow() + } + stub.MockTransactionEnd("TestPutAsset") + + // Update asset + stub.MockTransactionStart("TestUpdateAsset") + updateResult, err := assets.UpdateRecursive(sw, tt.updateReq) + if err != nil { + log.Println(err) + t.FailNow() + } + + lastUpdatedTimestamp, _ := stub.GetTxTimestamp() + lastUpdated := lastUpdatedTimestamp.AsTime().Format(time.RFC3339) + if !reflect.DeepEqual(tt.expectedResponse(lastUpdated), updateResult) { + log.Println("these should be deeply equal") + log.Println(tt.expectedResponse(lastUpdated)) + log.Println(updateResult) + t.FailNow() + } + stub.MockTransactionEnd("TestUpdateAsset") + + // Check state + stateJSON := stub.State[tt.assetkey] + var state map[string]interface{} + err = json.Unmarshal(stateJSON, &state) + if err != nil { + log.Println(err) + t.FailNow() + } + + if !reflect.DeepEqual(tt.expectedState(lastUpdated), state) { + log.Println("these should be deeply equal") + log.Println(tt.expectedState(lastUpdated)) + log.Println(state) + t.FailNow() + } + }) } } From 3b227b9812acdbe76c223219bd4f0923a2234b46 Mon Sep 17 00:00:00 2001 From: mikaellafs Date: Wed, 20 Sep 2023 14:09:11 -0300 Subject: [PATCH 18/31] Avoid getRecursive in updateRecursive Signed-off-by: mikaellafs --- assets/put.go | 87 ++++++++++++++++++++--------------------- test/assets_put_test.go | 19 +++------ 2 files changed, 48 insertions(+), 58 deletions(-) diff --git a/assets/put.go b/assets/put.go index 061baad..e065b98 100644 --- a/assets/put.go +++ b/assets/put.go @@ -103,60 +103,49 @@ func putRecursive(stub *sw.StubWrapper, object map[string]interface{}, root bool return nil, errors.WrapError(err, "failed checking if asset exists") } - asset := map[string]interface{}{} - if exists && !root { - asset, err = objAsKey.GetRecursive(stub) - if err != nil { - return nil, errors.WrapError(err, "failed fetching sub-asset that already exists") - } - if asset == nil { - return nil, errors.NewCCError("existing sub-asset could not be fetched", 404) - } - } else if exists { - asset, err = objAsKey.GetMap(stub) + propsToUpdate := map[string]bool{} + if exists { + asset, err := objAsKey.GetMap(stub) if err != nil { return nil, errors.WrapError(err, "failed fetching asset that already exists") } - } - // If asset key is not in object, add asset value to object (so that properties are not erased) - for k := range asset { - if _, ok := object[k]; !ok { - object[k] = asset[k] + // If asset key is not in object, add asset value to object (so that properties are not erased) + for k := range asset { + if _, ok := object[k]; !ok { + object[k] = asset[k] + } } - } - var shouldUpdate bool - for k, v := range object { - if !reflect.DeepEqual(v, asset[k]) { - shouldUpdate = true + // Check props to update + for k, v := range object { + if !reflect.DeepEqual(v, asset[k]) { + propsToUpdate[k] = true + } } } - if !shouldUpdate { - return asset, nil - } - - objAsAsset, err := NewAsset(object) - if err != nil { - return nil, errors.WrapError(err, "unable to create asset object") - } subAssetsMap := map[string]interface{}{} - subAssets := objAsAsset.Type().SubAssets() + subAssets := objAsKey.Type().SubAssets() for _, subAsset := range subAssets { + subAssetInterface, ok := object[subAsset.Tag] + if !ok { + // if subAsset is not included, continue onwards to the next possible subAsset + continue + } + + if propsToUpdate[subAsset.Tag] { + delete(propsToUpdate, subAsset.Tag) + } + + // Extract asset type isArray := false dType := subAsset.DataType if strings.HasPrefix(dType, "[]") { isArray = true dType = strings.TrimPrefix(dType, "[]") } - dType = strings.TrimPrefix(dType, "->") - subAssetInterface, ok := object[subAsset.Tag] - if !ok { - // if subAsset is not included, continue onwards to the next possible subAsset - continue - } var objArray []interface{} if !isArray { @@ -190,22 +179,30 @@ func putRecursive(stub *sw.StubWrapper, object map[string]interface{}, root bool } if isArray { - subAssetsMap[subAsset.Tag] = objArray + object[subAsset.Tag] = objArray } else { - subAssetsMap[subAsset.Tag] = objArray[0] + object[subAsset.Tag] = objArray[0] } + subAssetsMap[subAsset.Tag] = object[subAsset.Tag] } - putAsset, err := objAsAsset.Put(stub) - if err != nil { - return nil, errors.WrapError(err, fmt.Sprintf("failed to put asset of type %s", objAsAsset.TypeTag())) - } + if shouldUpdate := len(propsToUpdate) > 0; shouldUpdate || !exists { + objAsAsset, err := NewAsset(object) + if err != nil { + return nil, errors.WrapError(err, "unable to create asset object") + } - for tag, subAsset := range subAssetsMap { - putAsset[tag] = subAsset + object, err = objAsAsset.Put(stub) + if err != nil { + return nil, errors.WrapError(err, fmt.Sprintf("failed to put asset of type %s", objAsAsset.TypeTag())) + } + + for tag, subAsset := range subAssetsMap { + object[tag] = subAsset + } } - return putAsset, nil + return object, nil } // PutRecursive inserts asset and all its subassets in blockchain. diff --git a/test/assets_put_test.go b/test/assets_put_test.go index 36b371f..5d48825 100644 --- a/test/assets_put_test.go +++ b/test/assets_put_test.go @@ -217,11 +217,6 @@ func TestPutNewAssetRecursive(t *testing.T) { } func TestUpdateRecursive(t *testing.T) { - stub := mock.NewMockStub("org1MSP", new(testCC)) - sw := &sw.StubWrapper{ - Stub: stub, - } - tests := []struct { description string @@ -344,12 +339,6 @@ func TestUpdateRecursive(t *testing.T) { map[string]interface{}{ // This book will not be updated "@assetType": "book", "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "title": "Meu Nome é Maria", - "author": "Maria Viana", - "currentTenant": map[string]interface{}{ // This person will not be updated - "@assetType": "person", - "id": "31820792048", - }, }, map[string]interface{}{ // This book will be updated "@assetType": "book", @@ -365,7 +354,6 @@ func TestUpdateRecursive(t *testing.T) { }, }, expectedResponse: func(lastUpdated string) map[string]interface{} { - publishedTimeBook1, _ := time.Parse(time.RFC3339, "2019-05-06T22:12:41Z") publishedTimeBook2, _ := time.Parse(time.RFC3339, "2020-06-10T22:12:41Z") return map[string]interface{}{ @@ -395,7 +383,7 @@ func TestUpdateRecursive(t *testing.T) { "height": 1.66, }, "genres": []interface{}{"biography", "non-fiction"}, - "published": publishedTimeBook1, + "published": "2019-05-06T22:12:41Z", }, map[string]interface{}{ "@assetType": "book", @@ -445,6 +433,11 @@ func TestUpdateRecursive(t *testing.T) { } for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { + stub := mock.NewMockStub("org1MSP", new(testCC)) + sw := &sw.StubWrapper{ + Stub: stub, + } + // Put asset stub.MockTransactionStart("TestPutAsset") var err error From f97e1ad6152555a1873b42452eefcfc797ffe32b Mon Sep 17 00:00:00 2001 From: AlineLermen Date: Fri, 13 Oct 2023 07:58:15 -0300 Subject: [PATCH 19/31] Create CODEOWNERS file Signed-off-by: AlineLermen --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..d5e0e85 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @hyperledger-labs/cc-tools-committers \ No newline at end of file From a6ada056fb4cfe7628b43eb0d074943ec1af0bba Mon Sep 17 00:00:00 2001 From: AlineLermen Date: Fri, 13 Oct 2023 08:16:38 -0300 Subject: [PATCH 20/31] Create MAINTAINERS file Signed-off-by: AlineLermen --- MANTAINERS.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 MANTAINERS.md diff --git a/MANTAINERS.md b/MANTAINERS.md new file mode 100644 index 0000000..5eb1064 --- /dev/null +++ b/MANTAINERS.md @@ -0,0 +1,16 @@ +# Maintainers + +### **Active Maintainers** + +| Nome | Github | +|:-------|:--------| +| André Macedo | [andremacedopv](https://github.com/andremacedopv) | +| Samuel Venzi | [samuelvenzi](https://github.com/samuelvenzi) | +| Lucas Campelo | [lucas-campelo](https://github.com/lucas-campelo) | +| Marcos Sarres | [goledger](https://github.com/goledger) | + + +### **Retired Maintainers** +| Bruno Andreghetti | [bandreghetti](https://github.com/bandreghetti) | +| João Pedro | [JoaoPedroAssis](https://github.com/JoaoPedroAssis) | +| Arthur Paiva | [ArthurPaivaT](https://github.com/ArthurPaivaT) | \ No newline at end of file From 4a70de689ff8d2326fc9581e09c3ecb143d16bda Mon Sep 17 00:00:00 2001 From: AlineLermen Date: Fri, 13 Oct 2023 08:33:09 -0300 Subject: [PATCH 21/31] Fix table in MAINTAINERS Signed-off-by: AlineLermen --- MANTAINERS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MANTAINERS.md b/MANTAINERS.md index 5eb1064..d21de3a 100644 --- a/MANTAINERS.md +++ b/MANTAINERS.md @@ -11,6 +11,8 @@ ### **Retired Maintainers** +| Nome | Github | +|:-------|:--------| | Bruno Andreghetti | [bandreghetti](https://github.com/bandreghetti) | | João Pedro | [JoaoPedroAssis](https://github.com/JoaoPedroAssis) | | Arthur Paiva | [ArthurPaivaT](https://github.com/ArthurPaivaT) | \ No newline at end of file From 44e7c5bbc305b95ee35dbace78d161030dc9f87d Mon Sep 17 00:00:00 2001 From: mikaellafs Date: Thu, 19 Oct 2023 15:08:41 -0300 Subject: [PATCH 22/31] Fix resolve history reference Signed-off-by: mikaellafs --- assets/history.go | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/assets/history.go b/assets/history.go index 380c79d..8c93999 100644 --- a/assets/history.go +++ b/assets/history.go @@ -25,6 +25,7 @@ func History(stub *sw.StubWrapper, key string, resolve bool) (*HistoryResponse, defer resultsIterator.Close() historyResult := make([]map[string]interface{}, 0) + var subAssets []AssetProp for resultsIterator.HasNext() { queryResponse, err := resultsIterator.Next() @@ -40,15 +41,18 @@ func History(stub *sw.StubWrapper, key string, resolve bool) (*HistoryResponse, } if resolve { - key, err := NewKey(data) - if err != nil { - return nil, errors.WrapError(err, "failed to create key object to resolve result") + if subAssets == nil { + key, err := NewKey(data) + if err != nil { + return nil, errors.WrapError(err, "failed to create key object to resolve result") + } + subAssets = key.Type().SubAssets() } - asset, err := key.GetRecursive(stub) + + err := resolveHistory(stub, data, subAssets) if err != nil { return nil, errors.WrapError(err, "failed to resolve result") } - data = asset } historyResult = append(historyResult, data) @@ -60,3 +64,26 @@ func History(stub *sw.StubWrapper, key string, resolve bool) (*HistoryResponse, return &response, nil } + +func resolveHistory(stub *sw.StubWrapper, data map[string]interface{}, subAssets []AssetProp) errors.ICCError { + for _, refProp := range subAssets { + ref, ok := data[refProp.Tag].(map[string]interface{}) + if !ok { + continue + } + + key, err := NewKey(ref) + if err != nil { + return errors.WrapError(err, "could not make subasset key") + } + + resolved, err := key.GetRecursive(stub) + if err != nil { + return errors.WrapError(err, "failed to get subasset recursive") + } + + data[refProp.Tag] = resolved + } + + return nil +} From 6546b51507b6e630caa7babdf72457aa4d8299ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Fri, 27 Oct 2023 11:22:51 -0300 Subject: [PATCH 23/31] Update Create Asset with generic association test to remove lastTouchBy from expected response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Macedo --- test/tx_createAsset_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/tx_createAsset_test.go b/test/tx_createAsset_test.go index d9ccb7b..77a873f 100644 --- a/test/tx_createAsset_test.go +++ b/test/tx_createAsset_test.go @@ -135,7 +135,6 @@ func TestCreateAssetGenericAssociation(t *testing.T) { lastUpdated, _ := stub.GetTxTimestamp() expectedResponse := map[string]interface{}{ "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTouchBy": "org1MSP", "@lastTx": "createAsset", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "@assetType": "person", @@ -186,6 +185,8 @@ func TestCreateAssetGenericAssociation(t *testing.T) { t.FailNow() } + expectedResponse["@lastTouchBy"] = "org1MSP" + if !reflect.DeepEqual(state, expectedResponse) { log.Println("these should be equal") log.Printf("%#v\n", state) From d04e2d62609212e7bc1b344df54b52850bfd1876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Fri, 27 Oct 2023 11:56:40 -0300 Subject: [PATCH 24/31] Fix update recursive expected response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Macedo --- test/assets_put_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/assets_put_test.go b/test/assets_put_test.go index 8764a2c..4b00ca7 100644 --- a/test/assets_put_test.go +++ b/test/assets_put_test.go @@ -357,6 +357,7 @@ func TestUpdateRecursive(t *testing.T) { "@assetType": "library", "@key": "library:9c5ffeb3-2491-5a88-858c-653b1ea8dbc5", "@lastTx": "", + "@lastTouchBy": "org1MSP", "@lastUpdated": lastUpdated, "name": "biographies", "books": []interface{}{ @@ -364,6 +365,7 @@ func TestUpdateRecursive(t *testing.T) { "@assetType": "book", "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", "@lastTx": "", + "@lastTouchBy": "org1MSP", "@lastUpdated": lastUpdated, "title": "Meu Nome é Maria", "author": "Maria Viana", @@ -371,6 +373,7 @@ func TestUpdateRecursive(t *testing.T) { "@assetType": "person", "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", "@lastTx": "", + "@lastTouchBy": "org1MSP", "@lastUpdated": lastUpdated, "name": "Maria", "id": "31820792048", From b7ef13940a3d555eac60449804c9856232df7829 Mon Sep 17 00:00:00 2001 From: mikaellafs Date: Fri, 27 Oct 2023 16:11:33 -0300 Subject: [PATCH 25/31] Remove root param from putRecursive Signed-off-by: mikaellafs --- assets/put.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/put.go b/assets/put.go index 30a70b7..7e5cb4f 100644 --- a/assets/put.go +++ b/assets/put.go @@ -93,7 +93,7 @@ func (a *Asset) PutNew(stub *sw.StubWrapper) (map[string]interface{}, errors.ICC return res, nil } -func putRecursive(stub *sw.StubWrapper, object map[string]interface{}, root bool) (map[string]interface{}, errors.ICCError) { +func putRecursive(stub *sw.StubWrapper, object map[string]interface{}) (map[string]interface{}, errors.ICCError) { var err error objAsKey, err := NewKey(object) @@ -181,7 +181,7 @@ func putRecursive(stub *sw.StubWrapper, object map[string]interface{}, root bool return nil, errors.NewCCError(fmt.Sprintf("asset reference property '%s' must have an '@assetType' property", subAsset.Tag), 400) } } - putSubAsset, err := putRecursive(stub, obj, false) + putSubAsset, err := putRecursive(stub, obj) if err != nil { return nil, errors.WrapError(err, fmt.Sprintf("failed to put sub-asset %s recursively", subAsset.Tag)) } @@ -218,7 +218,7 @@ func putRecursive(stub *sw.StubWrapper, object map[string]interface{}, root bool // PutRecursive inserts asset and all its subassets in blockchain. // This method is experimental and might not work as intended. Use with caution. func PutRecursive(stub *sw.StubWrapper, object map[string]interface{}) (map[string]interface{}, errors.ICCError) { - return putRecursive(stub, object, true) + return putRecursive(stub, object) } // PutNewRecursive inserts asset and all its subassets in blockchain From b44550ebe15cf26ddf6e44dd09ca288f9363dc4c Mon Sep 17 00:00:00 2001 From: mikaellafs Date: Wed, 10 Jan 2024 14:26:26 -0300 Subject: [PATCH 26/31] Fix resolve history reference Signed-off-by: mikaellafs --- assets/history.go | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/assets/history.go b/assets/history.go index 380c79d..8c93999 100644 --- a/assets/history.go +++ b/assets/history.go @@ -25,6 +25,7 @@ func History(stub *sw.StubWrapper, key string, resolve bool) (*HistoryResponse, defer resultsIterator.Close() historyResult := make([]map[string]interface{}, 0) + var subAssets []AssetProp for resultsIterator.HasNext() { queryResponse, err := resultsIterator.Next() @@ -40,15 +41,18 @@ func History(stub *sw.StubWrapper, key string, resolve bool) (*HistoryResponse, } if resolve { - key, err := NewKey(data) - if err != nil { - return nil, errors.WrapError(err, "failed to create key object to resolve result") + if subAssets == nil { + key, err := NewKey(data) + if err != nil { + return nil, errors.WrapError(err, "failed to create key object to resolve result") + } + subAssets = key.Type().SubAssets() } - asset, err := key.GetRecursive(stub) + + err := resolveHistory(stub, data, subAssets) if err != nil { return nil, errors.WrapError(err, "failed to resolve result") } - data = asset } historyResult = append(historyResult, data) @@ -60,3 +64,26 @@ func History(stub *sw.StubWrapper, key string, resolve bool) (*HistoryResponse, return &response, nil } + +func resolveHistory(stub *sw.StubWrapper, data map[string]interface{}, subAssets []AssetProp) errors.ICCError { + for _, refProp := range subAssets { + ref, ok := data[refProp.Tag].(map[string]interface{}) + if !ok { + continue + } + + key, err := NewKey(ref) + if err != nil { + return errors.WrapError(err, "could not make subasset key") + } + + resolved, err := key.GetRecursive(stub) + if err != nil { + return errors.WrapError(err, "failed to get subasset recursive") + } + + data[refProp.Tag] = resolved + } + + return nil +} From a1c9712acb60062978f931cc76105f818d0a3a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Wed, 8 May 2024 16:43:39 -0300 Subject: [PATCH 27/31] Bump go version to 1.21 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Macedo --- go.mod | 29 +++++++++++-------- go.sum | 89 +++++++++++++++++----------------------------------------- 2 files changed, 44 insertions(+), 74 deletions(-) diff --git a/go.mod b/go.mod index 17e1b1b..50673a8 100644 --- a/go.mod +++ b/go.mod @@ -1,29 +1,36 @@ module github.com/hyperledger-labs/cc-tools -go 1.14 +go 1.21 require ( - github.com/fsnotify/fsnotify v1.4.9 // indirect - github.com/golang/protobuf v1.4.3 - github.com/google/go-cmp v0.5.4 // indirect + github.com/golang/protobuf v1.5.3 github.com/google/uuid v1.3.0 github.com/hyperledger/fabric v2.1.1+incompatible github.com/hyperledger/fabric-chaincode-go v0.0.0-20210603161043-af0e3898842a github.com/hyperledger/fabric-protos-go v0.0.0-20210528200356-82833ecdac31 + github.com/stretchr/testify v1.6.1 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fsnotify/fsnotify v1.4.9 // indirect github.com/kr/text v0.2.0 // indirect github.com/miekg/pkcs11 v1.0.3 // indirect github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/viper v1.7.1 // indirect - github.com/stretchr/testify v1.6.1 github.com/sykesm/zap-logfmt v0.0.4 // indirect + go.uber.org/atomic v1.6.0 // indirect + go.uber.org/multierr v1.5.0 // indirect go.uber.org/zap v1.16.0 // indirect - golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect - golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b // indirect - golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect - golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa // indirect - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect - google.golang.org/grpc v1.35.0 // indirect + golang.org/x/crypto v0.17.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/text v0.14.0 // indirect + google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect + google.golang.org/grpc v1.56.3 // indirect + google.golang.org/protobuf v1.30.0 // indirect gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.0 // indirect diff --git a/go.sum b/go.sum index 43a706f..355b7e3 100644 --- a/go.sum +++ b/go.sum @@ -24,10 +24,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -39,10 +37,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= @@ -63,34 +57,24 @@ github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFU github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= -github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= @@ -127,7 +111,6 @@ github.com/hyperledger/fabric-protos-go v0.0.0-20210528200356-82833ecdac31/go.mo github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= -github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= @@ -175,7 +158,6 @@ github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= @@ -186,9 +168,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -207,7 +187,6 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= @@ -238,9 +217,8 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= -golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -260,9 +238,8 @@ golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b h1:GgiSbuUyC0BlbUmHQBgFqu32eiRR/CEYdjOjOd4zE6Y= -golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -278,8 +255,8 @@ golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew= -golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -303,16 +280,13 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -335,13 +309,10 @@ golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa h1:5E4dL8+NgFOgjwbTKz+OOEGGhP+ectTmF842l6KjupQ= -golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= @@ -361,26 +332,18 @@ google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A= +google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.35.0 h1:TwIQcH3es+MojMVojxxfQ3l3OF2KzlRxML2xZq0kRo8= -google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/grpc v1.56.3 h1:8I4C0Yq1EjstUzUJzpcRVbuYA2mODtEmpWiQoN/b2nc= +google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 70ed47b29a7979624326846bfd53e1c304f8f694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Wed, 8 May 2024 17:14:44 -0300 Subject: [PATCH 28/31] Update CC-Tools version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Macedo --- .github/workflows/go.yml | 2 +- README.md | 2 +- test/main_test.go | 2 +- test/tx_getHeader_test.go | 4 ++-- transactions/getHeader.go | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ad7cc59..0e43b31 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.16 + go-version: 1.21 - name: Build run: go build -v ./... diff --git a/README.md b/README.md index afc09b2..ae8e436 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Go Report Card](https://goreportcard.com/badge/github.com/hyperledger-labs/cc-tools)](https://goreportcard.com/report/github.com/hyperledger-labs/cc-tools) [![GoDoc](https://godoc.org/github.com/hyperledger-labs/cc-tools?status.svg)](https://godoc.org/github.com/hyperledger-labs/cc-tools) -This project is a GoLedger open-source project aimed at providing tools for Hyperledger Fabric chaincode development in Golang. This might have breaking changes before we arrive at release v1.0.0. +This project is a GoLedger open-source project aimed at providing tools for Hyperledger Fabric chaincode development in Golang. ## Getting Started diff --git a/test/main_test.go b/test/main_test.go index fcc8af5..3161ac8 100644 --- a/test/main_test.go +++ b/test/main_test.go @@ -15,7 +15,7 @@ func TestMain(m *testing.M) { tx.InitHeader(tx.Header{ Name: "CC Tools Test", - Version: "v0.8.1", + Version: "v1.0.0", Colors: map[string][]string{ "@default": {"#4267B2", "#34495E", "#ECF0F1"}, }, diff --git a/test/tx_getHeader_test.go b/test/tx_getHeader_test.go index 77ea5f6..b9e9aec 100644 --- a/test/tx_getHeader_test.go +++ b/test/tx_getHeader_test.go @@ -11,7 +11,7 @@ func TestGetHeader(t *testing.T) { stub := mock.NewMockStub("org1MSP", new(testCC)) expectedResponse := map[string]interface{}{ - "ccToolsVersion": "v0.8.1", + "ccToolsVersion": "v1.0.0", "colors": []interface{}{ "#4267B2", "#34495E", @@ -20,7 +20,7 @@ func TestGetHeader(t *testing.T) { "name": "CC Tools Test", "orgMSP": "org1MSP", "orgTitle": "CC Tools Demo", - "version": "v0.8.1", + "version": "v1.0.0", } err := invokeAndVerify(stub, "getHeader", nil, expectedResponse, 200) if err != nil { diff --git a/transactions/getHeader.go b/transactions/getHeader.go index 573f27b..a5ab9c3 100644 --- a/transactions/getHeader.go +++ b/transactions/getHeader.go @@ -19,7 +19,7 @@ var header Header func InitHeader(h Header) { header = h - header.CCToolsVersion = "v0.8.1" + header.CCToolsVersion = "v1.0.0" } // GetHeader returns data in CCHeader From b7274bf62395c9d41afd6283931c2218b1132b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Wed, 8 May 2024 17:30:03 -0300 Subject: [PATCH 29/31] Update depedencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Macedo --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 50673a8..3072962 100644 --- a/go.mod +++ b/go.mod @@ -24,14 +24,14 @@ require ( go.uber.org/atomic v1.6.0 // indirect go.uber.org/multierr v1.5.0 // indirect go.uber.org/zap v1.16.0 // indirect - golang.org/x/crypto v0.17.0 // indirect - golang.org/x/net v0.17.0 // indirect - golang.org/x/sys v0.15.0 // indirect + golang.org/x/crypto v0.21.0 // indirect + golang.org/x/net v0.23.0 // indirect + golang.org/x/sys v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect google.golang.org/grpc v1.56.3 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 355b7e3..bf0f3d7 100644 --- a/go.sum +++ b/go.sum @@ -217,8 +217,8 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= -golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -255,8 +255,8 @@ golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -280,8 +280,8 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -360,8 +360,8 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= -gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From ed1264ac61297fd1798e23282a56d7cd3b6421c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Wed, 8 May 2024 17:59:52 -0300 Subject: [PATCH 30/31] Update tested versions on Readme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Macedo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ae8e436..bddc4c1 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This project is a GoLedger open-source project aimed at providing tools for Hype Make sure you visit the repository [hyperledger-labs/cc-tools-demo](https://github.com/hyperledger-labs/cc-tools-demo), which is a template of a functional chaincode that uses cc-tools and provides ready-to-use scripts to deploy development networks. This is our preferred way of working, but you can feel free to import the package and assemble the chaincode as you choose. -CC Tools has been tested with Hyperledger Fabric 1.x and 2.x realeases. +CC Tools has been tested with Hyperledger Fabric v2.2, v2.4 and v2.5 releases. ## Features - Standard asset data mapping (and their properties) From 10894c139aba66dbdcedb527ec337cf12abf74b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Macedo?= Date: Thu, 9 May 2024 17:38:38 -0300 Subject: [PATCH 31/31] Return lastTouchedBy to returns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Macedo --- assets/get.go | 3 - assets/put.go | 2 - assets/search.go | 2 - test/assets_get_test.go | 61 +++--- test/assets_put_test.go | 364 +++++++++----------------------- test/tryout_test.go | 37 ++-- test/tx_createAssetType_test.go | 2 +- test/tx_createAsset_test.go | 5 +- test/tx_deleteAsset_test.go | 1 - test/tx_readAsset_test.go | 25 +-- test/tx_updateAsset_test.go | 4 +- transactions/readAsset.go | 10 +- 12 files changed, 175 insertions(+), 341 deletions(-) diff --git a/assets/get.go b/assets/get.go index eb60a6b..a29a82b 100644 --- a/assets/get.go +++ b/assets/get.go @@ -41,8 +41,6 @@ func get(stub *sw.StubWrapper, pvtCollection, key string, committed bool) (*Asse return nil, errors.WrapErrorWithStatus(err, "failed to unmarshal asset from ledger", 500) } - delete(response, "@lastTouchBy") - return &response, nil } @@ -181,7 +179,6 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [ return nil, errors.WrapErrorWithStatus(err, "failed to unmarshal asset from ledger", 500) } - delete(response, "@lastTouchBy") keysCheckedInScope := make([]string, 0) for k, v := range response { diff --git a/assets/put.go b/assets/put.go index 7e5cb4f..7282f19 100644 --- a/assets/put.go +++ b/assets/put.go @@ -48,8 +48,6 @@ func (a *Asset) put(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCErr return nil, errors.WrapError(err, "failed to write asset to ledger") } - delete(*a, "@lastTouchBy") - return *a, nil } diff --git a/assets/search.go b/assets/search.go index c9273fc..ffe1e07 100644 --- a/assets/search.go +++ b/assets/search.go @@ -99,8 +99,6 @@ func Search(stub *sw.StubWrapper, request map[string]interface{}, privateCollect data = asset } - delete(data, "@lastTouchBy") - searchResult = append(searchResult, data) } diff --git a/test/assets_get_test.go b/test/assets_get_test.go index 515ce71..5ec10e2 100644 --- a/test/assets_get_test.go +++ b/test/assets_get_test.go @@ -16,12 +16,13 @@ func TestGetAsset(t *testing.T) { // State setup expectedResponse := assets.Asset{ - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTx": "createAsset", - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 0.0, + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", + "@lastTx": "createAsset", + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 0.0, } stub.MockTransactionStart("setupGetAsset") setupState, _ := json.Marshal(expectedResponse) @@ -92,9 +93,6 @@ func TestGetManyAssets(t *testing.T) { stub.PutState("person:916c708a-1d6c-5c4f-8f12-d9d36f2aad27", setupState) stub.MockTransactionEnd("setupGetManyAssets") - delete(asset1, "@lastTouchBy") - delete(asset2, "@lastTouchBy") - delete(asset3, "@lastTouchBy") expectedResponse := []*assets.Asset{&asset1, &asset2, &asset3} assetKeys := []assets.Key{ @@ -163,7 +161,6 @@ func TestGetCommittedAsset(t *testing.T) { t.FailNow() } - delete(expectedResponse, "@lastTouchBy") if !reflect.DeepEqual(*gotAsset, expectedResponse) { log.Println("these should be deeply equal") log.Println(expectedResponse) @@ -219,18 +216,20 @@ func TestGetRecursive(t *testing.T) { "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", } expectedResponse := map[string]interface{}{ - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTx": "createAsset", - "@assetType": "book", - "title": "Meu Nome é Maria", - "author": "Maria Viana", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTouchBy": "org2MSP", + "@lastTx": "createAsset", + "@assetType": "book", + "title": "Meu Nome é Maria", + "author": "Maria Viana", "currentTenant": map[string]interface{}{ - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTx": "createAsset", - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 0.0, + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", + "@lastTx": "createAsset", + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 0.0, }, "genres": []interface{}{"biography", "non-fiction"}, "published": "2019-05-06T22:12:41Z", @@ -296,16 +295,18 @@ func TestGetRecursiveWithPvtData(t *testing.T) { "@key": "library:37262f3f-5f08-5649-b488-e5abaad266e1", } expectedResponse := map[string]interface{}{ - "@assetType": "library", - "@key": "library:37262f3f-5f08-5649-b488-e5abaad266e1", - "@lastTx": "createAsset", - "name": "Biblioteca Maria da Silva", + "@assetType": "library", + "@key": "library:37262f3f-5f08-5649-b488-e5abaad266e1", + "@lastTouchBy": "org3MSP", + "@lastTx": "createAsset", + "name": "Biblioteca Maria da Silva", "entranceCode": map[string]interface{}{ - "@assetType": "secret", - "@key": "secret:73a3f9a7-eb91-5f4d-b1bb-c0487e90f40b", - "@lastTx": "createAsset", - "secretName": "testSecret", - "secret": "this is very secret", + "@assetType": "secret", + "@key": "secret:73a3f9a7-eb91-5f4d-b1bb-c0487e90f40b", + "@lastTouchBy": "org2MSP", + "@lastTx": "createAsset", + "secretName": "testSecret", + "secret": "this is very secret", }, } diff --git a/test/assets_put_test.go b/test/assets_put_test.go index 4b00ca7..2415af3 100644 --- a/test/assets_put_test.go +++ b/test/assets_put_test.go @@ -117,7 +117,6 @@ func TestPutAssetWithSubAsset(t *testing.T) { t.FailNow() } - expectedState["@lastTouchBy"] = "org1MSP" if !reflect.DeepEqual(expectedState, state) { log.Println("these should be deeply equal") log.Println(expectedState) @@ -159,6 +158,7 @@ func TestPutNewAssetRecursive(t *testing.T) { expectedBook := map[string]interface{}{ "@assetType": "book", "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTouchBy": "org1MSP", "@lastTx": "", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "title": "Meu Nome é Maria", @@ -166,6 +166,7 @@ func TestPutNewAssetRecursive(t *testing.T) { "currentTenant": map[string]interface{}{ "@assetType": "person", "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", "@lastTx": "", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "name": "Maria", @@ -216,266 +217,111 @@ func TestPutNewAssetRecursive(t *testing.T) { } func TestUpdateRecursive(t *testing.T) { - tests := []struct { - description string - - assetkey string - asset map[string]interface{} - updateReq map[string]interface{} - expectedResponse func(lastUpdated string) map[string]interface{} - expectedState func(lastUpdated string) map[string]interface{} - }{ - { - description: "update recursive book", - - assetkey: "book:a36a2920-c405-51c3-b584-dcd758338cb5", - asset: map[string]interface{}{ - "@assetType": "book", - "title": "Meu Nome é Maria", - "author": "Maria Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 1.66, - }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": "2019-05-06T22:12:41Z", - }, - updateReq: map[string]interface{}{ - "@assetType": "book", - "author": "Maria Viana", - "title": "Meu Nome é Maria", - "published": "2022-05-06T22:12:41Z", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "id": "31820792048", - "height": 1.88, - }, - }, - expectedResponse: func(lastUpdated string) map[string]interface{} { - publishedTime, _ := time.Parse(time.RFC3339, "2022-05-06T22:12:41Z") - return map[string]interface{}{ - "@assetType": "book", - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTx": "", - "@lastUpdated": lastUpdated, - "title": "Meu Nome é Maria", - "author": "Maria Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTx": "", - "@lastUpdated": lastUpdated, - "name": "Maria", - "id": "31820792048", - "height": 1.88, - }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": publishedTime, - } - }, - expectedState: func(lastUpdated string) map[string]interface{} { - return map[string]interface{}{ - "@assetType": "book", - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTouchBy": "org1MSP", - "@lastTx": "", - "@lastUpdated": lastUpdated, - "title": "Meu Nome é Maria", - "author": "Maria Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": "2022-05-06T22:12:41Z", - } - }, + stub := mock.NewMockStub("org1MSP", new(testCC)) + + // Create a book + stub.MockTransactionStart("TestPutAsset") + sw := &sw.StubWrapper{ + Stub: stub, + } + book := map[string]interface{}{ + "@assetType": "book", + "title": "Meu Nome é Maria", + "author": "Maria Viana", + "currentTenant": map[string]interface{}{ + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 1.66, }, - { - description: "update books in library", - - assetkey: "library:9c5ffeb3-2491-5a88-858c-653b1ea8dbc5", - asset: map[string]interface{}{ - "@assetType": "library", - "name": "biographies", - "books": []interface{}{ - map[string]interface{}{ - "@assetType": "book", - "title": "Meu Nome é Maria", - "author": "Maria Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 1.66, - }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": "2019-05-06T22:12:41Z", - }, - map[string]interface{}{ - "@assetType": "book", - "title": "Meu Nome é João", - "author": "João Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "name": "João", - "id": "42931801159", - "height": 1.90, - }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": "2020-06-06T22:12:41Z", - }, - }, - }, - updateReq: map[string]interface{}{ - "@assetType": "library", - "name": "biographies", - "books": []interface{}{ - map[string]interface{}{ // This book will not be updated - "@assetType": "book", - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - }, - map[string]interface{}{ // This book will be updated - "@assetType": "book", - "title": "Meu Nome é João", - "author": "João Viana", - "currentTenant": map[string]interface{}{ // This person will be updated - "@assetType": "person", - "id": "42931801159", - "height": 1.92, - }, - "published": "2020-06-10T22:12:41Z", - }, - }, - }, - expectedResponse: func(lastUpdated string) map[string]interface{} { - publishedTimeBook2, _ := time.Parse(time.RFC3339, "2020-06-10T22:12:41Z") - - return map[string]interface{}{ - "@assetType": "library", - "@key": "library:9c5ffeb3-2491-5a88-858c-653b1ea8dbc5", - "@lastTx": "", - "@lastTouchBy": "org1MSP", - "@lastUpdated": lastUpdated, - "name": "biographies", - "books": []interface{}{ - map[string]interface{}{ - "@assetType": "book", - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTx": "", - "@lastTouchBy": "org1MSP", - "@lastUpdated": lastUpdated, - "title": "Meu Nome é Maria", - "author": "Maria Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTx": "", - "@lastTouchBy": "org1MSP", - "@lastUpdated": lastUpdated, - "name": "Maria", - "id": "31820792048", - "height": 1.66, - }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": "2019-05-06T22:12:41Z", - }, - map[string]interface{}{ - "@assetType": "book", - "@key": "book:679f58a4-578f-563c-9c22-3f51b9fab6d5", - "@lastTx": "", - "@lastUpdated": lastUpdated, - "title": "Meu Nome é João", - "author": "João Viana", - "currentTenant": map[string]interface{}{ - "@assetType": "person", - "@key": "person:09c4f266-3bac-5d2f-813b-db3c41ab3375", - "@lastTx": "", - "@lastUpdated": lastUpdated, - "name": "João", - "id": "42931801159", - "height": 1.92, - }, - "genres": []interface{}{"biography", "non-fiction"}, - "published": publishedTimeBook2, - }, - }, - } - }, - expectedState: func(lastUpdated string) map[string]interface{} { - return map[string]interface{}{ - "@assetType": "library", - "@key": "library:9c5ffeb3-2491-5a88-858c-653b1ea8dbc5", - "@lastTouchBy": "org1MSP", - "@lastTx": "", - "@lastUpdated": lastUpdated, - "name": "biographies", - "books": []interface{}{ - map[string]interface{}{ - "@assetType": "book", - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - }, - map[string]interface{}{ - "@assetType": "book", - "@key": "book:679f58a4-578f-563c-9c22-3f51b9fab6d5", - }, - }, - } - }, + "genres": []interface{}{"biography", "non-fiction"}, + "published": "2019-05-06T22:12:41Z", + } + + var err error + _, err = assets.PutNewRecursive(sw, book) + if err != nil { + log.Println(err) + t.FailNow() + } + stub.MockTransactionEnd("TestPutAsset") + + // Update the book and the tenant + stub.MockTransactionStart("TestUpdateAsset") + book["published"] = "2022-05-06T22:12:41Z" + book["currentTenant"] = map[string]interface{}{ + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 1.88, + } + + putBook, err := assets.UpdateRecursive(sw, book) + if err != nil { + log.Println(err) + t.FailNow() + } + + publishedTime, _ := time.Parse(time.RFC3339, "2022-05-06T22:12:41Z") + lastUpdated, _ := stub.GetTxTimestamp() + expectedBook := map[string]interface{}{ + "@assetType": "book", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTouchBy": "org1MSP", + "@lastTx": "", + "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), + "title": "Meu Nome é Maria", + "author": "Maria Viana", + "currentTenant": map[string]interface{}{ + "@assetType": "person", + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", + "@lastTx": "", + "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), + "name": "Maria", + "id": "31820792048", + "height": 1.88, }, + "genres": []interface{}{"biography", "non-fiction"}, + "published": publishedTime, } - for _, tt := range tests { - t.Run(tt.description, func(t *testing.T) { - stub := mock.NewMockStub("org1MSP", new(testCC)) - sw := &sw.StubWrapper{ - Stub: stub, - } - - // Put asset - stub.MockTransactionStart("TestPutAsset") - var err error - _, err = assets.PutNewRecursive(sw, tt.asset) - if err != nil { - log.Println(err) - t.FailNow() - } - stub.MockTransactionEnd("TestPutAsset") - - // Update asset - stub.MockTransactionStart("TestUpdateAsset") - updateResult, err := assets.UpdateRecursive(sw, tt.updateReq) - if err != nil { - log.Println(err) - t.FailNow() - } - - lastUpdatedTimestamp, _ := stub.GetTxTimestamp() - lastUpdated := lastUpdatedTimestamp.AsTime().Format(time.RFC3339) - if !reflect.DeepEqual(tt.expectedResponse(lastUpdated), updateResult) { - log.Println("these should be deeply equal") - log.Println(tt.expectedResponse(lastUpdated)) - log.Println(updateResult) - t.FailNow() - } - stub.MockTransactionEnd("TestUpdateAsset") - - // Check state - stateJSON := stub.State[tt.assetkey] - var state map[string]interface{} - err = json.Unmarshal(stateJSON, &state) - if err != nil { - log.Println(err) - t.FailNow() - } - - if !reflect.DeepEqual(tt.expectedState(lastUpdated), state) { - log.Println("these should be deeply equal") - log.Println(tt.expectedState(lastUpdated)) - log.Println(state) - t.FailNow() - } - }) + + // Check if the book is updated + if !reflect.DeepEqual(expectedBook, putBook) { + log.Println("these should be deeply equal") + log.Println(expectedBook) + log.Println(putBook) + t.FailNow() + } + + expectedState := map[string]interface{}{ + "@assetType": "book", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTouchBy": "org1MSP", + "@lastTx": "", + "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), + "title": "Meu Nome é Maria", + "author": "Maria Viana", + "currentTenant": map[string]interface{}{ + "@assetType": "person", + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + }, + "genres": []interface{}{"biography", "non-fiction"}, + "published": "2022-05-06T22:12:41Z", + } + + stateJSON := stub.State["book:a36a2920-c405-51c3-b584-dcd758338cb5"] + var state map[string]interface{} + err = json.Unmarshal(stateJSON, &state) + if err != nil { + log.Println(err) + t.FailNow() + } + + if !reflect.DeepEqual(expectedState, state) { + log.Println("these should be deeply equal") + log.Println(expectedState) + log.Println(state) + t.FailNow() } } diff --git a/test/tryout_test.go b/test/tryout_test.go index d5a3089..ab32099 100644 --- a/test/tryout_test.go +++ b/test/tryout_test.go @@ -23,12 +23,13 @@ func TestTryout(t *testing.T) { } expectedPerson := []interface{}{ map[string]interface{}{ - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTx": "createAsset", - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 0.0, + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", + "@lastTx": "createAsset", + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 0.0, }, } @@ -58,11 +59,12 @@ func TestTryout(t *testing.T) { expectedBook := []interface{}{ map[string]interface{}{ - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTx": "createAsset", - "@assetType": "book", - "title": "Meu Nome é Maria", - "author": "Maria Viana", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTouchBy": "org2MSP", + "@lastTx": "createAsset", + "@assetType": "book", + "title": "Meu Nome é Maria", + "author": "Maria Viana", "currentTenant": map[string]interface{}{ "@assetType": "person", "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", @@ -110,12 +112,13 @@ func TestTryout(t *testing.T) { } expectedUpdatePerson := map[string]interface{}{ - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTx": "updateAsset", - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 1.67, + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org2MSP", + "@lastTx": "updateAsset", + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 1.67, } err = invokeAndVerify(stub, "updateAsset", reqUpdatePerson, expectedUpdatePerson, 200) diff --git a/test/tx_createAssetType_test.go b/test/tx_createAssetType_test.go index 7d38cd7..781c5c5 100644 --- a/test/tx_createAssetType_test.go +++ b/test/tx_createAssetType_test.go @@ -118,6 +118,7 @@ func TestCreateAssetType(t *testing.T) { lastUpdated, _ := stub.GetTxTimestamp() expectedResponse = map[string]interface{}{ "@key": "magazine:236a29db-f53c-59e1-ac6d-a4f264dbc477", + "@lastTouchBy": "org1MSP", "@lastTx": "createAsset", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "@assetType": "magazine", @@ -160,7 +161,6 @@ func TestCreateAssetType(t *testing.T) { t.FailNow() } - expectedResponse["@lastTouchBy"] = "org1MSP" if !reflect.DeepEqual(state, expectedResponse) { log.Println("these should be equal") log.Printf("%#v\n", state) diff --git a/test/tx_createAsset_test.go b/test/tx_createAsset_test.go index 77a873f..bc0bed8 100644 --- a/test/tx_createAsset_test.go +++ b/test/tx_createAsset_test.go @@ -35,6 +35,7 @@ func TestCreateAsset(t *testing.T) { lastUpdated, _ := stub.GetTxTimestamp() expectedResponse := map[string]interface{}{ "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", "@lastTx": "createAsset", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "@assetType": "person", @@ -79,7 +80,6 @@ func TestCreateAsset(t *testing.T) { t.FailNow() } - expectedResponse["@lastTouchBy"] = "org1MSP" if !reflect.DeepEqual(state, expectedResponse) { log.Println("these should be equal") log.Printf("%#v\n", state) @@ -135,6 +135,7 @@ func TestCreateAssetGenericAssociation(t *testing.T) { lastUpdated, _ := stub.GetTxTimestamp() expectedResponse := map[string]interface{}{ "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", "@lastTx": "createAsset", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "@assetType": "person", @@ -185,8 +186,6 @@ func TestCreateAssetGenericAssociation(t *testing.T) { t.FailNow() } - expectedResponse["@lastTouchBy"] = "org1MSP" - if !reflect.DeepEqual(state, expectedResponse) { log.Println("these should be equal") log.Printf("%#v\n", state) diff --git a/test/tx_deleteAsset_test.go b/test/tx_deleteAsset_test.go index 4f5ae2e..7ff2e7b 100644 --- a/test/tx_deleteAsset_test.go +++ b/test/tx_deleteAsset_test.go @@ -62,7 +62,6 @@ func TestDeleteAsset(t *testing.T) { t.FailNow() } - delete(expectedResponse, "@lastTouchBy") if !reflect.DeepEqual(resPayload, expectedResponse) { log.Println("these should be equal") log.Printf("%#v\n", resPayload) diff --git a/test/tx_readAsset_test.go b/test/tx_readAsset_test.go index 1cbd3ff..304a84e 100644 --- a/test/tx_readAsset_test.go +++ b/test/tx_readAsset_test.go @@ -55,7 +55,6 @@ func TestReadAsset(t *testing.T) { t.FailNow() } - delete(expectedResponse, "@lastTouchBy") if !reflect.DeepEqual(resPayload, expectedResponse) { log.Println("these should be equal") log.Printf("%#v\n", resPayload) @@ -110,18 +109,20 @@ func TestReadRecursive(t *testing.T) { "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", } expectedResponse := map[string]interface{}{ - "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", - "@lastTx": "createAsset", - "@assetType": "book", - "title": "Meu Nome é Maria", - "author": "Maria Viana", + "@key": "book:a36a2920-c405-51c3-b584-dcd758338cb5", + "@lastTouchBy": "org2MSP", + "@lastTx": "createAsset", + "@assetType": "book", + "title": "Meu Nome é Maria", + "author": "Maria Viana", "currentTenant": map[string]interface{}{ - "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", - "@lastTx": "createAsset", - "@assetType": "person", - "name": "Maria", - "id": "31820792048", - "height": 0.0, + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", + "@lastTx": "createAsset", + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 0.0, }, "genres": []interface{}{"biography", "non-fiction"}, "published": "2019-05-06T22:12:41Z", diff --git a/test/tx_updateAsset_test.go b/test/tx_updateAsset_test.go index 5192956..9787213 100644 --- a/test/tx_updateAsset_test.go +++ b/test/tx_updateAsset_test.go @@ -69,6 +69,7 @@ func TestUpdateAsset(t *testing.T) { expectedPerson := map[string]interface{}{ "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", "@lastTx": "updateAsset", "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), "@assetType": "person", @@ -92,10 +93,9 @@ func TestUpdateAsset(t *testing.T) { t.FailNow() } - expectedPerson["@lastTouchBy"] = "org1MSP" if !reflect.DeepEqual(state, expectedPerson) { log.Println("these should be equal") - log.Printf("%#v\n", state) + log.Printf("%#v\n", resPayload) log.Printf("%#v\n", expectedPerson) t.FailNow() } diff --git a/transactions/readAsset.go b/transactions/readAsset.go index 47ec840..23b5eee 100644 --- a/transactions/readAsset.go +++ b/transactions/readAsset.go @@ -51,15 +51,7 @@ var ReadAsset = Transaction{ return nil, errors.WrapErrorWithStatus(err, "failed to serialize asset", 500) } } else { - var asset *assets.Asset - asset, err = key.Get(stub) - if err != nil { - return nil, errors.WrapError(err, "failed to get asset state") - } - - delete(*asset, "@lastTouchBy") - - assetJSON, err = json.Marshal(asset) + assetJSON, err = key.GetBytes(stub) if err != nil { return nil, errors.WrapError(err, "failed to get asset state") }