pub mod common;
pub use common::*;
pub mod units;
pub use units::*;
pub mod ledger;
pub use ledger::*;
pub mod entries;
pub use entries::*;
pub mod ext_types;
pub use ext_types::*;
pub mod tags;
pub use tags::*;
pub mod permission_space;
pub use permission_space::PermissionSpace;
use hdk::prelude::*;
use serde::Deserializer;
#[derive(Serialize, Deserialize)]
#[hdk_link_types]
pub enum LinkTypes {
InitAgent,
ProposalNotification, CommitmentNotification, AcceptNotification, RejectNotification,
CodeTemplateToSmartAgreements,
SmartAgreementToRAVEs,
AllCodeTemplates,
AllMyCodeTemplates,
AllMySmartAgreements,
ParkedData,
ParkedSpendCredit,
ParkedSpendBalance,
NameableUnits,
RatedUnitsLinks,
SendExecutorParkedLinkNotification,
SendSpenderParkedInvoiceNotification,
SendReceiverDepositNotification,
SystemAnchor,
LaneDefinition,
GlobalUnits,
PrefixPath,
PathToEA,
PathToCT,
PathToDataBlob,
PathToDocDef,
DocDefToDataBlob,
}
#[derive(Serialize, Debug, Clone)]
pub struct ZomeFnInput<T: Default> {
#[serde(default)]
pub input: T,
#[serde(default, skip_serializing_if = "is_false")]
pub local: bool,
}
impl<'de, T: Default + Deserialize<'de>> Deserialize<'de> for ZomeFnInput<T> {
fn deserialize<D>(deserializer: D) -> Result<Self, <D as Deserializer<'de>>::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
struct Helper<T> {
#[serde(default)]
input: T,
#[serde(default)]
local: bool,
}
let helper = Option::<Helper<T>>::deserialize(deserializer)?;
match helper {
Some(h) => Ok(ZomeFnInput {
input: h.input,
local: h.local,
}),
None => Ok(ZomeFnInput {
input: T::default(),
local: false,
}),
}
}
}
fn is_false(b: &bool) -> bool {
!*b
}
impl<T: Default> ZomeFnInput<T> {
pub fn new(input: T, local: Option<bool>) -> Self {
Self {
input,
local: local.unwrap_or(false),
}
}
pub fn with_local(input: T, local: bool) -> Self {
Self { input, local }
}
pub fn get_strategy(&self) -> GetStrategy {
if self.local {
GetStrategy::Local
} else {
GetStrategy::Network
}
}
}
impl<T: Default> From<ZomeFnInput<T>> for GetStrategy {
fn from(val: ZomeFnInput<T>) -> Self {
if val.local {
GetStrategy::Local
} else {
GetStrategy::Network
}
}
}
impl<T: Default> From<ZomeFnInput<T>> for GetOptions {
fn from(val: ZomeFnInput<T>) -> Self {
if val.local {
GetOptions::local()
} else {
GetOptions::network()
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, SerializedBytes, Default)]
pub enum FolderType {
#[default]
Public,
System,
Lane,
}