ZCN S.C.

ZCN Smart Contract Functions

NewZCNSmartContract

Creates a new instance of the ZCN Smart Contract.

goCopy codefunc NewZCNSmartContract() smartcontractinterface.SmartContractInterface {
	var contract = &ZCNSmartContract{
		smartcontractinterface.NewSC(ADDRESS),
		make(map[string]smartContractFunction),
	}

	contract.InitSC()
	contract.setSC(contract.SmartContract, &smartcontract.BCContext{})
	return contract
}

InitSC

Initializes smart contract functions within the ZCN Smart Contract, associating each function with a key.

goCopy codefunc (zcn *ZCNSmartContract) InitSC()

Key Functions

  • Configuration

    • update-global-config: Updates the global configuration of the smart contract.

    • update-authorizer-config: Configures specific authorizers for the smart contract.

  • Bridge-Related

    • mint: Mints new ZCN tokens.

    • burn: Burns ZCN tokens, typically used for cross-chain interactions.

  • Authorizer Management

    • add-authorizer: Adds a new authorizer.

    • delete-authorizer: Removes an existing authorizer.

    • authorizer-health-check: Conducts a health check on an authorizer.

  • Delegate Pools

    • add-to-delegate-pool: Adds tokens to the delegate pool for staking.

    • delete-from-delegate-pool: Removes tokens from the delegate pool.

    • update-authorizer-stake-pool: Updates the stake pool for an authorizer.


Execution Statistics

ZCN Smart Contract records metrics for each major function to track performance:

Function Name
Description

add-authorizer

Tracks time taken to add a new authorizer.

delete-authorizer

Monitors time taken to delete an authorizer.

update-global-config

Tracks time taken to update the global configuration.

update-authorizer-config

Tracks time taken to update an authorizer's configuration.

mint

Measures the time taken for minting tokens.

burn

Measures the time taken for burning tokens.

add-to-delegate-pool

Tracks the time taken to add to the delegate pool.

delete-from-delegate-pool

Tracks the time taken to remove from the delegate pool.


Core Functions

Execute

Executes a specified function within the ZCN Smart Contract based on the provided method name and input data.

Function Signature:

goCopy codefunc (zcn *ZCNSmartContract) Execute(
	trans *transaction.Transaction,
	method string,
	input []byte,
	ctx cstate.StateContextI
) (string, error)

Parameters:

Field
Description

trans

Transaction to be executed.

method

Name of the method to execute within the smart contract.

input

Input data for the method in byte format.

ctx

Blockchain state context interface.

Returns:

  • string - Result of the function execution.

  • error - Error if the execution fails.


Cost Table Retrieval

GetCostTable

Retrieves the cost table for the smart contract, containing configuration costs associated with each operation.

Function Signature:

goCopy codefunc (zcn *ZCNSmartContract) GetCostTable(balances cstate.StateContextI) (map[string]int, error)

Parameters:

Field
Description

balances

Blockchain state context interface used to retrieve global costs.

Returns:

  • map[string]int - A map containing the cost configuration for each function.

  • error - Error if retrieval fails.

Last updated