Skip to content

Commit

Permalink
Fix Stub getTxTimestamp() and getDateTimestamp() functions
Browse files Browse the repository at this point in the history
These were not interpreted correctly from the protocol buffer transaction timestamp.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
  • Loading branch information
bestbeforetoday committed Jun 16, 2023
1 parent 690c91a commit 9e3991a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2,570 deletions.
26 changes: 14 additions & 12 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions libraries/fabric-shim/lib/stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {msp, peer, common} = require('@hyperledger/fabric-protos');
const util = require('util');
const crypto = require('crypto');
const {ChaincodeEvent} = require('@hyperledger/fabric-protos/lib/peer');
const Long = require('long');

const logger = require('./logger').getLogger('lib/stub.js');

Expand Down Expand Up @@ -416,7 +417,10 @@ class ChaincodeStub {
* Object returned: { seconds: [Long] { low: [int32], high: [int32], unsigned: [bool] }, nanos: [int32] }
*/
getTxTimestamp() {
return this.txTimestamp;
return {
nanos: this.txTimestamp.getNanos(),
seconds: Long.fromNumber(this.txTimestamp.getSeconds(), true),
};
}

/**
Expand All @@ -425,8 +429,7 @@ class ChaincodeStub {
* client's date, and will have the same value across all endorsers.
*/
getDateTimestamp() {
const date = new Date(this.txTimestamp.seconds * 1e3 + this.txTimestamp.nanos / 1e6);
return date;
return this.txTimestamp.toDate();
}

/**
Expand Down
Loading

0 comments on commit 9e3991a

Please sign in to comment.