Skip to content

Commit c098b7b

Browse files
committed
shim: ensure connected to sugondat-node
Closes thrumdev#36
1 parent c8d6e7f commit c098b7b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

sugondat-shim/src/sugondat_rpc.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl Client {
2525
pub async fn new(rpc_url: String) -> anyhow::Result<Self> {
2626
let raw = RpcClient::from_url(&rpc_url).await?;
2727
let subxt = sugondat_subxt::Client::from_rpc_client(raw.clone()).await?;
28+
check_if_compatible(&subxt)?;
2829
Ok(Self { raw, subxt })
2930
}
3031

@@ -112,6 +113,20 @@ impl Client {
112113
}
113114
}
114115

116+
/// Tries to find the `Blob` pallet in the runtime metadata. If it's not there, then we are not
117+
/// connected to a Sugondat node.
118+
fn check_if_compatible(client: &sugondat_subxt::Client) -> anyhow::Result<()> {
119+
assert!(sugondat_subxt::sugondat::PALLETS.contains(&"Blob"));
120+
if let Some(pallet) = client.metadata().pallet_by_name("Blob") {
121+
if pallet.call_variant_by_name("submit_blob").is_some() {
122+
return Ok(());
123+
}
124+
}
125+
Err(anyhow::anyhow!(
126+
"connected to a Substrate node that is not Sugondat"
127+
))
128+
}
129+
115130
/// Iterates over the extrinsics in a block and extracts the submit_blob extrinsics.
116131
fn extract_blobs(
117132
extrinsics: Vec<

0 commit comments

Comments
 (0)