Skip to content

Latest commit

 

History

History
429 lines (245 loc) · 11.9 KB

File metadata and controls

429 lines (245 loc) · 11.9 KB

Module 0x0::suins

The main module of the SuiNS application, defines the SuiNS object and the authorization mechanism for interacting with the main data storage.

Authorization mechanic: The Admin can authorize applications to access protected features of the SuiNS, they're named with a prefix app_*. Once authorized, application can get mutable access to the Registry and add to the application Balance.

At any moment any of the applications can be deathorized by the Admin making it impossible for the deauthorized module to access the registry.

Package Upgrades in mind:

Resource AdminCap

An admin capability. The admin has full control over the application. This object must be issued only once during module initialization.

struct AdminCap has store, key
Fields
id: object::UID

Resource SuiNS

The main application object. Stores the state of the application, used for adding / removing and reading name records.

Dynamic fields:

struct SuiNS has key
Fields
id: object::UID
balance: balance::Balance<sui::SUI>
The total balance of the SuiNS. Can be added to by authorized apps. Can be withdrawn only by the application Admin.

Struct SUINS

The one-time-witness used to claim Publisher object.

struct SUINS has drop
Fields
dummy_field: bool

Struct ConfigKey

Key under which a configuration is stored. It is type dependent, so that different configurations can be stored at the same time. Eg currently we store application Config (and Promotion configuration).

struct ConfigKey<Config> has copy, drop, store
Fields
dummy_field: bool

Struct RegistryKey

Key under which the Registry object is stored.

In the V1, the object stored under this key is Registry, however, for future migration purposes (if we ever need to change the Registry), we keep the phantom parameter so two different Registries can co-exist.

struct RegistryKey<Config> has copy, drop, store
Fields
dummy_field: bool

Struct AppKey

An authorization Key kept in the SuiNS - allows applications access protected features of the SuiNS (such as app_add_balance, etc.) The App type parameter is a witness which should be defined in the original module (Controller, Registry, Registrar - whatever).

struct AppKey<App: drop> has copy, drop, store
Fields
dummy_field: bool

Constants

An application is not authorized to access the feature.

const EAppNotAuthorized: u64 = 1;

Trying to withdraw from an empty balance.

const ENoProfits: u64 = 0;

Function init

Module initializer:

  • create SuiNS object
  • create admin capability
  • claim Publisher object (for Display and TransferPolicy)

Function withdraw

Withdraw from the SuiNS balance directly and access the Coins within the same transaction. This is useful for the admin to withdraw funds from the SuiNS and then send them somewhere specific or keep at the address.

Function authorize_app

Authorize an application to access protected features of the SuiNS.

public fun authorize_app<App: drop>(_: &suins::AdminCap, self: &mut suins::SuiNS)

Function deauthorize_app

Deauthorize an application by removing its authorization key.

public fun deauthorize_app<App: drop>(_: &suins::AdminCap, self: &mut suins::SuiNS): bool

Function is_app_authorized

Check if an application is authorized to access protected features of the SuiNS.

public fun is_app_authorized<App: drop>(self: &suins::SuiNS): bool

Function assert_app_is_authorized

Assert that an application is authorized to access protected features of the SuiNS. Aborts with EAppNotAuthorized if not.

public fun assert_app_is_authorized<App: drop>(self: &suins::SuiNS)

Function app_add_balance

Adds balance to the SuiNS.

public fun app_add_balance<App: drop>(_: App, self: &mut suins::SuiNS, balance: balance::Balance<sui::SUI>)

Function app_registry_mut

Get a mutable access to the Registry object. Can only be performed by authorized applications.

public fun app_registry_mut<App: drop, R: store>(_: App, self: &mut suins::SuiNS): &mut R

Function add_config

Attach dynamic configuration object to the application.

public fun add_config<Config: drop, store>(_: &suins::AdminCap, self: &mut suins::SuiNS, config: Config)

Function get_config

Borrow configuration object. Read-only mode for applications.

public fun get_config<Config: drop, store>(self: &suins::SuiNS): &Config

Function remove_config

Get the configuration object for editing. The admin should put it back after editing (no extra check performed). Can be used to swap configuration since the T has drop. Eg nothing is stopping the admin from removing the configuration object and adding a new one.

Fully taking the config also allows for edits within a transaction.

public fun remove_config<Config: drop, store>(_: &suins::AdminCap, self: &mut suins::SuiNS): Config

Function registry

Get a read-only access to the Registry object.

public fun registry<R: store>(self: &suins::SuiNS): &R

Function add_registry

Add a registry to the SuiNS. Can only be performed by the admin.

public fun add_registry<R: store>(_: &suins::AdminCap, self: &mut suins::SuiNS, registry: R)