Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lnurl tag #87

Merged
merged 1 commit into from Apr 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions crates/nostr/src/event/tag.rs
Expand Up @@ -186,6 +186,8 @@ pub enum TagKind {
Relays,
/// Amount (NIP57)
Amount,
/// Lnurl (NIP57)
Lnurl,
/// Custom tag kind
Custom(String),
}
Expand Down Expand Up @@ -216,6 +218,7 @@ impl fmt::Display for TagKind {
Self::Preimage => write!(f, "preimage"),
Self::Relays => write!(f, "relays"),
Self::Amount => write!(f, "amount"),
Self::Lnurl => write!(f, "lnurl"),
Self::Custom(tag) => write!(f, "{tag}"),
}
}
Expand Down Expand Up @@ -251,6 +254,7 @@ where
"preimage" => Self::Preimage,
"relays" => Self::Relays,
"amount" => Self::Amount,
"lnurl" => Self::Lnurl,
tag => Self::Custom(tag.to_string()),
}
}
Expand Down Expand Up @@ -337,6 +341,7 @@ pub enum Tag {
Preimage(String),
Relays(Vec<UncheckedUrl>),
Amount(u64),
Lnurl(String),
0xtrr marked this conversation as resolved.
Show resolved Hide resolved
PublishedAt(Timestamp),
}

Expand Down Expand Up @@ -385,6 +390,7 @@ impl Tag {
Tag::Preimage(..) => TagKind::Preimage,
Tag::Relays(..) => TagKind::Relays,
Tag::Amount(..) => TagKind::Amount,
Tag::Lnurl(..) => TagKind::Lnurl,
}
}
}
Expand Down Expand Up @@ -442,6 +448,7 @@ where
TagKind::Bolt11 => Ok(Self::Bolt11(content.to_string())),
TagKind::Preimage => Ok(Self::Preimage(content.to_string())),
TagKind::Amount => Ok(Self::Amount(content.parse()?)),
TagKind::Lnurl => Ok(Self::Lnurl(content.to_string())),
_ => Ok(Self::Generic(tag_kind, vec![content.to_string()])),
}
} else if tag_len == 3 {
Expand Down Expand Up @@ -627,6 +634,9 @@ impl From<Tag> for Vec<String> {
Tag::Amount(amount) => {
vec![TagKind::Amount.to_string(), amount.to_string()]
}
Tag::Lnurl(lnurl) => {
vec![TagKind::Lnurl.to_string(), lnurl]
}
}
}
}
Expand Down Expand Up @@ -921,6 +931,11 @@ mod tests {
.as_vec()
);

assert_eq!(
vec!["lnurl", "https://lnurltest.com/lnurl/payreq/1337"],
Tag::Lnurl(String::from("https://lnurltest.com/lnurl/payreq/1337")).as_vec(),
);

Ok(())
}

Expand Down