abi.rs
Overview
The abi.rs file provides static references to essential contract data used in the system's decentralized application (DApp) configuration and root components. Specifically, it exposes the contract addresses, Application Binary Interfaces (ABIs), and compiled contract code (tvc) as static string or byte slices. These constants enable other parts of the application to interact programmatically with the smart contracts by providing the necessary metadata and bytecode.
Constants
DAPP_ROOT_ADDR
Type:
&strDescription: Contains the address of the root contract for the DApp, loaded from an external file located at ../../../contracts/dappconfig/DappRoot.addr.
Usage: Used as the canonical on-chain address to reference the root contract within the system.
Example:
let root_address = abi::DAPP_ROOT_ADDR; // Use root_address to initialize contract interaction
DAPP_CONFIG_ABI
Type:
&strDescription: Holds the JSON ABI definition of the DappConfig contract, sourced from
../../../contracts/dappconfig/DappConfig.abi.json.Usage: Serves as the schema to encode and decode messages to/from the DappConfig contract.
Example:
let config_abi = abi::DAPP_CONFIG_ABI; // This can be parsed by ABI-handling libraries to interact with DappConfig
DAPP_ROOT_ABI
Type:
&strDescription: Contains the JSON ABI of the DappRoot contract, loaded from
../../../contracts/dappconfig/DappRoot.abi.json.Usage: Used to interpret and construct calls to the root contract.
Example:
let root_abi = abi::DAPP_ROOT_ABI; // Use root_abi for encoding transactions to the root contract
DAPP_CONFIG_TVC
Type:
&[u8](byte slice)Description: The compiled TVC (TON Virtual Code) bytecode of the DappConfig contract, included from
../../../contracts/dappconfig/DappConfig.tvc.Usage: Utilized when deploying the DappConfig contract or verifying contract code.
Example:
let config_tvc: &[u8] = abi::DAPP_CONFIG_TVC; // Use config_tvc as payload during contract deployment
Implementation Details
The file uses Rust's
include_str!andinclude_bytes!macros to embed contract-related external files at compile time. This approach ensures that the contract metadata and code are bundled within the compiled binary, eliminating runtime file I/O and increasing reliability.The embedded files are relative to the source file location, pointing to the contracts directory under
../../../contracts/dappconfig/.DAPP_ROOT_ADDRis a string representing the on-chain address, whileDAPP_CONFIG_TVCis raw bytecode necessary for deployment.This file does not define any functions or complex logic; it serves as a centralized source of contract constants.
Interaction with the System
Other modules that manage contract deployment, invocation, or address resolution import these constants to:
Identify contract addresses (
DAPP_ROOT_ADDR).Parse and encode contract messages using ABIs (
DAPP_CONFIG_ABI,DAPP_ROOT_ABI).Deploy contracts on-chain or verify existing contract bytecode (
DAPP_CONFIG_TVC).
This file acts as a bridge between the on-chain contract artifacts and the off-chain application logic, enabling seamless integration.
It simplifies contract management by centralizing contract metadata, reducing duplication, and minimizing errors caused by mismatched contract data.
File Structure Diagram
flowchart TD
A[abi.rs] --> B[DAPP_ROOT_ADDR]
A --> C[DAPP_CONFIG_ABI]
A --> D[DAPP_ROOT_ABI]
A --> E[DAPP_CONFIG_TVC]
B[Address String]
C[ABI JSON String]
D[ABI JSON String]
E[Bytecode TVC]
This diagram illustrates abi.rs as a container of four static constants: two ABI JSON strings (DAPP_CONFIG_ABI, DAPP_ROOT_ABI), one address string (DAPP_ROOT_ADDR), and one byte slice representing compiled contract code (DAPP_CONFIG_TVC).