-
Notifications
You must be signed in to change notification settings - Fork 688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to call arbitrary runtime apis using RelayChainInterface #5521
Allow to call arbitrary runtime apis using RelayChainInterface #5521
Conversation
hash: PHash, | ||
payload: &[u8], | ||
) -> RelayChainResult<Vec<u8>> { | ||
use sp_api::{CallApiAt, CallApiAtParams, CallContext, __private::Extensions}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module is called __private
out of a reason ;)
at: hash, | ||
function: method_name, | ||
arguments: payload.to_vec(), | ||
overlayed_changes: &RefCell::new(overlayed_changes), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overlayed_changes: &RefCell::new(overlayed_changes), | |
overlayed_changes: &RefCell::new(Default::default()), |
@@ -364,3 +380,18 @@ where | |||
(**self).version(relay_parent).await | |||
} | |||
} | |||
|
|||
pub async fn call_remote_runtime_function<R>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It saves the caller from having to manually do the Decode::decode
. I can remove it if you want, but I think it's useful.
e60932b
to
f276916
Compare
The CI pipeline was cancelled due to failure one of the required jobs. |
@bkchr solved your comments, anything else missing? |
58bad1e
to
5c19396
Compare
@bkchr can you help us get the CI passing? Just from a first glance I dont see anything wrong for prdoc but maybe I am missing something..., |
5a43147
When using the relay chain though a
Arc<dyn RelayChainInterface>
there is no way to call arbitrary runtime apis. Both implementations of that trait allow this, so it feels natural to expose this functionality in the trait.This PR adds a
call_runtime_api
method to RelayChainInterface trait, and a separate function also namedcall_runtime_api
which allows the caller to specify the input and output types, as opposed to having to encode them. This generic function cannot be part of the trait because adyn Trait
object cannot have generic methods.