use std::collections::HashSet;
use iota_types::base_types::{IotaAddress, ObjectID};
use once_cell::sync::OnceCell;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct TransactionDenyConfig {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
object_deny_list: Vec<ObjectID>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
package_deny_list: Vec<ObjectID>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
address_deny_list: Vec<IotaAddress>,
#[serde(default)]
package_publish_disabled: bool,
#[serde(default)]
package_upgrade_disabled: bool,
#[serde(default)]
shared_object_disabled: bool,
#[serde(default)]
user_transaction_disabled: bool,
#[serde(skip)]
object_deny_set: OnceCell<HashSet<ObjectID>>,
#[serde(skip)]
package_deny_set: OnceCell<HashSet<ObjectID>>,
#[serde(skip)]
address_deny_set: OnceCell<HashSet<IotaAddress>>,
#[serde(default)]
receiving_objects_disabled: bool,
#[serde(default)]
zklogin_sig_disabled: bool,
#[serde(default)]
zklogin_disabled_providers: HashSet<String>,
}
impl TransactionDenyConfig {
pub fn get_object_deny_set(&self) -> &HashSet<ObjectID> {
self.object_deny_set
.get_or_init(|| self.object_deny_list.iter().cloned().collect())
}
pub fn get_package_deny_set(&self) -> &HashSet<ObjectID> {
self.package_deny_set
.get_or_init(|| self.package_deny_list.iter().cloned().collect())
}
pub fn get_address_deny_set(&self) -> &HashSet<IotaAddress> {
self.address_deny_set
.get_or_init(|| self.address_deny_list.iter().cloned().collect())
}
pub fn package_publish_disabled(&self) -> bool {
self.package_publish_disabled
}
pub fn package_upgrade_disabled(&self) -> bool {
self.package_upgrade_disabled
}
pub fn shared_object_disabled(&self) -> bool {
self.shared_object_disabled
}
pub fn user_transaction_disabled(&self) -> bool {
self.user_transaction_disabled
}
pub fn receiving_objects_disabled(&self) -> bool {
self.receiving_objects_disabled
}
pub fn zklogin_sig_disabled(&self) -> bool {
self.zklogin_sig_disabled
}
pub fn zklogin_disabled_providers(&self) -> &HashSet<String> {
&self.zklogin_disabled_providers
}
}
#[derive(Default)]
pub struct TransactionDenyConfigBuilder {
config: TransactionDenyConfig,
}
impl TransactionDenyConfigBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn build(self) -> TransactionDenyConfig {
self.config
}
pub fn disable_user_transaction(mut self) -> Self {
self.config.user_transaction_disabled = true;
self
}
pub fn disable_shared_object_transaction(mut self) -> Self {
self.config.shared_object_disabled = true;
self
}
pub fn disable_package_publish(mut self) -> Self {
self.config.package_publish_disabled = true;
self
}
pub fn disable_package_upgrade(mut self) -> Self {
self.config.package_upgrade_disabled = true;
self
}
pub fn disable_receiving_objects(mut self) -> Self {
self.config.receiving_objects_disabled = true;
self
}
pub fn add_denied_object(mut self, id: ObjectID) -> Self {
self.config.object_deny_list.push(id);
self
}
pub fn add_denied_address(mut self, address: IotaAddress) -> Self {
self.config.address_deny_list.push(address);
self
}
pub fn add_denied_package(mut self, id: ObjectID) -> Self {
self.config.package_deny_list.push(id);
self
}
pub fn disable_zklogin_sig(mut self) -> Self {
self.config.zklogin_sig_disabled = true;
self
}
pub fn add_zklogin_disabled_provider(mut self, provider: String) -> Self {
self.config.zklogin_disabled_providers.insert(provider);
self
}
}