LicenseRoot.sol

Overview

The LicenseRoot.sol contract serves as the central management and deployment hub for license contracts within the system. It is responsible for issuing new licenses (LicenseContract) and business manager licenses (LicenseBMContract), maintaining license counts, and storing the bytecode required for license deployment. It enforces certain conditions such as minimum balance and unlock time before deployment and allows privileged deployment by the contract owner with restricted license quantities.

This contract interacts closely with:

Contract: LicenseRoot

State Variables

Variable

Type

Description

version

string

Constant indicating the contract version ("1.0.0").

_code

mapping

Maps an 8-bit unsigned integer ID to a TvmCell containing contract bytecode used for deployment.

_timeUnlock

uint32

Timestamp before which license deployment is locked.

_license_number

uint256

Counter tracking the number of deployed standard licenses.

_license_number_bm

uint256

Counter tracking the number of deployed business manager licenses.

_rootElection

address

Address of the root election contract, used during license deployment.

_rootBM

address

Address of the root business manager contract, used during BM license deployment.

_licenseLeft

uint128

Number of standard licenses left for owner deployment (initially 10,000).

_licenseBMLeft

uint128

Number of BM licenses left for owner deployment (initially 10,000).

Constructor

constructor (
    uint32 timeUnlock,
    uint256 license_number,
    uint256 license_number_bm,
    address rootElection,
    address rootBM
)

Initializes the contract with:

Private Methods

ensureBalance()

function ensureBalance() private pure

Public Methods

deployLicense(uint256 pubkey)

function deployLicense(uint256 pubkey) public accept
licenseRoot.deployLicense(userPubKey);

deployLicenseOwner(uint256 pubkey, bool isPrivileged)

function deployLicenseOwner(uint256 pubkey, bool isPrivileged) public onlyOwner accept
licenseRoot.deployLicenseOwner(ownerPubKey, true);

deployLicenseBM(uint256 pubkey)

function deployLicenseBM(uint256 pubkey) public accept
licenseRoot.deployLicenseBM(userPubKey);

deployLicenseBMOwner(uint256 pubkey)

function deployLicenseBMOwner(uint256 pubkey) public onlyOwner accept
licenseRoot.deployLicenseBMOwner(ownerPubKey);

setNewCode(uint8 id, TvmCell code)

function setNewCode(uint8 id, TvmCell code) public senderIs(address(this)) accept
licenseRoot.setNewCode(1, newCodeCell);

Getters

function getLastLicenseNum() external view returns(uint256 num, uint256 numbm)

Returns the latest standard license and BM license deployment numbers.

function getLicenseAddress(uint256 num) external view returns(address license_address)

Calculates the address of a deployed standard license by its number using BlockKeeperLib.calculateLicenseAddress.

function getLicenseBMAddress(uint256 num) external view returns(address license_address)

Calculates the address of a deployed BM license by its number using BlockKeeperLib.calculateLicenseBMAddress.

function getVersion() external pure returns(string, string)

Returns the version string "1.0.0" and the contract name "LicenseRoot".

Fallback/Receive Function

receive() external {}

Important Implementation Details

Interaction with Other Components

Visual Diagram

classDiagram
class LicenseRoot {
-string version
-mapping(uint8 => TvmCell) _code
-uint32 _timeUnlock
-uint256 _license_number
-uint256 _license_number_bm
-address _rootElection
-address _rootBM
-uint128 _licenseLeft
-uint128 _licenseBMLeft
+constructor()
-ensureBalance()
+deployLicense()
+deployLicenseOwner()
+deployLicenseBM()
+deployLicenseBMOwner()
+setNewCode()
+getLastLicenseNum()
+getLicenseAddress()
+getLicenseBMAddress()
+getVersion()
+receive()
}
LicenseRoot ..> LicenseContract : deploys
LicenseRoot ..> LicenseBMContract : deploys
LicenseRoot ..> BlockKeeperLib : uses
LicenseRoot ..|> Modifiers