multiversx_chain_vm/tx_execution/
exec_create.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use crate::{
    tx_mock::{TxCache, TxInput, TxResult},
    types::{VMAddress, VMCodeMetadata},
    with_shared::Shareable,
    world_mock::BlockchainState,
};

use super::BlockchainVMRef;

impl BlockchainVMRef {
    pub fn sc_create<F>(
        &self,
        tx_input: TxInput,
        contract_path: &[u8],
        code_metadata: VMCodeMetadata,
        state: &mut Shareable<BlockchainState>,
        f: F,
    ) -> (VMAddress, TxResult)
    where
        F: FnOnce(),
    {
        // nonce gets increased irrespective of whether the tx fails or not
        // must be done after computing the new address
        state.increase_account_nonce(&tx_input.from);
        state.subtract_tx_gas(&tx_input.from, tx_input.gas_limit, tx_input.gas_price);

        let (tx_result, new_address, blockchain_updates) = state.with_shared(|state_arc| {
            let tx_cache = TxCache::new(state_arc);

            self.deploy_contract(tx_input, contract_path.to_vec(), code_metadata, tx_cache, f)
        });

        blockchain_updates.apply(state);

        (new_address, tx_result)
    }
}