Skip to content

Commit

Permalink
Undone cancellations
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Oct 19, 2023
1 parent 91d84db commit b622998
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tests/src/cancellation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ test('create and update Cancellation', async () => {
});
});

test('create and delete Cancellation', async () => {
test.only('create and delete Cancellation', async () => {
await runScenario(async scenario => {
const { alice, bob } = await setup(scenario);

Expand Down
2 changes: 1 addition & 1 deletion ui/custom-elements.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"name": "getUndoneCancellationsFor",
"return": {
"type": {
"text": "Promise<Array<ActionHash>>"
"text": "Promise<Array<UndoneCancellation>>"
}
},
"parameters": [
Expand Down
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@holochain-open-dev/cancellations",
"version": "0.1.2",
"version": "0.1.3",
"scripts": {
"start": "vite --clearScreen false --port $UI_PORT",
"build": "npm run lint && tsc && npm run analyze -- --exclude dist",
Expand Down
7 changes: 6 additions & 1 deletion ui/src/cancellations-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ export class CancellationsClient extends ZomeClient<CancellationsSignal> {

getUndoneCancellationsFor(
actionHash: ActionHash
): Promise<Array<ActionHash>> {
): Promise<Array<UndoneCancellation>> {
return this.callZome('get_undone_cancellations_for', actionHash);
}
}

export interface UndoneCancellation {
cancellation_hash: ActionHash;
undo_records: Record[];
}
34 changes: 28 additions & 6 deletions zomes/coordinator/cancellations/src/cancellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub fn update_cancellation(input: UpdateCancellationInput) -> ExternResult<Recor
)?;
Ok(record)
}

#[hdk_extern]
pub fn undo_cancellation(original_cancellation_hash: ActionHash) -> ExternResult<()> {
let record = get_cancellation(original_cancellation_hash.clone())?.ok_or(wasm_error!(
Expand Down Expand Up @@ -105,18 +106,39 @@ pub fn get_cancellations_for(action_hash: ActionHash) -> ExternResult<Vec<Action
Ok(action_hashes)
}

#[derive(Serialize, Deserialize, Debug)]
pub struct UndoneCancellation {
cancellation_hash: ActionHash,
undo_records: Vec<Record>,
}

#[hdk_extern]
pub fn get_undone_cancellations_for(action_hash: ActionHash) -> ExternResult<Vec<ActionHash>> {
pub fn get_undone_cancellations_for(
action_hash: ActionHash,
) -> ExternResult<Vec<UndoneCancellation>> {
let details = get_link_details(action_hash, LinkTypes::Cancellations, None)?;
let action_hashes: Vec<ActionHash> = details
let undone_cancellations: Vec<UndoneCancellation> = details
.into_inner()
.into_iter()
.filter(|(_link, deletes)| deletes.len() > 0)
.filter_map(|(link, _deletes)| match link.hashed.content {
Action::CreateLink(cl) => Some(cl),
.filter_map(|(link, deletes)| match link.hashed.content {
Action::CreateLink(cl) => Some((cl, deletes)),
_ => None,
})
.filter_map(|link| link.target_address.into_action_hash())
.filter_map(|(link, deletes)| {
link.target_address
.into_action_hash()
.map(|cancellation_hash| UndoneCancellation {
cancellation_hash,
undo_records: deletes
.into_iter()
.map(|d| Record {
signed_action: d,
entry: RecordEntry::NA,
})
.collect(),
})
})
.collect();
Ok(action_hashes)
Ok(undone_cancellations)
}

0 comments on commit b622998

Please sign in to comment.