MCPcopy Create free account
hub / github.com/subquery/subql / getTimestamp

Function getTimestamp

packages/node/src/utils/substrate.ts:77–99  ·  view source on GitHub ↗
({
  block: { extrinsics },
}: SignedBlock)

Source from the content-addressed store, hash-verified

75}
76
77export 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
101export async function getHeaderForHash(
102 api: ApiPromise,

Callers 4

getBlockTimestampMethod · 0.90
substrate.test.tsFile · 0.90
substrateBlockToHeaderFunction · 0.85
wrapBlockFunction · 0.85

Calls 1

toJSONMethod · 0.80

Tested by

no test coverage detected