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

BE-790 Change default encode of value in TX details #157

Merged
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
11 changes: 11 additions & 0 deletions README-CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,14 @@ This document will describe about the detail of each configuration:
```shell
docker-compose down -v
```

## Value encoding in Transaction Details

* By default, the value of each read/write set is encoded by UTF-8. If you want to change the type of encoding, you can configure with the following property in the connection profile. Please refer to [Buffer | Node.js v14.7.0 Documentation](https://nodejs.org/docs/latest/api/buffer.html#buffer_buffers_and_character_encodings) for the supported encoding.

```json
"client": {
"rwSetEncoding": "hex"
}
```

4 changes: 4 additions & 0 deletions app/platform/fabric/FabricConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ class FabricConfig {
}
return peers;
}

getRWSetEncoding() {
return this.config.client.rwSetEncoding || 'utf8';
}
}

module.exports = FabricConfig;
22 changes: 22 additions & 0 deletions app/platform/fabric/sync/SyncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,11 @@ class SyncServices {
let chaincodeID;
let status;
let mspId = [];
this.convertFormatOfValue(
'value',
client.fabricGateway.fabricConfig.getRWSetEncoding(),
txObj
);
if (txid && txid !== '') {
const validation_codes =
block.metadata.metadata[block.metadata.metadata.length - 1];
Expand Down Expand Up @@ -697,6 +702,23 @@ class SyncServices {
blocksInProcess.splice(index, 1);
}

convertFormatOfValue(prop, encoding, obj) {
if (Array.isArray(obj)) {
for (let i = 0; i < obj.length; i++) {
this.convertFormatOfValue(prop, encoding, obj[i]);
}
} else if (!Buffer.isBuffer(obj) && typeof obj === 'object') {
// Each element of array of Buffer is excluded by the 1st condition
Object.keys(obj).forEach(key => {
if (key === prop && Buffer.isBuffer(obj[key])) {
obj[key] = obj[key].toString(encoding);
} else if (obj[key]) {
this.convertFormatOfValue(prop, encoding, obj[key]);
}
});
}
}

/**
*
*
Expand Down