-
Notifications
You must be signed in to change notification settings - Fork 19
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
Use augmented and generated types #1703
Conversation
There's some misunderstanding, I think. We mainly need the primitives types for sidechain, e.g. The parachain metadata only adds types/extrinsics for the parachain, which is nice-to-have, but not the main goal of the issue. Both parachain and sidechain have a pallet |
After checking, it is not possible to directly generate
|
You mean that the generated types in the idhub code are the same we have? 🤔 |
As of now, it appears to be the case.
Not entirely,they made changes to the content of |
Updated:
|
"gen-type:parachain": "yarn gen-type-parachain:defs && yarn gen-type-parachain:meta && yarn format", | ||
"gen-type-parachain:defs": "ts-node --skip-project node_modules/.bin/polkadot-types-from-defs --package . --input ./parachain-interfaces --endpoint ./litentry-parachain-metadata.json", | ||
"gen-type-parachain:meta": "ts-node --skip-project node_modules/.bin/polkadot-types-from-chain --package . --output ./parachain-interfaces --endpoint ./litentry-parachain-metadata.json", | ||
"gen-type:sidechain": "yarn gen-type-sidechain:defs && yarn gen-type-sidechain:meta && yarn format", | ||
"gen-type-sidechain:defs": "ts-node --skip-project node_modules/.bin/polkadot-types-from-defs --package . --input ./sidechain-interfaces --endpoint ./litentry-sidechain-metadata.json", | ||
"gen-type-sidechain:meta": "ts-node --skip-project node_modules/.bin/polkadot-types-from-chain --package . --output ./sidechain-interfaces --endpoint ./litentry-sidechain-metadata.json", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have these documented somewhere? If so then that probably needs updated as well 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; left minor comments/questions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect things like LitentryIdentity
and LitentryValidationData
would be deleted from type-definitions.ts
and types in metadata are used instead. Isn't it the case?
"paths": { | ||
"@polkadot/api/augment": ["./parachain-interfaces/augment-api.ts"], | ||
"@polkadot/types/augment": ["./parachain-interfaces/augment-types.ts"], | ||
"@polkadot/types/lookup": ["./sidechain-interfaces/types-lookup.ts"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These three paths are a mixture of parachain and sidechain interfaces, is this intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are different. The first two refer to the detection of API types (for example, when using api.tx, we need the parachain type). The last one refers to the configuration when we need to import a specific type (for example, importing LitentryPrimitivesIdentity).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the types that we need are in the parachain types-lookup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have contemplated merging them together: "@polkadot/types/lookup":[parachain..., sidechain...]
, but it is not supported. There are related issues mentioning this, so I think ultimately Rust needs to merge identity types
into parachain
.
Updated:
|
Major updates:
Once the CI passes, it is ready for review. |
7ffe8e5
to
bda99a7
Compare
575f7b2
to
514f003
Compare
tee-worker/ts-tests/identity.test.ts
Outdated
const substrateExtensionIdentity = { | ||
Substrate: { | ||
address: '0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48', //Bob | ||
network: 'Litentry', | ||
}, | ||
} as any; | ||
} as unknown as LitentryPrimitivesIdentity; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get why we need the as
when interfacing with the (mis-)augmented API, but why the assertion here?
If I get it correctly this is the input we want to pass to createType('LitentryPrimitivesIdentity', <_>)
, but from what we saw earlier that type is actually different from how LitentryPrimitivesIdentity
is declared, no? For instance, this input doesn't have the type
or isSubstrate
props.
This might still be a job for the ExtractEnumVariant
we discussed earlier 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might still be a job for the ExtractEnumVariant we discussed earlier
Your understanding is correct. If we want perfection, we do need to do it that way(ExtractEnumVariant). However, you will find that in our ts-test, we mostly use interfaces for LitentryPrimitivesIdentity
. I'm thinking that when assembling the parameters, we can define the LitentryPrimitivesIdentity
type ,but need pass it to createType
with Substrate: { address: '0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48', network: 'Litentry', }.
Do you think this is significant? Would it be enough for IDHub to know the LitentryPrimitivesIdentity
which interfaces it has?
If they want to define LitentryPrimitivesIdentity
, would it be enough for them to assemble their own ExtractEnumVariant
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want perfection, we do need to do it that way(ExtractEnumVariant).
I don't think we want perfection, but we should at least strive to have accurate definitions for the input and output datatypes in the API (even if we cannot get them to be inferred correctly in each usage).
However, you will find that in our ts-test, we mostly use interfaces for LitentryPrimitivesIdentity.
I don't follow what you mean by this 🤔
but need pass it to
createType
withSubstrate: { address: '0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48', network: 'Litentry', }
.
My point is that AFAICT this value ({ Substrate: { ... } }
) that we're passing to createType
is not a LitentryPrimitivesIdentity
, but rather some other type that at the moment doesn't have a name. We can derive that type from LitentryPrimitivesIdentity
with something like ExtractEnumVariant
, but they're not the same type and I think it only makes sense to make that distinction explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have decided to address this matter in another PR/issue.
Now there is a final decision. Do we want to assemble the Since this PR has been open for a while, I would like to make the final confirmation in the last stage. We can create a separate PR for the "looks-up" issue because that seems to be a TypeScript problem. |
I still see many conflicting files for this PR. |
resolves #1673
resolves #1667
resolves #1679 (@polkadot/api @polkadot/types @polkadot/kering)
@polkadot/typegen
still cannot be upgraded,this issue comment has been mentioned.litentry-parachain-metadata
. Because when I uselitentry-sidechain-metadata
, I found that the types are incorrect.It is no longer like this: