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: confirm session module before block retrieval #744

Merged
merged 3 commits into from
Nov 1, 2021

Conversation

TarikGul
Copy link
Member

@TarikGul TarikGul commented Nov 1, 2021

closes: #743

Updates the blocks endpoint to not fail when the connected chain doesn't have the session module to gather validators.

): Promise<Vec<AccountId32>> {
return historicApi.query.session
? historicApi.query.session.validators()
: ([] as unknown as Vec<AccountId32>);
Copy link
Contributor

@insipx insipx Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was brought up before but i forgot; why do we need to cast to unknown before Vec? why not just return []

Copy link
Member Author

@TarikGul TarikGul Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this comes down to the typescript compiler. Basically, the functions expects Vec<AccountId32> to be returned, and when we return [] its of type Array. Now the compiler sees Vec<AccountId32> and notices there is no straight type conversion from Vec<AccountId32> -> Array<any>, therefore it throws a type conversion error (Even though we know the exact output and input for the values). To get around type conversion issue we have to set it to unknown so the typescript compiler sees that the type is convertable.

@TarikGul TarikGul merged commit e6613a0 into master Nov 1, 2021
@TarikGul TarikGul deleted the tarik-fix-blocks branch November 1, 2021 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot read property 'validators' of undefined
3 participants