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:
The
LicenseContractandLicenseBMContractcontracts, which represent individual licenses.The
BlockKeeperLiblibrary, which provides utility functions for composing state initialization data and calculating license addresses.Modifier contracts (imported from modifiers.sol) for access control and transaction acceptance.
Two root contracts:
_rootElectionand_rootBM, which seem to be external management entities for election and business manager nodes respectively.
Contract: LicenseRoot
State Variables
Variable | Type | Description |
|---|---|---|
| string | Constant indicating the contract version ("1.0.0"). |
| mapping | Maps an 8-bit unsigned integer ID to a |
| uint32 | Timestamp before which license deployment is locked. |
| uint256 | Counter tracking the number of deployed standard licenses. |
| uint256 | Counter tracking the number of deployed business manager licenses. |
| address | Address of the root election contract, used during license deployment. |
| address | Address of the root business manager contract, used during BM license deployment. |
| uint128 | Number of standard licenses left for owner deployment (initially 10,000). |
| 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:
timeUnlock: The unlock timestamp for license deployment.license_number: Initial license count.license_number_bm: Initial BM license count.rootElection: Address of the election root contract.rootBM: Address of the business manager root contract.
Private Methods
ensureBalance()
function ensureBalance() private pure
Ensures the contract holds a minimum balance defined by
ROOT_BALANCE.If the balance is insufficient, it calls
gosh.mintshellq(ROOT_BALANCE)to mint the required tokens.No parameters or return values.
Public Methods
deployLicense(uint256 pubkey)
function deployLicense(uint256 pubkey) public accept
Deploys a new standard license contract for the given public key.
Checks if the current block timestamp is past
_timeUnlock; otherwise, reverts withERR_NOT_READY.Increments
_license_number.Uses
BlockKeeperLib.composeLicenseStateInitto prepare the state initialization data with the license code.Creates a new
LicenseContractwith initialization parameters including the public key, node wallet code, and_rootElection.The deployment requires a predefined fee (
FEE_DEPLOY_LICENSE).Usage example:
licenseRoot.deployLicense(userPubKey);
deployLicenseOwner(uint256 pubkey, bool isPrivileged)
function deployLicenseOwner(uint256 pubkey, bool isPrivileged) public onlyOwner accept
Allows the contract owner to deploy a privileged or standard license.
Requires
_licenseLeftto be at least 1; otherwise, reverts withERR_TOO_LOW_LICENSES.Decrements
_licenseLeft.Increments
_license_number.Similar deployment logic as
deployLicense, but includes theisPrivilegedflag.Usage example:
licenseRoot.deployLicenseOwner(ownerPubKey, true);
deployLicenseBM(uint256 pubkey)
function deployLicenseBM(uint256 pubkey) public accept
Deploys a new business manager license contract.
Checks time unlock as in
deployLicense.Increments
_license_number_bm.Uses
BlockKeeperLib.composeLicenseBMStateInitto prepare state init data.Creates a new
LicenseBMContractwith the public key, BM node wallet code, and_rootBM.Requires a predefined fee (
FEE_DEPLOY_LICENSE_BM).Usage example:
licenseRoot.deployLicenseBM(userPubKey);
deployLicenseBMOwner(uint256 pubkey)
function deployLicenseBMOwner(uint256 pubkey) public onlyOwner accept
Allows the contract owner to deploy a BM license.
Requires
_licenseBMLeftto be at least 1; otherwise, reverts withERR_TOO_LOW_LICENSES.Decrements
_licenseBMLeft.Increments
_license_number_bm.Similar deployment logic to
deployLicenseBM.Usage example:
licenseRoot.deployLicenseBMOwner(ownerPubKey);
setNewCode(uint8 id, TvmCell code)
function setNewCode(uint8 id, TvmCell code) public senderIs(address(this)) accept
Sets or updates the bytecode (
TvmCell) for a given codeid.Can only be called by the contract itself.
Ensures sufficient balance before storing the new code.
This allows upgrading or adding new license contract code versions.
Usage example:
licenseRoot.setNewCode(1, newCodeCell);
Getters
getLastLicenseNum()
function getLastLicenseNum() external view returns(uint256 num, uint256 numbm)
Returns the latest standard license and BM license deployment numbers.
getLicenseAddress(uint256 num)
function getLicenseAddress(uint256 num) external view returns(address license_address)
Calculates the address of a deployed standard license by its number using BlockKeeperLib.calculateLicenseAddress.
getLicenseBMAddress(uint256 num)
function getLicenseBMAddress(uint256 num) external view returns(address license_address)
Calculates the address of a deployed BM license by its number using BlockKeeperLib.calculateLicenseBMAddress.
getVersion()
function getVersion() external pure returns(string, string)
Returns the version string "1.0.0" and the contract name "LicenseRoot".
Fallback/Receive Function
receive() external {}
Allows the contract to receive plain transfer transactions.
Important Implementation Details
License Deployment Control: Deployment of licenses is gated by a timestamp (
_timeUnlock) and minimum contract balance to prevent premature or underfunded deployment.License Counters: Separate tracking of standard and BM license counts ensures unique license identities and proper license management.
Owner Privileges: The owner has a limited quota (
_licenseLeftand_licenseBMLeft) for deploying licenses with special privileges, enforcing controlled issuance.Code Storage: License contract bytecode is stored in the
_codemapping, allowing dynamic updates and modular deployment.Use of
BlockKeeperLib: This library is crucial for composing state initialization data and calculating deterministic contract addresses, ensuring consistent deployment and address resolution.Modifiers and Access Control: The contract uses modifiers such as
accept,onlyOwner, andsenderIs(fromModifierscontract) to enforce access control and proper message acceptance semantics.
Interaction with Other Components
LicenseContract and LicenseBMContract: New license contracts are deployed by this root contract, passing relevant initialization parameters including bytecode and root addresses.
BlockKeeperLib: Used extensively for state init composition and address calculations, indicating a shared library for contract management utilities.
Modifiers: The contract inherits from
Modifiers, which provides method access constraints and message acceptance controls.Root Election and Business Manager Contracts:
_rootElectionand_rootBMaddresses are passed into license deployments, suggesting these contracts manage or interact with deployed licenses.External Bytecode Management: The
_codemapping stores bytecode for licenses and node wallets, enabling modular and upgradeable deployment logic.
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