Skip to content

Commit

Permalink
Merge pull request #1901 from multiversx/contract-obj-refactor
Browse files Browse the repository at this point in the history
ContractObj wraps UniversalContractObj
  • Loading branch information
andrei-marinica authored Dec 13, 2024
2 parents bef75c5 + 96a414a commit 4bc903f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
20 changes: 7 additions & 13 deletions framework/derive/src/generate/snippets.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
pub fn contract_object_def() -> proc_macro2::TokenStream {
quote! {
pub struct ContractObj<A>
where
A: multiversx_sc::api::VMApi,
{
_phantom: core::marker::PhantomData<A>,
}
pub struct ContractObj<A>(multiversx_sc::contract_base::UniversalContractObj<A>)
where
A: multiversx_sc::api::VMApi;
}
}

Expand All @@ -26,20 +23,17 @@ pub fn new_contract_object_fn() -> proc_macro2::TokenStream {
where
A: multiversx_sc::api::VMApi,
{
ContractObj {
_phantom: core::marker::PhantomData,
}
ContractObj::<A>(multiversx_sc::contract_base::UniversalContractObj::<A>::new())
}

pub struct ContractBuilder;

impl multiversx_sc::contract_base::CallableContractBuilder for self::ContractBuilder {
fn new_contract_obj<A: multiversx_sc::api::VMApi + Send + Sync>(
&self,
) -> multiversx_sc::types::heap::Box<dyn multiversx_sc::contract_base::CallableContract> {
multiversx_sc::types::heap::Box::new(ContractObj::<A> {
_phantom: core::marker::PhantomData,
})
) -> multiversx_sc::types::heap::Box<dyn multiversx_sc::contract_base::CallableContract>
{
multiversx_sc::types::heap::Box::new(self::contract_obj::<A>())
}
}
}
Expand Down
17 changes: 6 additions & 11 deletions framework/scenario/tests/contract_without_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,12 +592,9 @@ mod sample_adder {
/////////////////////////////////////////////////////////////////////////////////////////////////
//////// CONTRACT OBJECT ////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
pub struct ContractObj<A>
pub struct ContractObj<A>(multiversx_sc::contract_base::UniversalContractObj<A>)
where
A: multiversx_sc::api::VMApi,
{
_phantom: core::marker::PhantomData<A>,
}
A: multiversx_sc::api::VMApi;

/////////////////////////////////////////////////////////////////////////////////////////////////
//////// CONTRACT OBJECT as CONTRACT BASE ///////////////////////////////////////////////////////
Expand Down Expand Up @@ -633,19 +630,17 @@ mod sample_adder {
where
A: multiversx_sc::api::VMApi,
{
ContractObj {
_phantom: core::marker::PhantomData,
}
ContractObj::<A>(multiversx_sc::contract_base::UniversalContractObj::<A>::new())
}

pub struct ContractBuilder;

impl multiversx_sc::contract_base::CallableContractBuilder for self::ContractBuilder {
fn new_contract_obj<A: multiversx_sc::api::VMApi + Send + Sync>(
&self,
) -> multiversx_sc::types::heap::Box<dyn multiversx_sc::contract_base::CallableContract>
{
multiversx_sc::types::heap::Box::new(ContractObj::<A> {
_phantom: core::marker::PhantomData,
})
multiversx_sc::types::heap::Box::new(self::contract_obj::<A>())
}
}

Expand Down

0 comments on commit 4bc903f

Please sign in to comment.