Enum holochain_types::dht_op::DhtOp
source · pub enum DhtOp {
StoreRecord(Signature, Action, Option<Box<Entry>>),
StoreEntry(Signature, NewEntryAction, Box<Entry>),
RegisterAgentActivity(Signature, Action),
RegisterUpdatedContent(Signature, Update, Option<Box<Entry>>),
RegisterUpdatedRecord(Signature, Update, Option<Box<Entry>>),
RegisterDeletedBy(Signature, Delete),
RegisterDeletedEntryAction(Signature, Delete),
RegisterAddLink(Signature, CreateLink),
RegisterRemoveLink(Signature, DeleteLink),
}
Expand description
A unit of DHT gossip. Used to notify an authority of new (meta)data to hold as well as changes to the status of already held data.
Variants§
StoreRecord(Signature, Action, Option<Box<Entry>>)
Used to notify the authority for an action that it has been created.
Conceptually, authorities receiving this DhtOp
do three things:
- Ensure that the record passes validation.
- Store the action into their DHT shard.
- Store the entry into their CAS.
- Note: they do not become responsible for keeping the set of references from that entry up-to-date.
StoreEntry(Signature, NewEntryAction, Box<Entry>)
Used to notify the authority for an entry that it has been created anew. (The same entry can be created more than once.)
Conceptually, authorities receiving this DhtOp
do four things:
- Ensure that the record passes validation.
- Store the entry into their DHT shard.
- Store the action into their CAS.
- Note: they do not become responsible for keeping the set of references from that action up-to-date.
- Add a “created-by” reference from the entry to the hash of the action.
TODO: document how those “created-by” references are stored in reality.
RegisterAgentActivity(Signature, Action)
Used to notify the authority for an agent’s public key that that agent has committed a new action.
Conceptually, authorities receiving this DhtOp
do three things:
- Ensure that the action alone passes surface-level validation.
- Store the action into their DHT shard.
- FIXME: @artbrock, do they?
- Add an “agent-activity” reference from the public key to the hash of the action.
TODO: document how those “agent-activity” references are stored in reality.
RegisterUpdatedContent(Signature, Update, Option<Box<Entry>>)
Op for updating an entry. This is sent to the entry authority.
RegisterUpdatedRecord(Signature, Update, Option<Box<Entry>>)
Op for updating a record. This is sent to the record authority.
RegisterDeletedBy(Signature, Delete)
Op for registering an action deletion with the Action authority
RegisterDeletedEntryAction(Signature, Delete)
Op for registering an action deletion with the Entry authority, so that the Entry can be marked Dead if all of its Actions have been deleted
RegisterAddLink(Signature, CreateLink)
Op for adding a link
RegisterRemoveLink(Signature, DeleteLink)
Op for removing a link
Implementations§
source§impl DhtOp
impl DhtOp
Mutable access to the Author
sourcepub fn timestamp(&self) -> Timestamp
pub fn timestamp(&self) -> Timestamp
Access to the Timestamp
Examples found in repository?
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
fn timestamp(&self) -> Timestamp {
self.timestamp()
}
fn region_data(&self) -> RegionData {
unimplemented!()
}
fn bound(_timestamp: Timestamp, _loc: kitsune_p2p_dht::Loc) -> Self {
unimplemented!()
}
}
/// A type for storing in databases that don't need the actual
/// data. Everything is a hash of the type except the signatures.
#[allow(missing_docs)]
#[derive(Clone, Debug, Serialize, Deserialize, derive_more::Display)]
pub enum DhtOpLight {
#[display(fmt = "StoreRecord")]
StoreRecord(ActionHash, Option<EntryHash>, OpBasis),
#[display(fmt = "StoreEntry")]
StoreEntry(ActionHash, EntryHash, OpBasis),
#[display(fmt = "RegisterAgentActivity")]
RegisterAgentActivity(ActionHash, OpBasis),
#[display(fmt = "RegisterUpdatedContent")]
RegisterUpdatedContent(ActionHash, EntryHash, OpBasis),
#[display(fmt = "RegisterUpdatedRecord")]
RegisterUpdatedRecord(ActionHash, EntryHash, OpBasis),
#[display(fmt = "RegisterDeletedBy")]
RegisterDeletedBy(ActionHash, OpBasis),
#[display(fmt = "RegisterDeletedEntryAction")]
RegisterDeletedEntryAction(ActionHash, OpBasis),
#[display(fmt = "RegisterAddLink")]
RegisterAddLink(ActionHash, OpBasis),
#[display(fmt = "RegisterRemoveLink")]
RegisterRemoveLink(ActionHash, OpBasis),
}
impl PartialEq for DhtOpLight {
fn eq(&self, other: &Self) -> bool {
// The ops are the same if they are the same type on the same action hash.
// We can't derive eq because `Option<EntryHash>` doesn't make the op different.
// We can ignore the basis because the basis is derived from the action and op type.
self.get_type() == other.get_type() && self.action_hash() == other.action_hash()
}
}
impl Eq for DhtOpLight {}
impl std::hash::Hash for DhtOpLight {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.get_type().hash(state);
self.action_hash().hash(state);
}
}
/// This enum is used to
#[allow(missing_docs)]
#[derive(
Clone,
Copy,
Debug,
Serialize,
Deserialize,
Eq,
PartialEq,
Hash,
derive_more::Display,
strum_macros::EnumString,
)]
pub enum DhtOpType {
#[display(fmt = "StoreRecord")]
StoreRecord,
#[display(fmt = "StoreEntry")]
StoreEntry,
#[display(fmt = "RegisterAgentActivity")]
RegisterAgentActivity,
#[display(fmt = "RegisterUpdatedContent")]
RegisterUpdatedContent,
#[display(fmt = "RegisterUpdatedRecord")]
RegisterUpdatedRecord,
#[display(fmt = "RegisterDeletedBy")]
RegisterDeletedBy,
#[display(fmt = "RegisterDeletedEntryAction")]
RegisterDeletedEntryAction,
#[display(fmt = "RegisterAddLink")]
RegisterAddLink,
#[display(fmt = "RegisterRemoveLink")]
RegisterRemoveLink,
}
impl ToSql for DhtOpType {
fn to_sql(
&self,
) -> holochain_sqlite::rusqlite::Result<holochain_sqlite::rusqlite::types::ToSqlOutput> {
Ok(holochain_sqlite::rusqlite::types::ToSqlOutput::Owned(
format!("{}", self).into(),
))
}
}
impl FromSql for DhtOpType {
fn column_result(
value: holochain_sqlite::rusqlite::types::ValueRef<'_>,
) -> holochain_sqlite::rusqlite::types::FromSqlResult<Self> {
String::column_result(value).and_then(|string| {
DhtOpType::from_str(&string)
.map_err(|_| holochain_sqlite::rusqlite::types::FromSqlError::InvalidType)
})
}
}
impl DhtOp {
fn as_unique_form(&self) -> UniqueForm<'_> {
match self {
Self::StoreRecord(_, action, _) => UniqueForm::StoreRecord(action),
Self::StoreEntry(_, action, _) => UniqueForm::StoreEntry(action),
Self::RegisterAgentActivity(_, action) => UniqueForm::RegisterAgentActivity(action),
Self::RegisterUpdatedContent(_, action, _) => {
UniqueForm::RegisterUpdatedContent(action)
}
Self::RegisterUpdatedRecord(_, action, _) => UniqueForm::RegisterUpdatedRecord(action),
Self::RegisterDeletedBy(_, action) => UniqueForm::RegisterDeletedBy(action),
Self::RegisterDeletedEntryAction(_, action) => {
UniqueForm::RegisterDeletedEntryAction(action)
}
Self::RegisterAddLink(_, action) => UniqueForm::RegisterAddLink(action),
Self::RegisterRemoveLink(_, action) => UniqueForm::RegisterRemoveLink(action),
}
}
/// Returns the basis hash which determines which agents will receive this DhtOp
pub fn dht_basis(&self) -> OpBasis {
self.as_unique_form().basis()
}
/// Convert a [DhtOp] to a [DhtOpLight] and basis
pub fn to_light(
// Hoping one day we can work out how to go from `&Create`
// to `&Action::Create(Create)` so punting on a reference
&self,
) -> DhtOpLight {
let basis = self.dht_basis();
match self {
DhtOp::StoreRecord(_, a, _) => {
let e = a.entry_data().map(|(e, _)| e.clone());
let h = ActionHash::with_data_sync(a);
DhtOpLight::StoreRecord(h, e, basis)
}
DhtOp::StoreEntry(_, a, _) => {
let e = a.entry().clone();
let h = ActionHash::with_data_sync(&Action::from(a.clone()));
DhtOpLight::StoreEntry(h, e, basis)
}
DhtOp::RegisterAgentActivity(_, a) => {
let h = ActionHash::with_data_sync(a);
DhtOpLight::RegisterAgentActivity(h, basis)
}
DhtOp::RegisterUpdatedContent(_, a, _) => {
let e = a.entry_hash.clone();
let h = ActionHash::with_data_sync(&Action::from(a.clone()));
DhtOpLight::RegisterUpdatedContent(h, e, basis)
}
DhtOp::RegisterUpdatedRecord(_, a, _) => {
let e = a.entry_hash.clone();
let h = ActionHash::with_data_sync(&Action::from(a.clone()));
DhtOpLight::RegisterUpdatedRecord(h, e, basis)
}
DhtOp::RegisterDeletedBy(_, a) => {
let h = ActionHash::with_data_sync(&Action::from(a.clone()));
DhtOpLight::RegisterDeletedBy(h, basis)
}
DhtOp::RegisterDeletedEntryAction(_, a) => {
let h = ActionHash::with_data_sync(&Action::from(a.clone()));
DhtOpLight::RegisterDeletedEntryAction(h, basis)
}
DhtOp::RegisterAddLink(_, a) => {
let h = ActionHash::with_data_sync(&Action::from(a.clone()));
DhtOpLight::RegisterAddLink(h, basis)
}
DhtOp::RegisterRemoveLink(_, a) => {
let h = ActionHash::with_data_sync(&Action::from(a.clone()));
DhtOpLight::RegisterRemoveLink(h, basis)
}
}
}
/// Get the signature for this op
pub fn signature(&self) -> &Signature {
match self {
DhtOp::StoreRecord(s, _, _)
| DhtOp::StoreEntry(s, _, _)
| DhtOp::RegisterAgentActivity(s, _)
| DhtOp::RegisterUpdatedContent(s, _, _)
| DhtOp::RegisterUpdatedRecord(s, _, _)
| DhtOp::RegisterDeletedBy(s, _)
| DhtOp::RegisterDeletedEntryAction(s, _)
| DhtOp::RegisterAddLink(s, _)
| DhtOp::RegisterRemoveLink(s, _) => s,
}
}
/// Extract inner Signature, Action and Option<Entry> from an op
pub fn into_inner(self) -> (Signature, Action, Option<Entry>) {
match self {
DhtOp::StoreRecord(s, h, e) => (s, h, e.map(|e| *e)),
DhtOp::StoreEntry(s, h, e) => (s, h.into(), Some(*e)),
DhtOp::RegisterAgentActivity(s, h) => (s, h, None),
DhtOp::RegisterUpdatedContent(s, h, e) => (s, h.into(), e.map(|e| *e)),
DhtOp::RegisterUpdatedRecord(s, h, e) => (s, h.into(), e.map(|e| *e)),
DhtOp::RegisterDeletedBy(s, h) => (s, h.into(), None),
DhtOp::RegisterDeletedEntryAction(s, h) => (s, h.into(), None),
DhtOp::RegisterAddLink(s, h) => (s, h.into(), None),
DhtOp::RegisterRemoveLink(s, h) => (s, h.into(), None),
}
}
/// Get the action from this op
/// This requires cloning and converting the action
/// as some ops don't hold the Action type
pub fn action(&self) -> Action {
match self {
DhtOp::StoreRecord(_, h, _) => h.clone(),
DhtOp::StoreEntry(_, h, _) => h.clone().into(),
DhtOp::RegisterAgentActivity(_, h) => h.clone(),
DhtOp::RegisterUpdatedContent(_, h, _) => h.clone().into(),
DhtOp::RegisterUpdatedRecord(_, h, _) => h.clone().into(),
DhtOp::RegisterDeletedBy(_, h) => h.clone().into(),
DhtOp::RegisterDeletedEntryAction(_, h) => h.clone().into(),
DhtOp::RegisterAddLink(_, h) => h.clone().into(),
DhtOp::RegisterRemoveLink(_, h) => h.clone().into(),
}
}
/// Get the entry from this op, if one exists
pub fn entry(&self) -> Option<&Entry> {
match self {
DhtOp::StoreRecord(_, _, e) => e.as_ref().map(|b| &**b),
DhtOp::StoreEntry(_, _, e) => Some(&*e),
DhtOp::RegisterUpdatedContent(_, _, e) => e.as_ref().map(|b| &**b),
DhtOp::RegisterUpdatedRecord(_, _, e) => e.as_ref().map(|b| &**b),
DhtOp::RegisterAgentActivity(_, _) => None,
DhtOp::RegisterDeletedBy(_, _) => None,
DhtOp::RegisterDeletedEntryAction(_, _) => None,
DhtOp::RegisterAddLink(_, _) => None,
DhtOp::RegisterRemoveLink(_, _) => None,
}
}
/// Get the type as a unit enum, for Display purposes
pub fn get_type(&self) -> DhtOpType {
match self {
DhtOp::StoreRecord(_, _, _) => DhtOpType::StoreRecord,
DhtOp::StoreEntry(_, _, _) => DhtOpType::StoreEntry,
DhtOp::RegisterUpdatedContent(_, _, _) => DhtOpType::RegisterUpdatedContent,
DhtOp::RegisterUpdatedRecord(_, _, _) => DhtOpType::RegisterUpdatedRecord,
DhtOp::RegisterAgentActivity(_, _) => DhtOpType::RegisterAgentActivity,
DhtOp::RegisterDeletedBy(_, _) => DhtOpType::RegisterDeletedBy,
DhtOp::RegisterDeletedEntryAction(_, _) => DhtOpType::RegisterDeletedEntryAction,
DhtOp::RegisterAddLink(_, _) => DhtOpType::RegisterAddLink,
DhtOp::RegisterRemoveLink(_, _) => DhtOpType::RegisterRemoveLink,
}
}
/// From a type, action and an entry (if there is one)
pub fn from_type(
op_type: DhtOpType,
action: SignedAction,
entry: Option<Entry>,
) -> DhtOpResult<Self> {
let SignedAction(action, signature) = action;
let r = match op_type {
DhtOpType::StoreRecord => DhtOp::StoreRecord(signature, action, entry.map(Box::new)),
DhtOpType::StoreEntry => {
let entry = entry.ok_or_else(|| DhtOpError::ActionWithoutEntry(action.clone()))?;
let action = match action {
Action::Create(c) => NewEntryAction::Create(c),
Action::Update(c) => NewEntryAction::Update(c),
_ => return Err(DhtOpError::OpActionMismatch(op_type, action.action_type())),
};
DhtOp::StoreEntry(signature, action, Box::new(entry))
}
DhtOpType::RegisterAgentActivity => DhtOp::RegisterAgentActivity(signature, action),
DhtOpType::RegisterUpdatedContent => {
DhtOp::RegisterUpdatedContent(signature, action.try_into()?, entry.map(Box::new))
}
DhtOpType::RegisterUpdatedRecord => {
DhtOp::RegisterUpdatedRecord(signature, action.try_into()?, entry.map(Box::new))
}
DhtOpType::RegisterDeletedBy => DhtOp::RegisterDeletedBy(signature, action.try_into()?),
DhtOpType::RegisterDeletedEntryAction => {
DhtOp::RegisterDeletedEntryAction(signature, action.try_into()?)
}
DhtOpType::RegisterAddLink => DhtOp::RegisterAddLink(signature, action.try_into()?),
DhtOpType::RegisterRemoveLink => {
DhtOp::RegisterRemoveLink(signature, action.try_into()?)
}
};
Ok(r)
}
fn to_order(&self) -> OpOrder {
OpOrder::new(self.get_type(), self.timestamp())
}
sourcepub fn timestamp_mut(&mut self) -> &mut Timestamp
pub fn timestamp_mut(&mut self) -> &mut Timestamp
Mutable access to the Timestamp
sourcepub fn signature_mut(&mut self) -> &mut Signature
pub fn signature_mut(&mut self) -> &mut Signature
Mutable access to the Signature
sourcepub fn action_seq_mut(&mut self) -> Option<&mut u32>
pub fn action_seq_mut(&mut self) -> Option<&mut u32>
Mutable access to the seq of the Action, if applicable
sourcepub fn action_entry_data_mut(
&mut self
) -> Option<(&mut EntryHash, &mut EntryType)>
pub fn action_entry_data_mut(
&mut self
) -> Option<(&mut EntryHash, &mut EntryType)>
Mutable access to the entry data of the Action, if applicable
Examples found in repository?
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
pub fn valid_dht_op(
keystore: MetaLairClient,
author: AgentPubKey,
must_be_public: bool,
) -> Facts<'static, DhtOp> {
facts![
brute(
"Action type matches Entry existence, and is public if exists",
move |op: &DhtOp| {
let action = op.action();
let h = action.entry_data();
let e = op.entry();
match (h, e) {
(Some((_entry_hash, entry_type)), Some(_e)) => {
// Ensure that entries are public
!must_be_public || entry_type.visibility().is_public()
}
(None, None) => true,
_ => false,
}
}
),
mapped(
"If there is entry data, the action must point to it",
|op: &DhtOp| {
if let Some(entry) = op.entry() {
// NOTE: this could be a `lens` if the previous check were short-circuiting,
// but it is possible that this check will run even if the previous check fails,
// so use a prism instead.
facts![prism(
"action's entry hash",
|op: &mut DhtOp| op.action_entry_data_mut().map(|(hash, _)| hash),
eq("hash of matching entry", EntryHash::with_data_sync(entry)),
)]
} else {
facts![always()]
}
}
),
lens(
"The author is the one specified",
DhtOp::author_mut,
eq_(author)
),
mapped("The Signature matches the Action", move |op: &DhtOp| {
use holochain_keystore::AgentPubKeyExt;
let action = op.action();
let agent = action.author();
let actual = tokio_helper::block_forever_on(agent.sign(&keystore, &action))
.expect("Can sign the action");
facts![lens("signature", DhtOp::signature_mut, eq_(actual))]
})
]
}
source§impl DhtOp
impl DhtOp
sourcepub fn dht_basis(&self) -> OpBasis
pub fn dht_basis(&self) -> OpBasis
Returns the basis hash which determines which agents will receive this DhtOp
Examples found in repository?
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
fn loc(&self) -> Loc {
self.dht_basis().get_loc()
}
fn timestamp(&self) -> Timestamp {
self.timestamp()
}
fn region_data(&self) -> RegionData {
unimplemented!()
}
fn bound(_timestamp: Timestamp, _loc: kitsune_p2p_dht::Loc) -> Self {
unimplemented!()
}
}
/// A type for storing in databases that don't need the actual
/// data. Everything is a hash of the type except the signatures.
#[allow(missing_docs)]
#[derive(Clone, Debug, Serialize, Deserialize, derive_more::Display)]
pub enum DhtOpLight {
#[display(fmt = "StoreRecord")]
StoreRecord(ActionHash, Option<EntryHash>, OpBasis),
#[display(fmt = "StoreEntry")]
StoreEntry(ActionHash, EntryHash, OpBasis),
#[display(fmt = "RegisterAgentActivity")]
RegisterAgentActivity(ActionHash, OpBasis),
#[display(fmt = "RegisterUpdatedContent")]
RegisterUpdatedContent(ActionHash, EntryHash, OpBasis),
#[display(fmt = "RegisterUpdatedRecord")]
RegisterUpdatedRecord(ActionHash, EntryHash, OpBasis),
#[display(fmt = "RegisterDeletedBy")]
RegisterDeletedBy(ActionHash, OpBasis),
#[display(fmt = "RegisterDeletedEntryAction")]
RegisterDeletedEntryAction(ActionHash, OpBasis),
#[display(fmt = "RegisterAddLink")]
RegisterAddLink(ActionHash, OpBasis),
#[display(fmt = "RegisterRemoveLink")]
RegisterRemoveLink(ActionHash, OpBasis),
}
impl PartialEq for DhtOpLight {
fn eq(&self, other: &Self) -> bool {
// The ops are the same if they are the same type on the same action hash.
// We can't derive eq because `Option<EntryHash>` doesn't make the op different.
// We can ignore the basis because the basis is derived from the action and op type.
self.get_type() == other.get_type() && self.action_hash() == other.action_hash()
}
}
impl Eq for DhtOpLight {}
impl std::hash::Hash for DhtOpLight {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.get_type().hash(state);
self.action_hash().hash(state);
}
}
/// This enum is used to
#[allow(missing_docs)]
#[derive(
Clone,
Copy,
Debug,
Serialize,
Deserialize,
Eq,
PartialEq,
Hash,
derive_more::Display,
strum_macros::EnumString,
)]
pub enum DhtOpType {
#[display(fmt = "StoreRecord")]
StoreRecord,
#[display(fmt = "StoreEntry")]
StoreEntry,
#[display(fmt = "RegisterAgentActivity")]
RegisterAgentActivity,
#[display(fmt = "RegisterUpdatedContent")]
RegisterUpdatedContent,
#[display(fmt = "RegisterUpdatedRecord")]
RegisterUpdatedRecord,
#[display(fmt = "RegisterDeletedBy")]
RegisterDeletedBy,
#[display(fmt = "RegisterDeletedEntryAction")]
RegisterDeletedEntryAction,
#[display(fmt = "RegisterAddLink")]
RegisterAddLink,
#[display(fmt = "RegisterRemoveLink")]
RegisterRemoveLink,
}
impl ToSql for DhtOpType {
fn to_sql(
&self,
) -> holochain_sqlite::rusqlite::Result<holochain_sqlite::rusqlite::types::ToSqlOutput> {
Ok(holochain_sqlite::rusqlite::types::ToSqlOutput::Owned(
format!("{}", self).into(),
))
}
}
impl FromSql for DhtOpType {
fn column_result(
value: holochain_sqlite::rusqlite::types::ValueRef<'_>,
) -> holochain_sqlite::rusqlite::types::FromSqlResult<Self> {
String::column_result(value).and_then(|string| {
DhtOpType::from_str(&string)
.map_err(|_| holochain_sqlite::rusqlite::types::FromSqlError::InvalidType)
})
}
}
impl DhtOp {
fn as_unique_form(&self) -> UniqueForm<'_> {
match self {
Self::StoreRecord(_, action, _) => UniqueForm::StoreRecord(action),
Self::StoreEntry(_, action, _) => UniqueForm::StoreEntry(action),
Self::RegisterAgentActivity(_, action) => UniqueForm::RegisterAgentActivity(action),
Self::RegisterUpdatedContent(_, action, _) => {
UniqueForm::RegisterUpdatedContent(action)
}
Self::RegisterUpdatedRecord(_, action, _) => UniqueForm::RegisterUpdatedRecord(action),
Self::RegisterDeletedBy(_, action) => UniqueForm::RegisterDeletedBy(action),
Self::RegisterDeletedEntryAction(_, action) => {
UniqueForm::RegisterDeletedEntryAction(action)
}
Self::RegisterAddLink(_, action) => UniqueForm::RegisterAddLink(action),
Self::RegisterRemoveLink(_, action) => UniqueForm::RegisterRemoveLink(action),
}
}
/// Returns the basis hash which determines which agents will receive this DhtOp
pub fn dht_basis(&self) -> OpBasis {
self.as_unique_form().basis()
}
/// Convert a [DhtOp] to a [DhtOpLight] and basis
pub fn to_light(
// Hoping one day we can work out how to go from `&Create`
// to `&Action::Create(Create)` so punting on a reference
&self,
) -> DhtOpLight {
let basis = self.dht_basis();
match self {
DhtOp::StoreRecord(_, a, _) => {
let e = a.entry_data().map(|(e, _)| e.clone());
let h = ActionHash::with_data_sync(a);
DhtOpLight::StoreRecord(h, e, basis)
}
DhtOp::StoreEntry(_, a, _) => {
let e = a.entry().clone();
let h = ActionHash::with_data_sync(&Action::from(a.clone()));
DhtOpLight::StoreEntry(h, e, basis)
}
DhtOp::RegisterAgentActivity(_, a) => {
let h = ActionHash::with_data_sync(a);
DhtOpLight::RegisterAgentActivity(h, basis)
}
DhtOp::RegisterUpdatedContent(_, a, _) => {
let e = a.entry_hash.clone();
let h = ActionHash::with_data_sync(&Action::from(a.clone()));
DhtOpLight::RegisterUpdatedContent(h, e, basis)
}
DhtOp::RegisterUpdatedRecord(_, a, _) => {
let e = a.entry_hash.clone();
let h = ActionHash::with_data_sync(&Action::from(a.clone()));
DhtOpLight::RegisterUpdatedRecord(h, e, basis)
}
DhtOp::RegisterDeletedBy(_, a) => {
let h = ActionHash::with_data_sync(&Action::from(a.clone()));
DhtOpLight::RegisterDeletedBy(h, basis)
}
DhtOp::RegisterDeletedEntryAction(_, a) => {
let h = ActionHash::with_data_sync(&Action::from(a.clone()));
DhtOpLight::RegisterDeletedEntryAction(h, basis)
}
DhtOp::RegisterAddLink(_, a) => {
let h = ActionHash::with_data_sync(&Action::from(a.clone()));
DhtOpLight::RegisterAddLink(h, basis)
}
DhtOp::RegisterRemoveLink(_, a) => {
let h = ActionHash::with_data_sync(&Action::from(a.clone()));
DhtOpLight::RegisterRemoveLink(h, basis)
}
}
}
sourcepub fn to_light(&self) -> DhtOpLight
pub fn to_light(&self) -> DhtOpLight
Convert a DhtOp to a DhtOpLight and basis
sourcepub fn into_inner(self) -> (Signature, Action, Option<Entry>)
pub fn into_inner(self) -> (Signature, Action, Option<Entry>)
Extract inner Signature, Action and Option
sourcepub fn action(&self) -> Action
pub fn action(&self) -> Action
Get the action from this op This requires cloning and converting the action as some ops don’t hold the Action type
Examples found in repository?
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
pub fn valid_dht_op(
keystore: MetaLairClient,
author: AgentPubKey,
must_be_public: bool,
) -> Facts<'static, DhtOp> {
facts![
brute(
"Action type matches Entry existence, and is public if exists",
move |op: &DhtOp| {
let action = op.action();
let h = action.entry_data();
let e = op.entry();
match (h, e) {
(Some((_entry_hash, entry_type)), Some(_e)) => {
// Ensure that entries are public
!must_be_public || entry_type.visibility().is_public()
}
(None, None) => true,
_ => false,
}
}
),
mapped(
"If there is entry data, the action must point to it",
|op: &DhtOp| {
if let Some(entry) = op.entry() {
// NOTE: this could be a `lens` if the previous check were short-circuiting,
// but it is possible that this check will run even if the previous check fails,
// so use a prism instead.
facts![prism(
"action's entry hash",
|op: &mut DhtOp| op.action_entry_data_mut().map(|(hash, _)| hash),
eq("hash of matching entry", EntryHash::with_data_sync(entry)),
)]
} else {
facts![always()]
}
}
),
lens(
"The author is the one specified",
DhtOp::author_mut,
eq_(author)
),
mapped("The Signature matches the Action", move |op: &DhtOp| {
use holochain_keystore::AgentPubKeyExt;
let action = op.action();
let agent = action.author();
let actual = tokio_helper::block_forever_on(agent.sign(&keystore, &action))
.expect("Can sign the action");
facts![lens("signature", DhtOp::signature_mut, eq_(actual))]
})
]
}
sourcepub fn entry(&self) -> Option<&Entry>
pub fn entry(&self) -> Option<&Entry>
Get the entry from this op, if one exists
Examples found in repository?
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
pub fn enzymatic_countersigning_enzyme(&self) -> Option<&AgentPubKey> {
if let Some(Entry::CounterSign(session_data, _)) = self.entry() {
if session_data.preflight_request().enzymatic {
session_data
.preflight_request()
.signing_agents
.get(0)
.map(|(pubkey, _)| pubkey)
} else {
None
}
} else {
None
}
}
More examples
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
pub fn valid_dht_op(
keystore: MetaLairClient,
author: AgentPubKey,
must_be_public: bool,
) -> Facts<'static, DhtOp> {
facts![
brute(
"Action type matches Entry existence, and is public if exists",
move |op: &DhtOp| {
let action = op.action();
let h = action.entry_data();
let e = op.entry();
match (h, e) {
(Some((_entry_hash, entry_type)), Some(_e)) => {
// Ensure that entries are public
!must_be_public || entry_type.visibility().is_public()
}
(None, None) => true,
_ => false,
}
}
),
mapped(
"If there is entry data, the action must point to it",
|op: &DhtOp| {
if let Some(entry) = op.entry() {
// NOTE: this could be a `lens` if the previous check were short-circuiting,
// but it is possible that this check will run even if the previous check fails,
// so use a prism instead.
facts![prism(
"action's entry hash",
|op: &mut DhtOp| op.action_entry_data_mut().map(|(hash, _)| hash),
eq("hash of matching entry", EntryHash::with_data_sync(entry)),
)]
} else {
facts![always()]
}
}
),
lens(
"The author is the one specified",
DhtOp::author_mut,
eq_(author)
),
mapped("The Signature matches the Action", move |op: &DhtOp| {
use holochain_keystore::AgentPubKeyExt;
let action = op.action();
let agent = action.author();
let actual = tokio_helper::block_forever_on(agent.sign(&keystore, &action))
.expect("Can sign the action");
facts![lens("signature", DhtOp::signature_mut, eq_(actual))]
})
]
}
sourcepub fn from_type(
op_type: DhtOpType,
action: SignedAction,
entry: Option<Entry>
) -> DhtOpResult<Self>
pub fn from_type(
op_type: DhtOpType,
action: SignedAction,
entry: Option<Entry>
) -> DhtOpResult<Self>
From a type, action and an entry (if there is one)
sourcepub fn enzymatic_countersigning_enzyme(&self) -> Option<&AgentPubKey>
pub fn enzymatic_countersigning_enzyme(&self) -> Option<&AgentPubKey>
Enzymatic countersigning session ops need special handling so that they arrive at the enzyme and not elsewhere. If this isn’t an enzymatic countersigning session then the return will be None so can be used as a boolean for filtering with is_some().
Trait Implementations§
source§impl<'arbitrary> Arbitrary<'arbitrary> for DhtOp
impl<'arbitrary> Arbitrary<'arbitrary> for DhtOp
source§fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Self>
Self
from the given unstructured data. Read moresource§fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Self>
fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Self>
Self
from the entirety of the given
unstructured data. Read moresource§impl<'de> Deserialize<'de> for DhtOp
impl<'de> Deserialize<'de> for DhtOp
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl HashableContent for DhtOp
impl HashableContent for DhtOp
source§fn hashable_content(&self) -> HashableContentBytes
fn hashable_content(&self) -> HashableContentBytes
source§impl OpRegion<RegionData> for DhtOp
impl OpRegion<RegionData> for DhtOp
source§fn region_data(&self) -> RegionData
fn region_data(&self) -> RegionData
source§fn bound(_timestamp: Timestamp, _loc: Loc) -> Self
fn bound(_timestamp: Timestamp, _loc: Loc) -> Self
source§fn coords(&self, topo: &Topology) -> SpacetimeQuantumCoords
fn coords(&self, topo: &Topology) -> SpacetimeQuantumCoords
source§impl Ord for DhtOp
impl Ord for DhtOp
source§impl PartialEq<DhtOp> for DhtOp
impl PartialEq<DhtOp> for DhtOp
source§impl PartialOrd<DhtOp> for DhtOp
impl PartialOrd<DhtOp> for DhtOp
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl TryFrom<&DhtOp> for SerializedBytes
impl TryFrom<&DhtOp> for SerializedBytes
§type Error = SerializedBytesError
type Error = SerializedBytesError
source§fn try_from(t: &DhtOp) -> Result<SerializedBytes, SerializedBytesError>
fn try_from(t: &DhtOp) -> Result<SerializedBytes, SerializedBytesError>
source§impl TryFrom<DhtOp> for SerializedBytes
impl TryFrom<DhtOp> for SerializedBytes
§type Error = SerializedBytesError
type Error = SerializedBytesError
source§fn try_from(t: DhtOp) -> Result<SerializedBytes, SerializedBytesError>
fn try_from(t: DhtOp) -> Result<SerializedBytes, SerializedBytesError>
source§impl TryFrom<SerializedBytes> for DhtOp
impl TryFrom<SerializedBytes> for DhtOp
§type Error = SerializedBytesError
type Error = SerializedBytesError
source§fn try_from(sb: SerializedBytes) -> Result<DhtOp, SerializedBytesError>
fn try_from(sb: SerializedBytes) -> Result<DhtOp, SerializedBytesError>
impl Eq for DhtOp
impl StructuralEq for DhtOp
impl StructuralPartialEq for DhtOp
Auto Trait Implementations§
impl RefUnwindSafe for DhtOp
impl Send for DhtOp
impl Sync for DhtOp
impl Unpin for DhtOp
impl UnwindSafe for DhtOp
Blanket Implementations§
§impl<T> Any for Twhere
T: Any + ?Sized,
impl<T> Any for Twhere
T: Any + ?Sized,
§fn type_id_compat(&self) -> TypeId
fn type_id_compat(&self) -> TypeId
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
§impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
§fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T, C> HashableContentExtSync<T> for Cwhere
T: HashTypeSync,
C: HashableContent<HashType = T>,
impl<T, C> HashableContentExtSync<T> for Cwhere
T: HashTypeSync,
C: HashableContent<HashType = T>,
source§fn into_hashed(self) -> HoloHashed<C>
fn into_hashed(self) -> HoloHashed<C>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.