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

Fix error trying to get timestamp with light blocks #2656

Merged
merged 2 commits into from
Jan 30, 2025
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
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
Loading