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

Is Polymesh compatible with substrate? #1334

Closed
Wangmmx opened this issue Oct 12, 2022 · 14 comments
Closed

Is Polymesh compatible with substrate? #1334

Wangmmx opened this issue Oct 12, 2022 · 14 comments

Comments

@Wangmmx
Copy link

Wangmmx commented Oct 12, 2022

Hi, I tried to call substrate.get_events, but the data I got could not be decoded successfully. Is there any special type? I am currently referring to https://github.com/ PolymeshAssociation/Polymesh/blob/develop/polymesh_schema.json

Btw, the polkadot.js.org could not display block details which has transfer event like me: https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fmainnet-rpc.polymesh.network#/explorer/query/4921857

@Neopallium
Copy link
Contributor

Neopallium commented Oct 12, 2022

We have our own Polkadot.js webapp here:
https://mainnet-app.polymesh.network/#/explorer/query/4921857
The error you are seeing is with how the webapp tries to summarize POLYX transfer. We had added some extra fields to the transfer event.

@Wangmmx
Copy link
Author

Wangmmx commented Oct 12, 2022

This works, thanks for your reply!

@Wangmmx Wangmmx closed this as completed Oct 12, 2022
@Neopallium
Copy link
Contributor

What substrate.get_events are you calling? Is it a TypeScript/JS package or Rust package?

@Wangmmx Wangmmx reopened this Oct 12, 2022
@Wangmmx
Copy link
Author

Wangmmx commented Oct 12, 2022

What substrate.get_events are you calling? Is it a TypeScript/JS package or Rust package?

I used polkascan-lib to decode and call, get_events from https://github.com/polkascan/py-substrate-interface/blob/b48f51538b46ec6bcebcb40b023aa41257211021/substrateinterface/base.py#L1509

@Neopallium
Copy link
Contributor

That library says that it supports most MetadataV14 chains, which we support now (since our v5.0 release last month). With the v14 metadata, the polymesh_schema.json file shouldn't be needed, at least not for blocks produced after the v5.0 upgrade.

@Neopallium
Copy link
Contributor

Maybe it needs some extra info for the type_registry_preset to support Polymesh.

@Wangmmx
Copy link
Author

Wangmmx commented Oct 12, 2022

Yes, I have tried most of the substrate coins successfully, but the polymesh has been failing to decode, maybe there are some infos missing.

Thank you for your willingness to help me, cause I have not updated this library synchronously for a long time, so it is not clear whether it is the problem with the library or the types I configured, I will try again

@Neopallium
Copy link
Contributor

I am going to try that python library locally here.

@Neopallium
Copy link
Contributor

Found the problem. Most substrate chains have their runtime package just one level deep (Polkadot polkadot_runtime::Event), but Polymesh has an extra package level polymesh_runtime_mainnet::runtime::Event. The python package scalecodec uses a *:: for each package level when searching for the Event type.

Add these line to the https://github.com/polkascan/py-scale-codec/blob/master/scalecodec/type_registry/polymesh-mainnet.json type registry file:

    "polymesh_runtime_develop::runtime::Event": "*::Event",
    "polymesh_runtime_testnet::runtime::Event": "*::Event",
    "polymesh_runtime_mainnet::runtime::Event": "*::Event",

I think you can download that file and use a local file instead of the built-in type registry files.

I will open a PR with scalecodec to add those lines.

@Wangmmx
Copy link
Author

Wangmmx commented Oct 12, 2022

It works! Thank you very much!
I'm so grateful for your willingness to help me and try it yourself ❤️

@Neopallium
Copy link
Contributor

Here is another way to patch in those types:

from substrateinterface import SubstrateInterface, Keypair
from substrateinterface.exceptions import SubstrateRequestException

# import logging
# logging.basicConfig(level=logging.DEBUG)

custom_types = {
    "types": {
        "polymesh_runtime_develop::runtime::Event": "*::Event",
        "polymesh_runtime_testnet::runtime::Event": "*::Event",
        "polymesh_runtime_mainnet::runtime::Event": "*::Event",
    }
}

try:
    substrate = SubstrateInterface(
        url="wss://mainnet-rpc.polymesh.network",
        type_registry=custom_types,
    )
except ConnectionRefusedError:
    print("⚠️ No local Substrate node running")
    exit()

events = substrate.get_events()
for event in events:
    print(f'* {event.value}')

@Wangmmx
Copy link
Author

Wangmmx commented Oct 12, 2022

Ok, now I am using a local JSON file 😄, I recorded the way you said.

@arjanz
Copy link

arjanz commented Oct 12, 2022

Hi guys,

As @Neopallium pointed out, the path used for the Event type in the Polymesh runtime was incompatible with the current wildcard search in scalecodec (*::runtime::Event)

I suspect though this is because a recent change in Substrate (paritytech/substrate#11981) so I made a generic solution for this.

I just released a fix in scalecodec package covering this: https://github.com/polkascan/py-scale-codec/releases/tag/v1.0.45

@Neopallium
Copy link
Contributor

@arjanz Confirmed that works. Thanks for the quick fix.

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

No branches or pull requests

3 participants