Files
pezkuwi-sdk/vendor/pezkuwi-subxt/subxt/src/constants/constants_client.rs
T
Kurdistan Tech Ministry e808130d44 fix: Add workspace dependencies for vendored pezkuwi-subxt and zombienet-sdk
- Add all missing workspace dependencies required by vendor crates
- Include external crates: scale-*, sp-core, sc-chain-spec, kube, etc.
- Include subxt dependencies: smoldot, web-time, wasm-bindgen, etc.
- Regenerate umbrella crate with updated dependencies
- Apply zepter std feature propagation fixes to vendor crates
- Apply rustfmt formatting to vendor and pezframe files
2025-12-23 09:37:11 +03:00

47 lines
1.9 KiB
Rust

// Copyright 2019-2025 Parity Technologies (UK) Ltd.
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use crate::{client::OfflineClientT, error::ConstantError, Config};
use derive_where::derive_where;
use pezkuwi_subxt_core::constants::address::Address;
/// A client for accessing constants.
#[derive_where(Clone; Client)]
pub struct ConstantsClient<T, Client> {
client: Client,
_marker: std::marker::PhantomData<T>,
}
impl<T, Client> ConstantsClient<T, Client> {
/// Create a new [`ConstantsClient`].
pub fn new(client: Client) -> Self {
Self { client, _marker: std::marker::PhantomData }
}
}
impl<T: Config, Client: OfflineClientT<T>> ConstantsClient<T, Client> {
/// Run the validation logic against some constant address you'd like to access. Returns
/// `Ok(())` if the address is valid (or if it's not possible to check since the address has no
/// validation hash). 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<Addr: Address>(&self, address: Addr) -> Result<(), ConstantError> {
let metadata = self.client.metadata();
pezkuwi_subxt_core::constants::validate(address, &metadata)
}
/// Access the constant at the address given, returning the type defined by this address.
/// This is probably used with addresses given from static codegen, although you can manually
/// construct your own, too.
pub fn at<Addr: Address>(&self, address: Addr) -> Result<Addr::Target, ConstantError> {
let metadata = self.client.metadata();
pezkuwi_subxt_core::constants::get(address, &metadata)
}
/// Access the bytes of a constant by the address it is registered under.
pub fn bytes_at<Addr: Address>(&self, address: Addr) -> Result<Vec<u8>, ConstantError> {
let metadata = self.client.metadata();
pezkuwi_subxt_core::constants::get_bytes(address, &metadata)
}
}