Skip to main content

Module 0x2::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 0x1::option; use 0x2::bag; use 0x2::config; use 0x2::dynamic_object_field; use 0x2::event; use 0x2::object; use 0x2::transfer; use 0x2::tx_context;

Resource DenyList

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

struct DenyList has key

Fields
id: object::UID
lists: 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.

struct ConfigWriteCap has drop

Fields
dummy_field: bool

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.

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.

struct AddressKey has copy, drop, store

Fields
pos0: address

Struct GlobalPauseKey

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

struct GlobalPauseKey has copy, drop, store

Fields
dummy_field: bool

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.

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(friend) fun add(deny_list: &mut deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>, addr: address, ctx: &mut 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(friend) fun remove(deny_list: &mut deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>, addr: address, ctx: &mut 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(friend) fun contains_current_epoch(deny_list: &deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>, addr: address, ctx: &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(friend) fun contains_next_epoch(deny_list: &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(friend) fun enable_global_pause(deny_list: &mut deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>, ctx: &mut 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(friend) fun disable_global_pause(deny_list: &mut deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>, ctx: &mut 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(friend) fun is_global_pause_enabled_current_epoch(deny_list: &deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>, ctx: &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(friend) fun is_global_pause_enabled_next_epoch(deny_list: &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 deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>, ctx: &mut 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 deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>): &mut config::Config<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: &deny_list::DenyList, per_type_index: u64, per_type_key: vector<u8>): &config::Config<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: &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) }

Function create

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

fun create(ctx: &mut 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); }