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

Encoding BoundedBTreeMap type error #230

Closed
dastanbeksamatov opened this issue Aug 2, 2022 · 4 comments · Fixed by polkascan/py-scale-codec#89
Closed

Encoding BoundedBTreeMap type error #230

dastanbeksamatov opened this issue Aug 2, 2022 · 4 comments · Fixed by polkascan/py-scale-codec#89

Comments

@dastanbeksamatov
Copy link

dastanbeksamatov commented Aug 2, 2022

Hey there,

I have been experiencing some strange behaviour while encoding a custom struct with field of BoundedBTreeMap type. It fails with this error message:

ValueError: value should be a list of tuples e.g.: [('1', 2), ('23', 24), ('28', 30), ('45', 80)]

Here is the struct and types definition

// Types
#[derive(Clone, Encode, Decode, Eq, PartialEq, TypeInfo, SmartDefault, MaxEncodedLen)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound(T: Config))]
pub struct SomeStruct<T: Config> {
	pub some_field: Option<BoundedVec<u32, T::SomeType>>,
	pub some_other_field: Option<BoundedVec<u64, T::SomeOtherType>>,
}

pub MapType<T> = BoundedBTreeMap<u32, SomeStruct<T as Config>, T::MaxSomeStructs>;

pub struct SomeDescriptorStruct<MapType> {
        pub name: [u8, 8],
        pub some_structs: MapType,
}

// Extrinsic definition
pub fn create_some_struct(
	origin: OriginFor<T>,
	descriptor: SomeDescriptorStruct<T>,
) -> DispatchResult {}

How I am calling it:

params = {
    "descriptor": {
        "name": "test1234".encode("utf-8"),
        "some_structs": [
            (
                1,
                {
                     some_field: [],
                     some_other_field: [],
                },
            )
        ],
    },
};

# self.connection is `SubstrateInterface` type
call = self.connection.compose_call(
    call_module="some_pallet", call_function="create_some_struct", call_params=params
)

extrinsic = self.connection.create_signed_extrinsic(call=call, keypair=keypair)

receipt = self.connection.submit_extrinsic(extrinsic, wait_for_inclusion=True)

Would really appreciate if you could point out what I am doing wrong or if it is an unexpected behaviour from the codec library?

@arjanz
Copy link
Member

arjanz commented Aug 3, 2022

I would like to debug this type for you, could you provide the metadata hex-bytes? (result of substrate.rpc_request("state_getMetadata", [])).

@dastanbeksamatov
Copy link
Author

dastanbeksamatov commented Aug 8, 2022

hey @arjanz, thanks for the response.

here is the link to our testnet's rpc calls, just query state -> get_metadata

@arjanz
Copy link
Member

arjanz commented Aug 9, 2022

@dastanbeksamatov Is the call you want to compose already available on the testnet you provided? That would help me a lot to debug

@arjanz
Copy link
Member

arjanz commented Nov 7, 2022

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 a pull request may close this issue.

2 participants