Skip to content

Commit

Permalink
Uploading code
Browse files Browse the repository at this point in the history
  • Loading branch information
pmikolajczyk41 committed Aug 18, 2023
1 parent fd4fba5 commit 2f5b017
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion drink/src/contract_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

use frame_support::{sp_runtime::AccountId32, weights::Weight};
use pallet_contracts::{CollectEvents, DebugInfo, Determinism};
use pallet_contracts_primitives::{Code, ContractExecResult, ContractInstantiateResult};
use pallet_contracts_primitives::{
Code, CodeUploadResult, ContractExecResult, ContractInstantiateResult,
};

use crate::{runtime::Runtime, EventRecordOf, Sandbox};

Expand All @@ -18,6 +20,13 @@ pub trait ContractApi<R: Runtime> {
gas_limit: Weight,
) -> ContractInstantiateResult<AccountId32, u128, EventRecordOf<R>>;

/// Interface for `bare_upload_code` contract call.
fn upload_contract(
&mut self,
contract_bytes: Vec<u8>,
origin: AccountId32,
) -> CodeUploadResult<<R as frame_system::Config>::Hash, u128>;

/// Interface for `bare_call` contract call.
fn call_contract(
&mut self,
Expand Down Expand Up @@ -52,6 +61,21 @@ impl<R: Runtime> ContractApi<R> for Sandbox<R> {
})
}

fn upload_contract(
&mut self,
contract_bytes: Vec<u8>,
origin: AccountId32,
) -> CodeUploadResult<<R as frame_system::Config>::Hash, u128> {
self.externalities.execute_with(|| {
pallet_contracts::Pallet::<R>::bare_upload_code(
origin,
contract_bytes,
None,
Determinism::Enforced,
)
})
}

fn call_contract(
&mut self,
address: AccountId32,
Expand Down

0 comments on commit 2f5b017

Please sign in to comment.