Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recursive search for @object properties #15

Merged
merged 3 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/dataType.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ var dataTypeMap = map[string]*DataType{
}
}

dataVal["@assetType"] = "@object"

retVal, err := json.Marshal(dataVal)
if err != nil {
return "", nil, errors.WrapErrorWithStatus(err, "failed to marshal return value", http.StatusInternalServerError)
Expand Down
10 changes: 10 additions & 0 deletions assets/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [
for k, v := range response {
switch prop := v.(type) {
case map[string]interface{}:

if prop["@assetType"].(string) == "@object" {
continue
}

propKey, err := NewKey(prop)
if err != nil {
return nil, errors.WrapErrorWithStatus(err, "failed to resolve asset references", 500)
Expand Down Expand Up @@ -205,6 +210,11 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [
case []interface{}:
for idx, elem := range prop {
if elemMap, ok := elem.(map[string]interface{}); ok {

if elemMap["@assetType"].(string) == "@object" {
continue
}

elemKey, err := NewKey(elemMap)
if err != nil {
return nil, errors.WrapErrorWithStatus(err, "failed to resolve asset references", 500)
Expand Down
9 changes: 9 additions & 0 deletions stubwrapper/stubWrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,12 @@ func (sw *StubWrapper) GetMSPID() (string, errors.ICCError) {
}
return mspid, nil
}

// SplitCompositeKey returns composite keys
func (sw *StubWrapper) SplitCompositeKey(compositeKey string) (string, []string, errors.ICCError) {
key, keys, err := sw.Stub.SplitCompositeKey(compositeKey)
if err != nil {
return "", nil, errors.WrapError(err, "stub.SplitCompositeKey call error")
}
return key, keys, nil
}
3 changes: 2 additions & 1 deletion test/tx_createAsset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func TestCreateAsset(t *testing.T) {
"id": "31820792048",
"height": 0.0,
"info": map[string]interface{}{
"passport": "1234",
"@assetType": "@object",
"passport": "1234",
},
}

Expand Down