2

In polkadotjs I have following code:

const opts = [{"UniqueIdenfier1":[0,"challengeprofile"]}]
let data = api.query.templateModule.periodName(
            ...opts,
            queryResHandler
          )

I want to convert it to rust subtxt:

#[subxt::subxt(runtime_metadata_path = "./artifacts/metadata.scale")]
pub mod polkadot {}

let client = subxt::client::OnlineClient::<PolkadotConfig>::from_url("ws://127.0.0.1:9944")
                        .await
                        .unwrap();
                
let period = polkadot::storage().template_module().period_name(&opts);

opt is an SumTreeName enum in substrate:

#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub enum SumTreeName {
    UniqueIdenfier1 { citizen_id: u128, name: Vec<u8>}
}

How to convert opts in rust format?

1 Answer 1

1

Solved by importing SumTreeName

 #[subxt::subxt(runtime_metadata_path = "./artifacts/metadata.scale")]
 pub mod polkadot {}


 let client = subxt::client::OnlineClient::<PolkadotConfig>::from_url("ws://127.0.0.1:9944")
                        .await
                        .unwrap();
 let key = polkadot::runtime_types::sortition_sum_game::types::SumTreeName::UniqueIdenfier1 {
                    citizen_id: 0,
                    name: "challengeprofile".as_bytes().to_vec(),
                };
 let period = polkadot::storage().template_module().period_name(&key);

Your Answer

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

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