1

I am struggling to figure out how to supply tuple parameters to a dynamic call in the latest subxt master branch. I know parameters are combinations of Value types.

My current non-working code looks like:

 let call = subxt::dynamic::tx(
        MODULE,
        "create_group",
        vec![
            Value::from_bytes(json.name.as_bytes()),
            Value::unnamed_composite(
                members
                    .into_iter()
                    .map(|(account_id, weight)| {
                        Value::unnamed_composite(vec![
                            Value::from_bytes(account_id),
                            Value::u128(weight.into()),
                        ])
                    })
                    .collect::<Vec<_>>(),
            ),
            Value::u128(json.threshold.into()),
            Value::u128(json.initial_balance),
        ],
    );

The call signature is :

     pub fn create_group(
            origin: OriginFor<T>,
            name: Vec<u8>,
            members: Vec<(T::AccountId, T::MemberCount)>,
            threshold: T::MemberCount,
            initial_balance: <<T as Config>::Currency as Currency<T::AccountId>>::Balance,
        ) -> DispatchResultWithPostInfo {

It compiles but I get the error:

Error encoding from dynamic value: Error at [0].[1]: Cannot encode to type; expected length 2 but got length 32

The auto-generated call works fine, but I am using dynamic calls because I need to be able to pass the call as a parameter to other extrinsics and it appears that that can only be done with dynamic queries.

The autogenerated call that works is:

     let call = borlaug_subxt::tx().groups().create_group(
         json.name.into(),
         members,
         json.threshold,
         json.initial_balance,
    );

And members is a vec of tuples of Account32,u32

2
  • The auto-generated call works fine, ? Could you please include this into the question too... I think you will be able to copy and paste from it
    – Simson
    May 25 at 2:07
  • Why do you need the members.iter(),map() ?
    – Simson
    May 25 at 2:08

1 Answer 1

2

Just to give this an answer; this was actually due to a bug in scale-value (see here and here). If you do a cargo update or otherwise ensure that you're using scale-value >= 0.8.1, it should now be fixed.

The value:

Value::unnamed_composite(vec![Value::unnamed_composite(vec![
    Value::u128(20u8.into()),
    Value::u128(30u16.into()),
])]);

Was previously not correctly being encoded into a Vec<(T::AccountId, T::MemberCount)>, but it will be now :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.