({
block: { extrinsics },
}: SignedBlock)
| 75 | } |
| 76 | |
| 77 | export function getTimestamp({ |
| 78 | block: { extrinsics }, |
| 79 | }: SignedBlock): Date | undefined { |
| 80 | // extrinsics can be undefined when fetching light blocks |
| 81 | if (extrinsics) { |
| 82 | for (const e of extrinsics) { |
| 83 | const { |
| 84 | method: { method, section }, |
| 85 | } = e; |
| 86 | if (section === 'timestamp' && method === 'set') { |
| 87 | const date = new Date(e.args[0].toJSON() as number); |
| 88 | if (isNaN(date.getTime())) { |
| 89 | throw new Error('timestamp args type wrong'); |
| 90 | } |
| 91 | return date; |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | // For network that doesn't use timestamp-set, return undefined |
| 96 | // See test `return undefined if no timestamp set extrinsic` |
| 97 | // E.g Shiden |
| 98 | return undefined; |
| 99 | } |
| 100 | |
| 101 | export async function getHeaderForHash( |
| 102 | api: ApiPromise, |
no test coverage detected