3

I'm retrieving the list of authorities from aura in the pallet like this:

let authorities = pallet_aura::Pallet::<T>::authorities();

this should return a Vec<T::AuthorityId> which is supposedly the same as sp_core::sr25519::Public since AuthorityId in Aura is defined like that here, so I did the following:

authorities.into_iter().map(|id| Public::from_h256(H256::from_slice(id.as_slice())));

I'm doing it this way because for some reason in AuthorityId I don't have access to any method like sp_core::sr25519::Public, (I specifically need the verify method) which is why in the pallet it throws an error:

 no method named `as_slice` found for associated type `<T as pallet_aura::Config>::AuthorityId` in the current scope

now, having said that, in outer node if I call the runtime api authorities() and I try to create sr25519 keys from it, it works:

let authorities= client
    .runtime_api()
    .authorities(&block_id)
    .expect("error");
authorities
    .iter()
    .map(|pubkey| Public::from_h256(H256::from_slice(pubkey.as_slice())))
    .collect()
  • why is this happening, even though its completely the same function, Im stuck with AuthorityId` which has literally zero methods? and are there simpler ways to retrieve the Public keys of the current authorities that does not require all this mess?

Ps: I tried importing the trait use sp_core::ByteArray; but it still didn't work.

1 Answer 1

1

Check https://github.com/paritytech/substrate/blob/549165727c3b3c14b6f90011085aaebbeff9d7e3/frame/aura/src/lib.rs#LL72-L76C20.

Because it doesn't have a ByteArray trait bound, you can't do that.

But it has a RuntimeAppPublic trait bound.

You can import sp_application_crypto::RuntimeAppPublic and call to_raw_vec() on it.

https://github.com/paritytech/substrate/blob/549165727c3b3c14b6f90011085aaebbeff9d7e3/primitives/application-crypto/src/traits.rs#L127-L128

0

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.