mod.rs
Overview
This file defines core data structures and modules related to decentralized application (dApp) configuration within the system. It provides a serializable and deserializable configuration structure (DappConfig) that stores key state attributes relevant to dApp operation, such as balance constraints and limit flags. Additionally, it declares two submodules, abi and dappconfig, which encapsulate related functionality or definitions, likely extending the configuration and interfacing capabilities of dApps.
Modules
abi
Declared as a public submodule.
Presumably contains Application Binary Interface definitions or utilities relevant to dApp contract interactions.
Usage and specifics are defined in the
abisubmodule file.
dappconfig
Declared as a public submodule.
Likely contains extended configurations or helper functions for dApp settings beyond the base
DappConfigstruct.Details are encapsulated within the
dappconfigsubmodule file.
Structs
DappConfig
A struct modeling the basic configuration state for a dApp.
Fields
Field | Type | Description |
|---|---|---|
|
| Flag indicating whether the dApp operates without limits (unlimited mode). |
|
| Tracks the available balance for the dApp, supporting very large integer values. |
Traits Derived
Clone— Enables cloning ofDappConfiginstances.Serialize and Deserialize — Allows conversion to/from data formats such as JSON or binary for storage or network transmission.
Debug — Supports formatting for debugging output.
PartialEq— Enables equality comparisons between instances.Default — Provides a default constructor initializing
is_unlimittofalseandavailable_balanceto zero.
Methods
set_is_unlimit
pub fn set_is_unlimit(&mut self, value: bool)
Description: Sets the
is_unlimitflag of theDappConfig.Parameters:
value: Boolean value to assign tois_unlimit.
Returns: Nothing.
Usage Example:
let mut config = DappConfig::default();
config.set_is_unlimit(true);
set_available_balance
pub fn set_available_balance(&mut self, value: i128)
Description: Updates the
available_balancefield.Parameters:
value: A signed 128-bit integer representing the new available balance.
Returns: Nothing.
Usage Example:
let mut config = DappConfig::default();
config.set_available_balance(5000);
Implementation Details
Uses the
serdecrate for serialization and deserialization, facilitating persistence and communication of configuration data.Utilizes Rust's primitive type
i128for representing balances, allowing support for very large numeric values, which is important for financial or token balances in dApps.The struct is designed to be mutable through setter methods that encapsulate direct field manipulation, promoting controlled updates to the configuration state.
Interactions with Other System Components
The
DappConfigstruct likely serves as a foundational configuration object consumed by other parts of the system managing dApp behavior, such as transaction handlers, user interface components, or smart contract interaction layers.The presence of
abianddappconfigsubmodules suggests modularization of ABI-related utilities and additional configuration logic respectively, which build upon or complement the base configuration provided byDappConfig.This file acts as a bridge between raw configuration data and the higher-level logic implemented in its submodules and potentially other parts of the application.
Diagram: Structure of mod.rs
classDiagram
class DappConfig {
+bool is_unlimit
+i128 available_balance
+set_is_unlimit()
+set_available_balance()
}
mod_rs --|> abi
mod_rs --|> dappconfig
mod_rs o-- DappConfig