Skip to content

Commit

Permalink
Also emit signal on create cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Oct 17, 2023
1 parent 01963f7 commit b0ad75d
Showing 1 changed file with 55 additions and 8 deletions.
63 changes: 55 additions & 8 deletions zomes/coordinator/cancellations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ pub enum Signal {
action: SignedActionHashed,
link_type: LinkTypes,
},
// EntryCreated {
// action: SignedActionHashed,
// app_entry: EntryTypes,
// },
EntryCreated {
action: SignedActionHashed,
app_entry: EntryTypes,
},
// EntryUpdated {
// action: SignedActionHashed,
// app_entry: EntryTypes,
// original_app_entry: EntryTypes,
// },
// EntryDeleted {
// action: SignedActionHashed,
// original_app_entry: EntryTypes,
// },
EntryDeleted {
action: SignedActionHashed,
original_app_entry: EntryTypes,
},
}
#[hdk_extern(infallible)]
pub fn post_commit(committed_actions: Vec<SignedActionHashed>) {
Expand Down Expand Up @@ -71,6 +71,53 @@ fn signal_action(action: SignedActionHashed) -> ExternResult<()> {
}
}
}
Action::Create(_create) => {
if let Ok(Some(app_entry)) = get_entry_for_action(&action.hashed.hash) {

emit_signal(Signal::EntryCreated { action, app_entry })?;
}
Ok(())
}
Action::Delete(delete) => {
if let Ok(Some(original_app_entry)) = get_entry_for_action(&delete.deletes_address) {
emit_signal(Signal::EntryDeleted {
action,
original_app_entry,
})?;
}
Ok(())
}

_ => Ok(()),
}
}

fn get_entry_for_action(action_hash: &ActionHash) -> ExternResult<Option<EntryTypes>> {
let record = match get_details(action_hash.clone(), GetOptions::default())? {
Some(Details::Record(record_details)) => record_details.record,
_ => {
return Ok(None);
}
};
let entry = match record.entry().as_option() {
Some(entry) => entry,
None => {
return Ok(None);
}
};
let (zome_index, entry_index) = match record.action().entry_type() {
Some(EntryType::App(AppEntryDef {
zome_index,
entry_index,
..
})) => (zome_index, entry_index),
_ => {
return Ok(None);
}
};
Ok(EntryTypes::deserialize_from_type(
zome_index.clone(),
entry_index.clone(),
entry,
)?)
}

0 comments on commit b0ad75d

Please sign in to comment.