1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use hdk::prelude::*;

/// Query for an existing Entry in the local source-chain matching the given EntryType name(s).  If
/// one exists, return it Address, otherwise commit it.
pub fn commit_idempotent(value: CreateInput) -> ExternResult<ActionHash> {
    for record in super::local_source_chain()? {
        if let RecordEntry::Present(entry) = record.entry() {
            if entry.clone() == value.entry {
                return Ok(record.action_address().clone());
            }
        }
    }
    let result = create(value)?;
    Ok(result)
}