node: The node instance for receiving notifications
api: The API interface for interacting with the network
MemoryManager is only for testing. For production, implement a persistent database using the DatabaseManager trait.
5
Create a Governance Subject
Every TAPLE network needs at least one governance subject:
// Create a minimal governance// First, add a key for the governancelet governance_key = api .add_keys(KeyDerivator::Ed25519) .await .expect("Error getting server response");// Compose the subject creation requestlet create_subject_request = EventRequest::Create(StartRequest { governance_id: DigestIdentifier::default(), name: "".to_string(), namespace: "".to_string(), schema_id: "governance".to_string(), public_key: governance_key,});
6
Sign and Submit the Request
Sign the request with your node’s private key:
// Create signed requestlet signed_request = Signed::<EventRequest> { content: create_subject_request.clone(), signature: Signature::new( &create_subject_request, &node_key_pair ).unwrap(),};// Send the signed request to the nodelet _request_id = api .external_request(signed_request) .await .unwrap();
7
Receive Event Notifications
Wait for the event to be processed:
// Wait until event notificationlet subject_id = if let Notification::NewEvent { sn: _, subject_id } = node.recv_notification() .await .expect("NewEvent notification received") { subject_id} else { panic!("Unexpected notification");};println!("Governance created with ID: {}", subject_id);
8
Query Subject Data
Retrieve the created subject:
// Get the new subject datalet subject = api .get_subject(DigestIdentifier::from_str(&subject_id).unwrap()) .await .unwrap_or_else(|_| panic!("Error getting subject"));println!("Subject ID: {}", subject.subject_id.to_str());println!("Subject SN: {}", subject.sn);
9
Graceful Shutdown
Always shut down the node gracefully:
// Shutdown the nodenode.shutdown_gracefully().await;
Make sure you’re using the same key pair for both signing and verification. The node key pair should be consistent with the settings.
Timeout waiting for notifications
Ensure your async runtime is configured correctly and the node is running. The notification channel may be blocked if the node hasn’t started processing.