Skip to content

Commit 2ebd82a

Browse files
author
nostronaut
committed
mmr: add mmr feature
1 parent 3daeb11 commit 2ebd82a

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

crates/nostr/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ nip19 = ["dep:bech32"]
2525
nip21 = ["nip19"]
2626
nip46 = ["nip04"]
2727
nip47 = ["nip04"]
28+
mmr = []
2829

2930
[dependencies]
3031
aes = { version = "0.8", optional = true }

crates/nostr/src/event/builder.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
//! Event builder
55
6-
use core::fmt;
7-
#[cfg(not(target_arch = "wasm32"))]
8-
use std::time::Instant;
9-
6+
#[cfg(feature = "mmr")]
107
use bitcoin_hashes::sha256::Hash;
8+
use core::fmt;
119
#[cfg(target_arch = "wasm32")]
1210
use instant::Instant;
1311
use secp256k1::XOnlyPublicKey;
1412
use serde_json::{json, Value};
13+
#[cfg(not(target_arch = "wasm32"))]
14+
use std::time::Instant;
1515
use url::Url;
1616

1717
pub use super::kind::Kind;
@@ -172,6 +172,7 @@ impl EventBuilder {
172172
}
173173

174174
/// Build MMR [`Event`]
175+
#[cfg(feature = "mmr")]
175176
pub fn to_mmr_event(
176177
self,
177178
keys: &Keys,
@@ -186,6 +187,7 @@ impl EventBuilder {
186187
}
187188

188189
/// Build unsigned MMR [`Event`]
190+
#[cfg(feature = "mmr")]
189191
pub fn to_unsigned_mmr_event(
190192
self,
191193
pubkey: XOnlyPublicKey,

crates/nostr/src/event/tag.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use core::fmt;
77
use core::num::ParseIntError;
88
use core::str::FromStr;
99

10+
#[cfg(feature = "mmr")]
1011
use bitcoin_hashes::sha256::Hash;
1112
use secp256k1::schnorr::Signature;
1213
use secp256k1::XOnlyPublicKey;
@@ -243,6 +244,7 @@ pub enum TagKind {
243244
Lnurl,
244245
/// Name tag
245246
Name,
247+
#[cfg(feature = "mmr")]
246248
/// Merkle mountain range
247249
Mmr,
248250
/// Custom tag kind
@@ -278,6 +280,7 @@ impl fmt::Display for TagKind {
278280
Self::Amount => write!(f, "amount"),
279281
Self::Lnurl => write!(f, "lnurl"),
280282
Self::Name => write!(f, "name"),
283+
#[cfg(feature = "mmr")]
281284
Self::Mmr => write!(f, "mmr"),
282285
Self::Custom(tag) => write!(f, "{tag}"),
283286
}
@@ -317,6 +320,7 @@ where
317320
"amount" => Self::Amount,
318321
"lnurl" => Self::Lnurl,
319322
"name" => Self::Name,
323+
#[cfg(feature = "mmr")]
320324
"mmr" => Self::Mmr,
321325
tag => Self::Custom(tag.to_string()),
322326
}
@@ -375,6 +379,7 @@ pub enum Tag {
375379
Lnurl(String),
376380
Name(String),
377381
PublishedAt(Timestamp),
382+
#[cfg(feature = "mmr")]
378383
Mmr {
379384
prev_event_id: Hash,
380385
prev_mmr_root: Hash,
@@ -430,6 +435,7 @@ impl Tag {
430435
Tag::Amount(..) => TagKind::Amount,
431436
Tag::Name(..) => TagKind::Name,
432437
Tag::Lnurl(..) => TagKind::Lnurl,
438+
#[cfg(feature = "mmr")]
433439
Tag::Mmr { .. } => TagKind::Mmr,
434440
}
435441
}
@@ -592,6 +598,7 @@ where
592598
conditions: Conditions::from_str(&tag[2])?,
593599
sig: Signature::from_str(&tag[3])?,
594600
}),
601+
#[cfg(feature = "mmr")]
595602
TagKind::Mmr => Ok(Self::Mmr {
596603
prev_event_id: Hash::from_str(tag[1].as_str())?,
597604
prev_mmr_root: Hash::from_str(tag[2].as_str())?,
@@ -742,6 +749,7 @@ impl From<Tag> for Vec<String> {
742749
Tag::Lnurl(lnurl) => {
743750
vec![TagKind::Lnurl.to_string(), lnurl]
744751
}
752+
#[cfg(feature = "mmr")]
745753
Tag::Mmr {
746754
prev_event_id,
747755
prev_mmr_root,

0 commit comments

Comments
 (0)