-
Notifications
You must be signed in to change notification settings - Fork 354
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
XCM crates squating breaks types #5741
Comments
@jacogr appending the |
I think users probably only require the type when they want to instantiate a |
There are no clashes - when a clash happens, it exposes the type by the Lookup id only. (These metadata type ids change with each and every runtime upgrade, so you end up in a much worse position using the ids plus some prefix. The type ids/indexes are far from stable, it is the things that changes the most each and every upgrade.) Types are generated for each metadata, so when (like in this case), there is a rename, the types will be different. So the breakage here is certainly expected, the type names are generated based on what is in the metadata. TL;DR The code behaves as expected. Nothing to do here, the names changed, the exposed types changed. These are generated automatically. |
I mean I get that the code works as expected. However, I think that people should not write their code in this way. They should not try to search for a type by name and instead get the type they are interested in by index from a call. This should be much more stable. I mean I'm also open to other suggestions. However for decoding we shouldn't have this problem as polkadot-js knows the types and can decode it properly. The only problem should be around encoding for transactions that we have seen now. |
You are never supposed to work with the type names directly. So you should never do - const something = api.createType('SomeType', { foo: 'bar' });
...
await api.tx.somewhere.something(something);
... In all cases you should just let the API create the types, aka - await api.tx.somewhere.something({ foo: 'bar' }); So if you don't use API do do the internal conversion and instead use a name-based So we can go round and round, it stays a wontfix. |
Ahh okay thank you! |
@jacogr is that articulated somewhere? Maybe it should be mentioned here, at least? Until the issue happened, we had no idea that this is a bad practice, and I can easily find tons of cases where people do it |
Just to add: I do think there is merit behind using Here is an example below: // This was taken directly from polkadot-js
export function createApiWithAugmentations(metadataHex: `0x${string}`): ApiPromise {
const registry = new TypeRegistry();
const metadata = new Metadata(registry, metadataHex);
registry.setMetadata(metadata);
const api = new ApiPromise({
provider: new WsProvider('ws://', false),
registry,
});
api.injectMetadata(metadata, true, registry);
return api;
}
const mockApi = createApiWithAugmentations(<some_metadata>);
const getSafeXcmVersion = () =>
Promise.resolve().then(() => {
return mockApi.registry.createType('Option<u32>', 2);
});
const adjustedMockApi = {
registry: mockApi.registry
query: {
polkadotXcm: {
safeXcmVersion: getSafeXcmVersion
}
}
} I also think it can be really useful when constructing the Edit: fix typo. |
@TarikGul just created a PR for said doc page: polkadot-js/docs#455 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query. |
I'm submitting a ...
What is the current behavior and expected behavior?
Due to some XCM crates squating there is a renaming of crates. As a result the latest metadata are having a
Staking
prefix which (apparently) broke teleporting in test faucetNormally this "check" on client side should not take place and types (e.g.
XcmVersionedMultiLocation
should not appear likeStakingXcmVersionedMultiLocation
)Current breaking of test faucet (rococo) and possible breakings in other apps
Version: 10.10.1
Environment:
Language:
The text was updated successfully, but these errors were encountered: