Skip to content

Commit

Permalink
Fix error trying to get timestamp with light blocks (#2656)
Browse files Browse the repository at this point in the history
* Fix error trying to get timestamp with light blocks

* Update changelog
  • Loading branch information
stwiname authored Jan 30, 2025
1 parent 8d3a8c8 commit 230a6b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 2 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Crash with iterating extrinsics when skipTransactions is enabled (#2656)

## [5.7.0] - 2025-01-28
### Changed
Expand Down
21 changes: 12 additions & 9 deletions packages/node/src/utils/substrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ export function wrapBlock(
export function getTimestamp({
block: { extrinsics },
}: SignedBlock): Date | undefined {
for (const e of extrinsics) {
const {
method: { method, section },
} = e;
if (section === 'timestamp' && method === 'set') {
const date = new Date(e.args[0].toJSON() as number);
if (isNaN(date.getTime())) {
throw new Error('timestamp args type wrong');
// extrinsics can be undefined when fetching light blocks
if (extrinsics) {
for (const e of extrinsics) {
const {
method: { method, section },
} = e;
if (section === 'timestamp' && method === 'set') {
const date = new Date(e.args[0].toJSON() as number);
if (isNaN(date.getTime())) {
throw new Error('timestamp args type wrong');
}
return date;
}
return date;
}
}
// For network that doesn't use timestamp-set, return undefined
Expand Down

0 comments on commit 230a6b1

Please sign in to comment.