Skip to content

Commit

Permalink
Merge pull request #50 from hyperledger-labs/develop
Browse files Browse the repository at this point in the history
Include last transaction ID as asset metadata
  • Loading branch information
samuelvenzi authored Aug 28, 2024
2 parents f6e887b + c2e4e8a commit 995dfb2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions assets/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func (a *Asset) injectMetadata(stub *sw.StubWrapper) errors.ICCError {
}
(*a)["@lastUpdated"] = lastUpdated.AsTime().Format(time.RFC3339)

lastTxID := stub.Stub.GetTxID()
(*a)["@lastTxID"] = lastTxID

return nil
}

Expand Down
7 changes: 7 additions & 0 deletions test/assets_put_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestPutAsset(t *testing.T) {
"@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19",
"@lastTouchBy": "org1MSP",
"@lastTx": "",
"@lastTxID": "TestPutAsset",
"@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339),
"@assetType": "person",
"name": "Maria",
Expand Down Expand Up @@ -161,6 +162,7 @@ func TestPutNewAssetRecursive(t *testing.T) {
"@lastTouchBy": "org1MSP",
"@lastTx": "",
"@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339),
"@lastTxID": "TestPutAsset",
"title": "Meu Nome é Maria",
"author": "Maria Viana",
"currentTenant": map[string]interface{}{
Expand All @@ -169,6 +171,7 @@ func TestPutNewAssetRecursive(t *testing.T) {
"@lastTouchBy": "org1MSP",
"@lastTx": "",
"@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339),
"@lastTxID": "TestPutAsset",
"name": "Maria",
"id": "31820792048",
"height": 1.66,
Expand All @@ -190,6 +193,7 @@ func TestPutNewAssetRecursive(t *testing.T) {
"@lastTouchBy": "org1MSP",
"@lastTx": "",
"@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339),
"@lastTxID": "TestPutAsset",
"title": "Meu Nome é Maria",
"author": "Maria Viana",
"currentTenant": map[string]interface{}{
Expand Down Expand Up @@ -270,6 +274,7 @@ func TestUpdateRecursive(t *testing.T) {
"@lastTouchBy": "org1MSP",
"@lastTx": "",
"@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339),
"@lastTxID": "TestUpdateAsset",
"title": "Meu Nome é Maria",
"author": "Maria Viana",
"currentTenant": map[string]interface{}{
Expand All @@ -278,6 +283,7 @@ func TestUpdateRecursive(t *testing.T) {
"@lastTouchBy": "org1MSP",
"@lastTx": "",
"@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339),
"@lastTxID": "TestUpdateAsset",
"name": "Maria",
"id": "31820792048",
"height": 1.88,
Expand All @@ -300,6 +306,7 @@ func TestUpdateRecursive(t *testing.T) {
"@lastTouchBy": "org1MSP",
"@lastTx": "",
"@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339),
"@lastTxID": "TestUpdateAsset",
"title": "Meu Nome é Maria",
"author": "Maria Viana",
"currentTenant": map[string]interface{}{
Expand Down
3 changes: 3 additions & 0 deletions test/tryout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestTryout(t *testing.T) {
"@lastTouchBy": "org1MSP",
"@lastTx": "createAsset",
"@assetType": "person",
"@lastTxID": "createAsset",
"name": "Maria",
"id": "31820792048",
"height": 0.0,
Expand Down Expand Up @@ -63,6 +64,7 @@ func TestTryout(t *testing.T) {
"@lastTouchBy": "org2MSP",
"@lastTx": "createAsset",
"@assetType": "book",
"@lastTxID": "createAsset",
"title": "Meu Nome é Maria",
"author": "Maria Viana",
"currentTenant": map[string]interface{}{
Expand Down Expand Up @@ -116,6 +118,7 @@ func TestTryout(t *testing.T) {
"@lastTouchBy": "org2MSP",
"@lastTx": "updateAsset",
"@assetType": "person",
"@lastTxID": "updateAsset",
"name": "Maria",
"id": "31820792048",
"height": 1.67,
Expand Down
1 change: 1 addition & 0 deletions test/tx_createAssetType_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func TestCreateAssetType(t *testing.T) {
"@lastTx": "createAsset",
"@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339),
"@assetType": "magazine",
"@lastTxID": "createAsset",
"name": "MAG",
"images": []interface{}{
"url.com/1",
Expand Down
3 changes: 3 additions & 0 deletions test/tx_createAsset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestCreateAsset(t *testing.T) {
"@lastTx": "createAsset",
"@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339),
"@assetType": "person",
"@lastTxID": "createAsset",
"name": "Maria",
"id": "31820792048",
"height": 0.0,
Expand Down Expand Up @@ -139,6 +140,7 @@ func TestCreateAssetGenericAssociation(t *testing.T) {
"@lastTx": "createAsset",
"@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339),
"@assetType": "person",
"@lastTxID": "createAsset",
"name": "Maria",
"id": "31820792048",
"height": 0.0,
Expand Down Expand Up @@ -250,6 +252,7 @@ func TestCreatePrivate(t *testing.T) {
"@assetType": "secret",
"@lastTouchBy": "org2MSP",
"@lastTx": "createAsset",
"@lastTxID": "createAsset",
"@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339),
"secretName": "testSecret",
"secret": "this is very secret",
Expand Down
1 change: 1 addition & 0 deletions test/tx_updateAsset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func TestUpdateAsset(t *testing.T) {
"@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19",
"@lastTouchBy": "org1MSP",
"@lastTx": "updateAsset",
"@lastTxID": "updateAsset",
"@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339),
"@assetType": "person",
"name": "Maria",
Expand Down

0 comments on commit 995dfb2

Please sign in to comment.