alloy_eips/eip4844/
env_settings.rs1use alloc::sync::Arc;
2use core::hash::{Hash, Hasher};
3
4pub use c_kzg::KzgSettings;
6
7const PRECOMPUTE: u64 = 0;
13
14#[derive(Clone, Debug, Default, Eq)]
16pub enum EnvKzgSettings {
17 #[default]
19 Default,
20 Custom(Arc<KzgSettings>),
22}
23
24impl PartialEq for EnvKzgSettings {
26 fn eq(&self, other: &Self) -> bool {
27 match (self, other) {
28 (Self::Default, Self::Default) => true,
29 (Self::Custom(a), Self::Custom(b)) => Arc::ptr_eq(a, b),
30 _ => false,
31 }
32 }
33}
34
35impl Hash for EnvKzgSettings {
36 fn hash<H: Hasher>(&self, state: &mut H) {
37 core::mem::discriminant(self).hash(state);
38 match self {
39 Self::Default => {}
40 Self::Custom(settings) => Arc::as_ptr(settings).hash(state),
41 }
42 }
43}
44
45impl EnvKzgSettings {
46 #[inline]
50 pub fn get(&self) -> &KzgSettings {
51 match self {
52 Self::Default => c_kzg::ethereum_kzg_settings(PRECOMPUTE),
53 Self::Custom(settings) => settings,
54 }
55 }
56
57 #[cfg(feature = "std")]
59 pub fn load_from_trusted_setup_file(
60 trusted_setup_file: &std::path::Path,
61 ) -> Result<Self, c_kzg::Error> {
62 let settings = KzgSettings::load_trusted_setup_file(trusted_setup_file, PRECOMPUTE)?;
63 Ok(Self::Custom(Arc::new(settings)))
64 }
65}