-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
74 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use anyhow::{bail, Context, Result}; | ||
use nostr_sdk::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt::Debug; | ||
|
||
//Newtype | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct GiftWrap(Event); | ||
impl GiftWrap { | ||
pub fn new(event: Event) -> Self { | ||
GiftWrap(event) | ||
} | ||
|
||
pub fn extract_report_request(&self, keys: &Keys) -> Result<ReportRequest> { | ||
let unwrapped_gift = self.extract_rumor(keys)?; | ||
let report_request = serde_json::from_str::<ReportRequest>(&unwrapped_gift.rumor.content) | ||
.context("Failed to parse report request")?; | ||
|
||
if !report_request.valid() { | ||
bail!("Invalid report request"); | ||
} | ||
|
||
Ok(report_request) | ||
} | ||
|
||
fn extract_rumor(&self, keys: &Keys) -> Result<UnwrappedGift> { | ||
extract_rumor(keys, &self.0).context("Couldn't extract rumor") | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ReportRequest { | ||
pub reported_event: Event, | ||
pub reporter_pubkey: PublicKey, | ||
pub reporter_text: Option<String>, | ||
} | ||
|
||
impl ReportRequest { | ||
pub fn as_json(&self) -> String { | ||
serde_json::to_string(self).expect("Failed to serialize ReportRequest to JSON") | ||
} | ||
|
||
pub fn valid(&self) -> bool { | ||
self.reported_event.verify().is_ok() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod actors; | ||
pub mod domain_objects; | ||
pub mod service_manager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters