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

Codegen output not implements codec::Decode #315

Closed
Tracked by #345 ...
boozook opened this issue Nov 9, 2021 · 3 comments
Closed
Tracked by #345 ...

Codegen output not implements codec::Decode #315

boozook opened this issue Nov 9, 2021 · 3 comments

Comments

@boozook
Copy link

boozook commented Nov 9, 2021

Some codegen output not implements codec::Decode.

To reproduce there's two runtimes metadata:
pontem.scale.zip

#[subxt::subxt(runtime_metadata_path = "nodes/pontem.scale")]
// or similar for pontem-xcmp.scale
pub mod pontem {}

Error: the trait Decode is not implemented for BTreeMap<pontem::runtime_types::polkadot_parachain::primitives::Id, MessageQueueChain>

build log errors
...
 error[E0277]: the trait bound `BTreeMap: Decode` is not satisfied
	--> src/main.rs:31:1
	 |
 31 | #[subxt::subxt(runtime_metadata_path = "nodes/pontem-xcmp.scale")]
	 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	 | |
	 | the trait `Decode` is not implemented for `BTreeMap`
	 | in this procedural macro expansion
	 |
	::: ~/.cargo/git/checkouts/subxt-d8146022e5587204/78fd590/macro/src/lib.rs:39:1
	 |
 39 | pub fn subxt(args: TokenStream, input: TokenStream) -> TokenStream {
	 | ------------------------------------------------------------------ in this expansion of `#[subxt::subxt]`
	 |
	 = help: the following implementations were found:
				   as Decode>
 note: required by a bound in `subxt::StorageEntry::Value`
	--> ~/.cargo/git/checkouts/subxt-d8146022e5587204/78fd590/src/storage.rs:50:17
	 |
 50 |     type Value: Decode;
	 |                 ^^^^^^ required by this bound in `subxt::StorageEntry::Value`

error[E0277]: the trait bound BTreeMap<pontem::runtime_types::polkadot_parachain::primitives::Id, Vec<pontem::runtime_types::polkadot_core_primitives::InboundHrmpMessage<u32>>>: Decode is not satisfied
--> src/main.rs:31:1
|
31 | #[subxt::subxt(runtime_metadata_path = "nodes/pontem-xcmp.scale")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| the trait Decode is not implemented for BTreeMap<pontem::runtime_types::polkadot_parachain::primitives::Id, Vec<pontem::runtime_types::polkadot_core_primitives::InboundHrmpMessage<u32>>>
| in this procedural macro expansion
|
::: ~/.cargo/git/checkouts/subxt-d8146022e5587204/78fd590/macro/src/lib.rs:39:1
|
39 | pub fn subxt(args: TokenStream, input: TokenStream) -> TokenStream {
| ------------------------------------------------------------------ in this expansion of #[subxt::subxt]
|
= help: the following implementations were found:
<BTreeMap<K, V> as Decode>
note: required by a bound in parity_scale_codec::Decode::decode
--> ~/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/parity-scale-codec-2.3.1/src/codec.rs:284:15
|
284 | fn decode<I: Input>(input: &mut I) -> Result<Self, Error>;
| ^^^^^ required by this bound in parity_scale_codec::Decode::decode

@kvinwang
Copy link
Contributor

workaround:

#[subxt::subxt(runtime_metadata_path = "nodes/pontem.scale")]
pub mod pontem {}
const _: () = {
    use pontem::runtime_types::polkadot_parachain::primitives::Id;

    impl PartialEq for Id {
        fn eq(&self, other: &Self) -> bool {
            self.0 == other.0
        }
    }

    impl Eq for Id {

    }

    impl PartialOrd for Id {
        fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
            self.0.partial_cmp(&other.0)
        }
    }

    impl Ord for Id {
        fn cmp(&self, other: &Self) -> std::cmp::Ordering {
            self.0.cmp(&other.0)
        }
    }
};

@ascjones
Copy link
Contributor

Alternatively you might be able to use substitute_type and define a local Id type e.g.

#[derive(Eq, PartialEq, Encode, Decode)]
pub struct ParachainId ( .. );

#[subxt::subxt(runtime_metadata_path = "nodes/pontem.scale")]
pub mod pontem {
   #[subxt(substitute_type = "polkadot_parachain::primitives::Id")]
    use super::ParachainId;
}

That might work.

@jsdw
Copy link
Collaborator

jsdw commented Feb 21, 2022

I believe that this will be closed by #456; you'll no longer need the Ord trait when that lands.

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

4 participants