Skip to content

Commit 5ba20ba

Browse files
committed
fix(doc-sync): import GuestSyncChannel trait and clarify PR #691 comment
Fix compilation error and clarify that publishing to PubSub works now; PR #691 is only needed to route incoming messages to event handlers.
1 parent ffdfa6f commit 5ba20ba

File tree

1 file changed

+9
-71
lines changed
  • hermes/apps/athena/modules/doc-sync/src

1 file changed

+9
-71
lines changed

hermes/apps/athena/modules/doc-sync/src/lib.rs

Lines changed: 9 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -380,84 +380,22 @@ fn json_response(
380380
}))
381381
}
382382

383-
/// # Document Sync Channel API
383+
/// Simple API for posting documents to IPFS PubSub.
384384
///
385-
/// Simple interface for posting documents to IPFS PubSub channels.
385+
/// Usage: `let cid = channel::post(document_bytes)?;`
386386
///
387-
/// ## ⚠️ IMPORTANT: Requires PR #691 for Full Functionality
387+
/// This publishes a document through the 4-step workflow: add to IPFS, pin, validate, publish to PubSub.
388388
///
389-
/// This module demonstrates the **publishing** side of doc-sync. The **subscribing**
390-
/// side (receiving documents) requires **PR #691** to route PubSub messages to the
391-
/// `on_new_doc` event handler.
392-
///
393-
/// ## Complete Pub/Sub Flow (with PR #691):
394-
///
395-
/// ### 1. Subscribe to Receive Documents (App B):
396-
/// ```rust,ignore
397-
/// // In your init() function:
398-
/// fn init() -> bool {
399-
/// let _channel = SyncChannel::new("documents");
400-
/// // → Subscribes to PubSub topic "doc-sync/documents"
401-
/// // → With PR #691: Host registers this as DocSync subscription
402-
/// // → Without PR #691: Subscription succeeds but no events triggered
403-
/// true
404-
/// }
405-
/// ```
406-
///
407-
/// ### 2. Publish a Document (App A or via curl):
408-
/// ```rust,ignore
409-
/// // From code:
410-
/// let cid = channel::post(b"Hello, IPFS!")?;
411-
///
412-
/// // From curl:
413-
/// // curl -X POST http://localhost:5000/api/doc-sync/post \
414-
/// // -H "Host: athena.hermes.local" -d "Hello, IPFS!"
415-
/// ```
416-
///
417-
/// ### 3. Receive the Document (App B - **REQUIRES PR #691**):
418-
/// ```rust,ignore
419-
/// // This handler is automatically called when a document arrives:
420-
/// fn on_new_doc(channel: ChannelName, doc: DocData) {
421-
/// // channel = "documents"
422-
/// // doc = b"Hello, IPFS!"
423-
/// println!("Received: {}", String::from_utf8_lossy(&doc));
424-
/// }
425-
/// ```
426-
///
427-
/// ## What PR #691 Adds:
428-
/// 1. **SubscriptionKind::DocSync** - Distinguishes doc-sync from regular subscriptions
429-
/// 2. **doc_sync_topic_message_handler()** - Routes messages with "doc-sync/" prefix
430-
/// 3. **OnNewDocEvent** - Event struct dispatched to subscribers
431-
/// 4. **Message validation** - Optional CatalystSignedDocument checks
432-
/// 5. **Event dispatch** - Triggers `on_new_doc` on all subscribed modules
433-
///
434-
/// ## Current Status:
435-
/// - ✅ Publishing works (this module)
436-
/// - ✅ Subscription registration works
437-
/// - ⏳ Event routing (needs PR #691)
438-
/// - ⏳ Message delivery to subscribers (needs PR #691)
389+
/// **Note:** Publishing to PubSub works now. PR #691 is needed to route incoming PubSub messages
390+
/// to the `on_new_doc` event handler. Without it, documents are published but subscribers don't
391+
/// receive events. See module docs for the complete pub/sub flow.
439392
pub mod channel {
440393
use super::*;
394+
use exports::hermes::doc_sync::api::GuestSyncChannel;
441395

442-
/// Posts a document to the default "documents" channel.
443-
///
444-
/// This executes the full 4-step workflow:
445-
/// 1. Add to IPFS → Get CID
446-
/// 2. Pin document → Ensure persistence
447-
/// 3. Pre-publish (TODO #630)
448-
/// 4. Publish to PubSub → Notify subscribers (needs PR #691 to trigger events)
396+
/// Post a document to the "documents" channel.
449397
///
450-
/// ## Example:
451-
/// ```rust,ignore
452-
/// match channel::post(b"Hello, world!".to_vec()) {
453-
/// Ok(cid) => println!("Published: {}", String::from_utf8_lossy(&cid)),
454-
/// Err(e) => eprintln!("Error: {:?}", e),
455-
/// }
456-
/// ```
457-
///
458-
/// ## Returns:
459-
/// - `Ok(cid)`: Document CID as bytes (e.g., "bafkreib...")
460-
/// - `Err(errno)`: If add/pin/publish fails
398+
/// Returns the document's CID on success.
461399
pub fn post(document_bytes: DocData) -> Result<Vec<u8>, exports::hermes::doc_sync::api::Errno> {
462400
let channel = SyncChannelImpl {
463401
name: "documents".to_string(),

0 commit comments

Comments
 (0)