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

Missing block timestamp in the block details #2811

Closed
satyamakgec opened this issue Jun 6, 2019 · 8 comments

Comments

@satyamakgec
Copy link

commented Jun 6, 2019

I don't know whether it was intentional or it was missed to add the timestamp of the block in the block metadata.
I was trying to access the event data and the timestamp at which events get emitted but it seems impossible to get

Block Data -

SignedBlock {
  'block' => Block {
  'header' => Header {
  'parentHash' => [Hash],
  'number' => [Compact],
  'stateRoot' => [Hash],
  'extrinsicsRoot' => [Hash],
  'digest' => [Digest],
  _jsonMap: Map {},
  _Types: [Object] },
  'extrinsics' => Extrinsics [
  [Extrinsic],
  [Extrinsic],
  [Extrinsic],
  _Type: [Function: Extrinsic] ],
  _jsonMap: Map {},
  _Types: { header: 'Header', extrinsics: 'Extrinsics' } },
  'justification' => Justification [  ],
  _jsonMap: Map {},
  _Types: { block: 'Block', justification: 'Justification' } }

Event data -

EventData [
  Bytes [ 83, 65, 84, 89 ],
  AccountId [
    142,
    175,
    4,
    21,
    22,
    135,
    115,
    99,
    38,
    201,
    254,
    161,
    126,
    37,
    252,
    82,
    135,
    97,
    54,
    147,
    201,
    18,
    144,
    156,
    178,
    38,
    170,
    71,
    148,
    242,
    106,
    72 ],
  AccountId [
    212,
    53,
    147,
    199,
    21,
    253,
    211,
    28,
    97,
    20,
    26,
    189,
    4,
    169,
    159,
    214,
    130,
    44,
    133,
    88,
    133,
    76,
    205,
    227,
    154,
    86,
    132,
    231,
    165,
    109,
    162,
    125 ],
  <BN: 2710>,
  _Types: [ [Function: Bytes],
    [Function: AccountId],
    [Function: AccountId],
    [Function: Balance] ],
  _meta: EventMetadata {
    'name' => [String: 'Approval'],
    'args' => _class [ [Type], [Type], [Type], [Type], _Type: [Function: Type] ],
    'documentation' => _class [ _Type: [Function: Text] ],
    _jsonMap: Map {},
    _Types: { name: 'Text', args: '_class', documentation: '_class' } },
  _method: 'Approval',
  _section: 'asset',
  _typeDef: [ { info: 3, name: undefined, type: 'Bytes' },
    { info: 3, name: undefined, type: 'AccountId' },
    { info: 3, name: undefined, type: 'AccountId' },
    { info: 3, name: undefined, type: 'Balance' } ] ]

In both data sets there is no way to get the timestamp

@bkchr

This comment has been minimized.

Copy link
Contributor

commented Jun 6, 2019

Which timestamp do you need? The one that is used in the block while building it?

@satyamakgec

This comment has been minimized.

Copy link
Author

commented Jun 6, 2019

@bkchr Yes, I think so because every event in the block will take the same timestamp.

@bkchr

This comment has been minimized.

Copy link
Contributor

commented Jun 6, 2019

As the timestamp is stored in the block, you should be able to extract it.
I assume you want to get this data in Javascript?

Cc @jacogr if it is js.

@jacogr

This comment has been minimized.

Copy link
Contributor

commented Jun 6, 2019

Substrate does not have the concept of "a block timestamp".

However, in each block an inherent is added (assuming it is pure substrate) which does the timestamp setting. So to extract, you would need to look at the extrinsics in the block, e.g https://polkascan.io/pre/alexander/system/block/1651859

So to extract -

  • retrieve block
  • get first extrinsic (set timestamp)
  • look at the data of it
@satyamakgec

This comment has been minimized.

Copy link
Author

commented Jun 6, 2019

@bkchr Yes, I want to access from the js. Thanks @jacogr to make me understand the process. Out of curiosity, I want to ask one more thing what does the second extrinsic do it also shows some data. By seeing its data I can guess that it gives the previous block number. Could you please shed some light on this as well.

{
        signature: {
          version: 1,
          signer: F7Hs,
          signature: 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
          nonce: 0,
          era: 0x00
        },
        method: {
          callIndex: 0x1400,
          args: {
            hint: 1426
          }
        }
      },
@bkchr

This comment has been minimized.

Copy link
Contributor

commented Jun 6, 2019

This is probably the aura slot number you are seeing.

@jacogr

This comment has been minimized.

Copy link
Contributor

commented Jun 6, 2019

For some reason, we never exposed the human-readable module & method names on the actual Method. (Easy enough to find, however from a convenience pov, was missing - addressed in polkadot-js/api#975)

So on polkadot, it always adds parachains.setHeads (as intrinsic #2) - can see that in the polkadot.js.org/apps explorer (or on polkascan). Substrate only adds the first by default.

@satyamakgec

This comment has been minimized.

Copy link
Author

commented Jun 7, 2019

Thanks, @jacogr & @bkchr for giving me insight. Closing the issue

@satyamakgec satyamakgec closed this Jun 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.