cennznet / api.js

CENNZnet JS API for browsers, React Native and Node.js
Apache License 2.0
10 stars 10 forks source link

First step to let user use custom metadata without specifying genesis… #331

Closed KarishmaBothara closed 3 years ago

KarishmaBothara commented 3 years ago

Closes https://github.com/cennznet/api.js/issues/310 Options supplied to create API instance, can now include two more option..

  1. fullMeta: boolean - if false (use minimum metadata)
  2. modules: string[] - use metadata only for these runtime module, user is interested in eg.. [System, GenericAsset,...]

Things to do. ~~Add the same logic for Rx API and test it Add unit test to getMetadata function Check extrinsic works fine~~

This is still wip PR

KarishmaBothara commented 3 years ago

We'd want some tests on getMetadata to check what happens if you give a bad module name etc. also a test to show this can solve the error in #310 would be great

The ideal outcome from this is that a user can do

api.connect({ provider: ..., modules: ['GenericAsset'] })

to only interact with generic assets I think in this case we should make some modules mandatory like 'System' and 'TransactionPayment' are always provided

This can solve https://github.com/cennznet/api.js/issues/310 would mean.. I have a runtime upgrade with new types and I don't use that module while creating an API.... cause the current API will always contain all the types for the current runtime..

KarishmaBothara commented 3 years ago

lgtm. Only question is if cennzx module gets updated with a new type lets say, does that mean the whole cennzx module will be out of action for the user until we update the static metadata?

Better than not being able to connect to the whole API of course.

If you don't include it as a part of metadata then it should work fine... But when you say api = await Api.create({provider, modules:['Cennzx']}) This can break... This PR will help when you introduce a runtime module in node... DApp user can still use the old API with upgraded node if they choose to use fullMeta = false or specify the custom modules they want to use... DApp user won't need to upgrade to new API version... But if they are keen on using the updated(new types added) module (it makes sense to use updated API version for it)