Skip to content

Commit

Permalink
Final fixes to macro expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
iduartgomez committed Oct 8, 2023
1 parent d3f7258 commit fc93d68
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 3 deletions.
3 changes: 2 additions & 1 deletion rust-macros/src/contract_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ impl ImplTrait {
::freenet_stdlib::prelude::StateSummary<'static>,
::freenet_stdlib::prelude::ContractError,
> {
let mut summary: ::core::option::Option<<#type_name as ::freenet_stdlib::contract_composition::ContractComponent>::Summary> = ::core::option::Option::None;
use ::freenet_stdlib::prelude::Encoder;
let summary = ::freenet_stdlib::contract_composition::from_bytes::inner_summarize_state::<
#type_name,
>(parameters.clone(), state.clone())?;
Expand All @@ -499,6 +499,7 @@ impl ImplTrait {
::freenet_stdlib::prelude::StateDelta<'static>,
::freenet_stdlib::prelude::ContractError,
> {
use ::freenet_stdlib::prelude::Encoder;
let delta = ::freenet_stdlib::contract_composition::from_bytes::inner_state_delta::<
#type_name,
>(parameters.clone(), state.clone(), summary.clone())?;
Expand Down
91 changes: 89 additions & 2 deletions rust/tests/chatroom.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#[cfg(not(feature = "unstable"))]
compile_error!("requires \"unstable\" feature");

use freenet_macros::contract;
use freenet_stdlib::contract_composition::{
ContractComponent, ParametersComponent, SummaryComponent,
};
use freenet_stdlib::typed_contract::BincodeEncoder;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -35,16 +37,40 @@ impl<'x> From<&'x ChatRoom> for dependency_2::PublicKey {
}
}

impl<'x> From<&'x ChatRoom> for String {
fn from(_: &'x ChatRoom) -> Self {
unreachable!()
}
}

#[derive(Serialize, Deserialize)]
pub struct ChatRoomSummary;

impl SummaryComponent<dependency_2::ChildSummary> for ChatRoomSummary {
fn merge(&mut self, _child_summary: dependency_2::ChildSummary) {
todo!()
unreachable!()
}
}

impl SummaryComponent<ChatRoomSummary> for ChatRoomSummary {
fn merge(&mut self, _child_summary: ChatRoomSummary) {
unreachable!()
}
}

impl<'x> From<&'x ChatRoom> for ChatRoomSummary {
fn from(_: &'x ChatRoom) -> Self {
unreachable!()
}
}

// #[contract(children(), encoder = BincodeEncoder)]
#[contract(
children(
Vec<dependency_2::ChatRoomMember>,
Vec<dependency_1::SignedComposable<dependency_2::ChatRoomMessage>>
),
encoder = BincodeEncoder
)]
impl ContractComponent for ChatRoom {
type Context = String;
type Parameters = ChatRoomParameters;
Expand Down Expand Up @@ -140,6 +166,67 @@ pub mod dependency_2 {
pub public_key: PublicKey,
}

#[allow(dead_code)]
impl ContractComponent for ChatRoomMember {
type Context = PublicKey;
type Parameters = ChatRoomMsgParameters;
type Delta = String;
type Summary = String;

fn verify<Child, Ctx>(
&self,
_: &Self::Parameters,
_: &Ctx,
_: &freenet_stdlib::typed_contract::RelatedContractsContainer,
) -> Result<freenet_stdlib::prelude::ValidateResult, freenet_stdlib::prelude::ContractError>
where
Child: ContractComponent,
Self::Context: for<'x> From<&'x Ctx>,
{
unreachable!()
}

fn verify_delta<Child>(
_: &Self::Parameters,
_: &Self::Delta,
) -> Result<bool, freenet_stdlib::prelude::ContractError>
where
Child: ContractComponent,
{
unreachable!()
}

fn merge(
&mut self,
_: &Self::Parameters,
_: &freenet_stdlib::contract_composition::TypedUpdateData<Self>,
_: &freenet_stdlib::typed_contract::RelatedContractsContainer,
) -> freenet_stdlib::typed_contract::MergeResult {
unreachable!()
}

fn summarize<ParentSummary>(
&self,
_: &Self::Parameters,
_: &mut ParentSummary,
) -> Result<(), freenet_stdlib::prelude::ContractError>
where
ParentSummary: freenet_stdlib::contract_composition::SummaryComponent<
<Self as ContractComponent>::Summary,
>,
{
unreachable!()
}

fn delta(
&self,
_: &Self::Parameters,
_: &Self::Summary,
) -> Result<Self::Delta, freenet_stdlib::prelude::ContractError> {
unreachable!()
}
}

#[derive(Serialize, Deserialize)]
pub struct ChatRoomMessage {
pub message: String,
Expand Down

0 comments on commit fc93d68

Please sign in to comment.