Skip to content

Commit f865a9e

Browse files
Fix private-data TypeScript chaincode (#1357)
The build is only testing the Go chaincode for the asset-transfer-private-data sample. The behavior of the TypeScript chaincode implementation is not consistent with the Go and Java versions, which prevents it from working correctly. This change fixes the TypeScript chaincode implementation for the asset-transfer-private-data sample so that it works correctly. Additionally, some JSON property names are explicitly set in the Go client application sample, which prevented it from working with the Java and TypeScript chaincode implementations. Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
1 parent a72b2b5 commit f865a9e

7 files changed

Lines changed: 863 additions & 415 deletions

File tree

.github/workflows/test-network-private.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ run-name: ${{ github.actor }} is running the Test Network Private tests 🔒
77
on:
88
workflow_dispatch:
99
push:
10-
branches: [ "main", "release-2.5" ]
10+
branches: ["main", "release-2.5"]
1111
pull_request:
12-
branches: [ "main", "release-2.5" ]
12+
branches: ["main", "release-2.5"]
1313

1414
concurrency:
1515
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -22,6 +22,8 @@ jobs:
2222
matrix:
2323
chaincode-language:
2424
- go
25+
- java
26+
- typescript
2527
chaincode-name:
2628
- private
2729
steps:

asset-transfer-private-data/application-gateway-go/app.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ func createAssets(contract *client.Contract) {
162162
fmt.Printf("\n--> Submit Transaction: CreateAsset, ID: %s\n", assetID1)
163163

164164
type assetTransientInput struct {
165-
ObjectType string
166-
AssetID string
167-
Color string
168-
Size uint8
169-
AppraisedValue uint16
165+
ObjectType string `json:"objectType"`
166+
AssetID string `json:"assetID"`
167+
Color string `json:"color"`
168+
Size uint8 `json:"size"`
169+
AppraisedValue uint16 `json:"appraisedValue"`
170170
}
171171

172172
asset1Data := assetTransientInput{
@@ -300,7 +300,9 @@ func transferAsset(contract *client.Contract, assetID string) (err error) {
300300
func deleteAsset(contract *client.Contract, assetID string) (err error) {
301301
fmt.Printf("\n--> Submit Transaction: DeleteAsset, ID: %s\n", assetID)
302302

303-
dataForDelete := struct{ AssetID string }{assetID}
303+
dataForDelete := struct {
304+
AssetID string `json:"assetID"`
305+
}{assetID}
304306

305307
if _, err = contract.Submit(
306308
"DeleteAsset",
@@ -318,7 +320,9 @@ func deleteAsset(contract *client.Contract, assetID string) (err error) {
318320
func purgeAsset(contract *client.Contract, assetID string) (err error) {
319321
fmt.Printf("\n--> Submit Transaction: PurgeAsset, ID: %s\n", assetID)
320322

321-
dataForPurge := struct{ AssetID string }{assetID}
323+
dataForPurge := struct {
324+
AssetID string `json:"assetID"`
325+
}{assetID}
322326

323327
if _, err = contract.Submit(
324328
"PurgeAsset",

asset-transfer-private-data/chaincode-typescript/npm-shrinkwrap.json

Lines changed: 505 additions & 285 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

asset-transfer-private-data/chaincode-typescript/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
"dependencies": {
2828
"fabric-contract-api": "~2.5",
2929
"fabric-shim": "~2.5",
30-
"json-stringify-deterministic": "^1.0.0",
31-
"sort-keys-recursive": "^2.1.0"
30+
"json-stringify-deterministic": "^1.0.12",
31+
"sort-keys-recursive": "^2.1.10"
3232
},
3333
"devDependencies": {
3434
"@types/node": "^18.19.33",

asset-transfer-private-data/chaincode-typescript/src/asset.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,52 @@
22
SPDX-License-Identifier: Apache-2.0
33
*/
44

5-
import { Object, Property } from "fabric-contract-api";
6-
import { nonEmptyString, positiveNumber } from "./utils";
5+
import { Object, Property } from 'fabric-contract-api';
6+
import { nonEmptyString, positiveNumber } from './utils';
77

88
@Object()
99
// Asset describes main asset details that are visible to all organizations
1010
export class Asset {
1111
@Property()
12-
docType?: string;
12+
objectType?: string;
1313

1414
@Property()
15-
ID: string = "";
15+
ID: string = '';
1616

1717
@Property()
18-
Color: string = "";
18+
Color: string = '';
1919

2020
@Property()
2121
Size: number = 0;
2222

2323
@Property()
24-
Owner: string = "";
24+
Owner: string = '';
2525

2626
static fromBytes(bytes: Uint8Array): Asset {
2727
if (bytes.length === 0) {
28-
throw new Error("no asset data");
28+
throw new Error('no asset data');
2929
}
30-
const json = Buffer.from(bytes).toString();
30+
const json = Buffer.from(bytes).toString('utf8');
3131
const properties = JSON.parse(json) as Partial<Asset>;
3232

33-
const result = new Asset();
34-
result.docType = properties.docType;
35-
result.ID = nonEmptyString(properties.ID, "ID field must be a non-empty string");
36-
result.Color = nonEmptyString(properties.Color, "Color field must be a non-empty string");
37-
result.Size = positiveNumber(properties.Size, "Size field must be a positive integer");
38-
result.Owner = nonEmptyString(properties.Owner, "appraiseOwner field must be a non-empty string");
39-
40-
return result;
33+
return {
34+
objectType: properties.objectType,
35+
ID: nonEmptyString(
36+
properties.ID,
37+
'ID field must be a non-empty string'
38+
),
39+
Color: nonEmptyString(
40+
properties.Color,
41+
'Color field must be a non-empty string'
42+
),
43+
Size: positiveNumber(
44+
properties.Size,
45+
'Size field must be a positive integer'
46+
),
47+
Owner: nonEmptyString(
48+
properties.Owner,
49+
'appraiseOwner field must be a non-empty string'
50+
),
51+
};
4152
}
4253
}

0 commit comments

Comments
 (0)