Skip to content

Commit

Permalink
Better API
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpolaczyk committed Aug 28, 2024
1 parent b940aad commit 124c0c9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cumulus/client/relay-chain-inprocess-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl RelayChainInterface for RelayChainInProcessInterface {
Ok(self.backend.blockchain().info().finalized_hash)
}

async fn call_remote_runtime_function(
async fn call_remote_runtime_function_encoded(
&self,
method_name: &'static str,
hash: PHash,
Expand Down
21 changes: 18 additions & 3 deletions cumulus/client/relay-chain-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub trait RelayChainInterface: Send + Sync {
/// Get the hash of the finalized block.
async fn finalized_block_hash(&self) -> RelayChainResult<PHash>;

async fn call_remote_runtime_function(
async fn call_remote_runtime_function_encoded(
&self,
method_name: &'static str,
hash: RelayHash,
Expand Down Expand Up @@ -304,13 +304,13 @@ where
(**self).finalized_block_hash().await
}

async fn call_remote_runtime_function(
async fn call_remote_runtime_function_encoded(
&self,
method_name: &'static str,
hash: RelayHash,
payload: &[u8],
) -> RelayChainResult<Vec<u8>> {
(**self).call_remote_runtime_function(method_name, hash, payload).await
(**self).call_remote_runtime_function_encoded(method_name, hash, payload).await
}

async fn is_major_syncing(&self) -> RelayChainResult<bool> {
Expand Down Expand Up @@ -381,3 +381,18 @@ where
(**self).version(relay_parent).await
}
}

impl dyn RelayChainInterface {
pub async fn call_remote_runtime_function<R>(
&self,
method_name: &'static str,
hash: RelayHash,
payload: impl Encode,
) -> RelayChainResult<R>
where R: Decode
{
let res = self.call_remote_runtime_function_encoded(method_name, hash, &payload.encode()).await?;
Decode::decode(&mut &*res).map_err(Into::into)
}

}
8 changes: 4 additions & 4 deletions cumulus/client/relay-chain-rpc-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ impl RelayChainInterface for RelayChainRpcInterface {
self.rpc_client.chain_get_finalized_head().await
}

async fn call_remote_runtime_function(
async fn call_remote_runtime_function_encoded(
&self,
method_name: &'static str,
hash: RelayHash,
payload: &[u8],
_method_name: &'static str,
_hash: RelayHash,
_payload: &[u8],
) -> RelayChainResult<Vec<u8>> {
// TODO: using self.rpc_client.call_remote_runtime_function is wrong!
// We need a new function that does not encode the payload, our payload is already encoded. Same for result
Expand Down

0 comments on commit 124c0c9

Please sign in to comment.