dappconfig.rs

Overview

The dappconfig.rs file provides utilities and functions for managing and interacting with decentralized application (DApp) configuration data within the context of a blockchain environment. It focuses on encoding, decoding, and handling the state and messages related to DApp configurations, including address calculation, message creation for configuration updates, and extraction of configuration parameters from blockchain account data.

Key functionalities include:


Detailed Explanations

Constants


Functions

get_dapp_config_abi() -> tvm_client::abi::Abi

Returns the ABI (Application Binary Interface) representation of the DApp configuration contract by parsing the JSON ABI string DAPP_CONFIG_ABI.


calculate_dapp_config_address(dapp_id: DAppIdentifier, mut data: StateInit) -> anyhow::Result<UInt256>

Calculates the unique blockchain address of a DApp configuration contract based on the DApp identifier and the contract's initial state.


get_i128_value(value: Int) -> i128

Converts a tvm_abi::Int (which internally uses big integers) into a native Rust i128.


decode_message_config(body: SliceData) -> anyhow::Result<Option<UInt256>>

Decodes a message body slice to extract the DApp identifier from a DApp configuration message.


decode_dapp_config_data(account: &Account) -> anyhow::Result<Option<DappConfig>>

Decodes the storage data from a blockchain account to reconstruct the DappConfig object.


create_config_touch_message(minted: i128, addr: UInt256, block_time: u32) -> anyhow::Result<Message>

Creates an internal blockchain message to update the DApp configuration with a new minted value.


get_available_balance_from_config(config: DappConfig) -> i128

Retrieves the available balance from a given DappConfig, applying special rules for unlimited flags.


Implementation Details and Algorithms


Interaction with Other Parts of the System


Mermaid Diagram: Structure and Key Functions Flow

flowchart TD
A[Start] --> B[get_dapp_config_abi]
B --> C[calculate_dapp_config_address]
C --> D[get_i128_value]
B --> E[decode_message_config]
E --> F[decode_dapp_config_data]
F --> G[get_available_balance_from_config]
B --> H[create_config_touch_message]
style A fill:#f9f,stroke:#333,stroke-width:2px
style B fill:#bbf,stroke:#333,stroke-width:1px
style C fill:#bbf,stroke:#333,stroke-width:1px
style D fill:#bbf,stroke:#333,stroke-width:1px
style E fill:#bbf,stroke:#333,stroke-width:1px
style F fill:#bbf,stroke:#333,stroke-width:1px
style G fill:#bbf,stroke:#333,stroke-width:1px
style H fill:#bbf,stroke:#333,stroke-width:1px

The diagram illustrates the flow from ABI retrieval through address calculation, message decoding, configuration data extraction, balance retrieval, and message creation functions, showing their interrelations.