Skip to content

Commit a1f69a2

Browse files
committed
nostr: add JsonUtil::try_as_json method
Internally call `try_as_json` instead of `as_json` in bindings. Ref #433 Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent e5b3958 commit a1f69a2

File tree

18 files changed

+41
-33
lines changed

18 files changed

+41
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ removed zap split from `client.zap` method, many improvements and more!
6262
* nostr: add `SecretKey::generate` ([Yuki Kishimoto])
6363
* nostr: add `Tag` struct ([Yuki Kishimoto])
6464
* nostr: add `EventBuilder::add_tags` method ([Yuki Kishimoto])
65+
* nostr: add `JsonUtil::try_as_json` method ([Yuki Kishimoto])
6566
* database: add `author` index ([Yuki Kishimoto])
6667
* pool: add `RelayPool::start` ([Yuki Kishimoto])
6768
* pool: add `NegentropyDirection` default ([Yuki Kishimoto])

bindings/nostr-ffi/src/event/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl Event {
188188
})
189189
}
190190

191-
pub fn as_json(&self) -> String {
192-
self.inner.as_json()
191+
pub fn as_json(&self) -> Result<String> {
192+
Ok(self.inner.try_as_json()?)
193193
}
194194
}

bindings/nostr-ffi/src/event/raw.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl RawEvent {
8282
self.inner.clone().into()
8383
}
8484

85-
pub fn as_json(&self) -> String {
86-
self.inner.as_json()
85+
pub fn as_json(&self) -> Result<String> {
86+
Ok(self.inner.try_as_json()?)
8787
}
8888
}

bindings/nostr-ffi/src/event/unsigned.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl UnsignedEvent {
8686
})
8787
}
8888

89-
pub fn as_json(&self) -> String {
90-
self.inner.as_json()
89+
pub fn as_json(&self) -> Result<String> {
90+
Ok(self.inner.try_as_json()?)
9191
}
9292
}

bindings/nostr-ffi/src/message/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ impl ClientMessage {
249249
Self { inner: e.into() }
250250
}
251251

252-
pub fn as_json(&self) -> String {
253-
self.inner.as_json()
252+
pub fn as_json(&self) -> Result<String> {
253+
Ok(self.inner.try_as_json()?)
254254
}
255255

256256
/// Clone `ClientMessage` and convert it to `ClientMessageEnum`

bindings/nostr-ffi/src/message/relay.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ impl RelayMessage {
251251
Self { inner: e.into() }
252252
}
253253

254-
pub fn as_json(&self) -> String {
255-
self.inner.as_json()
254+
pub fn as_json(&self) -> Result<String> {
255+
Ok(self.inner.try_as_json()?)
256256
}
257257

258258
/// Clone `RelayMessage` and convert it to `RelayMessageEnum`

bindings/nostr-ffi/src/nips/nip15.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ impl StallData {
132132
self.inner.clone().into()
133133
}
134134

135-
pub fn as_json(&self) -> String {
136-
self.inner.as_json()
135+
pub fn as_json(&self) -> Result<String> {
136+
Ok(self.inner.try_as_json()?)
137137
}
138138
}
139139

bindings/nostr-ffi/src/nips/nip46.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ impl NostrConnectMetadata {
6565
}
6666

6767
/// Serialize as JSON string
68-
pub fn as_json(&self) -> String {
69-
self.inner.as_json()
68+
pub fn as_json(&self) -> Result<String> {
69+
Ok(self.inner.try_as_json()?)
7070
}
7171
}
7272

bindings/nostr-ffi/src/types/filter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ impl Filter {
392392
})
393393
}
394394

395-
pub fn as_json(&self) -> String {
396-
self.inner.as_json()
395+
pub fn as_json(&self) -> Result<String> {
396+
Ok(self.inner.try_as_json()?)
397397
}
398398
}
399399

bindings/nostr-ffi/src/types/metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ impl Metadata {
113113
self.inner.clone().into()
114114
}
115115

116-
pub fn as_json(&self) -> String {
117-
self.inner.as_json()
116+
pub fn as_json(&self) -> Result<String> {
117+
Ok(self.inner.try_as_json()?)
118118
}
119119

120120
pub fn set_name(self: Arc<Self>, name: String) -> Self {

0 commit comments

Comments
 (0)