examples/publish_patch.rs on Nostr: #[tokio::main] #[cfg(feature = "nostr")] async fn main() { use ...
#[tokio::main]
#[cfg(feature = "nostr")]
async fn main() {
use get_file_hash_core::publish_patch;
use nostr_sdk::Keys;
use nostr_sdk::EventId;
use std::str::FromStr;
let keys = Keys::generate();
let relay_urls = get_file_hash_core::get_relay_urls();
let d_tag = "my-awesome-repo-example";
let commit_id = "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0"; // Example commit ID
// Dummy EventId for examples that require a build_manifest_event_id
const DUMMY_BUILD_MANIFEST_ID_STR: &str = "f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0";
let dummy_build_manifest_id = EventId::from_str(DUMMY_BUILD_MANIFEST_ID_STR).unwrap();
// Example 1: Without build_manifest_event_id
println!("Publishing patch without build_manifest_event_id...");
publish_patch!(
&keys,
&relay_urls,
d_tag,
commit_id,
"../Cargo.toml" // Use an existing file for the patch content
);
println!("Patch without build_manifest_event_id published.");
// Example 2: With build_manifest_event_id
println!("Publishing patch with build_manifest_event_id...");
publish_patch!(
&keys,
&relay_urls,
d_tag,
commit_id,
"../Cargo.toml", // Use an existing file for the patch content
Some(&dummy_build_manifest_id)
);
println!("Patch with build_manifest_event_id published.");
}
#[cfg(not(feature = "nostr"))]
fn main() {
println!("This example requires the 'nostr' feature. Please run with: cargo run --example publish_patch --features nostr");
}
Published at
2026-04-01 23:00:09 UTCEvent JSON
{
"id": "e78cd3ad2f9934e966f4386302c528b36a7d4daf5de3b98c0f447f44ee4f9bb6",
"pubkey": "06793393cdc9e0ed4d426aa6f5d26f2b22600d48243d5f1af091b4b590e29b4a",
"created_at": 1775084409,
"kind": 1,
"tags": [
[
"file",
"examples/publish_patch.rs"
],
[
"version",
"0.1.8"
]
],
"content": "#[tokio::main]\n#[cfg(feature = \"nostr\")]\nasync fn main() {\n use get_file_hash_core::publish_patch;\n use nostr_sdk::Keys;\n use nostr_sdk::EventId;\n use std::str::FromStr;\n\n let keys = Keys::generate();\n let relay_urls = get_file_hash_core::get_relay_urls();\n let d_tag = \"my-awesome-repo-example\";\n let commit_id = \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0\"; // Example commit ID\n\n // Dummy EventId for examples that require a build_manifest_event_id\n const DUMMY_BUILD_MANIFEST_ID_STR: \u0026str = \"f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0\";\n let dummy_build_manifest_id = EventId::from_str(DUMMY_BUILD_MANIFEST_ID_STR).unwrap();\n\n // Example 1: Without build_manifest_event_id\n println!(\"Publishing patch without build_manifest_event_id...\");\n publish_patch!(\n \u0026keys,\n \u0026relay_urls,\n d_tag,\n commit_id,\n \"../Cargo.toml\" // Use an existing file for the patch content\n );\n println!(\"Patch without build_manifest_event_id published.\");\n\n // Example 2: With build_manifest_event_id\n println!(\"Publishing patch with build_manifest_event_id...\");\n publish_patch!(\n \u0026keys,\n \u0026relay_urls,\n d_tag,\n commit_id,\n \"../Cargo.toml\", // Use an existing file for the patch content\n Some(\u0026dummy_build_manifest_id)\n );\n println!(\"Patch with build_manifest_event_id published.\");\n}\n\n#[cfg(not(feature = \"nostr\"))]\nfn main() {\n println!(\"This example requires the 'nostr' feature. Please run with: cargo run --example publish_patch --features nostr\");\n}\n",
"sig": "f2b25908dc0321fa69aca74c6697ca7969b296c5a03b00058ed45f4e3c34b7bfe128a18aa869140bec283796a3b19cd8d8def5c5d47b6b153c863c564b3d90ce"
}