Skip to content

shim: ensure connected to sugondat-node #61

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

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions sugondat-shim/src/sugondat_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl Client {
pub async fn new(rpc_url: String) -> anyhow::Result<Self> {
let raw = RpcClient::from_url(&rpc_url).await?;
let subxt = sugondat_subxt::Client::from_rpc_client(raw.clone()).await?;
check_if_compatible(&subxt)?;
Ok(Self { raw, subxt })
}

Expand Down Expand Up @@ -112,6 +113,20 @@ impl Client {
}
}

/// Tries to find the `Blob` pallet in the runtime metadata. If it's not there, then we are not
/// connected to a Sugondat node.
fn check_if_compatible(client: &sugondat_subxt::Client) -> anyhow::Result<()> {
assert!(sugondat_subxt::sugondat::PALLETS.contains(&"Blob"));
if let Some(pallet) = client.metadata().pallet_by_name("Blob") {
if pallet.call_variant_by_name("submit_blob").is_some() {
return Ok(());
}
}
Err(anyhow::anyhow!(
"connected to a Substrate node that is not Sugondat"
))
}

/// Iterates over the extrinsics in a block and extracts the submit_blob extrinsics.
fn extract_blobs(
extrinsics: Vec<
Expand Down