Skip to content
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

Specialize incompatible metadata errors #633

Merged
merged 1 commit into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion subxt/src/constants/constants_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ impl<T: Config, Client: OfflineClientT<T>> ConstantsClient<T, Client> {
.metadata()
.constant_hash(address.pallet_name(), address.constant_name())?;
if actual_hash != expected_hash {
return Err(MetadataError::IncompatibleMetadata.into())
return Err(MetadataError::IncompatibleConstantMetadata(
address.pallet_name().into(),
address.constant_name().into(),
)
.into())
}
}
Ok(())
Expand Down
12 changes: 9 additions & 3 deletions subxt/src/metadata/metadata_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ pub enum MetadataError {
/// Type is not in metadata.
#[error("Type {0} missing from type registry")]
TypeNotFound(u32),
/// Runtime pallet metadata is incompatible with the static one.
#[error("Pallet {0} has incompatible metadata")]
IncompatiblePalletMetadata(&'static str),
/// Runtime constant metadata is incompatible with the static one.
#[error("Pallet {0} Constant {0} has incompatible metadata")]
IncompatibleConstantMetadata(String, String),
/// Runtime call metadata is incompatible with the static one.
#[error("Pallet {0} Call {0} has incompatible metadata")]
IncompatibleCallMetadata(String, String),
/// Runtime storage metadata is incompatible with the static one.
#[error("Pallet {0} Storage {0} has incompatible metadata")]
IncompatibleStorageMetadata(String, String),
/// Runtime metadata is not fully compatible with the static one.
#[error("Node metadata is not fully compatible")]
IncompatibleMetadata,
Expand Down
8 changes: 7 additions & 1 deletion subxt/src/storage/storage_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,13 @@ fn validate_storage(
};
match expected_hash == hash {
true => Ok(()),
false => Err(crate::error::MetadataError::IncompatibleMetadata.into()),
false => {
Err(crate::error::MetadataError::IncompatibleStorageMetadata(
pallet_name.into(),
storage_name.into(),
)
.into())
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion subxt/src/tx/tx_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ impl<T: Config, C: OfflineClientT<T>> TxClient<T, C> {
let expected_hash =
metadata.call_hash(call.pallet_name(), call.call_name())?;
if actual_hash != expected_hash {
return Err(crate::metadata::MetadataError::IncompatibleMetadata.into())
return Err(crate::metadata::MetadataError::IncompatibleCallMetadata(
call.pallet_name().into(),
call.call_name().into(),
)
.into())
}
}
Ok(())
Expand Down