WakuMessage.timestamp field must use nanoseconds (#606)

This commit is contained in:
Franck R 2022-03-09 12:00:02 +11:00 committed by GitHub
parent 2798376776
commit e649f772a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 9 deletions

View File

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Handle errors thrown by `bytesToUtf8`. - Handle errors thrown by `bytesToUtf8`.
- `WakuMessage.timestamp` field must use nanoseconds (was using microseconds).
### Removed ### Removed

View File

@ -104,8 +104,8 @@ export class WakuMessage {
{ {
payload: _payload, payload: _payload,
timestampDeprecated: timestamp.valueOf() / 1000, timestampDeprecated: timestamp.valueOf() / 1000,
// nanoseconds https://rfc.vac.dev/spec/14/ // milliseconds 10^-3 to nanoseconds 10^-9
timestamp: Long.fromNumber(timestamp.valueOf()).mul(1000), timestamp: Long.fromNumber(timestamp.valueOf()).mul(1_000_000),
version, version,
contentTopic, contentTopic,
}, },
@ -281,8 +281,8 @@ export class WakuMessage {
// we catch the error and return undefined. // we catch the error and return undefined.
try { try {
if (this.proto.timestamp) { if (this.proto.timestamp) {
// nanoseconds https://rfc.vac.dev/spec/14/ // nanoseconds 10^-9 to milliseconds 10^-3
const timestamp = this.proto.timestamp.div(1000).toNumber(); const timestamp = this.proto.timestamp.div(1_000_000).toNumber();
return new Date(timestamp); return new Date(timestamp);
} }

View File

@ -107,12 +107,17 @@ export class HistoryRPC {
} as protoV2Beta4.PagingInfo; } as protoV2Beta4.PagingInfo;
let startTime, endTime; let startTime, endTime;
if (params.startTime) if (params.startTime) {
startTime = Long.fromNumber(params.startTime.valueOf()).mul(1000); // milliseconds 10^-3 to nanoseconds 10^-9
startTime = Long.fromNumber(params.startTime.valueOf()).mul(
if (params.endTime) 1_000_000
endTime = Long.fromNumber(params.endTime.valueOf()).mul(1000); );
}
if (params.endTime) {
// milliseconds 10^-3 to nanoseconds 10^-9
endTime = Long.fromNumber(params.endTime.valueOf()).mul(1_000_000);
}
return new HistoryRPC( return new HistoryRPC(
{ {
requestId: uuid(), requestId: uuid(),