pub fn execute(
session: &mut Session,
tx: &Transaction,
gas_per_deploy_byte: u64,
min_deploy_points: u64,
min_deploy_gas_price: u64,
) -> Result<CallReceipt<Result<Vec<u8>, ContractError>>, Error>Expand description
Executes a transaction in the provided session.
This function processes the transaction, invoking smart contracts or updating state.
During the execution the following steps are performed:
-
Check if the transaction contains contract deployment data, and if so, verifies if gas limit is enough for deployment and if the gas price is sufficient for deployment. If either gas price or gas limit is not sufficient for deployment, transaction is discarded.
-
Call the “spend_and_execute” function on the transfer contract with unlimited gas. If this fails, an error is returned. If an error is returned the transaction should be considered unspendable/invalid, but no re-execution of previous transactions is required.
-
If the transaction contains contract deployment data, additional checks are performed and if they pass, deployment is executed. The following checks are performed:
- gas limit should be is smaller than deploy charge plus gas used for spending funds
- transaction’s bytecode’s bytes are consistent with bytecode’s hash Deployment execution may fail for deployment-specific reasons, such as for example:
- contract already deployed
- corrupted bytecode If deployment execution fails, the entire gas limit is consumed and error is returned.
-
Call the “refund” function on the transfer contract with unlimited gas. The amount charged depends on the gas spent by the transaction, and the optional contract call in steps 2 or 3.
Note that deployment transaction will never be re-executed for reasons related to deployment, as it is either discarded or it charges the full gas limit. It might be re-executed only if some other transaction failed to fit the block.
§Arguments
session- A mutable reference to the session executing the transaction.tx- The transaction to execute.gas_per_deploy_byte- The amount of gas points charged for each byte in a contract-deployment bytecode.min_deploy_points- The minimum gas points charged for a contract deployment.min_deploy_gas_price- The minimum gas price set for a contract deployment
§Returns
A result indicating success or failure.