question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parsing Issue with Custom Type in `Constants` view

See original GitHub issue

There seems to be some parsing error when using a custom struct in the constants tab of the Polkadot JS Apps.

There might be a bug in Polkadot JS Apps, but in general here is the steps to get what I think you want.

We have a custom type:

#[derive(Encode, Decode)]
struct Rule {
    name: Vec<u8>,
    version: u32,
    ops: Vec<u32>,
}

We place a const in the decl_module so it exposes it in the metadata:

         /// Rules for the PoE
        const rule: Rule = Rule {
            name: b"rule 1".to_vec(),
            version: 1,
            ops: vec![2]
        };

Then we start our chain. In Polkadot JS Apps, I register a new custom type:

{
  "Rule": {
    "name": "Vec<u8>",
    "version": "u32",
    "ops": "Vec<u32>"
  }
}

Then I go look at the constants in the pallet:

image

It seems it does not correctly detect the length prefix. When i parse the bytes on my own, it works:

image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
shawntabrizicommented, Mar 28, 2020

can confirm it is fixed

image

thanks!

1reaction
jacogrcommented, Mar 28, 2020

Should be in apps in around 20 mins - if that doesn’t solve it, can re-open, but should be correct now. (Should have been fixed originally instead of hacked around for bytes-only)

Yes, as expected, the above based on the original API logic wouldn’t have parse correctly. (And your test was incorrect as well since it worked with partial data, i.e. the hex outputs never include the full picture, here is an additional length prefix in-front since it comes in as Vec<u8> in the metadata. So the UI actually did the correct thing based on what it was fed, and it was fed something wrong. And when it displayed, it also dropped the hex, which is then what you used as an input)

Read more comments on GitHub >

github_iconTop Results From Across the Web

parsing - How can I handle previously declared constants ...
Now consider the following situation, where the default value of bar is a constant defined previously in the same file: int BAZ =...
Read more >
Parsing error: "parserOptions.project" has been set for @ ...
When using eslint on a sub module that is currently not used by any other module, the following type of error message is...
Read more >
Parse Custom Code
CodeImporter class, parses the custom code, but does not re-parse the custom code if the custom code has been parsed previously and neither...
Read more >
Text Parsing Node Properties
You can create custom entity types by defining linguistic rules and referencing a custom file within SAS Text Miner. If SAS Visual Text ......
Read more >
argparse — Parser for command-line options, arguments ...
formatter_class - A class for customizing the help output. prefix_chars - The set of characters that prefix optional arguments (default: '-')
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found