1

I have generated the session keys using the author.rotateKeys() RPC call. The keys are of type Vec<u8> and the length is 128 bytes.

Generate session keys

I am trying to call the set_keys() method from pallet_session to a substrate node. I am using subxt for submitting extrinsics and I have generated a .scale file for interfacing. Now I am not sure how to create SessionKeys struct using the 128 bytes. When I hover over the SessionKeys struct I can see the following

https://docs.subsocial.network/rust-docs/latest/pallet_session/enum.Call.html#variant.set_keys

pub struct SessionKeys {
    pub grandpa: Public,
    pub babe: Public,
    pub im_online: Public,
    pub authority_discovery: Public,
} // size = 128 (0x80), align = 0x1

I can't see Public struct. How to instantiate it?

Also in runtime, i can see the following

impl_opaque_keys! {
pub struct SessionKeys {
    pub grandpa: Grandpa,
    pub babe: Babe,
    pub im_online: ImOnline,
    pub authority_discovery: AuthorityDiscovery,
}
}

How to convert a 128 bytes string into a SessionKeys struct?

let grandpa: substrate::runtime_types::sp_consensus_grandpa::app::Public =
    substrate::runtime_types::sp_consensus_grandpa::app::Public::from(keys[0..32].to_vec());
let babe: substrate::runtime_types::sp_consensus_babe::app::Public =
    substrate::runtime_types::sp_consensus_babe::app::Public::from(keys[32..64].to_vec());
let im_online: substrate::runtime_types::sp_im_online::app::Public =
    substrate::runtime_types::sp_im_online::app::Public::from(keys[64..96].to_vec());
let authority_discovery: substrate::runtime_types::sp_authority_discovery::app::Public =
    substrate::runtime_types::sp_authority_discovery::app::Public::from(keys[96..128].to_vec());
error[E0308]: mismatched types
   --> main/src/substrate.rs:98:75
    |
98  |         substrate::runtime_types::sp_consensus_grandpa::app::Public::from(keys[0..32].to_vec());
    |         ----------------------------------------------------------------- ^^^^^^^^^^^^^^^^^^^^ expected `Public`, found `Vec<u8>`
    |         |
    |         arguments to this function are incorrect
    |
    = note: expected struct `sp_consensus_grandpa::app::Public`
               found struct `Vec<u8>`

It is expecting a Public struct but I am passing a Vec<u8>. But how can I create a Public struct from a Vec<u8>?

1 Answer 1

1

Answered here https://github.com/paritytech/subxt/issues/1261#issuecomment-1809790645. We can see all the types here https://paritytech.github.io/subxt-explorer/

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.