membrane_invitations/
lib.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use std::collections::BTreeMap;

use hdk::prelude::*;
use private_event_sourcing::*;

#[private_event]
pub enum MembraneInvitationsEvent {
    Invite {
        recipients: BTreeSet<AgentPubKey>,
        role_name_to_clone: RoleName,
        dna_modifiers: DnaModifiers,
        membrane_proof: Option<MembraneProof>,
    },
}

impl PrivateEvent for MembraneInvitationsEvent {
    fn validate(
        &self,
        _event_hash: EntryHash,
        _author: AgentPubKey,
        _timestamp: Timestamp,
    ) -> ExternResult<ValidateCallbackResult> {
        Ok(ValidateCallbackResult::Valid)
    }

    fn recipients(
        &self,
        _event_hash: EntryHash,
        _author: AgentPubKey,
        _timestamp: Timestamp,
    ) -> ExternResult<BTreeSet<AgentPubKey>> {
        match self {
            MembraneInvitationsEvent::Invite { recipients, .. } => Ok(recipients.clone()),
        }
    }
}

#[derive(Serialize, Deserialize, Debug)]
pub struct SendInvitationInput {
    recipients: BTreeSet<AgentPubKey>,
    role_name_to_clone: RoleName,
    dna_modifiers: DnaModifiers,
    membrane_proof: Option<MembraneProof>,
}

#[hdk_extern]
pub fn send_invitation(input: SendInvitationInput) -> ExternResult<EntryHash> {
    create_private_event(MembraneInvitationsEvent::Invite {
        recipients: input.recipients,
        role_name_to_clone: input.role_name_to_clone,
        dna_modifiers: input.dna_modifiers,
        membrane_proof: input.membrane_proof,
    })
}

pub fn query_membrane_invitations_events(
) -> ExternResult<BTreeMap<EntryHashB64, SignedEvent<MembraneInvitationsEvent>>> {
    query_private_events()
}

#[hdk_extern]
pub fn recv_remote_signal(signal_bytes: SerializedBytes) -> ExternResult<()> {
    if let Ok(private_event_sourcing_remote_signal) =
        PrivateEventSourcingRemoteSignal::try_from(signal_bytes)
    {
        recv_private_events_remote_signal::<MembraneInvitationsEvent>(
            private_event_sourcing_remote_signal,
        )
    } else {
        Ok(())
    }
}