commit b645ff39a4f0951cee01554ad9b07aad25dbe93f parent 2d9bf80417d863f4c9aedf7325b22728bf4b51ac Author: triesap <tyson@radroots.org> Date: Sat, 11 Jul 2026 06:36:25 +0000 events: use neutral event envelope naming - rename core event, event-ref, event-pointer, draft, and signed-event APIs to transport-neutral names - rename the event-store private-beta baseline tables and queries to event-envelope terminology - update first-party lib consumers without compatibility aliases or old core reexports - add source-boundary tests for old core event names and old event-store table names Diffstat:
96 files changed, 696 insertions(+), 625 deletions(-)
diff --git a/crates/authority/src/authorization.rs b/crates/authority/src/authorization.rs @@ -3,9 +3,9 @@ use crate::{RadrootsActorContext, RadrootsAuthorityError, RadrootsEventSigner}; use radroots_events::contract::{RadrootsEventContract, event_contract}; #[cfg(test)] -use radroots_events::draft::RadrootsSignedNostrEventParts; +use radroots_events::draft::RadrootsSignedEventParts; use radroots_events::draft::{ - RadrootsDraftError, RadrootsFrozenEventDraft, RadrootsSignedNostrEvent, + RadrootsDraftError, RadrootsEventDraft, RadrootsSignedEvent, validate_signed_nostr_event_matches_draft, }; @@ -30,7 +30,7 @@ pub fn authorize_actor_for_contract( pub fn authorize_actor_for_draft( actor: &RadrootsActorContext, - draft: &RadrootsFrozenEventDraft, + draft: &RadrootsEventDraft, ) -> Result<&'static RadrootsEventContract, RadrootsAuthorityError> { let contract = event_contract(draft.contract_id.as_str()).ok_or_else(|| { RadrootsAuthorityError::UnknownContract { @@ -56,7 +56,7 @@ pub fn authorize_actor_for_draft( pub fn authorize_signer_for_draft<S>( signer: &S, - draft: &RadrootsFrozenEventDraft, + draft: &RadrootsEventDraft, ) -> Result<(), RadrootsAuthorityError> where S: RadrootsEventSigner + ?Sized, @@ -74,8 +74,8 @@ where pub fn sign_authorized_draft<S>( actor: &RadrootsActorContext, signer: &S, - draft: &RadrootsFrozenEventDraft, -) -> Result<RadrootsSignedNostrEvent, RadrootsAuthorityError> + draft: &RadrootsEventDraft, +) -> Result<RadrootsSignedEvent, RadrootsAuthorityError> where S: RadrootsEventSigner + ?Sized, { @@ -87,8 +87,8 @@ where } pub fn validate_signed_event_matches_draft( - signed_event: &RadrootsSignedNostrEvent, - draft: &RadrootsFrozenEventDraft, + signed_event: &RadrootsSignedEvent, + draft: &RadrootsEventDraft, ) -> Result<(), RadrootsAuthorityError> { validate_signed_nostr_event_matches_draft(signed_event, draft) .map_err(authority_error_from_draft_validation) @@ -175,8 +175,8 @@ mod tests { RadrootsActorContext::explicit_pubkey(pubkey, [RadrootsActorRole::Buyer]).expect("buyer") } - fn listing_draft(pubkey: &str) -> RadrootsFrozenEventDraft { - RadrootsFrozenEventDraft::new( + fn listing_draft(pubkey: &str) -> RadrootsEventDraft { + RadrootsEventDraft::new( "radroots.listing.published.v1", KIND_LISTING, 1_700_000_000, @@ -234,9 +234,9 @@ mod tests { fn sign_frozen_draft( &self, - draft: &RadrootsFrozenEventDraft, - ) -> Result<RadrootsSignedNostrEvent, RadrootsSignerError> { - RadrootsSignedNostrEvent::new(RadrootsSignedNostrEventParts { + draft: &RadrootsEventDraft, + ) -> Result<RadrootsSignedEvent, RadrootsSignerError> { + RadrootsSignedEvent::new(RadrootsSignedEventParts { id: self .overrides .event_id @@ -265,8 +265,8 @@ mod tests { } } - fn signed_event_from_draft(draft: &RadrootsFrozenEventDraft) -> RadrootsSignedNostrEvent { - RadrootsSignedNostrEvent::new(RadrootsSignedNostrEventParts { + fn signed_event_from_draft(draft: &RadrootsEventDraft) -> RadrootsSignedEvent { + RadrootsSignedEvent::new(RadrootsSignedEventParts { id: draft.expected_event_id.clone(), pubkey: draft.expected_pubkey.clone(), created_at: draft.created_at, @@ -346,7 +346,7 @@ mod tests { #[test] fn unknown_contract_and_kind_mismatch_fail() { let actor = seller_actor(hex_64('a').as_str()); - let unknown = RadrootsFrozenEventDraft { + let unknown = RadrootsEventDraft { contract_id: "radroots.unknown.v1".to_owned(), contract_registry_version: 1, kind: KIND_LISTING, @@ -361,7 +361,7 @@ mod tests { Err(RadrootsAuthorityError::UnknownContract { .. }) )); - let wrong_kind = RadrootsFrozenEventDraft { + let wrong_kind = RadrootsEventDraft { contract_id: "radroots.listing.published.v1".to_owned(), contract_registry_version: 1, kind: KIND_POST, @@ -500,7 +500,7 @@ mod tests { fn signed_event_pubkey_mismatch_fails() { let pubkey = hex_64('a'); let draft = listing_draft(pubkey.as_str()); - let signed = RadrootsSignedNostrEvent::new(RadrootsSignedNostrEventParts { + let signed = RadrootsSignedEvent::new(RadrootsSignedEventParts { id: draft.expected_event_id.clone(), pubkey: hex_64('b'), created_at: draft.created_at, @@ -533,7 +533,7 @@ mod tests { #[test] fn signed_event_computed_id_mismatch_fails() { let pubkey = hex_64('a'); - let inconsistent_draft = RadrootsFrozenEventDraft { + let inconsistent_draft = RadrootsEventDraft { contract_id: "radroots.listing.published.v1".to_owned(), contract_registry_version: 1, kind: KIND_LISTING, @@ -554,7 +554,7 @@ mod tests { #[test] fn sign_authorized_draft_calls_full_integrity_check() { let pubkey = hex_64('a'); - let inconsistent_draft = RadrootsFrozenEventDraft { + let inconsistent_draft = RadrootsEventDraft { contract_id: "radroots.listing.published.v1".to_owned(), contract_registry_version: 1, kind: KIND_LISTING, @@ -603,7 +603,7 @@ mod tests { #[test] fn order_request_draft_requires_buyer_role() { let pubkey = hex_64('a'); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.order.request.v1", KIND_ORDER_REQUEST, 1_700_000_000, diff --git a/crates/authority/src/local_signer.rs b/crates/authority/src/local_signer.rs @@ -1,7 +1,7 @@ #![forbid(unsafe_code)] use crate::{RadrootsAuthorityError, RadrootsEventSigner, RadrootsSignerError}; -use radroots_events::draft::{RadrootsFrozenEventDraft, RadrootsSignedNostrEvent}; +use radroots_events::draft::{RadrootsEventDraft, RadrootsSignedEvent}; use radroots_events::ids::RadrootsPublicKey; use radroots_nostr::prelude::{RadrootsNostrKeys, radroots_nostr_sign_frozen_draft}; @@ -25,8 +25,8 @@ impl RadrootsEventSigner for RadrootsLocalEventSigner { fn sign_frozen_draft( &self, - draft: &RadrootsFrozenEventDraft, - ) -> Result<RadrootsSignedNostrEvent, RadrootsSignerError> { + draft: &RadrootsEventDraft, + ) -> Result<RadrootsSignedEvent, RadrootsSignerError> { radroots_nostr_sign_frozen_draft(&self.keys, draft).map_err(|error| { RadrootsSignerError::SigningFailed { message: error.to_string(), @@ -38,10 +38,10 @@ impl RadrootsEventSigner for RadrootsLocalEventSigner { #[cfg(test)] mod tests { use super::*; - use radroots_events::RadrootsNostrEvent; + use radroots_events::RadrootsEventEnvelope; use radroots_events::kinds::KIND_POST; use radroots_nostr::prelude::{ - RadrootsNostrEventVerification, RadrootsNostrSecretKey, radroots_nostr_verify_event, + RadrootsEventEnvelopeVerification, RadrootsNostrSecretKey, radroots_nostr_verify_event, }; const FIXTURE_ALICE_SECRET_KEY_HEX: &str = @@ -55,8 +55,8 @@ mod tests { RadrootsNostrKeys::new(secret_key) } - fn post_draft() -> RadrootsFrozenEventDraft { - RadrootsFrozenEventDraft::new( + fn post_draft() -> RadrootsEventDraft { + RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, 1_700_000_000, @@ -67,8 +67,8 @@ mod tests { .expect("draft") } - fn verification_event(signed: &RadrootsSignedNostrEvent) -> RadrootsNostrEvent { - RadrootsNostrEvent { + fn verification_event(signed: &RadrootsSignedEvent) -> RadrootsEventEnvelope { + RadrootsEventEnvelope { id: signed.id.clone(), author: signed.pubkey.clone(), created_at: signed.created_at, @@ -97,7 +97,7 @@ mod tests { assert_eq!(signed.pubkey, draft.expected_pubkey); assert_eq!( radroots_nostr_verify_event(&verification_event(&signed)), - RadrootsNostrEventVerification::Verified + RadrootsEventEnvelopeVerification::Verified ); } } diff --git a/crates/authority/src/signer.rs b/crates/authority/src/signer.rs @@ -2,8 +2,8 @@ use crate::{RadrootsAuthorityError, RadrootsSignerError}; #[cfg(test)] -use radroots_events::draft::RadrootsSignedNostrEventParts; -use radroots_events::draft::{RadrootsFrozenEventDraft, RadrootsSignedNostrEvent}; +use radroots_events::draft::RadrootsSignedEventParts; +use radroots_events::draft::{RadrootsEventDraft, RadrootsSignedEvent}; use radroots_events::ids::RadrootsPublicKey; #[derive(Clone, Debug, PartialEq, Eq)] @@ -28,8 +28,8 @@ pub trait RadrootsEventSigner { fn sign_frozen_draft( &self, - draft: &RadrootsFrozenEventDraft, - ) -> Result<RadrootsSignedNostrEvent, RadrootsSignerError>; + draft: &RadrootsEventDraft, + ) -> Result<RadrootsSignedEvent, RadrootsSignerError>; } #[cfg(test)] @@ -45,8 +45,8 @@ mod tests { std::iter::repeat_n(character, 128).collect() } - fn draft_for(pubkey: &str) -> RadrootsFrozenEventDraft { - RadrootsFrozenEventDraft::new( + fn draft_for(pubkey: &str) -> RadrootsEventDraft { + RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, 1_700_000_000, @@ -85,8 +85,8 @@ mod tests { fn sign_frozen_draft( &self, - draft: &RadrootsFrozenEventDraft, - ) -> Result<RadrootsSignedNostrEvent, RadrootsSignerError> { + draft: &RadrootsEventDraft, + ) -> Result<RadrootsSignedEvent, RadrootsSignerError> { if let Some(failure) = &self.failure { return Err(match failure { RadrootsSignerError::Unavailable => RadrootsSignerError::Unavailable, @@ -98,7 +98,7 @@ mod tests { } }); } - RadrootsSignedNostrEvent::new(RadrootsSignedNostrEventParts { + RadrootsSignedEvent::new(RadrootsSignedEventParts { id: draft.expected_event_id.to_string(), pubkey: self.pubkey.to_string(), created_at: draft.created_at, diff --git a/crates/event_store/README b/crates/event_store/README @@ -1,3 +1,3 @@ # radroots_event_store -SQLx-backed canonical raw Nostr event storage for Rad Roots protocol events. +SQLx-backed canonical event-envelope storage for Rad Roots protocol events. diff --git a/crates/event_store/migrations/0001_event_store.down.sql b/crates/event_store/migrations/0001_event_store.down.sql @@ -2,7 +2,7 @@ DROP TABLE listing_search_fts; DROP TABLE trade_projection; DROP TABLE listing_projection; DROP TABLE projection_cursor; -DROP TABLE nostr_event_head; +DROP TABLE event_envelope_head; DROP TABLE event_transport_observation; -DROP TABLE nostr_event_tags; -DROP TABLE nostr_events; +DROP TABLE event_envelope_tags; +DROP TABLE event_envelopes; diff --git a/crates/event_store/migrations/0001_event_store.up.sql b/crates/event_store/migrations/0001_event_store.up.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS nostr_events ( +CREATE TABLE IF NOT EXISTS event_envelopes ( seq INTEGER PRIMARY KEY AUTOINCREMENT, event_id TEXT NOT NULL UNIQUE, pubkey TEXT NOT NULL, @@ -17,14 +17,14 @@ CREATE TABLE IF NOT EXISTS nostr_events ( updated_at_ms INTEGER NOT NULL ); -CREATE INDEX IF NOT EXISTS nostr_event_kind_created_idx ON nostr_events(kind, created_at, event_id); -CREATE INDEX IF NOT EXISTS nostr_event_contract_idx ON nostr_events(contract_id, seq); -CREATE INDEX IF NOT EXISTS nostr_event_projection_idx ON nostr_events(projection_eligible, seq); -CREATE INDEX IF NOT EXISTS nostr_event_verification_contract_idx -ON nostr_events(verification_status, contract_status, seq); +CREATE INDEX IF NOT EXISTS event_envelope_kind_created_idx ON event_envelopes(kind, created_at, event_id); +CREATE INDEX IF NOT EXISTS event_envelope_contract_idx ON event_envelopes(contract_id, seq); +CREATE INDEX IF NOT EXISTS event_envelope_projection_idx ON event_envelopes(projection_eligible, seq); +CREATE INDEX IF NOT EXISTS event_envelope_verification_contract_idx +ON event_envelopes(verification_status, contract_status, seq); -CREATE TABLE IF NOT EXISTS nostr_event_tags ( - event_id TEXT NOT NULL REFERENCES nostr_events(event_id) ON DELETE CASCADE, +CREATE TABLE IF NOT EXISTS event_envelope_tags ( + event_id TEXT NOT NULL REFERENCES event_envelopes(event_id) ON DELETE CASCADE, tag_index INTEGER NOT NULL, tag_name TEXT NOT NULL, tag_value TEXT, @@ -35,11 +35,11 @@ CREATE TABLE IF NOT EXISTS nostr_event_tags ( PRIMARY KEY (event_id, tag_index) ); -CREATE INDEX IF NOT EXISTS nostr_event_tag_lookup_idx ON nostr_event_tags(tag_name, tag_value, event_id); -CREATE INDEX IF NOT EXISTS nostr_event_tag_relay_idx ON nostr_event_tags(relay_indexed, tag_name, tag_value, event_id); +CREATE INDEX IF NOT EXISTS event_envelope_tag_lookup_idx ON event_envelope_tags(tag_name, tag_value, event_id); +CREATE INDEX IF NOT EXISTS event_envelope_tag_relay_idx ON event_envelope_tags(relay_indexed, tag_name, tag_value, event_id); CREATE TABLE IF NOT EXISTS event_transport_observation ( - event_id TEXT NOT NULL REFERENCES nostr_events(event_id) ON DELETE CASCADE, + event_id TEXT NOT NULL REFERENCES event_envelopes(event_id) ON DELETE CASCADE, transport_kind TEXT NOT NULL, endpoint_uri TEXT NOT NULL, endpoint_fingerprint TEXT NOT NULL, @@ -54,12 +54,12 @@ CREATE TABLE IF NOT EXISTS event_transport_observation ( CREATE INDEX IF NOT EXISTS event_transport_observation_endpoint_idx ON event_transport_observation(transport_kind, endpoint_fingerprint, last_observed_at_ms, event_id); -CREATE TABLE IF NOT EXISTS nostr_event_head ( +CREATE TABLE IF NOT EXISTS event_envelope_head ( coordinate_type TEXT NOT NULL, kind INTEGER NOT NULL, pubkey TEXT NOT NULL, d_tag TEXT, - event_id TEXT NOT NULL REFERENCES nostr_events(event_id) ON DELETE CASCADE, + event_id TEXT NOT NULL REFERENCES event_envelopes(event_id) ON DELETE CASCADE, created_at INTEGER NOT NULL, updated_at_ms INTEGER NOT NULL, CHECK ( @@ -68,15 +68,15 @@ CREATE TABLE IF NOT EXISTS nostr_event_head ( ) ); -CREATE UNIQUE INDEX IF NOT EXISTS nostr_event_head_replaceable_idx -ON nostr_event_head(kind, pubkey) +CREATE UNIQUE INDEX IF NOT EXISTS event_envelope_head_replaceable_idx +ON event_envelope_head(kind, pubkey) WHERE coordinate_type = 'replaceable'; -CREATE UNIQUE INDEX IF NOT EXISTS nostr_event_head_addressable_idx -ON nostr_event_head(kind, pubkey, d_tag) +CREATE UNIQUE INDEX IF NOT EXISTS event_envelope_head_addressable_idx +ON event_envelope_head(kind, pubkey, d_tag) WHERE coordinate_type = 'addressable'; -CREATE INDEX IF NOT EXISTS nostr_event_head_event_idx ON nostr_event_head(event_id); +CREATE INDEX IF NOT EXISTS event_envelope_head_event_idx ON event_envelope_head(event_id); CREATE TABLE IF NOT EXISTS projection_cursor ( projection_id TEXT PRIMARY KEY NOT NULL, @@ -87,7 +87,7 @@ CREATE TABLE IF NOT EXISTS projection_cursor ( CREATE TABLE IF NOT EXISTS listing_projection ( listing_addr TEXT PRIMARY KEY NOT NULL, - listing_event_id TEXT NOT NULL REFERENCES nostr_events(event_id) ON DELETE CASCADE, + listing_event_id TEXT NOT NULL REFERENCES event_envelopes(event_id) ON DELETE CASCADE, seller_pubkey TEXT NOT NULL, farm_pubkey TEXT NOT NULL, farm_d_tag TEXT NOT NULL, @@ -132,7 +132,7 @@ CREATE VIRTUAL TABLE IF NOT EXISTS listing_search_fts USING fts5( CREATE TABLE IF NOT EXISTS trade_projection ( order_id TEXT NOT NULL, - root_event_id TEXT NOT NULL REFERENCES nostr_events(event_id) ON DELETE CASCADE, + root_event_id TEXT NOT NULL REFERENCES event_envelopes(event_id) ON DELETE CASCADE, projection_version INTEGER NOT NULL, status TEXT NOT NULL, lifecycle_terminal INTEGER NOT NULL, @@ -140,15 +140,15 @@ CREATE TABLE IF NOT EXISTS trade_projection ( listing_addr TEXT, buyer_pubkey TEXT, seller_pubkey TEXT, - request_event_id TEXT REFERENCES nostr_events(event_id) ON DELETE SET NULL, - decision_event_id TEXT REFERENCES nostr_events(event_id) ON DELETE SET NULL, - agreement_event_id TEXT REFERENCES nostr_events(event_id) ON DELETE SET NULL, - pending_revision_event_id TEXT REFERENCES nostr_events(event_id) ON DELETE SET NULL, - cancellation_event_id TEXT REFERENCES nostr_events(event_id) ON DELETE SET NULL, - validation_receipt_event_id TEXT REFERENCES nostr_events(event_id) ON DELETE SET NULL, - last_event_id TEXT REFERENCES nostr_events(event_id) ON DELETE SET NULL, + request_event_id TEXT REFERENCES event_envelopes(event_id) ON DELETE SET NULL, + decision_event_id TEXT REFERENCES event_envelopes(event_id) ON DELETE SET NULL, + agreement_event_id TEXT REFERENCES event_envelopes(event_id) ON DELETE SET NULL, + pending_revision_event_id TEXT REFERENCES event_envelopes(event_id) ON DELETE SET NULL, + cancellation_event_id TEXT REFERENCES event_envelopes(event_id) ON DELETE SET NULL, + validation_receipt_event_id TEXT REFERENCES event_envelopes(event_id) ON DELETE SET NULL, + last_event_id TEXT REFERENCES event_envelopes(event_id) ON DELETE SET NULL, expected_listing_event_id TEXT, - current_listing_event_id TEXT REFERENCES nostr_events(event_id) ON DELETE SET NULL, + current_listing_event_id TEXT REFERENCES event_envelopes(event_id) ON DELETE SET NULL, economics_json TEXT, pending_inventory_json TEXT NOT NULL, committed_inventory_json TEXT NOT NULL, diff --git a/crates/event_store/src/model.rs b/crates/event_store/src/model.rs @@ -1,5 +1,5 @@ use crate::RadrootsEventStoreError; -use radroots_events::RadrootsNostrEvent; +use radroots_events::RadrootsEventEnvelope; use radroots_events::contract::{ RadrootsContractMatchError, RadrootsEventClass, RadrootsTagSemantic, RadrootsTagValueType, }; @@ -215,14 +215,14 @@ impl RadrootsTransportObservation { #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsEventIngest { - pub event: RadrootsNostrEvent, + pub event: RadrootsEventEnvelope, pub raw_json: Option<String>, pub observed_at_ms: i64, pub transport_observation: Option<RadrootsTransportObservation>, } impl RadrootsEventIngest { - pub fn new(event: RadrootsNostrEvent, observed_at_ms: i64) -> Self { + pub fn new(event: RadrootsEventEnvelope, observed_at_ms: i64) -> Self { Self { event, raw_json: None, diff --git a/crates/event_store/src/store.rs b/crates/event_store/src/store.rs @@ -7,7 +7,7 @@ use crate::model::{ RadrootsTransportObservation, RadrootsTransportObservationType, StoredEventClass, tag_semantic_name, tag_value_type_name, }; -use radroots_events::RadrootsNostrEvent; +use radroots_events::RadrootsEventEnvelope; use radroots_events::contract::{ RadrootsEventClass, RadrootsEventContract, identify_event_contract, }; @@ -83,7 +83,7 @@ impl RadrootsEventStore { &self, ) -> Result<RadrootsEventStoreStatusSummary, RadrootsEventStoreError> { let row = sqlx::query( - "SELECT COUNT(*) AS total_events, COALESCE(SUM(CASE WHEN projection_eligible = 1 THEN 1 ELSE 0 END), 0) AS projection_eligible_events, MAX(seq) AS last_event_seq, MAX(updated_at_ms) AS last_event_updated_at_ms FROM nostr_events", + "SELECT COUNT(*) AS total_events, COALESCE(SUM(CASE WHEN projection_eligible = 1 THEN 1 ELSE 0 END), 0) AS projection_eligible_events, MAX(seq) AS last_event_seq, MAX(updated_at_ms) AS last_event_updated_at_ms FROM event_envelopes", ) .fetch_one(&self.pool) .await?; @@ -138,7 +138,7 @@ impl RadrootsEventStore { projection_eligible = head.projection_eligible; head_decision = head.decision; sqlx::query( - "UPDATE nostr_events SET projection_eligible = ?, updated_at_ms = ? WHERE event_id = ?", + "UPDATE event_envelopes SET projection_eligible = ?, updated_at_ms = ? WHERE event_id = ?", ) .bind(bool_i64(projection_eligible)) .bind(ingest.observed_at_ms) @@ -179,7 +179,7 @@ impl RadrootsEventStore { event_id: &str, ) -> Result<Option<RadrootsStoredEvent>, RadrootsEventStoreError> { let row = sqlx::query( - "SELECT seq, event_id, pubkey, created_at, kind, tags_json, content, sig, raw_json, verification_status, contract_status, contract_id, event_class, projection_eligible, inserted_at_ms, updated_at_ms FROM nostr_events WHERE event_id = ?", + "SELECT seq, event_id, pubkey, created_at, kind, tags_json, content, sig, raw_json, verification_status, contract_status, contract_id, event_class, projection_eligible, inserted_at_ms, updated_at_ms FROM event_envelopes WHERE event_id = ?", ) .bind(event_id) .fetch_optional(&self.pool) @@ -192,7 +192,7 @@ impl RadrootsEventStore { event_id: &str, ) -> Result<Vec<RadrootsStoredEventTag>, RadrootsEventStoreError> { let rows = sqlx::query( - "SELECT event_id, tag_index, tag_name, tag_value, tag_json, contract_semantic, contract_value_type, relay_indexed FROM nostr_event_tags WHERE event_id = ? ORDER BY tag_index", + "SELECT event_id, tag_index, tag_name, tag_value, tag_json, contract_semantic, contract_value_type, relay_indexed FROM event_envelope_tags WHERE event_id = ? ORDER BY tag_index", ) .bind(event_id) .fetch_all(&self.pool) @@ -242,7 +242,7 @@ impl RadrootsEventStore { let row = match coordinate { RadrootsEventHeadCoordinate::Replaceable { kind, pubkey } => { sqlx::query( - "SELECT coordinate_type, kind, pubkey, d_tag, event_id, created_at, updated_at_ms FROM nostr_event_head WHERE coordinate_type = 'replaceable' AND kind = ? AND pubkey = ? AND d_tag IS NULL", + "SELECT coordinate_type, kind, pubkey, d_tag, event_id, created_at, updated_at_ms FROM event_envelope_head WHERE coordinate_type = 'replaceable' AND kind = ? AND pubkey = ? AND d_tag IS NULL", ) .bind(i64::from(*kind)) .bind(pubkey.as_str()) @@ -255,7 +255,7 @@ impl RadrootsEventStore { d_tag, } => { sqlx::query( - "SELECT coordinate_type, kind, pubkey, d_tag, event_id, created_at, updated_at_ms FROM nostr_event_head WHERE coordinate_type = 'addressable' AND kind = ? AND pubkey = ? AND d_tag = ?", + "SELECT coordinate_type, kind, pubkey, d_tag, event_id, created_at, updated_at_ms FROM event_envelope_head WHERE coordinate_type = 'addressable' AND kind = ? AND pubkey = ? AND d_tag = ?", ) .bind(i64::from(*kind)) .bind(pubkey.as_str()) @@ -307,7 +307,7 @@ impl RadrootsEventStore { .map(|cursor| cursor.last_event_seq) .unwrap_or(0); let rows = sqlx::query( - "SELECT seq, event_id, pubkey, created_at, kind, tags_json, content, sig, raw_json, verification_status, contract_status, contract_id, event_class, projection_eligible, inserted_at_ms, updated_at_ms FROM nostr_events WHERE projection_eligible = 1 AND seq > ? ORDER BY seq ASC LIMIT ?", + "SELECT seq, event_id, pubkey, created_at, kind, tags_json, content, sig, raw_json, verification_status, contract_status, contract_id, event_class, projection_eligible, inserted_at_ms, updated_at_ms FROM event_envelopes WHERE projection_eligible = 1 AND seq > ? ORDER BY seq ASC LIMIT ?", ) .bind(last_event_seq) .bind(i64::from(limit)) @@ -324,7 +324,7 @@ impl RadrootsEventStore { ) -> Result<Vec<RadrootsStoredEvent>, RadrootsEventStoreError> { validate_tag_query(tag_name, limit)?; let rows = sqlx::query( - "SELECT seq, event_id, pubkey, created_at, kind, tags_json, content, sig, raw_json, verification_status, contract_status, contract_id, event_class, projection_eligible, inserted_at_ms, updated_at_ms FROM nostr_events AS event WHERE projection_eligible = 1 AND EXISTS (SELECT 1 FROM nostr_event_tags AS tag WHERE tag.event_id = event.event_id AND tag.tag_name = ? AND tag.tag_value = ?) ORDER BY event.seq ASC LIMIT ?", + "SELECT seq, event_id, pubkey, created_at, kind, tags_json, content, sig, raw_json, verification_status, contract_status, contract_id, event_class, projection_eligible, inserted_at_ms, updated_at_ms FROM event_envelopes AS event WHERE projection_eligible = 1 AND EXISTS (SELECT 1 FROM event_envelope_tags AS tag WHERE tag.event_id = event.event_id AND tag.tag_name = ? AND tag.tag_value = ?) ORDER BY event.seq ASC LIMIT ?", ) .bind(tag_name) .bind(tag_value) @@ -349,7 +349,7 @@ impl RadrootsEventStore { .collect::<Vec<_>>() .join(", "); let sql = format!( - "SELECT seq, event_id, pubkey, created_at, kind, tags_json, content, sig, raw_json, verification_status, contract_status, contract_id, event_class, projection_eligible, inserted_at_ms, updated_at_ms FROM nostr_events AS event WHERE projection_eligible = 1 AND contract_id IN ({placeholders}) AND EXISTS (SELECT 1 FROM nostr_event_tags AS tag WHERE tag.event_id = event.event_id AND tag.tag_name = ? AND tag.tag_value = ?) ORDER BY event.seq ASC LIMIT ?" + "SELECT seq, event_id, pubkey, created_at, kind, tags_json, content, sig, raw_json, verification_status, contract_status, contract_id, event_class, projection_eligible, inserted_at_ms, updated_at_ms FROM event_envelopes AS event WHERE projection_eligible = 1 AND contract_id IN ({placeholders}) AND EXISTS (SELECT 1 FROM event_envelope_tags AS tag WHERE tag.event_id = event.event_id AND tag.tag_name = ? AND tag.tag_value = ?) ORDER BY event.seq ASC LIMIT ?" ); let mut query = sqlx::query(sql.as_str()); for contract_id in contract_ids { @@ -449,14 +449,14 @@ async fn query_string(pool: &SqlitePool, sql: &str) -> Result<String, RadrootsEv Ok(row.try_get(0)?) } -fn validate_event_identity(event: &RadrootsNostrEvent) -> Result<(), RadrootsEventStoreError> { +fn validate_event_identity(event: &RadrootsEventEnvelope) -> Result<(), RadrootsEventStoreError> { RadrootsEventId::parse(event.id.as_str())?; RadrootsPublicKey::parse(event.author.as_str())?; RadrootsEventSignature::parse(event.sig.as_str())?; Ok(()) } -fn classify_event(event: &RadrootsNostrEvent) -> EventClassification { +fn classify_event(event: &RadrootsEventEnvelope) -> EventClassification { match identify_event_contract(event.kind, &event.tags, &event.content) { Ok(contract) => EventClassification { contract_status: RadrootsEventContractStatus::Supported, @@ -469,7 +469,7 @@ fn classify_event(event: &RadrootsNostrEvent) -> EventClassification { } } -fn verify_event(event: &RadrootsNostrEvent) -> RadrootsEventVerificationStatus { +fn verify_event(event: &RadrootsEventEnvelope) -> RadrootsEventVerificationStatus { verification_status_from_nostr(radroots_nostr_verify_event(event)) } @@ -504,7 +504,7 @@ async fn insert_raw_event( .map(|contract| StoredEventClass::from_event_class(contract.class).as_str()); let projection_eligible = classification.base_projection_eligible(verification_status); let result = sqlx::query( - "INSERT OR IGNORE INTO nostr_events(event_id, pubkey, created_at, kind, tags_json, content, sig, raw_json, verification_status, contract_status, contract_id, event_class, projection_eligible, inserted_at_ms, updated_at_ms) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "INSERT OR IGNORE INTO event_envelopes(event_id, pubkey, created_at, kind, tags_json, content, sig, raw_json, verification_status, contract_status, contract_id, event_class, projection_eligible, inserted_at_ms, updated_at_ms) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", ) .bind(event.id.as_str()) .bind(event.author.as_str()) @@ -533,7 +533,7 @@ async fn event_seq( tx: &mut sqlx::Transaction<'_, sqlx::Sqlite>, event_id: &str, ) -> Result<i64, RadrootsEventStoreError> { - let row = sqlx::query("SELECT seq FROM nostr_events WHERE event_id = ?") + let row = sqlx::query("SELECT seq FROM event_envelopes WHERE event_id = ?") .bind(event_id) .fetch_one(&mut **tx) .await?; @@ -543,7 +543,7 @@ async fn event_seq( #[cfg_attr(coverage_nightly, coverage(off))] async fn insert_tags( tx: &mut sqlx::Transaction<'_, sqlx::Sqlite>, - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, contract: Option<&'static RadrootsEventContract>, ) -> Result<(), RadrootsEventStoreError> { for (index, tag) in event.tags.iter().enumerate() { @@ -560,7 +560,7 @@ async fn insert_tags( let contract_value_type = tag_contract.map(|tag| tag_value_type_name(tag.value_type)); let relay_indexed = tag_contract.map(|tag| tag.relay_indexed).unwrap_or(false); sqlx::query( - "INSERT INTO nostr_event_tags(event_id, tag_index, tag_name, tag_value, tag_json, contract_semantic, contract_value_type, relay_indexed) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", + "INSERT INTO event_envelope_tags(event_id, tag_index, tag_name, tag_value, tag_json, contract_semantic, contract_value_type, relay_indexed) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", ) .bind(event.id.as_str()) .bind(i64::try_from(index).map_err(|_| RadrootsEventStoreError::IntegerRange { @@ -603,7 +603,7 @@ async fn upsert_observation( async fn apply_event_head( tx: &mut sqlx::Transaction<'_, sqlx::Sqlite>, - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, contract: &RadrootsEventContract, updated_at_ms: i64, ) -> Result<AppliedHead, RadrootsEventStoreError> { @@ -647,7 +647,7 @@ async fn current_event_head( let row = match coordinate { RadrootsEventHeadCoordinate::Replaceable { kind, pubkey } => { sqlx::query( - "SELECT event_id, created_at FROM nostr_event_head WHERE coordinate_type = 'replaceable' AND kind = ? AND pubkey = ? AND d_tag IS NULL", + "SELECT event_id, created_at FROM event_envelope_head WHERE coordinate_type = 'replaceable' AND kind = ? AND pubkey = ? AND d_tag IS NULL", ) .bind(i64::from(*kind)) .bind(pubkey.as_str()) @@ -660,7 +660,7 @@ async fn current_event_head( d_tag, } => { sqlx::query( - "SELECT event_id, created_at FROM nostr_event_head WHERE coordinate_type = 'addressable' AND kind = ? AND pubkey = ? AND d_tag = ?", + "SELECT event_id, created_at FROM event_envelope_head WHERE coordinate_type = 'addressable' AND kind = ? AND pubkey = ? AND d_tag = ?", ) .bind(i64::from(*kind)) .bind(pubkey.as_str()) @@ -691,14 +691,14 @@ async fn upsert_head( match &head.coordinate { RadrootsEventHeadCoordinate::Replaceable { kind, pubkey } => { sqlx::query( - "DELETE FROM nostr_event_head WHERE coordinate_type = 'replaceable' AND kind = ? AND pubkey = ? AND d_tag IS NULL", + "DELETE FROM event_envelope_head WHERE coordinate_type = 'replaceable' AND kind = ? AND pubkey = ? AND d_tag IS NULL", ) .bind(i64::from(*kind)) .bind(pubkey.as_str()) .execute(&mut **tx) .await?; sqlx::query( - "INSERT INTO nostr_event_head(coordinate_type, kind, pubkey, d_tag, event_id, created_at, updated_at_ms) VALUES ('replaceable', ?, ?, NULL, ?, ?, ?)", + "INSERT INTO event_envelope_head(coordinate_type, kind, pubkey, d_tag, event_id, created_at, updated_at_ms) VALUES ('replaceable', ?, ?, NULL, ?, ?, ?)", ) .bind(i64::from(*kind)) .bind(pubkey.as_str()) @@ -714,7 +714,7 @@ async fn upsert_head( d_tag, } => { sqlx::query( - "DELETE FROM nostr_event_head WHERE coordinate_type = 'addressable' AND kind = ? AND pubkey = ? AND d_tag = ?", + "DELETE FROM event_envelope_head WHERE coordinate_type = 'addressable' AND kind = ? AND pubkey = ? AND d_tag = ?", ) .bind(i64::from(*kind)) .bind(pubkey.as_str()) @@ -722,7 +722,7 @@ async fn upsert_head( .execute(&mut **tx) .await?; sqlx::query( - "INSERT INTO nostr_event_head(coordinate_type, kind, pubkey, d_tag, event_id, created_at, updated_at_ms) VALUES ('addressable', ?, ?, ?, ?, ?, ?)", + "INSERT INTO event_envelope_head(coordinate_type, kind, pubkey, d_tag, event_id, created_at, updated_at_ms) VALUES ('addressable', ?, ?, ?, ?, ?, ?)", ) .bind(i64::from(*kind)) .bind(pubkey.as_str()) @@ -929,7 +929,7 @@ mod tests { created_at: u32, tags: Vec<Vec<String>>, content: &str, - ) -> RadrootsNostrEvent { + ) -> RadrootsEventEnvelope { let raw_event = radroots_nostr_build_event(kind, content, tags) .expect("builder") .custom_created_at(RadrootsNostrTimestamp::from_secs(u64::from(created_at))) @@ -938,7 +938,7 @@ mod tests { radroots_event_from_nostr(&raw_event) } - fn tamper_signature(event: &mut RadrootsNostrEvent) { + fn tamper_signature(event: &mut RadrootsEventEnvelope) { let replacement = if event.sig.starts_with('0') { "1" } else { "0" }; event.sig.replace_range(0..1, replacement); } @@ -947,7 +947,7 @@ mod tests { vec![vec!["d".to_owned(), d_tag.to_owned()]] } - fn head_coordinate_for_event(event: &RadrootsNostrEvent) -> RadrootsEventHeadCoordinate { + fn head_coordinate_for_event(event: &RadrootsEventEnvelope) -> RadrootsEventHeadCoordinate { let RadrootsEventHeadCandidateResult::Candidate(candidate) = event_head_candidate_for_event(event).expect("head candidate") else { @@ -1136,12 +1136,12 @@ mod tests { let store = RadrootsEventStore::open_memory().await.expect("open"); store.migrate_down().await.expect("down"); - let missing = sqlx::query("SELECT COUNT(*) FROM nostr_events") + let missing = sqlx::query("SELECT COUNT(*) FROM event_envelopes") .fetch_one(store.pool()) .await .err() .expect("table should be removed"); - assert!(missing.to_string().contains("nostr_events")); + assert!(missing.to_string().contains("event_envelopes")); } #[tokio::test] diff --git a/crates/event_store/tests/source_boundary.rs b/crates/event_store/tests/source_boundary.rs @@ -0,0 +1,33 @@ +use std::fs; +use std::path::Path; + +#[test] +fn event_store_schema_does_not_reintroduce_old_nostr_table_names() { + let root = Path::new(env!("CARGO_MANIFEST_DIR")); + let source = [ + fs::read_to_string(root.join("src/store.rs")).expect("read store source"), + fs::read_to_string(root.join("migrations/0001_event_store.up.sql")) + .expect("read up migration"), + fs::read_to_string(root.join("migrations/0001_event_store.down.sql")) + .expect("read down migration"), + ] + .join("\n"); + + for forbidden in ["nostr_events", "nostr_event_tags", "nostr_event_head"] { + assert!( + !source.contains(forbidden), + "radroots_event_store baseline must not reintroduce old table name `{forbidden}`" + ); + } + + for required in [ + "event_envelopes", + "event_envelope_tags", + "event_envelope_head", + ] { + assert!( + source.contains(required), + "radroots_event_store baseline must retain neutral table name `{required}`" + ); + } +} diff --git a/crates/events/src/contract.rs b/crates/events/src/contract.rs @@ -4,7 +4,7 @@ use alloc::{borrow::ToOwned, string::String, vec::Vec}; use crate::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, ids::{ RadrootsAddressableCoordinate, RadrootsDTag, RadrootsEventId, RadrootsPublicKey, relay_url_is_valid, @@ -3169,7 +3169,7 @@ pub fn identify_event_contract( } pub fn validate_event_contract( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<&'static RadrootsEventContract, RadrootsContractValidationError> { let contract = match identify_event_contract(event.kind, &event.tags, &event.content) { Ok(contract) => contract, @@ -3180,7 +3180,7 @@ pub fn validate_event_contract( } pub fn validate_event_contract_shape( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, contract_id: &str, ) -> Result<(), RadrootsContractValidationError> { validate_event_contract_parts(event.kind, &event.tags, event.content.as_str(), contract_id) @@ -3727,8 +3727,8 @@ mod tests { } } - fn unsigned_event(kind: u32, tags: Vec<Vec<&str>>, content: &str) -> RadrootsNostrEvent { - RadrootsNostrEvent { + fn unsigned_event(kind: u32, tags: Vec<Vec<&str>>, content: &str) -> RadrootsEventEnvelope { + RadrootsEventEnvelope { id: "0".repeat(64), author: "1".repeat(64), created_at: 1_700_000_000, @@ -3746,8 +3746,8 @@ mod tests { kind: u32, tags: Vec<Vec<String>>, content: &str, - ) -> RadrootsNostrEvent { - RadrootsNostrEvent { + ) -> RadrootsEventEnvelope { + RadrootsEventEnvelope { id: "0".repeat(64), author: "1".repeat(64), created_at: 1_700_000_000, diff --git a/crates/events/src/draft.rs b/crates/events/src/draft.rs @@ -14,7 +14,7 @@ use std::{ vec::Vec, }; -use crate::RadrootsNostrEvent; +use crate::RadrootsEventEnvelope; use crate::contract::{ RADROOTS_EVENT_CONTRACT_REGISTRY_VERSION, RadrootsContractValidationError, event_contract, validate_event_contract_parts, @@ -160,7 +160,7 @@ impl From<serde_json::Error> for RadrootsDraftError { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq, Eq)] -pub struct RadrootsFrozenEventDraft { +pub struct RadrootsEventDraft { pub contract_id: String, pub contract_registry_version: u32, pub kind: u32, @@ -171,7 +171,7 @@ pub struct RadrootsFrozenEventDraft { pub expected_event_id: String, } -impl RadrootsFrozenEventDraft { +impl RadrootsEventDraft { pub fn new( contract_id: impl Into<String>, kind: u32, @@ -228,7 +228,7 @@ impl RadrootsFrozenEventDraft { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq, Eq)] -pub struct RadrootsSignedNostrEventParts { +pub struct RadrootsSignedEventParts { pub id: String, pub pubkey: String, pub created_at: u32, @@ -241,7 +241,7 @@ pub struct RadrootsSignedNostrEventParts { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq, Eq)] -pub struct RadrootsSignedNostrEvent { +pub struct RadrootsSignedEvent { pub id: String, pub pubkey: String, pub created_at: u32, @@ -252,8 +252,8 @@ pub struct RadrootsSignedNostrEvent { pub raw_json: String, } -impl RadrootsSignedNostrEvent { - pub fn new(parts: RadrootsSignedNostrEventParts) -> Result<Self, RadrootsDraftError> { +impl RadrootsSignedEvent { + pub fn new(parts: RadrootsSignedEventParts) -> Result<Self, RadrootsDraftError> { let id = RadrootsEventId::parse(parts.id)?.into_string(); let pubkey = RadrootsPublicKey::parse(parts.pubkey)?.into_string(); let sig = RadrootsEventSignature::parse(parts.sig)?.into_string(); @@ -270,10 +270,10 @@ impl RadrootsSignedNostrEvent { } pub fn from_event( - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, raw_json: impl Into<String>, ) -> Result<Self, RadrootsDraftError> { - Self::new(RadrootsSignedNostrEventParts { + Self::new(RadrootsSignedEventParts { id: event.id, pubkey: event.author, created_at: event.created_at, @@ -287,8 +287,8 @@ impl RadrootsSignedNostrEvent { } pub fn validate_signed_nostr_event_matches_draft( - signed_event: &RadrootsSignedNostrEvent, - draft: &RadrootsFrozenEventDraft, + signed_event: &RadrootsSignedEvent, + draft: &RadrootsEventDraft, ) -> Result<(), RadrootsDraftError> { if signed_event.pubkey.as_str() != draft.expected_pubkey.as_str() { return Err(RadrootsDraftError::SignedEventPubkeyMismatch { @@ -405,8 +405,8 @@ mod tests { core::iter::repeat_n(character, 64).collect() } - fn signed_event_for_draft(draft: &RadrootsFrozenEventDraft) -> RadrootsSignedNostrEvent { - RadrootsSignedNostrEvent::new(RadrootsSignedNostrEventParts { + fn signed_event_for_draft(draft: &RadrootsEventDraft) -> RadrootsSignedEvent { + RadrootsSignedEvent::new(RadrootsSignedEventParts { id: draft.expected_event_id.clone(), pubkey: draft.expected_pubkey.clone(), created_at: draft.created_at, @@ -419,8 +419,8 @@ mod tests { .expect("signed event") } - fn post_draft() -> RadrootsFrozenEventDraft { - RadrootsFrozenEventDraft::new( + fn post_draft() -> RadrootsEventDraft { + RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, 1_700_000_000, @@ -437,7 +437,7 @@ mod tests { #[test] fn frozen_draft_computes_expected_event_id() { - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, 1_700_000_000, @@ -509,12 +509,11 @@ mod tests { #[test] fn draft_constructor_rejects_unknown_contract_and_kind_mismatch() { - let unknown = - RadrootsFrozenEventDraft::new("missing", KIND_POST, 1, Vec::new(), "", hex_64('a')) - .expect_err("unknown contract"); + let unknown = RadrootsEventDraft::new("missing", KIND_POST, 1, Vec::new(), "", hex_64('a')) + .expect_err("unknown contract"); assert!(matches!(unknown, RadrootsDraftError::UnknownContract(_))); - let mismatch = RadrootsFrozenEventDraft::new( + let mismatch = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_PROFILE, 1, @@ -528,7 +527,7 @@ mod tests { RadrootsDraftError::ContractKindMismatch { .. } )); - let invalid_pubkey = RadrootsFrozenEventDraft::new( + let invalid_pubkey = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, 1, @@ -542,7 +541,7 @@ mod tests { #[test] fn draft_constructor_rejects_contract_shape_errors() { - let missing_contract = RadrootsFrozenEventDraft::new( + let missing_contract = RadrootsEventDraft::new( "radroots.knowledge.claim.v1", KIND_KNOWLEDGE_CLAIM, 1, @@ -562,7 +561,7 @@ mod tests { } )); - let invalid_event_pointer = RadrootsFrozenEventDraft::new( + let invalid_event_pointer = RadrootsEventDraft::new( "radroots.knowledge.claim.v1", KIND_KNOWLEDGE_CLAIM, 1, @@ -591,7 +590,7 @@ mod tests { } )); - let invalid_relay = RadrootsFrozenEventDraft::new( + let invalid_relay = RadrootsEventDraft::new( "radroots.knowledge.claim.v1", KIND_KNOWLEDGE_CLAIM, 1, @@ -621,7 +620,7 @@ mod tests { } )); - let invalid_json = RadrootsFrozenEventDraft::new( + let invalid_json = RadrootsEventDraft::new( "radroots.knowledge.claim.v1", KIND_KNOWLEDGE_CLAIM, 1, @@ -644,7 +643,7 @@ mod tests { #[test] fn signed_event_validates_ids_and_roundtrips_with_serde() { - let signed = RadrootsSignedNostrEvent::new(RadrootsSignedNostrEventParts { + let signed = RadrootsSignedEvent::new(RadrootsSignedEventParts { id: hex_64('d'), pubkey: hex_64('e'), created_at: 10, @@ -656,7 +655,7 @@ mod tests { }) .expect("signed event"); let json = serde_json::to_string(&signed).expect("serialize"); - let decoded: RadrootsSignedNostrEvent = serde_json::from_str(&json).expect("deserialize"); + let decoded: RadrootsSignedEvent = serde_json::from_str(&json).expect("deserialize"); assert_eq!(decoded, signed); assert_eq!(decoded.pubkey, hex_64('e')); @@ -664,7 +663,7 @@ mod tests { #[test] fn signed_event_from_nostr_event_validates_parts() { - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: hex_64('1'), author: hex_64('2'), created_at: 42, @@ -673,15 +672,15 @@ mod tests { content: "hello".to_owned(), sig: "3".repeat(128), }; - let signed = RadrootsSignedNostrEvent::from_event(event, "{\"id\":\"fixture\"}") - .expect("signed event"); + let signed = + RadrootsSignedEvent::from_event(event, "{\"id\":\"fixture\"}").expect("signed event"); assert_eq!(signed.id, hex_64('1')); assert_eq!(signed.pubkey, hex_64('2')); assert_eq!(signed.sig, "3".repeat(128)); assert_eq!(signed.raw_json, "{\"id\":\"fixture\"}"); - let invalid = RadrootsSignedNostrEvent::new(RadrootsSignedNostrEventParts { + let invalid = RadrootsSignedEvent::new(RadrootsSignedEventParts { id: "not-hex".to_owned(), pubkey: hex_64('e'), created_at: 10, @@ -694,7 +693,7 @@ mod tests { .expect_err("invalid id"); assert!(matches!(invalid, RadrootsDraftError::IdParse(_))); - let invalid = RadrootsSignedNostrEvent::new(RadrootsSignedNostrEventParts { + let invalid = RadrootsSignedEvent::new(RadrootsSignedEventParts { id: hex_64('d'), pubkey: "not-hex".to_owned(), created_at: 10, @@ -707,7 +706,7 @@ mod tests { .expect_err("invalid pubkey"); assert!(matches!(invalid, RadrootsDraftError::IdParse(_))); - let invalid = RadrootsSignedNostrEvent::new(RadrootsSignedNostrEventParts { + let invalid = RadrootsSignedEvent::new(RadrootsSignedEventParts { id: hex_64('d'), pubkey: hex_64('e'), created_at: 10, diff --git a/crates/events/src/dto.rs b/crates/events/src/dto.rs @@ -19,7 +19,7 @@ mod tests { assert_eq!(registry.roots.len(), dto_roots().len()); let export_names = registry_export_names(®istry); - assert!(export_names.contains("RadrootsNostrEvent")); + assert!(export_names.contains("RadrootsEventEnvelope")); assert!(export_names.contains("RadrootsListingImageSize")); } @@ -34,7 +34,7 @@ mod tests { assert!(summary.nullable); let d_tag = registry - .struct_field_presence("RadrootsNostrEventRef", "d_tag") + .struct_field_presence("RadrootsEventRef", "d_tag") .expect("d_tag field exists"); assert!(!d_tag.required_on_deserialize); assert!(d_tag.nullable); diff --git a/crates/events/src/event_head.rs b/crates/events/src/event_head.rs @@ -3,7 +3,7 @@ #[cfg(not(feature = "std"))] use alloc::{string::String, vec::Vec}; -use crate::RadrootsNostrEvent; +use crate::RadrootsEventEnvelope; use crate::contract::{ RadrootsContractMatchError, RadrootsEventClass, RadrootsEventContract, identify_event_contract, }; @@ -73,7 +73,7 @@ pub enum RadrootsEventHeadDecision { } pub fn event_head_candidate_for_class( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, class: RadrootsEventClass, ) -> RadrootsEventHeadCandidateResult { match class { @@ -131,14 +131,14 @@ pub fn event_head_candidate_for_class( } pub fn event_head_candidate_for_contract( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, contract: &RadrootsEventContract, ) -> RadrootsEventHeadCandidateResult { event_head_candidate_for_class(event, contract.class) } pub fn event_head_candidate_for_event( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsEventHeadCandidateResult, RadrootsContractMatchError> { let contract = identify_event_contract(event.kind, &event.tags, &event.content)?; Ok(event_head_candidate_for_contract(event, contract)) @@ -195,8 +195,8 @@ mod tests { author: &str, created_at: u32, tags: Vec<Vec<String>>, - ) -> RadrootsNostrEvent { - RadrootsNostrEvent { + ) -> RadrootsEventEnvelope { + RadrootsEventEnvelope { id: id.to_string(), author: author.to_string(), created_at, @@ -214,7 +214,7 @@ mod tests { created_at: u32, tags: Vec<Vec<String>>, content: &str, - ) -> RadrootsNostrEvent { + ) -> RadrootsEventEnvelope { let mut event = event(kind, id, author, created_at, tags); event.content = content.to_string(); event diff --git a/crates/events/src/generated/dto_roots.rs b/crates/events/src/generated/dto_roots.rs @@ -3,9 +3,9 @@ pub fn dto_bindgen_roots() -> ::std::vec::Vec<::dto_bindgen::export::RootDescriptor> { ::std::vec![ - ::dto_bindgen::export::RootDescriptor::new::<crate::RadrootsNostrEvent>(), - ::dto_bindgen::export::RootDescriptor::new::<crate::RadrootsNostrEventPtr>(), - ::dto_bindgen::export::RootDescriptor::new::<crate::RadrootsNostrEventRef>(), + ::dto_bindgen::export::RootDescriptor::new::<crate::RadrootsEventEnvelope>(), + ::dto_bindgen::export::RootDescriptor::new::<crate::RadrootsEventPtr>(), + ::dto_bindgen::export::RootDescriptor::new::<crate::RadrootsEventRef>(), ::dto_bindgen::export::RootDescriptor::new::<crate::account::RadrootsAccountClaim>(), ::dto_bindgen::export::RootDescriptor::new::<crate::app_data::RadrootsAppData>(), ::dto_bindgen::export::RootDescriptor::new::<crate::comment::RadrootsComment>(), diff --git a/crates/events/src/ids.rs b/crates/events/src/ids.rs @@ -204,12 +204,12 @@ impl RadrootsAddressableCoordinateParts { } #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct RadrootsNostrEventPointer { +pub struct RadrootsEventEnvelopePointer { pub event_id: RadrootsEventId, pub relays: Vec<String>, } -impl RadrootsNostrEventPointer { +impl RadrootsEventEnvelopePointer { pub fn new<I, S>(event_id: RadrootsEventId, relays: I) -> Result<Self, RadrootsIdParseError> where I: IntoIterator<Item = S>, @@ -629,7 +629,7 @@ mod tests { #[test] fn nostr_event_pointers_validate_relay_values() { let event_id = RadrootsEventId::parse(hex_64('e')).expect("event id"); - let pointer = RadrootsNostrEventPointer::new( + let pointer = RadrootsEventEnvelopePointer::new( event_id.clone(), ["wss://relay.one.example", "wss://relay.two.example"], ) @@ -645,7 +645,7 @@ mod tests { ); assert_eq!( - RadrootsNostrEventPointer::new( + RadrootsEventEnvelopePointer::new( RadrootsEventId::parse(hex_64('e')).expect("event id"), [""], ) @@ -653,7 +653,7 @@ mod tests { RadrootsIdParseError::Empty ); assert_eq!( - RadrootsNostrEventPointer::new( + RadrootsEventEnvelopePointer::new( RadrootsEventId::parse(hex_64('e')).expect("event id"), ["http://relay.example"], ) @@ -661,7 +661,7 @@ mod tests { RadrootsIdParseError::InvalidFormat ); assert_eq!( - RadrootsNostrEventPointer::new( + RadrootsEventEnvelopePointer::new( RadrootsEventId::parse(hex_64('e')).expect("event id"), [" wss://relay.example"], ) @@ -669,7 +669,7 @@ mod tests { RadrootsIdParseError::InvalidCharacter ); assert_eq!( - RadrootsNostrEventPointer::new( + RadrootsEventEnvelopePointer::new( RadrootsEventId::parse(hex_64('e')).expect("event id"), ["wss://relay.example\n"], ) diff --git a/crates/events/src/job_feedback.rs b/crates/events/src/job_feedback.rs @@ -1,5 +1,5 @@ use crate::{ - RadrootsNostrEventPtr, + RadrootsEventPtr, job::{JobFeedbackStatus, JobPaymentRequest}, }; @@ -14,7 +14,7 @@ pub struct RadrootsJobFeedback { pub kind: u16, pub status: JobFeedbackStatus, pub extra_info: Option<String>, - pub request_event: RadrootsNostrEventPtr, + pub request_event: RadrootsEventPtr, pub customer_pubkey: Option<String>, pub payment: Option<JobPaymentRequest>, pub content: Option<String>, diff --git a/crates/events/src/job_result.rs b/crates/events/src/job_result.rs @@ -1,4 +1,4 @@ -use crate::{RadrootsNostrEventPtr, job::JobPaymentRequest, job_request::RadrootsJobInput}; +use crate::{RadrootsEventPtr, job::JobPaymentRequest, job_request::RadrootsJobInput}; #[cfg(not(feature = "std"))] use alloc::{string::String, vec::Vec}; @@ -9,7 +9,7 @@ use alloc::{string::String, vec::Vec}; #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsJobResult { pub kind: u16, - pub request_event: RadrootsNostrEventPtr, + pub request_event: RadrootsEventPtr, pub request_json: Option<String>, pub inputs: Vec<RadrootsJobInput>, pub customer_pubkey: Option<String>, diff --git a/crates/events/src/knowledge.rs b/crates/events/src/knowledge.rs @@ -5,7 +5,7 @@ use alloc::{string::String, vec::Vec}; use core::fmt; -use crate::RadrootsNostrEventRef; +use crate::RadrootsEventRef; use crate::ids::{ RadrootsAddressableCoordinate, RadrootsDTag, RadrootsEventId, RadrootsPublicKey, RadrootsRelayUrl, @@ -203,7 +203,7 @@ fn validate_relays( } fn validate_event_ref( - event_ref: &RadrootsNostrEventRef, + event_ref: &RadrootsEventRef, field: &'static str, ) -> Result<(), RadrootsKnowledgeValidationError> { validate_event_id(&event_ref.id, field)?; @@ -220,7 +220,7 @@ fn validate_event_ref( } fn validate_event_refs( - refs: &[RadrootsNostrEventRef], + refs: &[RadrootsEventRef], field: &'static str, ) -> Result<(), RadrootsKnowledgeValidationError> { for event_ref in refs { @@ -556,7 +556,7 @@ pub struct RadrootsWikiArticle { pub content_djot: String, pub summary: Option<String>, pub topics: Vec<String>, - pub references: Vec<RadrootsNostrEventRef>, + pub references: Vec<RadrootsEventRef>, pub forked_from: Vec<RadrootsWikiArticleVersionRef>, pub deferred_to: Option<RadrootsWikiArticleVersionRef>, } @@ -606,7 +606,7 @@ pub struct RadrootsKnowledgeSource { pub publication_year: Option<u16>, pub edition: Option<String>, pub canonical_url: Option<String>, - pub artifact_refs: Vec<RadrootsNostrEventRef>, + pub artifact_refs: Vec<RadrootsEventRef>, pub author_asserted_rights: Option<RadrootsRightsAssertion>, pub topics: Vec<String>, pub summary: Option<String>, @@ -625,7 +625,7 @@ pub struct RadrootsKnowledgeClaim { pub topics: Vec<String>, pub applies_to: Vec<String>, pub author_asserted_confidence: Option<String>, - pub supersedes: Vec<RadrootsNostrEventRef>, + pub supersedes: Vec<RadrootsEventRef>, } #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -633,8 +633,8 @@ pub struct RadrootsKnowledgeClaim { #[cfg_attr(feature = "dto-bindgen", dto(export))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsKnowledgeCitationSpan { - pub source_ref: RadrootsNostrEventRef, - pub artifact_ref: Option<RadrootsNostrEventRef>, + pub source_ref: RadrootsEventRef, + pub artifact_ref: Option<RadrootsEventRef>, pub page_start: Option<u32>, pub page_end: Option<u32>, pub section_path: Vec<String>, @@ -648,7 +648,7 @@ pub struct RadrootsKnowledgeCitationSpan { #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsKnowledgeNodeRef { pub node_type: String, - pub event_ref: Option<RadrootsNostrEventRef>, + pub event_ref: Option<RadrootsEventRef>, pub address_ref: Option<RadrootsAddressableRef>, pub external_id: Option<String>, pub label: Option<String>, @@ -664,9 +664,9 @@ pub struct RadrootsKnowledgeRelation { pub subject: RadrootsKnowledgeNodeRef, pub predicate: String, pub object: RadrootsKnowledgeNodeRef, - pub support_refs: Vec<RadrootsNostrEventRef>, + pub support_refs: Vec<RadrootsEventRef>, pub author_asserted_confidence: Option<String>, - pub supersedes: Vec<RadrootsNostrEventRef>, + pub supersedes: Vec<RadrootsEventRef>, } #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -681,7 +681,7 @@ pub struct RadrootsKnowledgeReview { pub verdict: String, pub scores: Vec<RadrootsKnowledgeReviewScore>, pub notes: Option<String>, - pub evidence_refs: Vec<RadrootsNostrEventRef>, + pub evidence_refs: Vec<RadrootsEventRef>, } #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -730,8 +730,8 @@ pub struct RadrootsKnowledgeFieldReport { pub summary: Option<String>, pub context: RadrootsKnowledgeFieldContext, pub observations: Vec<RadrootsKnowledgeObservation>, - pub artifact_refs: Vec<RadrootsNostrEventRef>, - pub related_refs: Vec<RadrootsNostrEventRef>, + pub artifact_refs: Vec<RadrootsEventRef>, + pub related_refs: Vec<RadrootsEventRef>, pub limitations: Vec<String>, } @@ -742,7 +742,7 @@ pub struct RadrootsKnowledgeFieldReport { pub struct RadrootsKnowledgeFieldContext { pub location_precision: RadrootsKnowledgeLocationPrecision, pub public_location: Option<RadrootsKnowledgeLocation>, - pub private_location_ref: Option<RadrootsNostrEventRef>, + pub private_location_ref: Option<RadrootsEventRef>, pub topics: Vec<String>, pub context_tags: Vec<String>, } @@ -804,7 +804,7 @@ pub struct RadrootsEvidenceBounty { pub title: String, pub summary: Option<String>, pub topics: Vec<String>, - pub target_refs: Vec<RadrootsNostrEventRef>, + pub target_refs: Vec<RadrootsEventRef>, pub reward_note: Option<String>, pub closes_at: Option<String>, } @@ -816,12 +816,12 @@ pub struct RadrootsEvidenceBounty { pub struct RadrootsKnowledgeChangeProposal { pub schema: String, pub schema_version: u16, - pub target: RadrootsNostrEventRef, + pub target: RadrootsEventRef, pub proposal_type: String, pub summary: String, pub rationale: Option<String>, - pub evidence_refs: Vec<RadrootsNostrEventRef>, - pub supersedes: Vec<RadrootsNostrEventRef>, + pub evidence_refs: Vec<RadrootsEventRef>, + pub supersedes: Vec<RadrootsEventRef>, } #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -833,9 +833,9 @@ pub struct RadrootsContributionAttestation { pub schema_version: u16, pub contributor_pubkey: String, pub contribution_type: String, - pub subject_refs: Vec<RadrootsNostrEventRef>, + pub subject_refs: Vec<RadrootsEventRef>, pub summary: String, - pub evidence_refs: Vec<RadrootsNostrEventRef>, + pub evidence_refs: Vec<RadrootsEventRef>, } #[cfg(test)] @@ -846,12 +846,12 @@ mod tests { core::iter::repeat_n(character, 64).collect() } - fn event_ref() -> RadrootsNostrEventRef { + fn event_ref() -> RadrootsEventRef { event_ref_with_kind(1) } - fn event_ref_with_kind(kind: u32) -> RadrootsNostrEventRef { - RadrootsNostrEventRef { + fn event_ref_with_kind(kind: u32) -> RadrootsEventRef { + RadrootsEventRef { id: "0".repeat(64), author: "1".repeat(64), kind, diff --git a/crates/events/src/lib.rs b/crates/events/src/lib.rs @@ -66,7 +66,7 @@ pub mod trade_validation; #[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] #[cfg_attr(feature = "dto-bindgen", dto(export))] #[derive(Clone, Debug, PartialEq, Eq)] -pub struct RadrootsNostrEvent { +pub struct RadrootsEventEnvelope { pub id: String, pub author: String, pub created_at: u32, @@ -80,7 +80,7 @@ pub struct RadrootsNostrEvent { #[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] #[cfg_attr(feature = "dto-bindgen", dto(export))] #[derive(Clone, Debug, PartialEq, Eq)] -pub struct RadrootsNostrEventRef { +pub struct RadrootsEventRef { pub id: String, pub author: String, pub kind: u32, @@ -92,7 +92,7 @@ pub struct RadrootsNostrEventRef { #[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] #[cfg_attr(feature = "dto-bindgen", dto(export))] #[derive(Clone, Debug, PartialEq, Eq)] -pub struct RadrootsNostrEventPtr { +pub struct RadrootsEventPtr { pub id: String, pub relays: Option<String>, } diff --git a/crates/events/src/message.rs b/crates/events/src/message.rs @@ -1,6 +1,6 @@ #![forbid(unsafe_code)] -use crate::RadrootsNostrEventPtr; +use crate::RadrootsEventPtr; #[cfg(not(feature = "std"))] use alloc::{string::String, vec::Vec}; @@ -12,7 +12,7 @@ use alloc::{string::String, vec::Vec}; pub struct RadrootsMessage { pub recipients: Vec<RadrootsMessageRecipient>, pub content: String, - pub reply_to: Option<RadrootsNostrEventPtr>, + pub reply_to: Option<RadrootsEventPtr>, pub subject: Option<String>, } diff --git a/crates/events/src/message_file.rs b/crates/events/src/message_file.rs @@ -1,6 +1,6 @@ #![forbid(unsafe_code)] -use crate::RadrootsNostrEventPtr; +use crate::RadrootsEventPtr; use crate::message::RadrootsMessageRecipient; #[cfg(not(feature = "std"))] @@ -13,7 +13,7 @@ use alloc::{string::String, vec::Vec}; pub struct RadrootsMessageFile { pub recipients: Vec<RadrootsMessageRecipient>, pub file_url: String, - pub reply_to: Option<RadrootsNostrEventPtr>, + pub reply_to: Option<RadrootsEventPtr>, pub subject: Option<String>, pub file_type: String, pub encryption_algorithm: String, diff --git a/crates/events/src/trade_validation.rs b/crates/events/src/trade_validation.rs @@ -3,7 +3,7 @@ #[cfg(not(feature = "std"))] use alloc::{string::String, vec::Vec}; -use crate::{RadrootsNostrEventPtr, order::RadrootsListingParseError}; +use crate::{RadrootsEventPtr, order::RadrootsListingParseError}; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] @@ -87,7 +87,7 @@ impl std::error::Error for RadrootsTradeValidationListingError {} #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsTradeValidationListingRequest { - pub listing_event: Option<RadrootsNostrEventPtr>, + pub listing_event: Option<RadrootsEventPtr>, } #[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] diff --git a/crates/events/tests/source_boundary.rs b/crates/events/tests/source_boundary.rs @@ -0,0 +1,36 @@ +use std::fs; +use std::path::Path; + +#[test] +fn generic_event_source_does_not_reintroduce_old_core_nostr_event_names() { + let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("src"); + let source = read_sources(&src); + + for forbidden in [ + "RadrootsNostrEvent", + "RadrootsNostrEventRef", + "RadrootsNostrEventPtr", + "RadrootsFrozenEventDraft", + "RadrootsSignedNostrEvent", + "RadrootsSignedNostrEventParts", + ] { + assert!( + !source.contains(forbidden), + "radroots_events generic source must not expose old core event name `{forbidden}`" + ); + } +} + +fn read_sources(root: &Path) -> String { + let mut source = String::new(); + for entry in fs::read_dir(root).expect("read source directory") { + let entry = entry.expect("source entry"); + let path = entry.path(); + if path.is_dir() { + source.push_str(read_sources(&path).as_str()); + } else if path.extension().is_some_and(|extension| extension == "rs") { + source.push_str(fs::read_to_string(path).expect("read source file").as_str()); + } + } + source +} diff --git a/crates/events_codec/src/app_data/decode.rs b/crates/events_codec/src/app_data/decode.rs @@ -5,7 +5,7 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, app_data::{KIND_APP_DATA, RadrootsAppData}, tags::TAG_D, }; @@ -82,7 +82,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/article/decode.rs b/crates/events_codec/src/article/decode.rs @@ -5,7 +5,7 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, article::RadrootsArticle, farm::RadrootsFarmRef, kinds::{KIND_ARTICLE, KIND_FARM}, @@ -95,7 +95,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/calendar/decode.rs b/crates/events_codec/src/calendar/decode.rs @@ -5,7 +5,7 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, calendar::{ RadrootsCalendar, RadrootsCalendarDateEvent, RadrootsCalendarEventRsvp, RadrootsCalendarTimeEvent, @@ -282,7 +282,7 @@ pub fn date_parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, @@ -313,7 +313,7 @@ pub fn time_parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, @@ -344,7 +344,7 @@ pub fn calendar_parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, @@ -375,7 +375,7 @@ pub fn rsvp_parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/comment/decode.rs b/crates/events_codec/src/comment/decode.rs @@ -5,7 +5,7 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, comment::RadrootsComment, kinds::{KIND_COMMENT, KIND_POST}, social::RadrootsSocialTarget, @@ -248,7 +248,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/coop/decode.rs b/crates/events_codec/src/coop/decode.rs @@ -7,7 +7,7 @@ use alloc::{ vec::Vec, }; -use radroots_events::{RadrootsNostrEvent, coop::RadrootsCoop, kinds::KIND_COOP, tags::TAG_D}; +use radroots_events::{RadrootsEventEnvelope, coop::RadrootsCoop, kinds::KIND_COOP, tags::TAG_D}; use crate::d_tag::validate_d_tag_tag; use crate::error::EventParseError; @@ -94,7 +94,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/document/decode.rs b/crates/events_codec/src/document/decode.rs @@ -8,7 +8,7 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, document::RadrootsDocument, kinds::KIND_DOCUMENT, tags::TAG_D, + RadrootsEventEnvelope, document::RadrootsDocument, kinds::KIND_DOCUMENT, tags::TAG_D, }; use crate::d_tag::validate_d_tag_tag; @@ -157,7 +157,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/event_ref.rs b/crates/events_codec/src/event_ref.rs @@ -6,13 +6,13 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEventRef, + RadrootsEventRef, ids::{RadrootsDTag, RadrootsEventId, RadrootsPublicKey, RadrootsRelayUrl}, }; use crate::error::EventParseError; -pub fn build_event_ref_tag(tag: &str, event: &RadrootsNostrEventRef) -> Vec<String> { +pub fn build_event_ref_tag(tag: &str, event: &RadrootsEventRef) -> Vec<String> { let relays_len = event.relays.as_ref().map(|r| r.len()).unwrap_or(0); let mut out = Vec::with_capacity(5 + relays_len); out.push(tag.to_string()); @@ -29,7 +29,7 @@ pub fn build_event_ref_tag(tag: &str, event: &RadrootsNostrEventRef) -> Vec<Stri pub fn parse_event_ref_tag( tag: &[String], tag_name: &'static str, -) -> Result<RadrootsNostrEventRef, EventParseError> { +) -> Result<RadrootsEventRef, EventParseError> { if tag.first().map(|s| s.as_str()) != Some(tag_name) { return Err(EventParseError::InvalidTag(tag_name)); } @@ -65,7 +65,7 @@ pub fn parse_event_ref_tag( None }; - Ok(RadrootsNostrEventRef { + Ok(RadrootsEventRef { id: id.clone(), author: author.clone(), kind, @@ -84,7 +84,7 @@ pub fn find_event_ref_tag<'a>( pub fn push_nip10_ref_tags( tags: &mut Vec<Vec<String>>, - event: &RadrootsNostrEventRef, + event: &RadrootsEventRef, tag_e: &'static str, tag_p: &'static str, tag_k: &'static str, @@ -131,7 +131,7 @@ pub fn parse_nip10_ref_tags( tag_p: &'static str, tag_k: &'static str, tag_a: &'static str, -) -> Result<RadrootsNostrEventRef, EventParseError> { +) -> Result<RadrootsEventRef, EventParseError> { let e_tag = find_event_ref_tag(tags, tag_e).ok_or(EventParseError::MissingTag(tag_e))?; let id = e_tag.get(1).ok_or(EventParseError::InvalidTag(tag_e))?; if id.trim().is_empty() { @@ -185,7 +185,7 @@ pub fn parse_nip10_ref_tags( let relays = relays.or(addr_relays); - Ok(RadrootsNostrEventRef { + Ok(RadrootsEventRef { id: id.clone(), author: author.clone(), kind, diff --git a/crates/events_codec/src/farm/decode.rs b/crates/events_codec/src/farm/decode.rs @@ -7,7 +7,7 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, farm::RadrootsFarm, kinds::KIND_FARM, location::{has_textual_locality, is_public_geohash5}, @@ -185,7 +185,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/farm_crdt/decode.rs b/crates/events_codec/src/farm_crdt/decode.rs @@ -2,7 +2,7 @@ use alloc::{string::String, vec::Vec}; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, farm_crdt::{KIND_FARM_CRDT_CHANGE, RADROOTS_FARM_CRDT_TAG, RadrootsFarmCrdtChange}, farm_workspace::KIND_FARM_WORKSPACE_MANIFEST, tags::{TAG_A, TAG_D, TAG_H, TAG_P, TAG_T}, @@ -73,7 +73,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/farm_file/decode.rs b/crates/events_codec/src/farm_file/decode.rs @@ -5,7 +5,7 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, farm_crdt::RadrootsFarmCrdtDocumentKind, farm_file::{ KIND_FARM_FILE_METADATA, RadrootsFarmFileDimensions, RadrootsFarmFileMetadata, @@ -132,7 +132,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/farm_workspace/decode.rs b/crates/events_codec/src/farm_workspace/decode.rs @@ -2,7 +2,7 @@ use alloc::{string::String, vec::Vec}; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, farm_workspace::{ KIND_FARM_WORKSPACE_MANIFEST, RADROOTS_FARM_WORKSPACE_TAG, RadrootsFarmWorkspaceManifest, }, @@ -108,7 +108,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/file_metadata/decode.rs b/crates/events_codec/src/file_metadata/decode.rs @@ -5,7 +5,7 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, file_metadata::RadrootsFileMetadata, kinds::KIND_PUBLIC_FILE_METADATA, social::RadrootsSocialMediaThumbnail, @@ -123,7 +123,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/follow/decode.rs b/crates/events_codec/src/follow/decode.rs @@ -2,7 +2,7 @@ use alloc::{string::String, vec::Vec}; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, follow::{RadrootsFollow, RadrootsFollowProfile}, kinds::KIND_FOLLOW, }; @@ -102,7 +102,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/geochat/decode.rs b/crates/events_codec/src/geochat/decode.rs @@ -4,7 +4,7 @@ use alloc::{ vec::Vec, }; -use radroots_events::{RadrootsNostrEvent, geochat::RadrootsGeoChat, kinds::KIND_GEOCHAT}; +use radroots_events::{RadrootsEventEnvelope, geochat::RadrootsGeoChat, kinds::KIND_GEOCHAT}; use crate::error::EventParseError; use crate::parsed::{RadrootsParsedData, RadrootsParsedEvent}; @@ -121,7 +121,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/gift_wrap/decode.rs b/crates/events_codec/src/gift_wrap/decode.rs @@ -5,7 +5,7 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, gift_wrap::{RadrootsGiftWrap, RadrootsGiftWrapRecipient}, kinds::KIND_GIFT_WRAP, }; @@ -111,7 +111,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/http_auth/decode.rs b/crates/events_codec/src/http_auth/decode.rs @@ -2,7 +2,7 @@ use alloc::{string::String, vec::Vec}; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, http_auth::{KIND_HTTP_AUTH, RadrootsHttpAuth}, tags::{TAG_METHOD, TAG_PAYLOAD, TAG_URL_AUTH}, }; @@ -75,7 +75,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/job/encode.rs b/crates/events_codec/src/job/encode.rs @@ -4,7 +4,7 @@ use core::fmt; use alloc::{string::String, vec, vec::Vec}; pub use crate::wire::{WireEventParts, canonicalize_tags, empty_content, to_frozen_draft}; -pub use radroots_events::draft::RadrootsFrozenEventDraft; +pub use radroots_events::draft::RadrootsEventDraft; #[derive(Debug)] pub enum JobEncodeError { diff --git a/crates/events_codec/src/job/feedback/decode.rs b/crates/events_codec/src/job/feedback/decode.rs @@ -1,5 +1,5 @@ use radroots_events::{ - RadrootsNostrEvent, RadrootsNostrEventPtr, job::JobPaymentRequest, + RadrootsEventEnvelope, RadrootsEventPtr, job::JobPaymentRequest, job_feedback::RadrootsJobFeedback, kinds::KIND_JOB_FEEDBACK, }; @@ -59,7 +59,7 @@ pub fn job_feedback_from_tags( kind: kind as u16, status, extra_info, - request_event: RadrootsNostrEventPtr { + request_event: RadrootsEventPtr { id: req_id, relays: relay_hint, }, @@ -113,7 +113,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/job/request/decode.rs b/crates/events_codec/src/job/request/decode.rs @@ -1,5 +1,5 @@ use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, job_request::{RadrootsJobInput, RadrootsJobParam, RadrootsJobRequest}, kinds::is_request_kind, }; @@ -96,7 +96,7 @@ pub fn parsed_from_event( ) -> Result<RadrootsParsedEvent<RadrootsJobRequest>, JobParseError> { let data = data_from_event(id.clone(), author.clone(), published_at, kind, tags.clone())?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/job/result/decode.rs b/crates/events_codec/src/job/result/decode.rs @@ -1,6 +1,6 @@ use radroots_events::{ - RadrootsNostrEvent, RadrootsNostrEventPtr, job::JobPaymentRequest, - job_request::RadrootsJobInput, job_result::RadrootsJobResult, kinds::is_result_kind, + RadrootsEventEnvelope, RadrootsEventPtr, job::JobPaymentRequest, job_request::RadrootsJobInput, + job_result::RadrootsJobResult, kinds::is_result_kind, }; #[cfg(not(feature = "std"))] @@ -53,7 +53,7 @@ pub fn job_result_from_tags( Ok(RadrootsJobResult { kind: kind as u16, - request_event: RadrootsNostrEventPtr { + request_event: RadrootsEventPtr { id: req_id, relays: relay_hint, }, @@ -109,7 +109,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/job/traits.rs b/crates/events_codec/src/job/traits.rs @@ -171,7 +171,7 @@ impl<'a, E: JobEventBorrow<'a>> JobEventLike for BorrowedEventAdapter<'a, E> { } } -impl<'a> JobEventBorrow<'a> for radroots_events::RadrootsNostrEvent { +impl<'a> JobEventBorrow<'a> for radroots_events::RadrootsEventEnvelope { #[inline] fn raw_id(&'a self) -> &'a str { &self.id diff --git a/crates/events_codec/src/knowledge/decode.rs b/crates/events_codec/src/knowledge/decode.rs @@ -26,7 +26,7 @@ use radroots_events::knowledge::{ validate_wiki_redirect, }; use radroots_events::tags::{TAG_A, TAG_CONTRACT, TAG_D, TAG_E, TAG_G, TAG_P, TAG_SUMMARY, TAG_T}; -use radroots_events::{RadrootsNostrEvent, RadrootsNostrEventRef}; +use radroots_events::{RadrootsEventEnvelope, RadrootsEventRef}; use serde::de::DeserializeOwned; use crate::error::EventParseError; @@ -174,7 +174,7 @@ fn ensure_mirrored_tags( fn event_refs( tags: &[Vec<String>], name: &'static str, -) -> Result<Vec<RadrootsNostrEventRef>, EventParseError> { +) -> Result<Vec<RadrootsEventRef>, EventParseError> { matching_tags(tags, name) .into_iter() .map(|tag| parse_event_ref_tag(tag, name)) @@ -375,7 +375,7 @@ fn json_content<T: DeserializeOwned>(content: &str) -> Result<T, EventParseError serde_json::from_str(content).map_err(|_| EventParseError::InvalidJson("content")) } -fn parsed<T>(event: RadrootsNostrEvent, data: T) -> RadrootsParsedEvent<T> { +fn parsed<T>(event: RadrootsEventEnvelope, data: T) -> RadrootsParsedEvent<T> { let parsed_data = RadrootsParsedData::new( event.id.clone(), event.author.clone(), @@ -442,7 +442,7 @@ fn contains_private_coordinate_key(value: &serde_json::Value) -> bool { } pub fn wiki_article_from_event( - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, ) -> Result<RadrootsParsedEvent<RadrootsWikiArticle>, EventParseError> { ensure_kind(event.kind, KIND_WIKI_ARTICLE, "wiki article")?; let d_tag = required_one_value(&event.tags, TAG_D)?; @@ -472,7 +472,7 @@ pub fn wiki_article_from_event( } pub fn wiki_redirect_from_event( - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, ) -> Result<RadrootsParsedEvent<RadrootsWikiRedirect>, EventParseError> { ensure_kind(event.kind, KIND_WIKI_REDIRECT, "wiki redirect")?; if !event.content.is_empty() { @@ -490,7 +490,7 @@ pub fn wiki_redirect_from_event( } pub fn wiki_merge_request_from_event( - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, ) -> Result<RadrootsParsedEvent<RadrootsWikiMergeRequest>, EventParseError> { ensure_kind(event.kind, KIND_WIKI_MERGE_REQUEST, "wiki merge request")?; let target_article = address_from_a_tag(&event.tags, TAG_A)?; @@ -517,7 +517,7 @@ pub fn wiki_merge_request_from_event( } pub fn knowledge_source_from_event( - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, ) -> Result<RadrootsParsedEvent<RadrootsKnowledgeSource>, EventParseError> { ensure_kind(event.kind, KIND_KNOWLEDGE_SOURCE, "knowledge source")?; require_contract_tag(&event.tags, RADROOTS_KNOWLEDGE_SOURCE_SCHEMA)?; @@ -534,7 +534,7 @@ pub fn knowledge_source_from_event( } pub fn evidence_bounty_from_event( - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, ) -> Result<RadrootsParsedEvent<RadrootsEvidenceBounty>, EventParseError> { ensure_kind(event.kind, KIND_EVIDENCE_BOUNTY, "evidence bounty")?; require_contract_tag(&event.tags, RADROOTS_EVIDENCE_BOUNTY_SCHEMA)?; @@ -551,7 +551,7 @@ pub fn evidence_bounty_from_event( } pub fn knowledge_claim_from_event( - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, ) -> Result<RadrootsParsedEvent<RadrootsKnowledgeClaim>, EventParseError> { ensure_kind(event.kind, KIND_KNOWLEDGE_CLAIM, "knowledge claim")?; require_contract_tag(&event.tags, RADROOTS_KNOWLEDGE_CLAIM_SCHEMA)?; @@ -568,7 +568,7 @@ pub fn knowledge_claim_from_event( } pub fn knowledge_relation_from_event( - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, ) -> Result<RadrootsParsedEvent<RadrootsKnowledgeRelation>, EventParseError> { ensure_kind(event.kind, KIND_KNOWLEDGE_RELATION, "knowledge relation")?; require_contract_tag(&event.tags, RADROOTS_KNOWLEDGE_RELATION_SCHEMA)?; @@ -581,7 +581,7 @@ pub fn knowledge_relation_from_event( } pub fn knowledge_review_from_event( - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, ) -> Result<RadrootsParsedEvent<RadrootsKnowledgeReview>, EventParseError> { ensure_kind(event.kind, KIND_KNOWLEDGE_REVIEW, "knowledge review")?; require_contract_tag(&event.tags, RADROOTS_KNOWLEDGE_REVIEW_SCHEMA)?; @@ -599,7 +599,7 @@ pub fn knowledge_review_from_event( } pub fn knowledge_field_report_from_event( - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, ) -> Result<RadrootsParsedEvent<RadrootsKnowledgeFieldReport>, EventParseError> { ensure_kind( event.kind, @@ -617,7 +617,7 @@ pub fn knowledge_field_report_from_event( } pub fn knowledge_change_proposal_from_event( - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, ) -> Result<RadrootsParsedEvent<RadrootsKnowledgeChangeProposal>, EventParseError> { ensure_kind( event.kind, @@ -634,7 +634,7 @@ pub fn knowledge_change_proposal_from_event( } pub fn contribution_attestation_from_event( - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, ) -> Result<RadrootsParsedEvent<RadrootsContributionAttestation>, EventParseError> { ensure_kind( event.kind, diff --git a/crates/events_codec/src/knowledge/encode.rs b/crates/events_codec/src/knowledge/encode.rs @@ -6,7 +6,7 @@ use alloc::{ vec::Vec, }; -use radroots_events::RadrootsNostrEventRef; +use radroots_events::RadrootsEventRef; use radroots_events::kinds::{ KIND_CONTRIBUTION_ATTESTATION, KIND_EVIDENCE_BOUNTY, KIND_KNOWLEDGE_CHANGE_PROPOSAL, KIND_KNOWLEDGE_CLAIM, KIND_KNOWLEDGE_FIELD_REPORT, KIND_KNOWLEDGE_RELATION, @@ -62,7 +62,7 @@ fn push_topics(tags: &mut Vec<Vec<String>>, topics: &[String]) { } } -fn push_event_refs(tags: &mut Vec<Vec<String>>, tag_name: &str, refs: &[RadrootsNostrEventRef]) { +fn push_event_refs(tags: &mut Vec<Vec<String>>, tag_name: &str, refs: &[RadrootsEventRef]) { for event_ref in refs { tags.push(build_event_ref_tag(tag_name, event_ref)); } @@ -118,8 +118,8 @@ fn push_wiki_version_ref_tags( tags.push(marker_event_tag(version_ref, marker)); } -fn review_target_ref(target: &RadrootsKnowledgeReviewTarget) -> RadrootsNostrEventRef { - RadrootsNostrEventRef { +fn review_target_ref(target: &RadrootsKnowledgeReviewTarget) -> RadrootsEventRef { + RadrootsEventRef { id: target.event_id.clone(), author: target.author_pubkey.clone(), kind: target.kind, diff --git a/crates/events_codec/src/list/decode.rs b/crates/events_codec/src/list/decode.rs @@ -2,7 +2,7 @@ use alloc::{string::String, vec::Vec}; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, kinds::{KIND_LIST_READ_WRITE_RELAYS, is_nip51_list_set_kind, is_nip51_standard_list_kind}, list::{RadrootsList, RadrootsListEntry}, tags::TAG_R, @@ -126,7 +126,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/list_set/decode.rs b/crates/events_codec/src/list_set/decode.rs @@ -2,7 +2,7 @@ use alloc::{string::String, vec::Vec}; use radroots_events::{ - RadrootsNostrEvent, kinds::is_nip51_list_set_kind, list::RadrootsListEntry, + RadrootsEventEnvelope, kinds::is_nip51_list_set_kind, list::RadrootsListEntry, list_set::RadrootsListSet, }; @@ -135,7 +135,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/listing/decode.rs b/crates/events_codec/src/listing/decode.rs @@ -11,7 +11,7 @@ use radroots_core::{ RadrootsCoreQuantity, RadrootsCoreQuantityPrice, RadrootsCoreUnit, }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, farm::RadrootsFarmRef, ids::{RadrootsDTag, RadrootsInventoryBinId}, kinds::{KIND_FARM, KIND_PLOT, KIND_RESOURCE_AREA, is_listing_kind}, @@ -627,7 +627,7 @@ pub fn parsed_from_event( } pub fn data_from_nostr_event( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsParsedData<RadrootsListing>, EventParseError> { data_from_event( event.id.clone(), @@ -640,7 +640,7 @@ pub fn data_from_nostr_event( } pub fn parsed_from_nostr_event( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsParsedEvent<RadrootsListing>, EventParseError> { parsed_from_event( event.id.clone(), diff --git a/crates/events_codec/src/message/decode.rs b/crates/events_codec/src/message/decode.rs @@ -4,7 +4,7 @@ use alloc::{ vec::Vec, }; -use radroots_events::{RadrootsNostrEvent, kinds::KIND_MESSAGE, message::RadrootsMessage}; +use radroots_events::{RadrootsEventEnvelope, kinds::KIND_MESSAGE, message::RadrootsMessage}; use crate::error::EventParseError; use crate::message::tags::{parse_recipients, parse_reply_tag, parse_subject_tag}; @@ -77,7 +77,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/message/tags.rs b/crates/events_codec/src/message/tags.rs @@ -6,7 +6,7 @@ use alloc::{ vec::Vec, }; -use radroots_events::{RadrootsNostrEventPtr, message::RadrootsMessageRecipient}; +use radroots_events::{RadrootsEventPtr, message::RadrootsMessageRecipient}; use crate::error::{EventEncodeError, EventParseError}; @@ -46,7 +46,7 @@ pub(crate) fn build_recipient_tags( } pub(crate) fn build_reply_tag( - reply_to: &Option<RadrootsNostrEventPtr>, + reply_to: &Option<RadrootsEventPtr>, ) -> Result<Option<Vec<String>>, EventEncodeError> { let reply_to = match reply_to { Some(reply_to) => reply_to, @@ -114,7 +114,7 @@ pub(crate) fn parse_recipients( pub(crate) fn parse_reply_tag( tags: &[Vec<String>], -) -> Result<Option<RadrootsNostrEventPtr>, EventParseError> { +) -> Result<Option<RadrootsEventPtr>, EventParseError> { let tag = match tags .iter() .find(|t| t.first().map(|s| s.as_str()) == Some("e")) @@ -131,7 +131,7 @@ pub(crate) fn parse_reply_tag( Some(value) => Some(value.clone()), None => None, }; - Ok(Some(RadrootsNostrEventPtr { + Ok(Some(RadrootsEventPtr { id: id.clone(), relays: relay, })) @@ -156,7 +156,7 @@ pub(crate) fn parse_subject_tag(tags: &[Vec<String>]) -> Result<Option<String>, mod tests { use super::*; use crate::test_fixtures::RELAY_PRIMARY_WSS; - use radroots_events::{RadrootsNostrEventPtr, message::RadrootsMessageRecipient}; + use radroots_events::{RadrootsEventPtr, message::RadrootsMessageRecipient}; #[test] fn parse_recipients_rejects_missing_p_tags() { @@ -185,7 +185,7 @@ mod tests { parse_reply_tag(&[vec!["e".to_string(), " ".to_string()]]).expect_err("empty reply id"); assert!(matches!(err, EventParseError::InvalidTag("e"))); - let err = build_reply_tag(&Some(RadrootsNostrEventPtr { + let err = build_reply_tag(&Some(RadrootsEventPtr { id: " ".to_string(), relays: None, })) @@ -198,7 +198,7 @@ mod tests { #[test] fn build_and_parse_reply_tags_cover_optional_relay_paths() { - let tag = build_reply_tag(&Some(RadrootsNostrEventPtr { + let tag = build_reply_tag(&Some(RadrootsEventPtr { id: "reply".to_string(), relays: Some(RELAY_PRIMARY_WSS.to_string()), })) @@ -211,7 +211,7 @@ mod tests { Some(RELAY_PRIMARY_WSS.to_string()) ); - let tag = build_reply_tag(&Some(RadrootsNostrEventPtr { + let tag = build_reply_tag(&Some(RadrootsEventPtr { id: "reply".to_string(), relays: None, })) @@ -226,7 +226,7 @@ mod tests { .expect("parse reply tag without relay"); assert_eq!( parsed, - Some(RadrootsNostrEventPtr { + Some(RadrootsEventPtr { id: "reply".to_string(), relays: None, }) @@ -315,7 +315,7 @@ mod tests { .expect_err("invalid recipient relay"); assert!(matches!(err, EventParseError::InvalidTag("p"))); - let err = build_reply_tag(&Some(RadrootsNostrEventPtr { + let err = build_reply_tag(&Some(RadrootsEventPtr { id: "reply".to_string(), relays: Some(" ".to_string()), })) diff --git a/crates/events_codec/src/message_file/decode.rs b/crates/events_codec/src/message_file/decode.rs @@ -5,7 +5,7 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, kinds::KIND_MESSAGE_FILE, message_file::{RadrootsMessageFile, RadrootsMessageFileDimensions}, }; @@ -189,7 +189,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/order/decode.rs b/crates/events_codec/src/order/decode.rs @@ -3,7 +3,7 @@ use alloc::{string::String, vec::Vec}; #[cfg(feature = "serde_json")] use radroots_events::{ - RadrootsNostrEvent, RadrootsNostrEventPtr, + RadrootsEventEnvelope, RadrootsEventPtr, ids::{RadrootsEventId, RadrootsIdParseError, RadrootsListingAddress, RadrootsPublicKey}, kinds::is_order_event_kind, order::{ @@ -94,14 +94,14 @@ impl std::error::Error for RadrootsOrderEnvelopeParseError { #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsOrderEventContext { pub counterparty_pubkey: RadrootsPublicKey, - pub listing_event: Option<RadrootsNostrEventPtr>, + pub listing_event: Option<RadrootsEventPtr>, pub root_event_id: Option<RadrootsEventId>, pub prev_event_id: Option<RadrootsEventId>, } #[cfg(feature = "serde_json")] pub fn order_envelope_from_event<T: DeserializeOwned>( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsOrderEnvelope<T>, RadrootsOrderEnvelopeParseError> { if !is_order_event_kind(event.kind) { return Err(RadrootsOrderEnvelopeParseError::InvalidKind(event.kind)); @@ -136,7 +136,7 @@ pub fn order_envelope_from_event<T: DeserializeOwned>( #[cfg(feature = "serde_json")] pub fn order_request_from_event( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsOrderEnvelope<RadrootsOrderRequest>, RadrootsOrderEnvelopeParseError> { let envelope = order_envelope_from_event::<RadrootsOrderRequest>(event)?; if envelope.message_type != RadrootsOrderEventType::OrderRequested { @@ -162,7 +162,7 @@ pub fn order_request_from_event( #[cfg(feature = "serde_json")] pub fn order_decision_from_event( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsOrderEnvelope<RadrootsOrderDecision>, RadrootsOrderEnvelopeParseError> { let envelope = order_envelope_from_event::<RadrootsOrderDecision>(event)?; if envelope.message_type != RadrootsOrderEventType::OrderDecision { @@ -188,7 +188,7 @@ pub fn order_decision_from_event( #[cfg(feature = "serde_json")] pub fn order_revision_proposal_from_event( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsOrderEnvelope<RadrootsOrderRevisionProposal>, RadrootsOrderEnvelopeParseError> { let envelope = order_envelope_from_event::<RadrootsOrderRevisionProposal>(event)?; if envelope.message_type != RadrootsOrderEventType::OrderRevisionProposed { @@ -225,7 +225,7 @@ pub fn order_revision_proposal_from_event( #[cfg(feature = "serde_json")] pub fn order_revision_decision_from_event( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsOrderEnvelope<RadrootsOrderRevisionDecision>, RadrootsOrderEnvelopeParseError> { let envelope = order_envelope_from_event::<RadrootsOrderRevisionDecision>(event)?; if envelope.message_type != RadrootsOrderEventType::OrderRevisionDecision { @@ -262,7 +262,7 @@ pub fn order_revision_decision_from_event( #[cfg(feature = "serde_json")] pub fn order_cancellation_from_event( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsOrderEnvelope<RadrootsOrderCancellation>, RadrootsOrderEnvelopeParseError> { let envelope = order_envelope_from_event::<RadrootsOrderCancellation>(event)?; if envelope.message_type != RadrootsOrderEventType::OrderCancelled { @@ -379,7 +379,7 @@ fn map_tag_parse_error_for_order_envelope( #[cfg(feature = "serde_json")] fn validate_order_binding<T>( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, envelope: &RadrootsOrderEnvelope<T>, payload_order_id: &str, payload_listing_addr: &str, @@ -426,7 +426,7 @@ mod tests { RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreUnit, }; use radroots_events::{ - RadrootsNostrEvent, RadrootsNostrEventPtr, + RadrootsEventEnvelope, RadrootsEventPtr, ids::{ RadrootsEventId, RadrootsInventoryBinId, RadrootsListingAddress, RadrootsOrderId, RadrootsOrderQuoteId, RadrootsOrderRevisionId, RadrootsPublicKey, @@ -618,8 +618,8 @@ mod tests { } } - fn listing_event_ptr() -> RadrootsNostrEventPtr { - RadrootsNostrEventPtr { + fn listing_event_ptr() -> RadrootsEventPtr { + RadrootsEventPtr { id: event_id_wire('a'), relays: Some("wss://relay.example.com".into()), } @@ -652,9 +652,9 @@ mod tests { order_id: impl Into<String>, payload: &T, tags: Vec<Vec<String>>, - ) -> RadrootsNostrEvent { + ) -> RadrootsEventEnvelope { let envelope = RadrootsOrderEnvelope::new(message_type, listing_addr, order_id, payload); - RadrootsNostrEvent { + RadrootsEventEnvelope { id: event_id_wire('e'), author, created_at: 1, @@ -891,7 +891,7 @@ mod tests { fn order_request_parse_roundtrips_and_validates_tags() { let payload = order_request(); let built = order_request_event_build(&listing_event_ptr(), &payload).unwrap(); - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: event_id_wire('e'), author: buyer_pubkey_wire(), created_at: 1, @@ -920,7 +920,7 @@ mod tests { payload.order_id.clone(), payload, ); - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: event_id_wire('e'), author: buyer_pubkey_wire(), created_at: 1, @@ -946,7 +946,7 @@ mod tests { let root_event_id = event_id('1'); let prev_event_id = event_id('9'); let built = order_decision_event_build(&root_event_id, &prev_event_id, &payload).unwrap(); - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: event_id_wire('e'), author: seller_pubkey_wire(), created_at: 1, @@ -968,7 +968,7 @@ mod tests { let prev_event_id = event_id('9'); let built = order_cancellation_event_build(&root_event_id, &prev_event_id, &payload).unwrap(); - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: event_id_wire('e'), author: buyer_pubkey_wire(), created_at: 1, @@ -995,7 +995,7 @@ mod tests { &payload, ) .unwrap(); - let mut event = RadrootsNostrEvent { + let mut event = RadrootsEventEnvelope { id: event_id_wire('e'), author: seller_pubkey_wire(), created_at: 1, @@ -1023,7 +1023,7 @@ mod tests { &payload, ) .unwrap(); - let mut event = RadrootsNostrEvent { + let mut event = RadrootsEventEnvelope { id: event_id_wire('e'), author: buyer_pubkey_wire(), created_at: 1, @@ -1089,7 +1089,7 @@ mod tests { #[test] fn order_envelope_parse_rejects_content_tag_and_envelope_mismatches() { let payload = serde_json::json!({}); - let invalid_json = RadrootsNostrEvent { + let invalid_json = RadrootsEventEnvelope { id: event_id_wire('e'), author: buyer_pubkey_wire(), created_at: 1, @@ -1110,7 +1110,7 @@ mod tests { &payload, ); invalid_version_envelope.version = 99; - let invalid_version = RadrootsNostrEvent { + let invalid_version = RadrootsEventEnvelope { id: event_id_wire('e'), author: buyer_pubkey_wire(), created_at: 1, @@ -1303,7 +1303,7 @@ mod tests { request_payload.order_id = order_id("other-order"); let request_built = order_request_event_build(&listing_event_ptr(), &order_request()).unwrap(); - let mut request_event = RadrootsNostrEvent { + let mut request_event = RadrootsEventEnvelope { id: event_id_wire('e'), author: buyer_pubkey_wire(), created_at: 1, @@ -1347,7 +1347,7 @@ mod tests { &proposal_payload, ) .unwrap(); - let mut proposal_event = RadrootsNostrEvent { + let mut proposal_event = RadrootsEventEnvelope { id: event_id_wire('e'), author: seller_pubkey_wire(), created_at: 1, @@ -1385,7 +1385,7 @@ mod tests { &revision_decision_payload, ) .unwrap(); - let mut revision_decision_event = RadrootsNostrEvent { + let mut revision_decision_event = RadrootsEventEnvelope { id: event_id_wire('e'), author: buyer_pubkey_wire(), created_at: 1, @@ -1495,7 +1495,7 @@ mod tests { let payload = serde_json::json!({}); let envelope = RadrootsOrderEnvelope::new(message_type, listing_addr_wire(), "order-1", &payload); - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: event_id_wire('e'), author: seller_pubkey_wire(), created_at: 1, @@ -1519,7 +1519,7 @@ mod tests { #[test] fn order_parse_rejects_forbidden_kind() { - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: event_id_wire('e'), author: seller_pubkey_wire(), created_at: 1, @@ -1538,7 +1538,7 @@ mod tests { let root_event_id = event_id('1'); let prev_event_id = event_id('9'); let built = order_decision_event_build(&root_event_id, &prev_event_id, &payload).unwrap(); - let mut event = RadrootsNostrEvent { + let mut event = RadrootsEventEnvelope { id: event_id_wire('e'), author: seller_pubkey_wire(), created_at: 1, @@ -1559,7 +1559,7 @@ mod tests { fn order_parse_rejects_author_and_counterparty_mismatch() { let payload = order_request(); let built = order_request_event_build(&listing_event_ptr(), &payload).unwrap(); - let mut event = RadrootsNostrEvent { + let mut event = RadrootsEventEnvelope { id: event_id_wire('e'), author: seller_pubkey_wire(), created_at: 1, @@ -1587,7 +1587,7 @@ mod tests { let prev_event_id = event_id('9'); let cancellation_parts = order_cancellation_event_build(&root_event_id, &prev_event_id, &cancellation).unwrap(); - let cancellation_event = RadrootsNostrEvent { + let cancellation_event = RadrootsEventEnvelope { id: event_id_wire('e'), author: seller_pubkey_wire(), created_at: 1, @@ -1606,7 +1606,7 @@ mod tests { let root_event_id = event_id('1'); let prev_event_id = event_id('9'); let built = order_decision_event_build(&root_event_id, &prev_event_id, &payload).unwrap(); - let mut event = RadrootsNostrEvent { + let mut event = RadrootsEventEnvelope { id: event_id_wire('e'), author: seller_pubkey_wire(), created_at: 1, diff --git a/crates/events_codec/src/order/encode.rs b/crates/events_codec/src/order/encode.rs @@ -1,6 +1,6 @@ #[cfg(feature = "serde_json")] use radroots_events::{ - RadrootsNostrEventPtr, + RadrootsEventPtr, ids::RadrootsEventId, order::{ RadrootsOrderCancellation, RadrootsOrderDecision, RadrootsOrderEnvelope, @@ -77,7 +77,7 @@ struct OrderEnvelopeEventBuildParts<'a, T> { message_type: RadrootsOrderEventType, listing_addr: &'a str, order_id: &'a str, - listing_event: Option<&'a RadrootsNostrEventPtr>, + listing_event: Option<&'a RadrootsEventPtr>, root_event_id: Option<&'a RadrootsEventId>, prev_event_id: Option<&'a RadrootsEventId>, payload: &'a T, @@ -124,7 +124,7 @@ fn order_envelope_event_build<T: serde::Serialize>( #[cfg(feature = "serde_json")] pub fn order_request_event_build( - listing_event: &RadrootsNostrEventPtr, + listing_event: &RadrootsEventPtr, payload: &RadrootsOrderRequest, ) -> Result<WireEventParts, EventEncodeError> { payload.validate().map_err(map_order_payload_error)?; @@ -236,7 +236,7 @@ mod tests { }; use crate::error::EventEncodeError; use radroots_events::{ - RadrootsNostrEventPtr, + RadrootsEventPtr, ids::RadrootsEventId, order::{RadrootsOrderEnvelopeError, RadrootsOrderEventType, RadrootsOrderPayloadError}, }; @@ -402,7 +402,7 @@ mod tests { message_type: RadrootsOrderEventType::OrderRequested, listing_addr: "listing-address", order_id: "order-1", - listing_event: Some(&RadrootsNostrEventPtr { + listing_event: Some(&RadrootsEventPtr { id: String::new(), relays: None, }), diff --git a/crates/events_codec/src/order/tags.rs b/crates/events_codec/src/order/tags.rs @@ -2,8 +2,8 @@ use alloc::{borrow::ToOwned, string::String, vec, vec::Vec}; use radroots_events::{ - RadrootsNostrEventPtr, - ids::{RadrootsEventId, RadrootsNostrEventPointer}, + RadrootsEventPtr, + ids::{RadrootsEventEnvelopePointer, RadrootsEventId}, tags::{TAG_D, TAG_E_PREV, TAG_E_ROOT}, }; @@ -21,7 +21,7 @@ fn push_tag(tags: &mut Vec<Vec<String>>, name: &'static str, value: impl Into<St fn build_event_ptr_tag( name: &'static str, - ptr: &RadrootsNostrEventPtr, + ptr: &RadrootsEventPtr, field_prefix: &'static str, ) -> Result<Vec<String>, EventEncodeError> { if ptr.id.trim().is_empty() { @@ -36,7 +36,7 @@ fn build_event_ptr_tag( if relay.trim().is_empty() { return Err(EventEncodeError::EmptyRequiredField("listing_event.relays")); } - RadrootsNostrEventPointer::new(event_id, [relay.as_str()]) + RadrootsEventEnvelopePointer::new(event_id, [relay.as_str()]) .map_err(|_| EventEncodeError::InvalidField("listing_event.relays"))?; tag.push(relay.clone()); } @@ -46,7 +46,7 @@ fn build_event_ptr_tag( fn parse_event_ptr_tag( tags: &[Vec<String>], name: &'static str, -) -> Result<Option<RadrootsNostrEventPtr>, EventParseError> { +) -> Result<Option<RadrootsEventPtr>, EventParseError> { let Some(tag) = tags .iter() .find(|tag| tag.first().map(|value| value.as_str()) == Some(name)) @@ -65,10 +65,10 @@ fn parse_event_ptr_tag( None => None, }; if let Some(relay) = relay.as_ref() { - RadrootsNostrEventPointer::new(event_id.clone(), [relay.as_str()]) + RadrootsEventEnvelopePointer::new(event_id.clone(), [relay.as_str()]) .map_err(|_| EventParseError::InvalidTag(name))?; } - Ok(Some(RadrootsNostrEventPtr { + Ok(Some(RadrootsEventPtr { id: event_id.as_str().to_owned(), relays: relay, })) @@ -79,7 +79,7 @@ pub fn order_envelope_tags<P, A, D>( recipient_pubkey: P, listing_addr: A, order_id: Option<D>, - listing_event: Option<&RadrootsNostrEventPtr>, + listing_event: Option<&RadrootsEventPtr>, root_event_id: Option<&str>, prev_event_id: Option<&str>, ) -> Result<Vec<Vec<String>>, EventEncodeError> @@ -147,7 +147,7 @@ pub fn parse_order_counterparty_tag(tags: &[Vec<String>]) -> Result<String, Even #[inline] pub fn parse_order_listing_event_tag( tags: &[Vec<String>], -) -> Result<Option<RadrootsNostrEventPtr>, EventParseError> { +) -> Result<Option<RadrootsEventPtr>, EventParseError> { parse_event_ptr_tag(tags, TAG_LISTING_EVENT) } @@ -253,7 +253,7 @@ mod tests { job::error::JobParseError, }; use radroots_events::{ - RadrootsNostrEventPtr, + RadrootsEventPtr, kinds::KIND_LISTING, tags::{TAG_D, TAG_E_PREV, TAG_E_ROOT}, }; @@ -290,7 +290,7 @@ mod tests { "buyer", listing_addr.as_str(), Some("order-1"), - Some(&RadrootsNostrEventPtr { + Some(&RadrootsEventPtr { id: listing_event_id.clone(), relays: Some("wss://relay.example".into()), }), @@ -324,7 +324,7 @@ mod tests { "buyer", listing_addr.as_str(), None::<&str>, - Some(&RadrootsNostrEventPtr { + Some(&RadrootsEventPtr { id: listing_event_id.clone(), relays: None, }), @@ -350,7 +350,7 @@ mod tests { "buyer", listing_addr.as_str(), Some("order-1"), - None::<&RadrootsNostrEventPtr>, + None::<&RadrootsEventPtr>, Some("root-event"), Some("prev-event"), ) @@ -375,7 +375,7 @@ mod tests { "buyer", listing_addr.as_str(), None::<&str>, - Some(&RadrootsNostrEventPtr { + Some(&RadrootsEventPtr { id: listing_event_id.clone(), relays: None, }), @@ -422,7 +422,7 @@ mod tests { "buyer", listing_addr.as_str(), None::<&str>, - Some(&RadrootsNostrEventPtr { + Some(&RadrootsEventPtr { id: " ".into(), relays: None, }), @@ -439,7 +439,7 @@ mod tests { "buyer", listing_addr.as_str(), None::<&str>, - Some(&RadrootsNostrEventPtr { + Some(&RadrootsEventPtr { id: "not-an-event-id".into(), relays: None, }), @@ -456,7 +456,7 @@ mod tests { "buyer", listing_addr.as_str(), None::<&str>, - Some(&RadrootsNostrEventPtr { + Some(&RadrootsEventPtr { id: event_id('d'), relays: Some(" ".into()), }), @@ -517,7 +517,7 @@ mod tests { ); assert_eq!( parse_order_listing_event_tag(&tags).expect("snapshot"), - Some(RadrootsNostrEventPtr { + Some(RadrootsEventPtr { id: listing_event_id, relays: Some("wss://relay".into()), }) @@ -591,7 +591,7 @@ mod tests { assert_eq!( parse_order_listing_event_tag(&[vec![String::from(TAG_LISTING_EVENT), event_id('a'),]]) .expect("snapshot without relay"), - Some(RadrootsNostrEventPtr { + Some(RadrootsEventPtr { id: event_id('a'), relays: None, }) diff --git a/crates/events_codec/src/parsed.rs b/crates/events_codec/src/parsed.rs @@ -1,7 +1,7 @@ #[cfg(not(feature = "std"))] use alloc::{string::String, vec::Vec}; -use radroots_events::RadrootsNostrEvent; +use radroots_events::RadrootsEventEnvelope; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq, Eq)] @@ -29,13 +29,13 @@ impl<T> RadrootsParsedData<T> { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct RadrootsParsedEvent<T> { - pub event: RadrootsNostrEvent, + pub event: RadrootsEventEnvelope, pub data: RadrootsParsedData<T>, } impl<T> RadrootsParsedEvent<T> { #[inline] - pub fn new(event: RadrootsNostrEvent, data: RadrootsParsedData<T>) -> Self { + pub fn new(event: RadrootsEventEnvelope, data: RadrootsParsedData<T>) -> Self { Self { event, data } } @@ -51,7 +51,7 @@ impl<T> RadrootsParsedEvent<T> { data: T, ) -> Self { Self { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id: id.clone(), author: author.clone(), created_at: published_at, @@ -68,7 +68,7 @@ impl<T> RadrootsParsedEvent<T> { #[cfg(test)] mod tests { use super::{RadrootsParsedData, RadrootsParsedEvent}; - use radroots_events::RadrootsNostrEvent; + use radroots_events::RadrootsEventEnvelope; #[test] fn parsed_data_constructor_maps_fields() { @@ -88,7 +88,7 @@ mod tests { #[test] fn parsed_event_constructor_maps_event_and_data() { - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: "id".to_string(), author: "author".to_string(), created_at: 22, diff --git a/crates/events_codec/src/plot/decode.rs b/crates/events_codec/src/plot/decode.rs @@ -7,7 +7,7 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, farm::RadrootsFarmRef, kinds::{KIND_FARM, KIND_PLOT}, plot::RadrootsPlot, @@ -159,7 +159,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/post/decode.rs b/crates/events_codec/src/post/decode.rs @@ -6,7 +6,7 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, farm::RadrootsFarmRef, kinds::{KIND_FARM, KIND_POST}, post::RadrootsPost, @@ -93,7 +93,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/profile/decode.rs b/crates/events_codec/src/profile/decode.rs @@ -6,7 +6,7 @@ use alloc::{ use super::RadrootsProfileData; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, kinds::KIND_PROFILE, profile::{ RADROOTS_PROFILE_TYPE_TAG_KEY, RadrootsProfile, RadrootsProfileType, @@ -113,7 +113,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/reaction/decode.rs b/crates/events_codec/src/reaction/decode.rs @@ -5,7 +5,7 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, kinds::KIND_REACTION, reaction::RadrootsReaction, + RadrootsEventEnvelope, kinds::KIND_REACTION, reaction::RadrootsReaction, social::RadrootsSocialTarget, tags::TAG_E_ROOT, }; @@ -75,7 +75,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/relay_auth/decode.rs b/crates/events_codec/src/relay_auth/decode.rs @@ -2,7 +2,7 @@ use alloc::{string::String, vec::Vec}; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, relay_auth::{KIND_RELAY_AUTH, RadrootsRelayAuth}, tags::{TAG_CHALLENGE, TAG_RELAY}, }; @@ -67,7 +67,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/report/decode.rs b/crates/events_codec/src/report/decode.rs @@ -5,7 +5,7 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, kinds::KIND_REPORT, report::RadrootsReport, social::{RadrootsReportFileTarget, RadrootsReportType, RadrootsSocialTarget}, @@ -89,7 +89,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/repost/decode.rs b/crates/events_codec/src/repost/decode.rs @@ -5,7 +5,7 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, kinds::{KIND_GENERIC_REPOST, KIND_POST, KIND_REPOST}, repost::{RadrootsGenericRepost, RadrootsRepost}, social::RadrootsSocialTarget, @@ -153,7 +153,7 @@ pub fn repost_parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, @@ -184,7 +184,7 @@ pub fn generic_repost_parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/resource_area/decode.rs b/crates/events_codec/src/resource_area/decode.rs @@ -7,7 +7,8 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, kinds::KIND_RESOURCE_AREA, resource_area::RadrootsResourceArea, tags::TAG_D, + RadrootsEventEnvelope, kinds::KIND_RESOURCE_AREA, resource_area::RadrootsResourceArea, + tags::TAG_D, }; use crate::d_tag::validate_d_tag_tag; @@ -95,7 +96,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/resource_cap/decode.rs b/crates/events_codec/src/resource_cap/decode.rs @@ -7,8 +7,8 @@ use alloc::{ }; use radroots_events::{ - RadrootsNostrEvent, kinds::KIND_RESOURCE_HARVEST_CAP, resource_cap::RadrootsResourceHarvestCap, - tags::TAG_D, + RadrootsEventEnvelope, kinds::KIND_RESOURCE_HARVEST_CAP, + resource_cap::RadrootsResourceHarvestCap, tags::TAG_D, }; use crate::d_tag::validate_d_tag_tag; @@ -90,7 +90,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/seal/decode.rs b/crates/events_codec/src/seal/decode.rs @@ -4,7 +4,7 @@ use alloc::{ vec::Vec, }; -use radroots_events::{RadrootsNostrEvent, kinds::KIND_SEAL, seal::RadrootsSeal}; +use radroots_events::{RadrootsEventEnvelope, kinds::KIND_SEAL, seal::RadrootsSeal}; use crate::error::EventParseError; use crate::parsed::{RadrootsParsedData, RadrootsParsedEvent}; @@ -69,7 +69,7 @@ pub fn parsed_from_event( tags.clone(), )?; Ok(RadrootsParsedEvent { - event: RadrootsNostrEvent { + event: RadrootsEventEnvelope { id, author, created_at: published_at, diff --git a/crates/events_codec/src/verification.rs b/crates/events_codec/src/verification.rs @@ -5,7 +5,7 @@ use core::fmt; #[cfg(feature = "nostr")] use core::str::FromStr; -use radroots_events::RadrootsNostrEvent; +use radroots_events::RadrootsEventEnvelope; use radroots_events::contract::{ RadrootsContractValidationError, RadrootsEventContract, validate_event_contract as validate_radroots_event_contract, @@ -31,30 +31,30 @@ use crate::parsed::RadrootsParsedEvent; #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsIdVerifiedEvent { - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, } impl RadrootsIdVerifiedEvent { - pub fn event(&self) -> &RadrootsNostrEvent { + pub fn event(&self) -> &RadrootsEventEnvelope { &self.event } - pub fn into_event(self) -> RadrootsNostrEvent { + pub fn into_event(self) -> RadrootsEventEnvelope { self.event } } #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsSignatureVerifiedEvent { - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, } impl RadrootsSignatureVerifiedEvent { - pub fn event(&self) -> &RadrootsNostrEvent { + pub fn event(&self) -> &RadrootsEventEnvelope { &self.event } - pub fn into_event(self) -> RadrootsNostrEvent { + pub fn into_event(self) -> RadrootsEventEnvelope { self.event } } @@ -67,12 +67,12 @@ impl RadrootsSignatureVerifiedEvent { /// checked by `decode_validated_event`. #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsContractValidatedEvent { - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, contract: &'static RadrootsEventContract, } impl RadrootsContractValidatedEvent { - pub fn event(&self) -> &RadrootsNostrEvent { + pub fn event(&self) -> &RadrootsEventEnvelope { &self.event } @@ -84,7 +84,7 @@ impl RadrootsContractValidatedEvent { self.contract.id } - pub fn into_event(self) -> RadrootsNostrEvent { + pub fn into_event(self) -> RadrootsEventEnvelope { self.event } } @@ -205,7 +205,7 @@ pub enum RadrootsDecodedEvent { } impl RadrootsDecodedEvent { - pub fn event(&self) -> &RadrootsNostrEvent { + pub fn event(&self) -> &RadrootsEventEnvelope { match self { Self::WikiArticle(parsed) => &parsed.event, Self::WikiRedirect(parsed) => &parsed.event, @@ -223,7 +223,7 @@ impl RadrootsDecodedEvent { } pub fn verify_event_id( - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, ) -> Result<RadrootsIdVerifiedEvent, RadrootsNip01VerificationError> { RadrootsEventId::parse(event.id.as_str()) .map_err(|_| RadrootsNip01VerificationError::MalformedEnvelope)?; @@ -337,12 +337,12 @@ pub fn decode_validated_event( /// Verify NIP-01 identity, validate the Radroots contract, and decode the event. /// /// The pipeline is: -/// `RadrootsNostrEvent -> verify_event_id -> RadrootsIdVerifiedEvent -> +/// `RadrootsEventEnvelope -> verify_event_id -> RadrootsIdVerifiedEvent -> /// verify_event_signature -> RadrootsSignatureVerifiedEvent -> /// validate_event_contract -> RadrootsContractValidatedEvent -> /// decode_validated_event -> RadrootsDecodedEvent`. pub fn verify_and_decode_radroots_event( - event: RadrootsNostrEvent, + event: RadrootsEventEnvelope, ) -> Result<RadrootsDecodedEvent, RadrootsDecodeError> { let id_verified = verify_event_id(event)?; let signature_verified = verify_event_signature(id_verified)?; @@ -352,7 +352,7 @@ pub fn verify_and_decode_radroots_event( #[cfg(feature = "nostr")] fn raw_event_from_radroots( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<nostr::Event, RadrootsNip01VerificationError> { let id = nostr::EventId::from_hex(event.id.as_str()) .map_err(|_| RadrootsNip01VerificationError::MalformedEnvelope)?; diff --git a/crates/events_codec/src/wire.rs b/crates/events_codec/src/wire.rs @@ -4,7 +4,7 @@ use alloc::{ vec::Vec, }; -use radroots_events::draft::{RadrootsDraftError, RadrootsFrozenEventDraft}; +use radroots_events::draft::{RadrootsDraftError, RadrootsEventDraft}; #[derive(Debug, Clone)] pub struct WireEventParts { @@ -18,8 +18,8 @@ pub fn to_frozen_draft( contract_id: impl Into<String>, expected_pubkey: impl AsRef<str>, created_at: u32, -) -> Result<RadrootsFrozenEventDraft, RadrootsDraftError> { - RadrootsFrozenEventDraft::new( +) -> Result<RadrootsEventDraft, RadrootsDraftError> { + RadrootsEventDraft::new( contract_id, parts.kind, created_at, diff --git a/crates/events_codec/tests/common/mod.rs b/crates/events_codec/tests/common/mod.rs @@ -1,9 +1,9 @@ #![allow(dead_code)] -use radroots_events::{RadrootsNostrEvent, RadrootsNostrEventPtr, RadrootsNostrEventRef}; +use radroots_events::{RadrootsEventEnvelope, RadrootsEventPtr, RadrootsEventRef}; -pub fn event_ref(id: &str, author: &str, kind: u32) -> RadrootsNostrEventRef { - RadrootsNostrEventRef { +pub fn event_ref(id: &str, author: &str, kind: u32) -> RadrootsEventRef { + RadrootsEventRef { id: id.to_string(), author: author.to_string(), kind, @@ -18,8 +18,8 @@ pub fn event_ref_with_d( kind: u32, d_tag: &str, relays: Option<Vec<String>>, -) -> RadrootsNostrEventRef { - RadrootsNostrEventRef { +) -> RadrootsEventRef { + RadrootsEventRef { id: id.to_string(), author: author.to_string(), kind, @@ -28,15 +28,15 @@ pub fn event_ref_with_d( } } -pub fn event_ptr(id: &str, relays: Option<&str>) -> RadrootsNostrEventPtr { - RadrootsNostrEventPtr { +pub fn event_ptr(id: &str, relays: Option<&str>) -> RadrootsEventPtr { + RadrootsEventPtr { id: id.to_string(), relays: relays.map(|s| s.to_string()), } } -pub fn nostr_event(kind: u32, content: &str, tags: Vec<Vec<String>>) -> RadrootsNostrEvent { - RadrootsNostrEvent { +pub fn nostr_event(kind: u32, content: &str, tags: Vec<Vec<String>>) -> RadrootsEventEnvelope { + RadrootsEventEnvelope { id: "id".to_string(), author: "author".to_string(), created_at: 123, diff --git a/crates/events_codec/tests/job_traits.rs b/crates/events_codec/tests/job_traits.rs @@ -1,7 +1,7 @@ #[path = "../src/test_fixtures.rs"] mod test_fixtures; -use radroots_events::RadrootsNostrEvent; +use radroots_events::RadrootsEventEnvelope; use radroots_events::job::{JobFeedbackStatus, JobInputType, JobPaymentRequest}; use radroots_events::job_feedback::RadrootsJobFeedback; use radroots_events::job_request::{RadrootsJobInput, RadrootsJobParam, RadrootsJobRequest}; @@ -40,7 +40,7 @@ fn borrowed_event_adapter_builds_request_metadata() { let req = sample_request(); let parts = to_request_wire_parts(&req, "payload").unwrap(); - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: "id".to_string(), author: "author".to_string(), created_at: 42, @@ -63,7 +63,7 @@ fn borrowed_event_adapter_builds_request_metadata() { fn sample_result() -> RadrootsJobResult { RadrootsJobResult { kind: (KIND_JOB_RESULT_MIN + 1) as u16, - request_event: radroots_events::RadrootsNostrEventPtr { + request_event: radroots_events::RadrootsEventPtr { id: "req".to_string(), relays: Some(RELAY_PRIMARY_WSS.to_string()), }, @@ -89,7 +89,7 @@ fn sample_feedback() -> RadrootsJobFeedback { kind: KIND_JOB_FEEDBACK as u16, status: JobFeedbackStatus::Processing, extra_info: Some("processing".to_string()), - request_event: radroots_events::RadrootsNostrEventPtr { + request_event: radroots_events::RadrootsEventPtr { id: "req".to_string(), relays: Some(RELAY_PRIMARY_WSS.to_string()), }, @@ -107,7 +107,7 @@ fn sample_feedback() -> RadrootsJobFeedback { fn borrowed_event_adapter_builds_request_metadata_and_index() { let req = sample_request(); let parts = to_request_wire_parts(&req, "payload").unwrap(); - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: "id".to_string(), author: "author".to_string(), created_at: 42, @@ -139,7 +139,7 @@ fn borrowed_event_adapter_builds_request_metadata_and_index() { fn borrowed_event_adapter_builds_result_metadata_and_index() { let result = sample_result(); let parts = to_result_wire_parts(&result, "payload").unwrap(); - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: "id".to_string(), author: "author".to_string(), created_at: 42, @@ -172,7 +172,7 @@ fn borrowed_event_adapter_builds_result_metadata_and_index() { fn borrowed_event_adapter_builds_feedback_metadata_and_index() { let feedback = sample_feedback(); let parts = to_feedback_wire_parts(&feedback, "payload").unwrap(); - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: "id".to_string(), author: "author".to_string(), created_at: 42, diff --git a/crates/events_codec/tests/knowledge.rs b/crates/events_codec/tests/knowledge.rs @@ -1,6 +1,6 @@ #![cfg(all(feature = "knowledge", feature = "nostr"))] -use radroots_events::RadrootsNostrEvent; +use radroots_events::RadrootsEventEnvelope; use radroots_events::contract::validate_event_contract_shape; use radroots_events::kinds::{ KIND_KNOWLEDGE_CLAIM, KIND_KNOWLEDGE_REVIEW, KIND_KNOWLEDGE_SOURCE, KIND_WIKI_ARTICLE, @@ -41,8 +41,8 @@ fn hex_64(character: char) -> String { core::iter::repeat_n(character, 64).collect() } -fn event_ref(character: char, kind: u32) -> radroots_events::RadrootsNostrEventRef { - radroots_events::RadrootsNostrEventRef { +fn event_ref(character: char, kind: u32) -> radroots_events::RadrootsEventRef { + radroots_events::RadrootsEventRef { id: hex_64(character), author: hex_64('a'), kind, @@ -73,8 +73,8 @@ fn article_version_ref_for(event_id_character: char, d_tag: &str) -> RadrootsWik } } -fn event_from_parts(parts: WireEventParts) -> RadrootsNostrEvent { - RadrootsNostrEvent { +fn event_from_parts(parts: WireEventParts) -> RadrootsEventEnvelope { + RadrootsEventEnvelope { id: hex_64('0'), author: hex_64('a'), created_at: 1_800_000_000, @@ -85,7 +85,7 @@ fn event_from_parts(parts: WireEventParts) -> RadrootsNostrEvent { } } -fn replace_first_tag_value(event: &mut RadrootsNostrEvent, name: &str, value: String) { +fn replace_first_tag_value(event: &mut RadrootsEventEnvelope, name: &str, value: String) { let tag = event .tags .iter_mut() @@ -99,7 +99,7 @@ fn marked_tag(tag: &[String], name: &str, marker: &str) -> bool { tag.first().map(String::as_str) == Some(name) && tag.last().map(String::as_str) == Some(marker) } -fn marked_tag_index(event: &RadrootsNostrEvent, name: &str, marker: &str) -> usize { +fn marked_tag_index(event: &RadrootsEventEnvelope, name: &str, marker: &str) -> usize { event .tags .iter() @@ -145,7 +145,7 @@ fn invalid_relay() -> String { "http://relay.radroots.example".to_string() } -fn sign_parts(parts: WireEventParts) -> RadrootsNostrEvent { +fn sign_parts(parts: WireEventParts) -> RadrootsEventEnvelope { let tags = parts .tags .into_iter() @@ -160,7 +160,7 @@ fn sign_parts(parts: WireEventParts) -> RadrootsNostrEvent { .custom_created_at(nostr::Timestamp::from_secs(1_800_000_000)) .sign_with_keys(&keys) .expect("signed event"); - RadrootsNostrEvent { + RadrootsEventEnvelope { id: event.id.to_hex(), author: event.pubkey.to_hex(), created_at: event.created_at.as_secs() as u32, diff --git a/crates/events_codec/tests/knowledge_fixtures.rs b/crates/events_codec/tests/knowledge_fixtures.rs @@ -2,7 +2,7 @@ use std::collections::BTreeSet; -use radroots_events::RadrootsNostrEvent; +use radroots_events::RadrootsEventEnvelope; use radroots_events::contract::{ RadrootsContractValidationError, RadrootsEventClass, all_event_contracts, validate_event_contract_shape, @@ -36,8 +36,8 @@ use radroots_test_fixtures::knowledge::{ wiki_redirect, }; -fn event_from_parts(parts: WireEventParts) -> RadrootsNostrEvent { - RadrootsNostrEvent { +fn event_from_parts(parts: WireEventParts) -> RadrootsEventEnvelope { + RadrootsEventEnvelope { id: hex_64('0'), author: hex_64('a'), created_at: 1_800_000_000, @@ -48,7 +48,7 @@ fn event_from_parts(parts: WireEventParts) -> RadrootsNostrEvent { } } -fn sign_parts(parts: WireEventParts) -> RadrootsNostrEvent { +fn sign_parts(parts: WireEventParts) -> RadrootsEventEnvelope { let tags = parts .tags .into_iter() @@ -63,7 +63,7 @@ fn sign_parts(parts: WireEventParts) -> RadrootsNostrEvent { .custom_created_at(nostr::Timestamp::from_secs(1_800_000_000)) .sign_with_keys(&keys) .expect("signed event"); - RadrootsNostrEvent { + RadrootsEventEnvelope { id: event.id.to_hex(), author: event.pubkey.to_hex(), created_at: event.created_at.as_secs() as u32, diff --git a/crates/events_codec/tests/listing.rs b/crates/events_codec/tests/listing.rs @@ -6,7 +6,7 @@ use radroots_core::{ RadrootsCoreQuantity, RadrootsCoreQuantityPrice, RadrootsCoreUnit, }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, farm::RadrootsFarmRef, ids::{RadrootsDTag, RadrootsInventoryBinId}, kinds::{ @@ -928,7 +928,7 @@ fn listing_parsed_wrappers_preserve_event_metadata() { assert_eq!(parsed.event.sig, "sig"); assert_eq!(parsed.data.data.d_tag, listing.d_tag); - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: "event-id".to_string(), author: "author-pubkey".to_string(), created_at: 7, diff --git a/crates/events_codec/tests/message.rs b/crates/events_codec/tests/message.rs @@ -2,7 +2,7 @@ mod test_fixtures; use radroots_events::{ - RadrootsNostrEventPtr, + RadrootsEventPtr, kinds::{KIND_MESSAGE, KIND_POST}, message::{RadrootsMessage, RadrootsMessageRecipient}, }; @@ -96,7 +96,7 @@ fn message_to_wire_parts_sets_tags() { }, ], content: "hello".to_string(), - reply_to: Some(RadrootsNostrEventPtr { + reply_to: Some(RadrootsEventPtr { id: "reply".to_string(), relays: Some(RELAY_SECONDARY_WSS.to_string()), }), @@ -149,7 +149,7 @@ fn message_to_wire_parts_supports_reply_without_relay() { relay_url: None, }], content: "hello".to_string(), - reply_to: Some(RadrootsNostrEventPtr { + reply_to: Some(RadrootsEventPtr { id: "reply".to_string(), relays: None, }), @@ -330,7 +330,7 @@ fn message_build_tags_rejects_invalid_optional_fields() { relay_url: None, }], content: "hello".to_string(), - reply_to: Some(RadrootsNostrEventPtr { + reply_to: Some(RadrootsEventPtr { id: " ".to_string(), relays: None, }), @@ -348,7 +348,7 @@ fn message_build_tags_rejects_invalid_optional_fields() { relay_url: None, }], content: "hello".to_string(), - reply_to: Some(RadrootsNostrEventPtr { + reply_to: Some(RadrootsEventPtr { id: "reply".to_string(), relays: Some(" ".to_string()), }), diff --git a/crates/events_codec/tests/message_file.rs b/crates/events_codec/tests/message_file.rs @@ -1,7 +1,7 @@ #[path = "../src/test_fixtures.rs"] mod test_fixtures; -use radroots_events::RadrootsNostrEventPtr; +use radroots_events::RadrootsEventPtr; use radroots_events::kinds::{KIND_MESSAGE, KIND_MESSAGE_FILE}; use radroots_events::message::RadrootsMessageRecipient; use radroots_events::message_file::{RadrootsMessageFile, RadrootsMessageFileDimensions}; @@ -32,7 +32,7 @@ fn sample_message_file() -> RadrootsMessageFile { }, ], file_url: file_url("encrypted.bin"), - reply_to: Some(RadrootsNostrEventPtr { + reply_to: Some(RadrootsEventPtr { id: "reply".to_string(), relays: Some(RELAY_SECONDARY_WSS.to_string()), }), @@ -147,7 +147,7 @@ fn message_file_build_tags_requires_crypto_fields() { #[test] fn message_file_build_tags_rejects_invalid_reply_subject_and_fallbacks() { let mut message = sample_message_file(); - message.reply_to = Some(RadrootsNostrEventPtr { + message.reply_to = Some(RadrootsEventPtr { id: " ".to_string(), relays: None, }); diff --git a/crates/events_codec/tests/tag_builders.rs b/crates/events_codec/tests/tag_builders.rs @@ -6,7 +6,7 @@ use radroots_core::{ RadrootsCoreDiscountThreshold, RadrootsCoreDiscountValue, RadrootsCoreMoney, RadrootsCoreQuantity, RadrootsCoreQuantityPrice, RadrootsCoreUnit, }; -use radroots_events::RadrootsNostrEventPtr; +use radroots_events::RadrootsEventPtr; use radroots_events::app_data::RadrootsAppData; use radroots_events::comment::RadrootsComment; use radroots_events::coop::RadrootsCoop; @@ -196,7 +196,7 @@ fn event_tag_builder_impls_build_tags_for_all_supported_types() { relay_url: Some(RELAY_PRIMARY_WSS.to_string()), }], content: "hello".to_string(), - reply_to: Some(RadrootsNostrEventPtr { + reply_to: Some(RadrootsEventPtr { id: "reply".to_string(), relays: Some(RELAY_PRIMARY_WSS.to_string()), }), @@ -380,7 +380,7 @@ fn event_tag_builder_impls_build_tags_for_all_supported_types() { let job_result = RadrootsJobResult { kind: (KIND_JOB_RESULT_MIN + 1) as u16, - request_event: RadrootsNostrEventPtr { + request_event: RadrootsEventPtr { id: "req".to_string(), relays: Some(RELAY_PRIMARY_WSS.to_string()), }, @@ -405,7 +405,7 @@ fn event_tag_builder_impls_build_tags_for_all_supported_types() { kind: KIND_JOB_FEEDBACK as u16, status: JobFeedbackStatus::Processing, extra_info: Some("queued".to_string()), - request_event: RadrootsNostrEventPtr { + request_event: RadrootsEventPtr { id: "req".to_string(), relays: Some(RELAY_PRIMARY_WSS.to_string()), }, @@ -628,7 +628,7 @@ fn listing_and_message_builders_cover_optional_shapes() { relay_url: None, }], content: "hello".to_string(), - reply_to: Some(RadrootsNostrEventPtr { + reply_to: Some(RadrootsEventPtr { id: "reply".to_string(), relays: None, }), @@ -642,7 +642,7 @@ fn listing_and_message_builders_cover_optional_shapes() { relay_url: None, }], content: "hello".to_string(), - reply_to: Some(RadrootsNostrEventPtr { + reply_to: Some(RadrootsEventPtr { id: " ".to_string(), relays: None, }), diff --git a/crates/nostr/src/draft_signing.rs b/crates/nostr/src/draft_signing.rs @@ -5,12 +5,12 @@ use crate::event_convert::radroots_event_from_nostr; use crate::events::radroots_nostr_build_event; use crate::types::{RadrootsNostrKeys, RadrootsNostrTimestamp}; use nostr::JsonUtil; -use radroots_events::draft::{RadrootsFrozenEventDraft, RadrootsSignedNostrEvent}; +use radroots_events::draft::{RadrootsEventDraft, RadrootsSignedEvent}; pub fn radroots_nostr_sign_frozen_draft( keys: &RadrootsNostrKeys, - draft: &RadrootsFrozenEventDraft, -) -> Result<RadrootsSignedNostrEvent, RadrootsNostrError> { + draft: &RadrootsEventDraft, +) -> Result<RadrootsSignedEvent, RadrootsNostrError> { let actual_pubkey = keys.public_key().to_hex(); if actual_pubkey != draft.expected_pubkey { return Err(RadrootsNostrError::FrozenDraftPubkeyMismatch { @@ -33,8 +33,7 @@ pub fn radroots_nostr_sign_frozen_draft( } let raw_json = event.as_json(); - RadrootsSignedNostrEvent::from_event(radroots_event_from_nostr(&event), raw_json) - .map_err(Into::into) + RadrootsSignedEvent::from_event(radroots_event_from_nostr(&event), raw_json).map_err(Into::into) } #[cfg(test)] @@ -44,7 +43,7 @@ mod tests { use crate::test_fixtures::{FIXTURE_ALICE, FIXTURE_BOB}; use crate::types::{RadrootsNostrKeys, RadrootsNostrSecretKey}; use nostr::JsonUtil; - use radroots_events::draft::RadrootsFrozenEventDraft; + use radroots_events::draft::RadrootsEventDraft; use radroots_events::kinds::KIND_POST; fn fixture_keys(secret_key_hex: &str) -> RadrootsNostrKeys { @@ -52,8 +51,8 @@ mod tests { RadrootsNostrKeys::new(secret_key) } - fn post_draft(expected_pubkey: &str) -> RadrootsFrozenEventDraft { - RadrootsFrozenEventDraft::new( + fn post_draft(expected_pubkey: &str) -> RadrootsEventDraft { + RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, 1_700_000_000, diff --git a/crates/nostr/src/event_convert.rs b/crates/nostr/src/event_convert.rs @@ -1,12 +1,12 @@ #![forbid(unsafe_code)] use crate::types::RadrootsNostrEvent as RadrootsNostrRawEvent; -use radroots_events::{RadrootsNostrEvent, RadrootsNostrEventPtr}; +use radroots_events::{RadrootsEventEnvelope, RadrootsEventPtr}; use crate::util::event_created_at_u32_saturating; -pub fn radroots_event_from_nostr(event: &RadrootsNostrRawEvent) -> RadrootsNostrEvent { - RadrootsNostrEvent { +pub fn radroots_event_from_nostr(event: &RadrootsNostrRawEvent) -> RadrootsEventEnvelope { + RadrootsEventEnvelope { id: event.id.to_string(), author: event.pubkey.to_string(), created_at: event_created_at_u32_saturating(event), @@ -17,8 +17,8 @@ pub fn radroots_event_from_nostr(event: &RadrootsNostrRawEvent) -> RadrootsNostr } } -pub fn radroots_event_ptr_from_nostr(event: &RadrootsNostrRawEvent) -> RadrootsNostrEventPtr { - RadrootsNostrEventPtr { +pub fn radroots_event_ptr_from_nostr(event: &RadrootsNostrRawEvent) -> RadrootsEventPtr { + RadrootsEventPtr { id: event.id.to_string(), relays: None, } diff --git a/crates/nostr/src/event_verify.rs b/crates/nostr/src/event_verify.rs @@ -8,7 +8,7 @@ use crate::types::{ RadrootsNostrPublicKey, RadrootsNostrTag, RadrootsNostrTimestamp, }; use nostr::secp256k1::schnorr::Signature; -use radroots_events::RadrootsNostrEvent; +use radroots_events::RadrootsEventEnvelope; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum RadrootsNostrEventVerification { @@ -19,7 +19,9 @@ pub enum RadrootsNostrEventVerification { MalformedEnvelope, } -pub fn radroots_nostr_verify_event(event: &RadrootsNostrEvent) -> RadrootsNostrEventVerification { +pub fn radroots_nostr_verify_event( + event: &RadrootsEventEnvelope, +) -> RadrootsNostrEventVerification { let Some(raw_event) = raw_event_from_radroots(event) else { return RadrootsNostrEventVerification::MalformedEnvelope; }; @@ -33,7 +35,7 @@ pub fn radroots_nostr_verify_event(event: &RadrootsNostrEvent) -> RadrootsNostrE } pub fn radroots_nostr_verify_event_id( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> RadrootsNostrEventVerification { let Some(raw_event) = raw_event_from_radroots(event) else { return RadrootsNostrEventVerification::MalformedEnvelope; @@ -45,7 +47,7 @@ pub fn radroots_nostr_verify_event_id( } } -fn raw_event_from_radroots(event: &RadrootsNostrEvent) -> Option<RadrootsNostrRawEvent> { +fn raw_event_from_radroots(event: &RadrootsEventEnvelope) -> Option<RadrootsNostrRawEvent> { let id = RadrootsNostrEventId::from_hex(event.id.as_str()).ok()?; let public_key = RadrootsNostrPublicKey::from_hex(event.author.as_str()).ok()?; let kind_u16 = u16::try_from(event.kind).ok()?; @@ -80,7 +82,7 @@ mod tests { RadrootsNostrKeys::new(secret_key) } - fn signed_event() -> RadrootsNostrEvent { + fn signed_event() -> RadrootsEventEnvelope { let raw_event = radroots_nostr_build_event( KIND_POST, "hello", diff --git a/crates/outbox/src/model.rs b/crates/outbox/src/model.rs @@ -1,7 +1,7 @@ #![forbid(unsafe_code)] use crate::RadrootsOutboxError; -use radroots_events::draft::{RadrootsFrozenEventDraft, RadrootsSignedNostrEvent}; +use radroots_events::draft::{RadrootsEventDraft, RadrootsSignedEvent}; use radroots_transport::{ RadrootsTransportKind, RadrootsTransportMeshScopeId, RadrootsTransportOutcomeKind, RadrootsTransportSatisfactionClass, RadrootsTransportSatisfactionPolicy, @@ -301,7 +301,7 @@ impl RadrootsOutboxDeliveryPlanInput { #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsOutboxOperationInput { pub operation_kind: String, - pub draft: RadrootsFrozenEventDraft, + pub draft: RadrootsEventDraft, pub delivery_plan: RadrootsOutboxDeliveryPlanInput, pub idempotency_key: Option<String>, pub created_at_ms: i64, @@ -310,7 +310,7 @@ pub struct RadrootsOutboxOperationInput { impl RadrootsOutboxOperationInput { pub fn new( operation_kind: impl Into<String>, - draft: RadrootsFrozenEventDraft, + draft: RadrootsEventDraft, delivery_plan: RadrootsOutboxDeliveryPlanInput, created_at_ms: i64, ) -> Self { @@ -332,8 +332,8 @@ impl RadrootsOutboxOperationInput { #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsOutboxSignedOperationInput { pub operation_kind: String, - pub draft: RadrootsFrozenEventDraft, - pub signed_event: RadrootsSignedNostrEvent, + pub draft: RadrootsEventDraft, + pub signed_event: RadrootsSignedEvent, pub delivery_plan: RadrootsOutboxDeliveryPlanInput, pub idempotency_key: Option<String>, pub event_store_inserted: bool, @@ -344,8 +344,8 @@ pub struct RadrootsOutboxSignedOperationInput { impl RadrootsOutboxSignedOperationInput { pub fn new( operation_kind: impl Into<String>, - draft: RadrootsFrozenEventDraft, - signed_event: RadrootsSignedNostrEvent, + draft: RadrootsEventDraft, + signed_event: RadrootsSignedEvent, delivery_plan: RadrootsOutboxDeliveryPlanInput, event_store_inserted: bool, event_store_ingested_at_ms: i64, @@ -410,8 +410,8 @@ pub struct RadrootsOutboxEventRecord { pub operation_id: i64, pub event_id: String, pub expected_pubkey: String, - pub draft: RadrootsFrozenEventDraft, - pub signed_event: Option<RadrootsSignedNostrEvent>, + pub draft: RadrootsEventDraft, + pub signed_event: Option<RadrootsSignedEvent>, pub raw_event_json: Option<String>, pub state: RadrootsOutboxEventState, pub attempt_count: i64, @@ -487,8 +487,8 @@ pub struct RadrootsOutboxClaimedEvent { pub state: RadrootsOutboxEventState, pub claim_token: String, pub active_delivery_plan_id: Option<i64>, - pub draft: RadrootsFrozenEventDraft, - pub signed_event: Option<RadrootsSignedNostrEvent>, + pub draft: RadrootsEventDraft, + pub signed_event: Option<RadrootsSignedEvent>, pub delivery_targets: Vec<RadrootsOutboxDeliveryTargetRecord>, } diff --git a/crates/outbox/src/store.rs b/crates/outbox/src/store.rs @@ -17,9 +17,9 @@ use radroots_event_store::{ RadrootsEventIngest, RadrootsEventStore, RadrootsTransportObservation, RadrootsTransportObservationType, }; -use radroots_events::RadrootsNostrEvent; +use radroots_events::RadrootsEventEnvelope; use radroots_events::draft::{ - RadrootsFrozenEventDraft, RadrootsSignedNostrEvent, validate_signed_nostr_event_matches_draft, + RadrootsEventDraft, RadrootsSignedEvent, validate_signed_nostr_event_matches_draft, }; use radroots_transport::{ RADROOTS_RETICULUM_PREVIEW_ENDPOINT_URI, RadrootsTransportError, RadrootsTransportKind, @@ -613,9 +613,9 @@ impl RadrootsOutbox { &self, outbox_event_id: i64, claim_token: &str, - signed_event: RadrootsSignedNostrEvent, + signed_event: RadrootsSignedEvent, now_ms: i64, - ) -> Result<RadrootsSignedNostrEvent, RadrootsOutboxError> { + ) -> Result<RadrootsSignedEvent, RadrootsOutboxError> { let mut tx = self.pool.begin().await?; let record = event_by_id_tx(&mut tx, outbox_event_id).await?; let stored = record.claim_token.as_deref(); @@ -1716,7 +1716,7 @@ async fn signed_event_lifecycle_for_plans( async fn ensure_event_signed( tx: &mut sqlx::Transaction<'_, sqlx::Sqlite>, outbox_event_id: i64, - signed_event: &RadrootsSignedNostrEvent, + signed_event: &RadrootsSignedEvent, event_store_inserted: bool, event_store_ingested_at_ms: i64, ) -> Result<(), RadrootsOutboxError> { @@ -2152,7 +2152,7 @@ fn operation_from_row( fn event_from_row( row: sqlx::sqlite::SqliteRow, ) -> Result<RadrootsOutboxEventRecord, RadrootsOutboxError> { - let draft: RadrootsFrozenEventDraft = + let draft: RadrootsEventDraft = serde_json::from_str(row.try_get::<String, _>("draft_json")?.as_str())?; let signed_event = row .try_get::<Option<String>, _>("signed_event_json")? @@ -2332,8 +2332,8 @@ fn parse_transport_outcome_kind( } } -fn event_from_signed(signed_event: &RadrootsSignedNostrEvent) -> RadrootsNostrEvent { - RadrootsNostrEvent { +fn event_from_signed(signed_event: &RadrootsSignedEvent) -> RadrootsEventEnvelope { + RadrootsEventEnvelope { id: signed_event.id.clone(), author: signed_event.pubkey.clone(), created_at: signed_event.created_at, @@ -2348,13 +2348,13 @@ fn event_from_signed(signed_event: &RadrootsSignedNostrEvent) -> RadrootsNostrEv struct OperationDigestInput<'a> { operation_kind: &'a str, expected_pubkey: &'a str, - draft: &'a RadrootsFrozenEventDraft, + draft: &'a RadrootsEventDraft, } fn operation_idempotency_digest( operation_kind: &str, expected_pubkey: &str, - draft: &RadrootsFrozenEventDraft, + draft: &RadrootsEventDraft, ) -> String { let input = OperationDigestInput { operation_kind, @@ -2571,8 +2571,8 @@ mod tests { std::iter::repeat_n(character, 64).collect() } - fn post_draft(expected_pubkey: &str, content: &str) -> RadrootsFrozenEventDraft { - RadrootsFrozenEventDraft::new( + fn post_draft(expected_pubkey: &str, content: &str) -> RadrootsEventDraft { + RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, 1_700_000_000, @@ -2723,7 +2723,7 @@ mod tests { } fn operation_input( - draft: RadrootsFrozenEventDraft, + draft: RadrootsEventDraft, created_at_ms: i64, ) -> RadrootsOutboxOperationInput { RadrootsOutboxOperationInput::new( @@ -2738,8 +2738,8 @@ mod tests { } fn signed_operation_input( - draft: RadrootsFrozenEventDraft, - signed_event: RadrootsSignedNostrEvent, + draft: RadrootsEventDraft, + signed_event: RadrootsSignedEvent, created_at_ms: i64, ) -> RadrootsOutboxSignedOperationInput { RadrootsOutboxSignedOperationInput::new( diff --git a/crates/replica_sync/src/ingest.rs b/crates/replica_sync/src/ingest.rs @@ -12,7 +12,7 @@ use base64::Engine; use base64::engine::general_purpose::URL_SAFE_NO_PAD; use radroots_core::RadrootsCoreDecimal; -use radroots_events::RadrootsNostrEvent; +use radroots_events::RadrootsEventEnvelope; use radroots_events::event_head::{ RadrootsCurrentEventHead, RadrootsEventHeadCandidateResult, RadrootsEventHeadCoordinate, RadrootsEventHeadDecision as ProtocolEventHeadDecision, event_head_candidate_for_event, @@ -154,14 +154,14 @@ impl RadrootsReplicaIdFactory for RadrootsReplicaDefaultIdFactory { #[cfg(feature = "std")] pub fn radroots_replica_ingest_event( exec: &dyn SqlExecutor, - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsReplicaIngestOutcome, RadrootsReplicaEventsError> { radroots_replica_ingest_event_with_factory(exec, event, &RadrootsReplicaDefaultIdFactory) } pub fn radroots_replica_ingest_event_with_factory( exec: &dyn SqlExecutor, - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, factory: &dyn RadrootsReplicaIdFactory, ) -> Result<RadrootsReplicaIngestOutcome, RadrootsReplicaEventsError> { if let Err(err) = exec.begin() { @@ -188,7 +188,7 @@ pub fn radroots_replica_ingest_event_with_factory( fn ingest_event_inner( exec: &dyn SqlExecutor, - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, factory: &dyn RadrootsReplicaIdFactory, ) -> Result<RadrootsReplicaIngestOutcome, RadrootsReplicaEventsError> { match event.kind { @@ -206,7 +206,7 @@ fn ingest_event_inner( fn ingest_profile_event( exec: &dyn SqlExecutor, - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsReplicaIngestOutcome, RadrootsReplicaEventsError> { let data_result = profile_decode::data_from_event( event.id.clone(), @@ -297,7 +297,7 @@ fn ingest_profile_event( fn ingest_farm_event( exec: &dyn SqlExecutor, - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, _factory: &dyn RadrootsReplicaIdFactory, ) -> Result<RadrootsReplicaIngestOutcome, RadrootsReplicaEventsError> { let farm = farm_decode::farm_from_event(event.kind, &event.tags, &event.content)?; @@ -380,7 +380,7 @@ fn ingest_farm_event( fn ingest_plot_event( exec: &dyn SqlExecutor, - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, factory: &dyn RadrootsReplicaIdFactory, ) -> Result<RadrootsReplicaIngestOutcome, RadrootsReplicaEventsError> { let plot = plot_decode::plot_from_event(event.kind, &event.tags, &event.content)?; @@ -456,7 +456,7 @@ fn ingest_plot_event( fn ingest_listing_event( exec: &dyn SqlExecutor, - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsReplicaIngestOutcome, RadrootsReplicaEventsError> { let listing = listing_decode::listing_from_event(event.kind, &event.tags, &event.content)?; let decision = event_head_decision(exec, event)?; @@ -478,7 +478,7 @@ fn ingest_listing_event( fn ingest_list_set_event( exec: &dyn SqlExecutor, - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsReplicaIngestOutcome, RadrootsReplicaEventsError> { if event.kind != radroots_events::kinds::KIND_LIST_SET_GENERIC { return Ok(RadrootsReplicaIngestOutcome::Skipped); @@ -539,7 +539,7 @@ fn ingest_list_set_event( )) } -fn listing_event_addr(event: &RadrootsNostrEvent, listing: &RadrootsListing) -> String { +fn listing_event_addr(event: &RadrootsEventEnvelope, listing: &RadrootsListing) -> String { format!("{}:{}:{}", event.kind, event.author, listing.d_tag) } @@ -819,7 +819,7 @@ fn trade_product_partial_from_fields(fields: &ITradeProductFields) -> ITradeProd pub fn radroots_replica_ingest_event_head( exec: &dyn SqlExecutor, - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsReplicaIngestOutcome, RadrootsReplicaEventsError> { let decision = event_head_decision(exec, event)?; if !decision.apply { @@ -882,7 +882,7 @@ fn upsert_event_head( fn event_head_decision( exec: &dyn SqlExecutor, - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<EventHeadDecision, RadrootsReplicaEventsError> { let candidate_result = match event_head_candidate_for_event(event) { Ok(candidate) => candidate, @@ -1726,7 +1726,7 @@ mod tests { created_at: u32, profile_type: Option<RadrootsProfileType>, name: &str, - ) -> RadrootsNostrEvent { + ) -> RadrootsEventEnvelope { let profile = RadrootsProfile { name: name.to_string(), display_name: Some(format!("{name}-display")), @@ -1746,7 +1746,7 @@ mod tests { radroots_profile_type_tag_value(profile_type).to_string(), ]); } - RadrootsNostrEvent { + RadrootsEventEnvelope { id: format!("{id:064x}"), author: author.to_string(), created_at, @@ -1765,7 +1765,7 @@ mod tests { name: &str, location: Option<RadrootsFarmPublicLocation>, tags: Option<Vec<String>>, - ) -> RadrootsNostrEvent { + ) -> RadrootsEventEnvelope { let farm = RadrootsFarm { d_tag: d_tag.to_string(), name: name.to_string(), @@ -1777,7 +1777,7 @@ mod tests { tags, }; let tags = farm_encode::farm_build_tags(&farm).expect("farm tags"); - RadrootsNostrEvent { + RadrootsEventEnvelope { id: format!("{id:064x}"), author: author.to_string(), created_at, @@ -1798,7 +1798,7 @@ mod tests { name: &str, location: Option<RadrootsPlotLocation>, tags: Option<Vec<String>>, - ) -> RadrootsNostrEvent { + ) -> RadrootsEventEnvelope { let plot = RadrootsPlot { d_tag: d_tag.to_string(), farm: farm_ref, @@ -1808,7 +1808,7 @@ mod tests { tags, }; let tags = plot_encode::plot_build_tags(&plot).expect("plot tags"); - RadrootsNostrEvent { + RadrootsEventEnvelope { id: format!("{id:064x}"), author: author.to_string(), created_at, @@ -1825,9 +1825,9 @@ mod tests { created_at: u32, kind: u32, list_set: &RadrootsListSet, - ) -> RadrootsNostrEvent { + ) -> RadrootsEventEnvelope { let parts = list_set_encode::to_wire_parts_with_kind(list_set, kind).expect("list set"); - RadrootsNostrEvent { + RadrootsEventEnvelope { id: format!("{id:064x}"), author: author.to_string(), created_at, @@ -1845,9 +1845,9 @@ mod tests { d_tag: &str, status: &str, title: &str, - ) -> RadrootsNostrEvent { + ) -> RadrootsEventEnvelope { let farm_d_tag = "AAAAAAAAAAAAAAAAAAAAAA"; - RadrootsNostrEvent { + RadrootsEventEnvelope { id: format!("{id:064x}"), author: author.to_string(), created_at, @@ -2132,7 +2132,7 @@ mod tests { commit_err: None, rollback_count: Arc::new(AtomicUsize::new(0)), }; - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: format!("{:064x}", 1u64), author: "a".repeat(64), created_at: 1, @@ -2180,7 +2180,7 @@ mod tests { commit_err: None, rollback_count: Arc::new(AtomicUsize::new(0)), }; - let unsupported = RadrootsNostrEvent { + let unsupported = RadrootsEventEnvelope { id: format!("{:064x}", 2u64), author: "a".repeat(64), created_at: 2, diff --git a/crates/replica_sync/tests/ingest_roundtrip.rs b/crates/replica_sync/tests/ingest_roundtrip.rs @@ -1,4 +1,4 @@ -use radroots_events::RadrootsNostrEvent; +use radroots_events::RadrootsEventEnvelope; use radroots_events::farm::{RadrootsFarm, RadrootsFarmPublicLocation, RadrootsFarmRef}; use radroots_events::gcs::{RadrootsGcsLocation, RadrootsGeoJsonPoint, RadrootsGeoJsonPolygon}; use radroots_events::kinds::{ @@ -183,8 +183,8 @@ fn unwrap_sql_panics_on_error() { assert!(result.is_err()); } -fn draft_to_event(draft: &RadrootsReplicaEventDraft, index: u32) -> RadrootsNostrEvent { - RadrootsNostrEvent { +fn draft_to_event(draft: &RadrootsReplicaEventDraft, index: u32) -> RadrootsEventEnvelope { + RadrootsEventEnvelope { id: format!("{:064x}", index as u64 + 1), author: draft.author.clone(), created_at: 1_720_000_000 + index, @@ -551,7 +551,7 @@ fn sync_all_selector_and_options_paths_are_supported() { fn ingest_rejects_unsupported_kind() { let exec = SqliteExecutor::open_memory().expect("db"); migrations::run_all_up(&exec).expect("migrations"); - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: format!("{:064x}", 1u64), author: "a".repeat(64), created_at: 1_720_000_001, @@ -773,7 +773,7 @@ fn ingest_reports_query_fail_paths_for_profile_farm_plot_and_list_sets() { let exec = SqliteExecutor::open_memory().expect("db"); migrations::run_all_up(&exec).expect("migrations"); - let assert_query_fail = |needle: &'static str, event: &RadrootsNostrEvent| { + let assert_query_fail = |needle: &'static str, event: &RadrootsEventEnvelope| { let fail = QueryFailExecutor { inner: &exec, needle, @@ -922,8 +922,8 @@ fn event_with_parts( kind: u32, content: String, tags: Vec<Vec<String>>, -) -> RadrootsNostrEvent { - RadrootsNostrEvent { +) -> RadrootsEventEnvelope { + RadrootsEventEnvelope { id: format!("{id:064x}"), author: author.to_string(), created_at, @@ -983,7 +983,7 @@ fn profile_event( created_at: u32, profile_type: Option<RadrootsProfileType>, name: &str, -) -> RadrootsNostrEvent { +) -> RadrootsEventEnvelope { let profile = RadrootsProfile { name: name.to_string(), display_name: Some(format!("{name}_display")), @@ -1021,7 +1021,7 @@ fn farm_event( name: &str, location: Option<RadrootsFarmPublicLocation>, tags: Option<Vec<String>>, -) -> RadrootsNostrEvent { +) -> RadrootsEventEnvelope { let farm = RadrootsFarm { d_tag: d_tag.to_string(), name: name.to_string(), @@ -1053,7 +1053,7 @@ fn plot_event( name: &str, location: Option<RadrootsPlotLocation>, tags: Option<Vec<String>>, -) -> RadrootsNostrEvent { +) -> RadrootsEventEnvelope { let plot = RadrootsPlot { d_tag: d_tag.to_string(), farm: farm_ref, @@ -1079,7 +1079,7 @@ fn list_set_event( created_at: u32, kind: u32, list_set: &RadrootsListSet, -) -> RadrootsNostrEvent { +) -> RadrootsEventEnvelope { let parts = list_set_encode::to_wire_parts_with_kind(list_set, kind).expect("list set parts"); event_with_parts(id, author, created_at, kind, parts.content, parts.tags) } diff --git a/crates/runtime/src/transport.rs b/crates/runtime/src/transport.rs @@ -3,7 +3,7 @@ use std::future::Future; use std::pin::Pin; use std::sync::Arc; -use radroots_events::draft::RadrootsSignedNostrEvent; +use radroots_events::draft::RadrootsSignedEvent; #[cfg(feature = "transport-workers")] use radroots_transport::RadrootsTransportTargetReceipt; use radroots_transport::{ @@ -56,7 +56,7 @@ impl From<RadrootsTransportError> for RadrootsRuntimeTransportError { #[derive(Clone, Debug, PartialEq, Eq)] pub enum RadrootsRuntimeTransportPayload { - SignedNostrEvent(RadrootsSignedNostrEvent), + SignedNostrEvent(RadrootsSignedEvent), DigestOnly(String), } @@ -546,7 +546,7 @@ pub struct RadrootsRuntimeInboundObservation { #[cfg(feature = "transport-workers")] impl RadrootsRuntimeInboundObservation { pub fn verified_signed_event( - event: &RadrootsSignedNostrEvent, + event: &RadrootsSignedEvent, transport_kind: RadrootsTransportKind, endpoint_uri: impl Into<String>, observed_at_ms: i64, @@ -562,7 +562,7 @@ impl RadrootsRuntimeInboundObservation { pub fn require_verified_for_signed_event( &self, - event: &RadrootsSignedNostrEvent, + event: &RadrootsSignedEvent, ) -> Result<(), RadrootsRuntimeTransportError> { if !self.verified { return Err( @@ -587,7 +587,7 @@ impl RadrootsRuntimeInboundObservation { pub trait RadrootsRuntimeInboundObservationSink: Send + Sync { fn record_verified_observation<'a>( &'a self, - event: RadrootsSignedNostrEvent, + event: RadrootsSignedEvent, observation: RadrootsRuntimeInboundObservation, ) -> RadrootsRuntimeTransportFuture<'a, ()>; } @@ -595,7 +595,7 @@ pub trait RadrootsRuntimeInboundObservationSink: Send + Sync { #[cfg(feature = "transport-workers")] pub fn record_verified_inbound_observation<'a, S>( sink: &'a S, - event: RadrootsSignedNostrEvent, + event: RadrootsSignedEvent, observation: RadrootsRuntimeInboundObservation, ) -> RadrootsRuntimeTransportFuture<'a, ()> where @@ -623,7 +623,7 @@ mod tests { RadrootsRuntimeLeaseRecord, record_verified_inbound_observation, recover_expired_leases, }; #[cfg(feature = "transport-workers")] - use radroots_events::draft::{RadrootsSignedNostrEvent, RadrootsSignedNostrEventParts}; + use radroots_events::draft::{RadrootsSignedEvent, RadrootsSignedEventParts}; use radroots_transport::{ RadrootsTransport, RadrootsTransportDeliveryReceipt, RadrootsTransportDeliveryRequest, RadrootsTransportDeliveryTargetStatus, RadrootsTransportFetchReceipt, @@ -709,8 +709,8 @@ mod tests { } #[cfg(feature = "transport-workers")] - fn signed_event() -> RadrootsSignedNostrEvent { - RadrootsSignedNostrEvent::new(RadrootsSignedNostrEventParts { + fn signed_event() -> RadrootsSignedEvent { + RadrootsSignedEvent::new(RadrootsSignedEventParts { id: "d".repeat(64), pubkey: "e".repeat(64), created_at: 10, @@ -732,7 +732,7 @@ mod tests { impl RadrootsRuntimeInboundObservationSink for RecordingInboundSink { fn record_verified_observation<'a>( &'a self, - event: RadrootsSignedNostrEvent, + event: RadrootsSignedEvent, observation: RadrootsRuntimeInboundObservation, ) -> RadrootsRuntimeTransportFuture<'a, ()> { Box::pin(async move { diff --git a/crates/sp1_host_trade/src/lib.rs b/crates/sp1_host_trade/src/lib.rs @@ -1748,7 +1748,7 @@ mod tests { verify_order_acceptance_proof_artifact_structure, }; use base64::Engine; - use radroots_events::{RadrootsNostrEvent, kinds::KIND_TRADE_VALIDATION_RECEIPT}; + use radroots_events::{RadrootsEventEnvelope, kinds::KIND_TRADE_VALIDATION_RECEIPT}; use radroots_sp1_guest_trade::{ RADROOTS_SP1_TRADE_KIND_LISTING, RADROOTS_SP1_TRADE_KIND_ORDER_DECISION, RADROOTS_SP1_TRADE_KIND_ORDER_REQUEST, RADROOTS_SP1_TRADE_ORDER_ACCEPTANCE_PROOF_TARGET, @@ -2488,7 +2488,7 @@ mod tests { ); let parts = validation_receipt_event_build("order-1", &receipt).expect("event parts"); - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd".to_string(), author: "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" .to_string(), diff --git a/crates/test_fixtures/src/knowledge.rs b/crates/test_fixtures/src/knowledge.rs @@ -1,4 +1,4 @@ -use radroots_events::RadrootsNostrEventRef; +use radroots_events::RadrootsEventRef; use radroots_events::kinds::{ KIND_CONTRIBUTION_ATTESTATION, KIND_EVIDENCE_BOUNTY, KIND_FILE_METADATA, KIND_KNOWLEDGE_CHANGE_PROPOSAL, KIND_KNOWLEDGE_CLAIM, KIND_KNOWLEDGE_FIELD_REPORT, @@ -140,8 +140,8 @@ pub fn hex_64(character: char) -> String { core::iter::repeat_n(character, 64).collect() } -pub fn event_ref(character: char, kind: u32) -> RadrootsNostrEventRef { - RadrootsNostrEventRef { +pub fn event_ref(character: char, kind: u32) -> RadrootsEventRef { + RadrootsEventRef { id: hex_64(character), author: hex_64('a'), kind, diff --git a/crates/trade/src/dvm.rs b/crates/trade/src/dvm.rs @@ -13,7 +13,7 @@ use std::{ }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, ids::{ RadrootsEventId, RadrootsIdParseError, RadrootsInventoryBinId, RadrootsListingAddress, RadrootsOrderId, RadrootsPublicKey, @@ -319,7 +319,7 @@ pub struct RadrootsTradeTransitionProofResultBinding { #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsTradeTransitionProofResultTags { - pub request_event: RadrootsNostrEvent, + pub request_event: RadrootsEventEnvelope, pub request_event_id: RadrootsEventId, pub customer_pubkey: RadrootsPublicKey, pub inputs: Vec<RadrootsTradeDvmInputTag>, @@ -399,7 +399,7 @@ pub fn build_transition_proof_request_tags( } pub fn parse_transition_proof_request_event( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsTradeTransitionProofRequestEnvelope, RadrootsTradeDvmError> { if event.kind != KIND_TRADE_TRANSITION_PROOF_REQUEST { return Err(RadrootsTradeDvmError::UnsupportedKind { @@ -432,7 +432,7 @@ pub fn parse_transition_proof_request_tags( } pub fn build_transition_proof_result_tags( - request_event: &RadrootsNostrEvent, + request_event: &RadrootsEventEnvelope, customer_pubkey: &RadrootsPublicKey, inputs: &[RadrootsTradeDvmInputTag], binding: &RadrootsTradeTransitionProofResultBinding, @@ -496,7 +496,7 @@ pub fn build_transition_proof_result_tags( #[cfg_attr(coverage_nightly, coverage(off))] fn serialize_request_event( - request_event: &RadrootsNostrEvent, + request_event: &RadrootsEventEnvelope, ) -> Result<String, RadrootsTradeDvmError> { serde_json::to_string(request_event).map_err(RadrootsTradeDvmError::SerializeRequestEvent) } @@ -512,7 +512,7 @@ pub fn parse_transition_proof_result_tags( }); } let request_event_json = required_tag_value(tags, RADROOTS_DVM_TAG_REQUEST)?; - let request_event: RadrootsNostrEvent = serde_json::from_str(request_event_json) + let request_event: RadrootsEventEnvelope = serde_json::from_str(request_event_json) .map_err(RadrootsTradeDvmError::InvalidRequestEvent)?; if request_event.kind != KIND_TRADE_TRANSITION_PROOF_REQUEST { return Err(RadrootsTradeDvmError::RequestEventKind { @@ -859,8 +859,8 @@ mod tests { } } - fn request_event(content: &RadrootsTradeTransitionProofRequestV1) -> RadrootsNostrEvent { - RadrootsNostrEvent { + fn request_event(content: &RadrootsTradeTransitionProofRequestV1) -> RadrootsEventEnvelope { + RadrootsEventEnvelope { id: event_id(10).into_string(), author: BUYER.to_string(), created_at: 1, diff --git a/crates/trade/src/listing/mod.rs b/crates/trade/src/listing/mod.rs @@ -6,7 +6,7 @@ pub mod price_ext; pub mod validation; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, ids::{ RadrootsAddressableCoordinateParts, RadrootsDTag, RadrootsIdParseError, RadrootsListingAddress, RadrootsPublicKey, @@ -127,7 +127,7 @@ fn ensure_public_listing_kind(kind: u32) -> Result<(), RadrootsPublicListingAddr } pub fn parse_listing_event( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsListing, ListingParseError> { if !is_listing_kind(event.kind) { return Err(ListingParseError::InvalidKind(event.kind)); @@ -143,7 +143,7 @@ mod tests { parse_public_listing_address, }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, ids::RadrootsListingAddress, kinds::{KIND_LISTING, KIND_LISTING_DRAFT, KIND_PROFILE}, order::RadrootsListingParseError, @@ -151,8 +151,8 @@ mod tests { const SELLER: &str = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; - fn listing_event() -> RadrootsNostrEvent { - RadrootsNostrEvent { + fn listing_event() -> RadrootsEventEnvelope { + RadrootsEventEnvelope { id: "event-1".into(), author: SELLER.into(), created_at: 1, @@ -188,7 +188,7 @@ mod tests { #[test] fn parse_listing_event_rejects_non_listing_kind() { - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: "event-1".into(), author: "seller".into(), created_at: 1, diff --git a/crates/trade/src/listing/mutation.rs b/crates/trade/src/listing/mutation.rs @@ -17,7 +17,7 @@ use std::string::{String, ToString}; use radroots_events::ids::RadrootsListingAddress; #[cfg(feature = "serde_json")] use radroots_events::{ - draft::{RadrootsDraftError, RadrootsFrozenEventDraft}, + draft::{RadrootsDraftError, RadrootsEventDraft}, kinds::{KIND_LISTING, KIND_LISTING_DRAFT}, }; #[cfg(feature = "serde_json")] @@ -121,7 +121,7 @@ impl RadrootsListingMutation { pub fn build_listing_mutation_draft( mutation: &RadrootsListingMutation, created_at: u32, -) -> Result<RadrootsFrozenEventDraft, RadrootsListingMutationError> { +) -> Result<RadrootsEventDraft, RadrootsListingMutationError> { let (draft, kind, contract_id) = match mutation { RadrootsListingMutation::Publish { draft } | RadrootsListingMutation::Update { draft } => { (draft, KIND_LISTING, LISTING_PUBLISHED_CONTRACT_ID) @@ -151,7 +151,7 @@ mod tests { RadrootsCoreQuantityPrice, RadrootsCoreUnit, }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, farm::RadrootsFarmRef, ids::{RadrootsDTag, RadrootsInventoryBinId, RadrootsListingAddress, RadrootsPublicKey}, kinds::{KIND_LISTING, KIND_LISTING_DRAFT}, @@ -446,7 +446,7 @@ mod tests { let publish = RadrootsListingMutation::publish(canonical_draft()); let draft = build_listing_mutation_draft(&publish, 1_700_000_000).expect("draft"); - let event = RadrootsNostrEvent { + let event = RadrootsEventEnvelope { id: String::new(), author: draft.expected_pubkey.clone(), created_at: draft.created_at, diff --git a/crates/trade/src/listing/validation.rs b/crates/trade/src/listing/validation.rs @@ -7,7 +7,7 @@ use radroots_core::{ RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreQuantity, RadrootsCoreUnit, }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, ids::RadrootsListingAddress, kinds::is_listing_kind, listing::{ @@ -42,7 +42,7 @@ pub struct RadrootsTradeListing { } pub fn validate_listing_event( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsTradeListing, TradeListingValidationError> { if !is_listing_kind(event.kind) { return Err(TradeListingValidationError::InvalidKind { kind: event.kind }); @@ -188,7 +188,7 @@ mod tests { RadrootsCoreQuantityPrice, RadrootsCoreUnit, }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, farm::RadrootsFarmRef, ids::{RadrootsDTag, RadrootsInventoryBinId}, kinds::{KIND_LISTING, KIND_LISTING_DRAFT}, @@ -270,8 +270,8 @@ mod tests { } } - fn base_event(listing: &RadrootsListing) -> RadrootsNostrEvent { - RadrootsNostrEvent { + fn base_event(listing: &RadrootsListing) -> RadrootsEventEnvelope { + RadrootsEventEnvelope { id: "evt".into(), author: SELLER.into(), created_at: 0, diff --git a/crates/trade/src/order.rs b/crates/trade/src/order.rs @@ -9,7 +9,7 @@ use alloc::{ #[cfg(feature = "event_store")] use radroots_event_store::{RadrootsEventStore, RadrootsEventStoreError, RadrootsStoredEvent}; #[cfg(feature = "serde_json")] -use radroots_events::RadrootsNostrEvent; +use radroots_events::RadrootsEventEnvelope; use radroots_events::ids::{ RadrootsEventId, RadrootsIdParseError, RadrootsInventoryBinId, RadrootsListingAddress, RadrootsOrderId, RadrootsPublicKey, @@ -167,7 +167,7 @@ pub enum RadrootsOrderEventDecodeError { #[cfg(feature = "serde_json")] pub fn order_event_record_from_event( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsOrderEventRecord, RadrootsOrderEventDecodeError> { let message_type = RadrootsOrderEventType::from_kind(event.kind) .ok_or(RadrootsOrderEventDecodeError::UnsupportedKind { kind: event.kind })?; @@ -357,14 +357,14 @@ pub async fn order_projection_query_for_trade_locator( #[cfg(feature = "event_store")] fn stored_order_event_to_nostr_event( stored_event: &RadrootsStoredEvent, -) -> Result<RadrootsNostrEvent, RadrootsOrderStoreQueryError> { +) -> Result<RadrootsEventEnvelope, RadrootsOrderStoreQueryError> { let tags = serde_json::from_str(&stored_event.tags_json).map_err(|source| { RadrootsOrderStoreQueryError::InvalidStoredTagsJson { event_id: stored_event.event_id.clone(), source, } })?; - Ok(RadrootsNostrEvent { + Ok(RadrootsEventEnvelope { id: stored_event.event_id.clone(), author: stored_event.pubkey.clone(), created_at: stored_event.created_at, @@ -2666,7 +2666,7 @@ mod tests { RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreUnit, }; use radroots_events::{ - RadrootsNostrEvent, RadrootsNostrEventPtr, + RadrootsEventEnvelope, RadrootsEventPtr, ids::{ RadrootsEventId, RadrootsInventoryBinId, RadrootsListingAddress, RadrootsOrderId, RadrootsOrderQuoteId, RadrootsOrderRevisionId, RadrootsPublicKey, @@ -2735,16 +2735,16 @@ mod tests { } #[cfg(feature = "serde_json")] - fn listing_event_ptr() -> RadrootsNostrEventPtr { - RadrootsNostrEventPtr { + fn listing_event_ptr() -> RadrootsEventPtr { + RadrootsEventPtr { id: event_id(80).into_string(), relays: Some("wss://relay.example.test".into()), } } #[cfg(feature = "serde_json")] - fn event_from_parts(raw_id: u8, author: &str, parts: WireEventParts) -> RadrootsNostrEvent { - RadrootsNostrEvent { + fn event_from_parts(raw_id: u8, author: &str, parts: WireEventParts) -> RadrootsEventEnvelope { + RadrootsEventEnvelope { id: event_id(raw_id).into_string(), author: author.into(), created_at: 1, @@ -3356,7 +3356,7 @@ mod tests { && record.payload.reason == "changed plans" )); - let unsupported = RadrootsNostrEvent { + let unsupported = RadrootsEventEnvelope { id: event_id(16).into_string(), author: BUYER.into(), created_at: 1, diff --git a/crates/trade/src/projection.rs b/crates/trade/src/projection.rs @@ -7,7 +7,7 @@ use radroots_event_store::{ RadrootsProjectionCursor, RadrootsStoredEvent, }; use radroots_events::{ - RadrootsNostrEvent, + RadrootsEventEnvelope, ids::{RadrootsEventId, RadrootsIdParseError, RadrootsListingAddress, RadrootsOrderId}, kinds::{KIND_TRADE_VALIDATION_RECEIPT, is_listing_kind, is_order_event_kind}, listing::{RadrootsListingAvailability, RadrootsListingDeliveryMethod, RadrootsListingStatus}, @@ -709,7 +709,7 @@ fn push_order_record( } fn request_listing_event_id( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<Option<RadrootsEventId>, RadrootsTradeProjectionError> { let context = order_event_context_from_tags(RadrootsOrderEventType::OrderRequested, &event.tags) @@ -752,14 +752,14 @@ async fn current_listing_event_id( fn stored_event_to_nostr_event( stored_event: &RadrootsStoredEvent, -) -> Result<RadrootsNostrEvent, RadrootsTradeProjectionError> { +) -> Result<RadrootsEventEnvelope, RadrootsTradeProjectionError> { let tags = serde_json::from_str(&stored_event.tags_json).map_err(|source| { RadrootsTradeProjectionError::InvalidStoredTagsJson { event_id: stored_event.event_id.clone(), source, } })?; - Ok(RadrootsNostrEvent { + Ok(RadrootsEventEnvelope { id: stored_event.event_id.clone(), author: stored_event.pubkey.clone(), created_at: stored_event.created_at, @@ -912,7 +912,7 @@ mod tests { RadrootsEventIngest, RadrootsTransportObservation, RadrootsTransportObservationType, }; use radroots_events::{ - RadrootsNostrEventPtr, + RadrootsEventPtr, farm::RadrootsFarmRef, ids::RadrootsOrderQuoteId, kinds::KIND_LISTING, @@ -1005,7 +1005,7 @@ mod tests { } } - fn signed_listing_event() -> RadrootsNostrEvent { + fn signed_listing_event() -> RadrootsEventEnvelope { let parts = radroots_events_codec::listing::encode::to_wire_parts(&listing()) .expect("listing parts"); sign_parts( @@ -1017,7 +1017,7 @@ mod tests { ) } - fn listing_addr(event: &RadrootsNostrEvent) -> RadrootsListingAddress { + fn listing_addr(event: &RadrootsEventEnvelope) -> RadrootsListingAddress { RadrootsListingAddress::parse(format!( "{}:{}:{}", KIND_LISTING, @@ -1056,7 +1056,7 @@ mod tests { } } - fn order_request(listing_event: &RadrootsNostrEvent) -> RadrootsOrderRequest { + fn order_request(listing_event: &RadrootsEventEnvelope) -> RadrootsOrderRequest { RadrootsOrderRequest { order_id: order_id(), listing_addr: listing_addr(listing_event), @@ -1070,16 +1070,16 @@ mod tests { } } - fn signed_order_request_event(listing_event: &RadrootsNostrEvent) -> RadrootsNostrEvent { + fn signed_order_request_event(listing_event: &RadrootsEventEnvelope) -> RadrootsEventEnvelope { signed_order_request_event_at(listing_event, 1_700_000_010) } fn signed_order_request_event_at( - listing_event: &RadrootsNostrEvent, + listing_event: &RadrootsEventEnvelope, created_at: u32, - ) -> RadrootsNostrEvent { + ) -> RadrootsEventEnvelope { let parts = order_request_event_build( - &RadrootsNostrEventPtr { + &RadrootsEventPtr { id: listing_event.id.clone(), relays: Some("wss://relay.example.test".to_owned()), }, @@ -1096,9 +1096,9 @@ mod tests { } fn signed_order_decision_event( - request: &RadrootsNostrEvent, - listing_event: &RadrootsNostrEvent, - ) -> RadrootsNostrEvent { + request: &RadrootsEventEnvelope, + listing_event: &RadrootsEventEnvelope, + ) -> RadrootsEventEnvelope { let decision = RadrootsOrderDecision { order_id: order_id(), listing_addr: listing_addr(listing_event), @@ -1123,11 +1123,11 @@ mod tests { } fn signed_receipt_event( - listing_event: &RadrootsNostrEvent, - request: &RadrootsNostrEvent, - decision: &RadrootsNostrEvent, + listing_event: &RadrootsEventEnvelope, + request: &RadrootsEventEnvelope, + decision: &RadrootsEventEnvelope, result: RadrootsValidationReceiptResult, - ) -> RadrootsNostrEvent { + ) -> RadrootsEventEnvelope { let request_id = RadrootsEventId::parse(request.id.as_str()).expect("request"); let listing_event_id = RadrootsEventId::parse(listing_event.id.as_str()).expect("listing"); let decision_id = RadrootsEventId::parse(decision.id.as_str()).expect("decision"); @@ -1182,7 +1182,7 @@ mod tests { tags: Vec<Vec<String>>, created_at: u32, keys: &RadrootsNostrKeys, - ) -> RadrootsNostrEvent { + ) -> RadrootsEventEnvelope { let raw_event = radroots_nostr_build_event(kind, content, tags) .expect("builder") .custom_created_at(RadrootsNostrTimestamp::from_secs(u64::from(created_at))) diff --git a/crates/trade/src/validation_receipt.rs b/crates/trade/src/validation_receipt.rs @@ -9,7 +9,8 @@ use alloc::{ use base64::Engine as _; use radroots_events::{ - RadrootsNostrEvent, ids::RadrootsPublicKey, kinds::KIND_TRADE_VALIDATION_RECEIPT, tags::TAG_D, + RadrootsEventEnvelope, ids::RadrootsPublicKey, kinds::KIND_TRADE_VALIDATION_RECEIPT, + tags::TAG_D, }; use radroots_events_codec::wire::WireEventParts; use serde::{Deserialize, Serialize}; @@ -574,13 +575,13 @@ pub fn validation_receipt_event_build( } pub fn validation_receipt_from_event( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, ) -> Result<RadrootsVerifiedValidationReceipt, RadrootsValidationReceiptError> { verify_validation_receipt_event(event, RadrootsValidationReceiptExpectedBinding::default()) } pub fn verify_validation_receipt_event( - event: &RadrootsNostrEvent, + event: &RadrootsEventEnvelope, expected: RadrootsValidationReceiptExpectedBinding<'_>, ) -> Result<RadrootsVerifiedValidationReceipt, RadrootsValidationReceiptError> { if event.kind != KIND_TRADE_VALIDATION_RECEIPT { @@ -863,7 +864,7 @@ mod tests { verify_validation_receipt_event, }; use radroots_events::{ - RadrootsNostrEvent, ids::RadrootsPublicKey, kinds::KIND_TRADE_VALIDATION_RECEIPT, + RadrootsEventEnvelope, ids::RadrootsPublicKey, kinds::KIND_TRADE_VALIDATION_RECEIPT, tags::TAG_D, }; @@ -919,10 +920,10 @@ mod tests { receipt } - fn sample_validation_receipt_event() -> RadrootsNostrEvent { + fn sample_validation_receipt_event() -> RadrootsEventEnvelope { let receipt = sample_validation_receipt(); let parts = validation_receipt_event_build("order-1", &receipt).expect("event parts"); - RadrootsNostrEvent { + RadrootsEventEnvelope { id: event_id('9'), author: event_id('a'), created_at: 1, diff --git a/crates/transport_nostr/src/outbox.rs b/crates/transport_nostr/src/outbox.rs @@ -9,8 +9,8 @@ use radroots_event_store::{ RadrootsEventIngest, RadrootsEventStore, RadrootsTransportObservation, RadrootsTransportObservationType, }; -use radroots_events::RadrootsNostrEvent; -use radroots_events::draft::RadrootsSignedNostrEvent; +use radroots_events::RadrootsEventEnvelope; +use radroots_events::draft::RadrootsSignedEvent; use radroots_outbox::{ RadrootsOutbox, RadrootsOutboxClaimedEvent, RadrootsOutboxDeliveryTargetRecord, RadrootsOutboxDeliveryTargetStatus, RadrootsOutboxEventStoreIngestReceipt, @@ -541,7 +541,7 @@ fn satisfaction_policy_for_required_accept_count( async fn ingest_publish_observation( event_store: &RadrootsEventStore, - signed_event: &RadrootsSignedNostrEvent, + signed_event: &RadrootsSignedEvent, relay_url: &str, message: Option<&str>, observed_at_ms: i64, @@ -563,8 +563,8 @@ async fn ingest_publish_observation( Ok(()) } -fn event_from_signed(signed_event: &RadrootsSignedNostrEvent) -> RadrootsNostrEvent { - RadrootsNostrEvent { +fn event_from_signed(signed_event: &RadrootsSignedEvent) -> RadrootsEventEnvelope { + RadrootsEventEnvelope { id: signed_event.id.clone(), author: signed_event.pubkey.clone(), created_at: signed_event.created_at, diff --git a/crates/transport_nostr/src/publish.rs b/crates/transport_nostr/src/publish.rs @@ -4,7 +4,7 @@ use crate::{RadrootsRelayOutcome, RadrootsRelayTargetSet, RadrootsRelayTransport #[cfg(feature = "client")] use core::time::Duration; use futures::future::BoxFuture; -use radroots_events::draft::RadrootsSignedNostrEvent; +use radroots_events::draft::RadrootsSignedEvent; use radroots_transport::{ RadrootsTransportKind, RadrootsTransportSatisfactionPolicy, RadrootsTransportTarget, }; @@ -24,7 +24,7 @@ const RELAY_CONNECT_TIMEOUT: Duration = Duration::from_secs(10); #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsRelayPublishRequest { - pub signed_event: RadrootsSignedNostrEvent, + pub signed_event: RadrootsSignedEvent, pub targets: RadrootsRelayTargetSet, pub satisfaction_policy: RadrootsTransportSatisfactionPolicy, pub idempotency_key: Option<String>, @@ -33,7 +33,7 @@ pub struct RadrootsRelayPublishRequest { impl RadrootsRelayPublishRequest { pub fn new( - signed_event: RadrootsSignedNostrEvent, + signed_event: RadrootsSignedEvent, targets: RadrootsRelayTargetSet, now_ms: i64, ) -> Self { @@ -386,7 +386,7 @@ impl RadrootsRelayPublishAdapter for RadrootsNostrClientPublishAdapter { #[cfg(feature = "client")] fn ensure_raw_event_matches_signed_event( event: &RadrootsNostrEvent, - signed_event: &RadrootsSignedNostrEvent, + signed_event: &RadrootsSignedEvent, ) -> Result<(), RadrootsRelayTransportError> { let mismatches = [ ("id", event.id.to_hex(), signed_event.id.clone()), @@ -432,7 +432,7 @@ fn ensure_raw_event_matches_signed_event( mod tests { use super::{RadrootsNostrEvent, ensure_raw_event_matches_signed_event}; use nostr::JsonUtil; - use radroots_events::draft::{RadrootsFrozenEventDraft, RadrootsSignedNostrEvent}; + use radroots_events::draft::{RadrootsEventDraft, RadrootsSignedEvent}; use radroots_events::kinds::KIND_POST; use radroots_nostr::prelude::{ RadrootsNostrKeys, RadrootsNostrSecretKey, radroots_nostr_sign_frozen_draft, @@ -443,11 +443,11 @@ mod tests { const FIXTURE_ALICE_PUBLIC_KEY_HEX: &str = "585591529da0bab31b3b1b1f986611cf5f435dca84f978c89ee8a40cca7103df"; - fn signed_post(content: &str) -> (RadrootsNostrEvent, RadrootsSignedNostrEvent) { + fn signed_post(content: &str) -> (RadrootsNostrEvent, RadrootsSignedEvent) { let secret_key = RadrootsNostrSecretKey::from_hex(FIXTURE_ALICE_SECRET_KEY_HEX).expect("secret key"); let keys = RadrootsNostrKeys::new(secret_key); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, 1_700_000_000, @@ -462,7 +462,7 @@ mod tests { (raw_event, signed_event) } - fn assert_mismatch(raw_event: &RadrootsNostrEvent, signed_event: RadrootsSignedNostrEvent) { + fn assert_mismatch(raw_event: &RadrootsNostrEvent, signed_event: RadrootsSignedEvent) { assert!(ensure_raw_event_matches_signed_event(raw_event, &signed_event).is_err()); } diff --git a/crates/transport_nostr/tests/transport.rs b/crates/transport_nostr/tests/transport.rs @@ -4,7 +4,7 @@ use radroots_event_store::{ RadrootsEventStore, RadrootsEventVerificationStatus, RadrootsTransportObservationRow, RadrootsTransportObservationType, }; -use radroots_events::draft::{RadrootsFrozenEventDraft, RadrootsSignedNostrEvent}; +use radroots_events::draft::{RadrootsEventDraft, RadrootsSignedEvent}; use radroots_events::kinds::KIND_POST; use radroots_nostr::prelude::{ RadrootsNostrFilter, RadrootsNostrKeys, RadrootsNostrKind, RadrootsNostrSecretKey, @@ -124,7 +124,7 @@ fn fixture_keys() -> RadrootsNostrKeys { RadrootsNostrKeys::new(secret_key) } -fn signed_post(content: &str) -> RadrootsSignedNostrEvent { +fn signed_post(content: &str) -> RadrootsSignedEvent { signed_event_with_kind_and_hashtag(content, KIND_POST, "soil") } @@ -156,8 +156,8 @@ fn signed_event_with_kind_and_hashtag( content: &str, kind: u32, hashtag: &str, -) -> RadrootsSignedNostrEvent { - let draft = RadrootsFrozenEventDraft::new( +) -> RadrootsSignedEvent { + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", kind, 1_700_000_000, @@ -185,7 +185,7 @@ async fn complete_claimed_signing( outbox: &RadrootsOutbox, claimed: &RadrootsOutboxClaimedEvent, now_ms: i64, -) -> RadrootsSignedNostrEvent { +) -> RadrootsSignedEvent { if let Some(signed_event) = claimed.signed_event.clone() { return signed_event; } @@ -217,7 +217,7 @@ fn scoped_nostr_target(relay_url: &str, scope: &str, label: &str) -> RadrootsTra } fn outbox_operation_input<I, S>( - draft: RadrootsFrozenEventDraft, + draft: RadrootsEventDraft, relays: I, satisfaction_policy: RadrootsTransportSatisfactionPolicy, ) -> RadrootsOutboxOperationInput @@ -243,7 +243,7 @@ where } fn all_accepted_outbox_operation_input<I, S>( - draft: RadrootsFrozenEventDraft, + draft: RadrootsEventDraft, relays: I, ) -> RadrootsOutboxOperationInput where @@ -1412,7 +1412,7 @@ async fn outbox_publish_persists_partial_success_and_skips_accepted_retry() { let signed = signed_post("hello"); let outbox = RadrootsOutbox::open_memory().await.expect("outbox"); let store = RadrootsEventStore::open_memory().await.expect("store"); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, signed.created_at, @@ -1552,7 +1552,7 @@ async fn outbox_publish_fans_out_endpoint_receipts_to_scoped_logical_targets() { let signed = signed_post("scoped duplicate relay"); let outbox = RadrootsOutbox::open_memory().await.expect("outbox"); let store = RadrootsEventStore::open_memory().await.expect("store"); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, signed.created_at, @@ -1666,7 +1666,7 @@ async fn outbox_publish_required_target_failure_is_not_satisfied_by_optional_suc let signed = signed_post("required target optional success"); let outbox = RadrootsOutbox::open_memory().await.expect("outbox"); let store = RadrootsEventStore::open_memory().await.expect("store"); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, signed.created_at, @@ -1769,7 +1769,7 @@ async fn outbox_publish_required_target_success_is_not_blocked_by_optional_retry let signed = signed_post("required target optional failure"); let outbox = RadrootsOutbox::open_memory().await.expect("outbox"); let store = RadrootsEventStore::open_memory().await.expect("store"); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, signed.created_at, @@ -1875,7 +1875,7 @@ async fn outbox_publish_required_targets_fan_out_same_endpoint_scoped_receipts() let signed = signed_post("required target scoped duplicate relay"); let outbox = RadrootsOutbox::open_memory().await.expect("outbox"); let store = RadrootsEventStore::open_memory().await.expect("store"); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, signed.created_at, @@ -1965,7 +1965,7 @@ async fn outbox_transport_publish_failure_releases_retryable_claim() { let signed = signed_post("adapter transport failure"); let outbox = RadrootsOutbox::open_memory().await.expect("outbox"); let store = RadrootsEventStore::open_memory().await.expect("store"); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, signed.created_at, @@ -2056,7 +2056,7 @@ async fn outbox_publish_marks_published_without_adapter_when_all_relays_already_ let signed = signed_post("already accepted"); let outbox = RadrootsOutbox::open_memory().await.expect("outbox"); let store = RadrootsEventStore::open_memory().await.expect("store"); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, signed.created_at, @@ -2145,7 +2145,7 @@ async fn outbox_publish_ignores_unknown_adapter_receipts() { let signed = signed_post("unknown receipt"); let outbox = RadrootsOutbox::open_memory().await.expect("outbox"); let store = RadrootsEventStore::open_memory().await.expect("store"); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, signed.created_at, @@ -2211,7 +2211,7 @@ async fn outbox_publish_skips_non_nostr_targets() { let signed = signed_post("mixed target"); let outbox = RadrootsOutbox::open_memory().await.expect("outbox"); let store = RadrootsEventStore::open_memory().await.expect("store"); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, signed.created_at, @@ -2289,7 +2289,7 @@ async fn outbox_publish_marks_published_when_delivery_plan_satisfaction_is_met_w let signed = signed_post("quorum"); let outbox = RadrootsOutbox::open_memory().await.expect("outbox"); let store = RadrootsEventStore::open_memory().await.expect("store"); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, signed.created_at, @@ -2394,7 +2394,7 @@ async fn outbox_publish_republishes_accepted_relays_when_policy_requests_it() { let signed = signed_post("republish accepted"); let outbox = RadrootsOutbox::open_memory().await.expect("outbox"); let store = RadrootsEventStore::open_memory().await.expect("store"); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, signed.created_at, @@ -2477,7 +2477,7 @@ async fn outbox_publish_republish_policy_keeps_terminal_targets_excluded() { let signed = signed_post("republish terminal excluded"); let outbox = RadrootsOutbox::open_memory().await.expect("outbox"); let store = RadrootsEventStore::open_memory().await.expect("store"); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, signed.created_at, @@ -2557,7 +2557,7 @@ async fn outbox_publish_requires_claimed_signed_event() { let signed = signed_post("missing signature"); let outbox = RadrootsOutbox::open_memory().await.expect("outbox"); let store = RadrootsEventStore::open_memory().await.expect("store"); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, signed.created_at, @@ -2604,7 +2604,7 @@ async fn outbox_publish_propagates_non_transport_adapter_errors_after_target_fil let signed = signed_post("adapter non transport failure"); let outbox = RadrootsOutbox::open_memory().await.expect("outbox"); let store = RadrootsEventStore::open_memory().await.expect("store"); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, signed.created_at, @@ -2661,7 +2661,7 @@ async fn outbox_publish_rejects_invalid_relay_target_uri_before_adapter_publish( let signed = signed_post("invalid relay target"); let outbox = RadrootsOutbox::open_memory().await.expect("outbox"); let store = RadrootsEventStore::open_memory().await.expect("store"); - let draft = RadrootsFrozenEventDraft::new( + let draft = RadrootsEventDraft::new( "radroots.social.post.v1", KIND_POST, signed.created_at,