I am coding a pallet in which I need to know who I am inside a offchain worker to check if I should send a transaction or not. Right now I have access to the account in the send_signed_transaction
callback but it doesn`t seem like an elegant way.
This is what I would need:
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn offchain_worker(now: BlockNumberFor<T>) {
let signer = Signer::<T, T::AuthorityId>::all_accounts();
if !signer.can_sign() {
log::warn!(
target: LOG_TARGET,
"Skipping offchain worker because no local account is available."
);
return;
}
if !sp_io::offchain::is_validator() {
return;
}
// What i need
let who = signer.iam();
let validators = Validators::<T>::get();
let approvedValidators = ApprovedValidators::<T>::get();
if (!approvedValidators.contains(&who)) {
return;
}
if (validators.contains(&who)) {
return;
}
signer.send_signed_transaction(|_account| Call::add_validator_again {
validator_id: _account.id.clone(),
});
return;
}
}