Skip to content

Conversation

@mnaamani
Copy link
Member

@mnaamani mnaamani commented Aug 12, 2020

Basic examples on using the polkadot js api and joystream types, ported from https://github.com/Joystream/joystream-api-examples

@mnaamani mnaamani requested a review from Lezek123 August 12, 2020 06:01
@shamil-gadelshin
Copy link
Contributor

Could we move the api-examples folder to the tests? The root directory space is a scarce resource and it is crowded already.

@mnaamani
Copy link
Member Author

Could we move the api-examples folder to the tests? The root directory space is a scarce resource and it is crowded already.

Yes it is getting a bit crowded. I think utils/ might be a better location. Will update

@mnaamani mnaamani marked this pull request as draft August 12, 2020 08:15
import { BTreeSet } from '@polkadot/types'
import { types } from '@joystream/types'

async function main() {
Copy link
Member Author

Choose a reason for hiding this comment

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

This script only needs to create some types and doesn't need to read state from chain, and therefore shouldn't require creating an api instance or connecting to a node. I this type of scenario, what is the proper way to create a type registry and register our types so we can construct them safely.

cc: @Lezek123

Copy link
Contributor

Choose a reason for hiding this comment

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

I added a function to do this in https://github.com/Joystream/joystream/pull/1176/files#diff-9e9b5c1632859d4c7bee5d17dd9f7c5c, it's not well-tested yet, but I think it should work fine. I can move this to another PR if needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mnaamani mnaamani marked this pull request as ready for review August 17, 2020 08:42
return
}
obj = obj.unwrap()
console.log(`contentId: ${new joy.media.ContentId(id).encode()}, ipfs: ${obj.ipfs_content_id}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be api.createType('ContentId', id).encode()
I'm not sure if the joy global is very useful at this point, since we should be able to create any type with api.createType().

Copy link
Member Author

Choose a reason for hiding this comment

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

will fix 👍


const substrateWasm = await api.query.substrate.code.at(currentBlockHash)

console.log(substrateWasm.toHex())
Copy link
Contributor

Choose a reason for hiding this comment

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

This gives me just 0x as output (but also happens in Pioneer via Extrinsics tab)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I was surprised by this as well. Does this have anything to do with the limit on the size of Vec you identified?

Copy link
Contributor

@Lezek123 Lezek123 Aug 19, 2020

Choose a reason for hiding this comment

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

While working on #1177 I noticed that in the augment-api.ts auto-generated by @polkadot/typegen based on runtime metadata there is no substrate module at all.

So i did a little digging and found out that:

  • This module is not part of the metadata retrieved via api.rpc.state.getMetadata() (even when I get it from our current testnet node)
  • The same query also outputs 0x on current Kusama
  • It doesn't throw any errors (which happens in case of the Vec size limit issue that I ran into)


wgId.forEach((id) => {
set.add(new CuratorApplicationId(api.registry, id))
set.add(createType(registry, 'CuratorApplicationId', id))
Copy link
Contributor

@Lezek123 Lezek123 Aug 19, 2020

Choose a reason for hiding this comment

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

I found out we can actually use registry.createType() instead, which is probably a better approach (I'm going to change it in @joystream/types too)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yes that is neater, and one less import :)

@mnaamani mnaamani merged commit d7c2feb into Joystream:iznik Aug 20, 2020
@mnaamani mnaamani deleted the iznik-api-examples branch September 1, 2020 14:08
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.

3 participants