core integration into subxt, except for examples

This commit is contained in:
Tadeo hepperle
2024-02-02 16:12:15 +01:00
parent 14b21ab0df
commit 4e2d3fd9cf
38 changed files with 173 additions and 2013 deletions
+2 -30
View File
@@ -36,19 +36,7 @@ impl<T: Config, Client: OfflineClientT<T>> ConstantsClient<T, Client> {
/// Return an error if the address was not valid or something went wrong trying to validate it (ie
/// the pallet or constant in question do not exist at all).
pub fn validate<Address: ConstantAddress>(&self, address: &Address) -> Result<(), Error> {
if let Some(actual_hash) = address.validation_hash() {
let expected_hash = self
.client
.metadata()
.pallet_by_name_err(address.pallet_name())?
.constant_hash(address.constant_name())
.ok_or_else(|| {
MetadataError::ConstantNameNotFound(address.constant_name().to_owned())
})?;
if actual_hash != expected_hash {
return Err(MetadataError::IncompatibleCodegen.into());
}
}
subxt_core::constants::validate_constant(&self.client.metadata(), address)?;
Ok(())
}
@@ -59,23 +47,7 @@ impl<T: Config, Client: OfflineClientT<T>> ConstantsClient<T, Client> {
&self,
address: &Address,
) -> Result<Address::Target, Error> {
let metadata = self.client.metadata();
// 1. Validate constant shape if hash given:
self.validate(address)?;
// 2. Attempt to decode the constant into the type given:
let constant = metadata
.pallet_by_name_err(address.pallet_name())?
.constant_by_name(address.constant_name())
.ok_or_else(|| {
MetadataError::ConstantNameNotFound(address.constant_name().to_owned())
})?;
let value = <Address::Target as DecodeWithMetadata>::decode_with_metadata(
&mut constant.value(),
constant.ty(),
&metadata,
)?;
let value = subxt_core::constants::get_constant(&self.client.metadata(), address)?;
Ok(value)
}
}