Skip to content

Commit

Permalink
Merge pull request #15 from GoLedgerDev/develop
Browse files Browse the repository at this point in the history
Fix recursive search for @object properties
  • Loading branch information
samuelvenzi authored Dec 28, 2022
2 parents aa2c482 + 3b28d3c commit 128f971
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
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

0 comments on commit 128f971

Please sign in to comment.