pub fn new(
        storage: &mut Storage,
        origin: AccountId,
        code_hash: Hash,
        input_data: Vec<u8>,
        cluster_id: Vec<u8>,
        salt: Vec<u8>,
        block_number: BlockNumber,
        now: u64,
    ) -> Result<(Self, ExecSideEffects), ExecError> {
        if origin == AccountId::new(Default::default()) {
            return Err(ExecError {
                source: DispatchError::BadOrigin,
                message: "Default account is not allowed to create contracts".to_string(),
            });
        }

        let (address, effects) = storage.execute_with(false, move || -> Result<_, ExecError> {
            System::set_block_number(block_number);
            Timestamp::set_timestamp(now);

            let result = Contracts::bare_instantiate(
                origin.clone(),
                0,
                GAS_LIMIT,
                None,
                pallet_contracts_primitives::Code::Existing(code_hash),
                input_data,
                salt.clone(),
                true,
            );
            log::info!("Contract instantiation result: {:?}", &result);
            match result.result {
                Err(err) => {
                    return Err(ExecError {
                        source: err,
                        message: String::from_utf8_lossy(&result.debug_message).to_string(),
                    });
                }
                Ok(rv) => {
                    if rv.result.did_revert() {
                        return Err(ExecError {
                            source: DispatchError::Other("Contract reverted"),
                            message: String::from_utf8_lossy(&result.debug_message).to_string(),
                        });
                    }
                }
            }
            let preimage = contract_id_preimage(
                origin.as_ref(),
                code_hash.as_ref(),
                cluster_id.as_ref(),
                salt.as_ref(),
            );
            Ok(AccountId::from(hashing::blake2_256(&preimage)))
        });
        Ok((Self::from_address(address?), effects))
    }
/// Create a new contract instance.
///
/// # Parameters
///
/// * `origin`: The owner of the created contract instance.
/// * `code_hash`: The hash of contract code which has been uploaded.
/// * `input_data`: The input data to pass to the contract constructor.
/// * `salt`: Used for the address derivation.
Create a new contract instance.
Create a new contract instance .
pub fn new(
        storage: &mut Storage,
        origin: AccountId,
        code_hash: Hash,
        input_data: Vec<u8>,
        cluster_id: Vec<u8>,
        salt: Vec<u8>,
        block_number: BlockNumber,
        now: u64,
    ) -> Result<(Self, ExecSideEffects), ExecError> {
        if origin == AccountId::new(Default::default()) {
            return Err(ExecError {
                source: DispatchError::BadOrigin,
                message: "Default account is not allowed to create contracts".to_string(),
            });
        }
        let (address, effects) = storage.execute_with(false, move || -> Result<_, ExecError> {
            System::set_block_number(block_number);
            Timestamp::set_timestamp(now);
            let result = Contracts::bare_instantiate(
                origin.clone(),
                0,
                GAS_LIMIT,
                None,
                pallet_contracts_primitives::Code::Existing(code_hash),
                input_data,
                salt.clone(),
                true,
            );
            log::info!("Contract instantiation result: {:?}", &result);
            match result.result {
                Err(err) => {
                    return Err(ExecError {
                        source: err,
                        message: String::from_utf8_lossy(&result.debug_message).to_string(),
                    });
                }
                Ok(rv) => {
                    if rv.result.did_revert() {
                        return Err(ExecError {
                            source: DispatchError::Other("Contract reverted"),
                            message: String::from_utf8_lossy(&result.debug_message).to_string(),
                        });
                    }
                }
            }
            let preimage = contract_id_preimage(
                origin.as_ref(),
                code_hash.as_ref(),
                cluster_id.as_ref(),
                salt.as_ref(),
            );
            Ok(AccountId::from(hashing::blake2_256(&preimage)))
        });
        Ok((Self::from_address(address?), effects))
    }
pub fn new ( storage : & mut Storage , origin : AccountId , code_hash : Hash , input_data : Vec < u8 > , cluster_id : Vec < u8 > , salt : Vec < u8 > , block_number : BlockNumber , now : u64 , ) -> Result < ( Self , ExecSideEffects ) , ExecError > { if origin == AccountId :: new ( Default :: default ( ) ) { return Err ( ExecError { source : DispatchError :: BadOrigin , message : " " . to_string ( ) , } ) ; } let ( address , effects ) = storage . execute_with ( false , move | | -> Result < _ , ExecError > { System :: set_block_number ( block_number ) ; Timestamp :: set_timestamp ( now ) ; let result = Contracts :: bare_instantiate ( origin . clone ( ) , 0 , GAS_LIMIT , None , pallet_contracts_primitives :: Code :: Existing ( code_hash ) , input_data , salt . clone ( ) , true , ) ; log :: info ! ( " " result ) ; match result . result { Err ( err ) => { return Err ( ExecError { source : err , message : String :: from_utf8_lossy ( & result . debug_message ) . to_string ( ) , } ) ; } Ok ( rv ) => { if rv . result . did_revert ( ) { return Err ( ExecError { source : DispatchError :: Other ( " " ) , message : String :: from_utf8_lossy ( & result . debug_message ) . to_string ( ) , } ) ; } } } let preimage = contract_id_preimage ( origin . as_ref ( ) , code_hash . as_ref ( ) , cluster_id . as_ref ( ) , salt . as_ref ( ) , ) ; Ok ( AccountId :: from ( hashing :: blake2_256 ( & preimage ) ) ) } ) ; Ok ( ( Self :: from_address ( address ? ) , effects ) ) }
Create a new contract instance.
Create a new contract instance .
storage
&mut Storage
origin
AccountId
code_hash
Hash
input_data
Vec<u8>
cluster_id
Vec<u8>
salt
Vec<u8>
block_number
BlockNumber
now
u64
storage
&mut Storage
origin
AccountId
code_hash
Hash
input_data
Vec<u8>
cluster_id
Vec<u8>
salt
Vec<u8>
block_number
BlockNumber
now
u64