I have seen .into()
used several times like frame_system::RawOrigin::Signed(who).into()
. From what I understand it does some conversion but the docs for into do not make it clear (to me) how to know what it is converting to. For context a specific example I am interested in comes from sudo_as()
in the sudo module.
fn sudo_as(origin, who: <T::Lookup as StaticLookup>::Source, call: Box<<T as Trait>::Call>) {
// This is a public call, so we ensure that the origin is some signed account.
let sender = ensure_signed(origin)?;
ensure!(sender == Self::key(), Error::<T>::RequireSudo);
let who = T::Lookup::lookup(who)?;
let res = match call.dispatch(frame_system::RawOrigin::Signed(who).into()) {
Ok(_) => true,
Err(e) => {
sp_runtime::print(e);
false
}
};
Self::deposit_event(RawEvent::SudoAsDone(res));
}
You are correct that into
will return "the right" type depending on the context from which it was called. In the example you provide, you can look at the docs for the dispatch
function and see that it requires an Origin
as a parameter. However, as you can see the who
variable is being used to create a RawOrigin
type. So the into
function is being used to convert the provided type (RawOrigin
) to whatever type is needed (Origin
, in this case).