Skip to main content

Module iota::deny_list

Defines the DenyList type. The DenyList shared object is used to restrict access to instances of certain core types from being used as inputs by specified addresses in the deny list.

use iota::address; use iota::bag; use iota::config; use iota::dynamic_field; use iota::dynamic_object_field; use iota::event; use iota::hex; use iota::object; use iota::transfer; use iota::tx_context; use std::ascii; use std::bcs; use std::option; use std::string; use std::vector;

Struct DenyList

A shared object that stores the addresses that are blocked for a given core type.

public struct DenyList has key

Fields
id: iota::object::UID
lists: iota::bag::Bag

The individual deny lists.

Struct ConfigWriteCap

The capability used to write to the deny list config. Ensures that the Configs for the DenyList are modified only by this module.

public struct ConfigWriteCap has drop

Fields

Struct ConfigKey

The dynamic object field key used to store the Config for a given type, essentially a (per_type_index, per_type_key) pair.

public struct ConfigKey has copy, drop, store

Fields
per_type_index: u64
per_type_key: vector<u8>

Struct AddressKey

The setting key used to store the deny list for a given address in the Config.

public struct AddressKey has copy, drop, store

Fields
0: address

Struct GlobalPauseKey

The setting key used to store the global pause setting in the Config.

public struct GlobalPauseKey has copy, drop, store

Fields

Struct PerTypeConfigCreated

The event emitted when a new Config is created for a given type. This can be useful for tracking the ID of a type's Config object.

public struct PerTypeConfigCreated has copy, drop, store

Fields

Constants

Trying to create a deny list object when not called by the system address.

const ENotSystemAddress: u64 = 0;

Function add

public(package) fun add(deny_list: &mut iota::deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>, addr: address, ctx: &mut iota::tx_context::TxContext)

Implementation

public(package) fun add( deny_list: &mut DenyList, per_type_index: u64, per_type_key: vector<u8>, addr: address, ctx: &mut TxContext, ) { let per_type_config = deny_list.per_type_config_entry!(per_type_index, per_type_key, ctx); let setting_name = AddressKey(addr); let next_epoch_entry = per_type_config.entry!<_, AddressKey, bool>( &mut ConfigWriteCap(), setting_name, |_deny_list, _cap, _ctx| true, ctx, ); *next_epoch_entry = true; }

Function remove

public(package) fun remove(deny_list: &mut iota::deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>, addr: address, ctx: &mut iota::tx_context::TxContext)

Implementation

public(package) fun remove( deny_list: &mut DenyList, per_type_index: u64, per_type_key: vector<u8>, addr: address, ctx: &mut TxContext, ) { let per_type_config = deny_list.per_type_config_entry!(per_type_index, per_type_key, ctx); let setting_name = AddressKey(addr); per_type_config.remove_for_next_epoch<_, AddressKey, bool>( &mut ConfigWriteCap(), setting_name, ctx, ); }

Function contains_current_epoch

public(package) fun contains_current_epoch(deny_list: &iota::deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>, addr: address, ctx: &iota::tx_context::TxContext): bool

Implementation

public(package) fun contains_current_epoch( deny_list: &DenyList, per_type_index: u64, per_type_key: vector<u8>, addr: address, ctx: &TxContext, ): bool { if (!deny_list.per_type_exists(per_type_index, per_type_key)) return false; let per_type_config = deny_list.borrow_per_type_config(per_type_index, per_type_key); let setting_name = AddressKey(addr); config::read_setting(object::id(per_type_config), setting_name, ctx).destroy_or!(false) }

Function contains_next_epoch

public(package) fun contains_next_epoch(deny_list: &iota::deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>, addr: address): bool

Implementation

public(package) fun contains_next_epoch( deny_list: &DenyList, per_type_index: u64, per_type_key: vector<u8>, addr: address, ): bool { if (!deny_list.per_type_exists(per_type_index, per_type_key)) return false; let per_type_config = deny_list.borrow_per_type_config(per_type_index, per_type_key); let setting_name = AddressKey(addr); per_type_config.read_setting_for_next_epoch(setting_name).destroy_or!(false) }

Function enable_global_pause

public(package) fun enable_global_pause(deny_list: &mut iota::deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>, ctx: &mut iota::tx_context::TxContext)

Implementation

public(package) fun enable_global_pause( deny_list: &mut DenyList, per_type_index: u64, per_type_key: vector<u8>, ctx: &mut TxContext, ) { let per_type_config = deny_list.per_type_config_entry!(per_type_index, per_type_key, ctx); let setting_name = GlobalPauseKey(); let next_epoch_entry = per_type_config.entry!<_, GlobalPauseKey, bool>( &mut ConfigWriteCap(), setting_name, |_deny_list, _cap, _ctx| true, ctx, ); *next_epoch_entry = true; }

Function disable_global_pause

public(package) fun disable_global_pause(deny_list: &mut iota::deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>, ctx: &mut iota::tx_context::TxContext)

Implementation

public(package) fun disable_global_pause( deny_list: &mut DenyList, per_type_index: u64, per_type_key: vector<u8>, ctx: &mut TxContext, ) { let per_type_config = deny_list.per_type_config_entry!(per_type_index, per_type_key, ctx); let setting_name = GlobalPauseKey(); per_type_config.remove_for_next_epoch<_, GlobalPauseKey, bool>( &mut ConfigWriteCap(), setting_name, ctx, ); }

Function is_global_pause_enabled_current_epoch

public(package) fun is_global_pause_enabled_current_epoch(deny_list: &iota::deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>, ctx: &iota::tx_context::TxContext): bool

Implementation

public(package) fun is_global_pause_enabled_current_epoch( deny_list: &DenyList, per_type_index: u64, per_type_key: vector<u8>, ctx: &TxContext, ): bool { if (!deny_list.per_type_exists(per_type_index, per_type_key)) return false; let per_type_config = deny_list.borrow_per_type_config(per_type_index, per_type_key); let setting_name = GlobalPauseKey(); config::read_setting(object::id(per_type_config), setting_name, ctx).destroy_or!(false) }

Function is_global_pause_enabled_next_epoch

public(package) fun is_global_pause_enabled_next_epoch(deny_list: &iota::deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>): bool

Implementation

public(package) fun is_global_pause_enabled_next_epoch( deny_list: &DenyList, per_type_index: u64, per_type_key: vector<u8>, ): bool { if (!deny_list.per_type_exists(per_type_index, per_type_key)) return false; let per_type_config = deny_list.borrow_per_type_config(per_type_index, per_type_key); let setting_name = GlobalPauseKey(); per_type_config.read_setting_for_next_epoch(setting_name).destroy_or!(false) }

Function add_per_type_config

fun add_per_type_config(deny_list: &mut iota::deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>, ctx: &mut iota::tx_context::TxContext)

Implementation

fun add_per_type_config( deny_list: &mut DenyList, per_type_index: u64, per_type_key: vector<u8>, ctx: &mut TxContext, ) { let key = ConfigKey { per_type_index, per_type_key }; let config = config::new(&mut ConfigWriteCap(), ctx); let config_id = object::id(&config); ofield::internal_add(&mut deny_list.id, key, config); iota::event::emit(PerTypeConfigCreated { key, config_id }); }

Function borrow_per_type_config_mut

fun borrow_per_type_config_mut(deny_list: &mut iota::deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>): &mut iota::config::Config<iota::deny_list::ConfigWriteCap>

Implementation

fun borrow_per_type_config_mut( deny_list: &mut DenyList, per_type_index: u64, per_type_key: vector<u8>, ): &mut Config<ConfigWriteCap> { let key = ConfigKey { per_type_index, per_type_key }; ofield::internal_borrow_mut(&mut deny_list.id, key) }

Function borrow_per_type_config

fun borrow_per_type_config(deny_list: &iota::deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>): &iota::config::Config<iota::deny_list::ConfigWriteCap>

Implementation

fun borrow_per_type_config( deny_list: &DenyList, per_type_index: u64, per_type_key: vector<u8>, ): &Config<ConfigWriteCap> { let key = ConfigKey { per_type_index, per_type_key }; ofield::internal_borrow(&deny_list.id, key) }

Function per_type_exists

fun per_type_exists(deny_list: &iota::deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>): bool

Implementation

fun per_type_exists(deny_list: &DenyList, per_type_index: u64, per_type_key: vector<u8>): bool { let key = ConfigKey { per_type_index, per_type_key }; ofield::exists_(&deny_list.id, key) }

Macro function per_type_config_entry

macro fun per_type_config_entry($deny_list: &mut iota::deny_list::DenyList, $per_type_index: u64, $per_type_key: vector<u8>, $ctx: &mut iota::tx_context::TxContext): &mut iota::config::Config<iota::deny_list::ConfigWriteCap>

Implementation

macro fun per_type_config_entry( $deny_list: &mut DenyList, $per_type_index: u64, $per_type_key: vector<u8>, $ctx: &mut TxContext, ): &mut Config<ConfigWriteCap> { let deny_list = $deny_list; let per_type_index = $per_type_index; let per_type_key = $per_type_key; let ctx = $ctx; if (!deny_list.per_type_exists(per_type_index, per_type_key)) { deny_list.add_per_type_config(per_type_index, per_type_key, ctx); }; deny_list.borrow_per_type_config_mut(per_type_index, per_type_key) }

Function create

Creation of the deny list object is restricted to the system address via a system transaction.

fun create(ctx: &mut iota::tx_context::TxContext)

Implementation

fun create(ctx: &mut TxContext) { assert!(ctx.sender() == @0x0, ENotSystemAddress); let deny_list_object = DenyList { id: object::iota_deny_list_object_id(), lists: bag::new(ctx), }; transfer::share_object(deny_list_object); }