diff --git a/CHANGELOG.md b/CHANGELOG.md index 61c300b..c1db315 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ * Expose `UnsignedEvent` ([Yuki Kishimoto]) * Expose `EventBuilder` ([Yuki Kishimoto]) * Expose `Client::send_event_builder` ([Yuki Kishimoto]) +* Add `SendEventOutput` ([Yuki Kishimoto]) ### Fixed diff --git a/lib/nostr_sdk.dart b/lib/nostr_sdk.dart index cf0d7fa..6a12380 100644 --- a/lib/nostr_sdk.dart +++ b/lib/nostr_sdk.dart @@ -13,3 +13,4 @@ export 'src/rust/api/protocol/signer.dart'; export 'src/rust/api/relay/options.dart'; export 'src/rust/api/client.dart'; export 'src/rust/api/client/options.dart'; +export 'src/rust/api/client/output.dart'; diff --git a/lib/src/rust/api/client.dart b/lib/src/rust/api/client.dart index 3b94491..cabff71 100644 --- a/lib/src/rust/api/client.dart +++ b/lib/src/rust/api/client.dart @@ -5,6 +5,7 @@ import '../frb_generated.dart'; import 'client/builder.dart'; +import 'client/output.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; import 'protocol/event.dart'; import 'protocol/event/builder.dart'; @@ -37,12 +38,12 @@ abstract class Client implements RustOpaqueInterface { /// /// Send `Event` to all relays with `WRITE` flag. /// If `gossip` option is enabled, the event will be sent also to NIP65 relays (automatically discovered). - Future sendEvent({required Event event}); + Future sendEvent({required Event event}); /// Send event /// /// Take an [`EventBuilder`], sign it by using the [`NostrSigner`] and broadcast to relays (check [`Client::send_event`] from more details). /// /// Return an error if the [`NostrSigner`] is not set. - Future sendEventBuilder({required EventBuilder builder}); + Future sendEventBuilder({required EventBuilder builder}); } diff --git a/lib/src/rust/api/client/output.dart b/lib/src/rust/api/client/output.dart new file mode 100644 index 0000000..0ff47a4 --- /dev/null +++ b/lib/src/rust/api/client/output.dart @@ -0,0 +1,39 @@ +// This file is automatically generated, so please do not edit it. +// Generated by `flutter_rust_bridge`@ 2.0.0. + +// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import + +import '../../frb_generated.dart'; +import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; + +// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `from` + +/// Output +class SendEventOutput { + /// Event ID + final String id; + + /// Set of relays that success + final Set success; + + /// Map of relays that failed, with related errors. + final Map failed; + + const SendEventOutput({ + required this.id, + required this.success, + required this.failed, + }); + + @override + int get hashCode => id.hashCode ^ success.hashCode ^ failed.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is SendEventOutput && + runtimeType == other.runtimeType && + id == other.id && + success == other.success && + failed == other.failed; +} diff --git a/lib/src/rust/frb_generated.dart b/lib/src/rust/frb_generated.dart index 478ba94..7c20eb5 100644 --- a/lib/src/rust/frb_generated.dart +++ b/lib/src/rust/frb_generated.dart @@ -6,6 +6,7 @@ import 'api/client.dart'; import 'api/client/builder.dart'; import 'api/client/options.dart'; +import 'api/client/output.dart'; import 'api/protocol/event.dart'; import 'api/protocol/event/builder.dart'; import 'api/protocol/event/tag.dart'; @@ -92,10 +93,10 @@ abstract class NostrSdkApi extends BaseApi { Client crateApiClientClientNew(); - Future crateApiClientClientSendEvent( + Future crateApiClientClientSendEvent( {required Client that, required Event event}); - Future crateApiClientClientSendEventBuilder( + Future crateApiClientClientSendEventBuilder( {required Client that, required EventBuilder builder}); Client crateApiClientBuilderClientBuilderBuild({required ClientBuilder that}); @@ -539,7 +540,7 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi { ); @override - Future crateApiClientClientSendEvent( + Future crateApiClientClientSendEvent( {required Client that, required Event event}) { return handler.executeNormal(NormalTask( callFfi: (port_) { @@ -552,7 +553,7 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi { funcId: 6, port: port_); }, codec: SseCodec( - decodeSuccessData: sse_decode_String, + decodeSuccessData: sse_decode_send_event_output, decodeErrorData: sse_decode_AnyhowException, ), constMeta: kCrateApiClientClientSendEventConstMeta, @@ -568,7 +569,7 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi { ); @override - Future crateApiClientClientSendEventBuilder( + Future crateApiClientClientSendEventBuilder( {required Client that, required EventBuilder builder}) { return handler.executeNormal(NormalTask( callFfi: (port_) { @@ -581,7 +582,7 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi { funcId: 7, port: port_); }, codec: SseCodec( - decodeSuccessData: sse_decode_String, + decodeSuccessData: sse_decode_send_event_output, decodeErrorData: sse_decode_AnyhowException, ), constMeta: kCrateApiClientClientSendEventBuilderConstMeta, @@ -3053,6 +3054,13 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi { return UnsignedEventImpl.frbInternalDcoDecode(raw as List); } + @protected + Map dco_decode_Map_String_String(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return Map.fromEntries(dco_decode_list_record_string_string(raw) + .map((e) => MapEntry(e.$1, e.$2))); + } + @protected Client dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_Client( @@ -3148,6 +3156,12 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi { return UnsignedEventImpl.frbInternalDcoDecode(raw as List); } + @protected + Set dco_decode_Set_String(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return Set.from(dco_decode_list_String(raw)); + } + @protected String dco_decode_String(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -3226,12 +3240,44 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi { return raw as Uint8List; } + @protected + List<(String, String)> dco_decode_list_record_string_string(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return (raw as List).map(dco_decode_record_string_string).toList(); + } + @protected String? dco_decode_opt_String(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs return raw == null ? null : dco_decode_String(raw); } + @protected + (String, String) dco_decode_record_string_string(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + final arr = raw as List; + if (arr.length != 2) { + throw Exception('Expected 2 elements, got ${arr.length}'); + } + return ( + dco_decode_String(arr[0]), + dco_decode_String(arr[1]), + ); + } + + @protected + SendEventOutput dco_decode_send_event_output(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + final arr = raw as List; + if (arr.length != 3) + throw Exception('unexpected arr length: expect 3 but see ${arr.length}'); + return SendEventOutput( + id: dco_decode_String(arr[0]), + success: dco_decode_Set_String(arr[1]), + failed: dco_decode_Map_String_String(arr[2]), + ); + } + @protected SignerBackend dco_decode_signer_backend(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -3502,6 +3548,14 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi { sse_decode_usize(deserializer), sse_decode_i_32(deserializer)); } + @protected + Map sse_decode_Map_String_String( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var inner = sse_decode_list_record_string_string(deserializer); + return Map.fromEntries(inner.map((e) => MapEntry(e.$1, e.$2))); + } + @protected Client sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_Client( @@ -3609,6 +3663,13 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi { sse_decode_usize(deserializer), sse_decode_i_32(deserializer)); } + @protected + Set sse_decode_Set_String(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var inner = sse_decode_list_String(deserializer); + return Set.from(inner); + } + @protected String sse_decode_String(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -3703,6 +3764,19 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi { return deserializer.buffer.getUint8List(len_); } + @protected + List<(String, String)> sse_decode_list_record_string_string( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + + var len_ = sse_decode_i_32(deserializer); + var ans_ = <(String, String)>[]; + for (var idx_ = 0; idx_ < len_; ++idx_) { + ans_.add(sse_decode_record_string_string(deserializer)); + } + return ans_; + } + @protected String? sse_decode_opt_String(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -3714,6 +3788,25 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi { } } + @protected + (String, String) sse_decode_record_string_string( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var var_field0 = sse_decode_String(deserializer); + var var_field1 = sse_decode_String(deserializer); + return (var_field0, var_field1); + } + + @protected + SendEventOutput sse_decode_send_event_output(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var var_id = sse_decode_String(deserializer); + var var_success = sse_decode_Set_String(deserializer); + var var_failed = sse_decode_Map_String_String(deserializer); + return SendEventOutput( + id: var_id, success: var_success, failed: var_failed); + } + @protected SignerBackend sse_decode_signer_backend(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -3995,6 +4088,14 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi { serializer); } + @protected + void sse_encode_Map_String_String( + Map self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_list_record_string_string( + self.entries.map((e) => (e.key, e.value)).toList(), serializer); + } + @protected void sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_Client( @@ -4107,6 +4208,12 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi { serializer); } + @protected + void sse_encode_Set_String(Set self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_list_String(self.toList(), serializer); + } + @protected void sse_encode_String(String self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -4195,6 +4302,16 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi { serializer.buffer.putUint8List(self); } + @protected + void sse_encode_list_record_string_string( + List<(String, String)> self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_i_32(self.length, serializer); + for (final item in self) { + sse_encode_record_string_string(item, serializer); + } + } + @protected void sse_encode_opt_String(String? self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -4205,6 +4322,23 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi { } } + @protected + void sse_encode_record_string_string( + (String, String) self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_String(self.$1, serializer); + sse_encode_String(self.$2, serializer); + } + + @protected + void sse_encode_send_event_output( + SendEventOutput self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_String(self.id, serializer); + sse_encode_Set_String(self.success, serializer); + sse_encode_Map_String_String(self.failed, serializer); + } + @protected void sse_encode_signer_backend(SignerBackend self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -4327,15 +4461,16 @@ class ClientImpl extends RustOpaque implements Client { /// /// Send `Event` to all relays with `WRITE` flag. /// If `gossip` option is enabled, the event will be sent also to NIP65 relays (automatically discovered). - Future sendEvent({required Event event}) => NostrSdk.instance.api - .crateApiClientClientSendEvent(that: this, event: event); + Future sendEvent({required Event event}) => + NostrSdk.instance.api + .crateApiClientClientSendEvent(that: this, event: event); /// Send event /// /// Take an [`EventBuilder`], sign it by using the [`NostrSigner`] and broadcast to relays (check [`Client::send_event`] from more details). /// /// Return an error if the [`NostrSigner`] is not set. - Future sendEventBuilder({required EventBuilder builder}) => + Future sendEventBuilder({required EventBuilder builder}) => NostrSdk.instance.api .crateApiClientClientSendEventBuilder(that: this, builder: builder); } diff --git a/lib/src/rust/frb_generated.io.dart b/lib/src/rust/frb_generated.io.dart index f2db071..a972da2 100644 --- a/lib/src/rust/frb_generated.io.dart +++ b/lib/src/rust/frb_generated.io.dart @@ -6,6 +6,7 @@ import 'api/client.dart'; import 'api/client/builder.dart'; import 'api/client/options.dart'; +import 'api/client/output.dart'; import 'api/protocol/event.dart'; import 'api/protocol/event/builder.dart'; import 'api/protocol/event/tag.dart'; @@ -191,6 +192,9 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { dco_decode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_UnsignedEvent( dynamic raw); + @protected + Map dco_decode_Map_String_String(dynamic raw); + @protected Client dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_Client( @@ -250,6 +254,9 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_UnsignedEvent( dynamic raw); + @protected + Set dco_decode_Set_String(dynamic raw); + @protected String dco_decode_String(dynamic raw); @@ -282,9 +289,18 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { @protected Uint8List dco_decode_list_prim_u_8_strict(dynamic raw); + @protected + List<(String, String)> dco_decode_list_record_string_string(dynamic raw); + @protected String? dco_decode_opt_String(dynamic raw); + @protected + (String, String) dco_decode_record_string_string(dynamic raw); + + @protected + SendEventOutput dco_decode_send_event_output(dynamic raw); + @protected SignerBackend dco_decode_signer_backend(dynamic raw); @@ -424,6 +440,10 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { sse_decode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_UnsignedEvent( SseDeserializer deserializer); + @protected + Map sse_decode_Map_String_String( + SseDeserializer deserializer); + @protected Client sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_Client( @@ -483,6 +503,9 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_UnsignedEvent( SseDeserializer deserializer); + @protected + Set sse_decode_Set_String(SseDeserializer deserializer); + @protected String sse_decode_String(SseDeserializer deserializer); @@ -516,9 +539,20 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { @protected Uint8List sse_decode_list_prim_u_8_strict(SseDeserializer deserializer); + @protected + List<(String, String)> sse_decode_list_record_string_string( + SseDeserializer deserializer); + @protected String? sse_decode_opt_String(SseDeserializer deserializer); + @protected + (String, String) sse_decode_record_string_string( + SseDeserializer deserializer); + + @protected + SendEventOutput sse_decode_send_event_output(SseDeserializer deserializer); + @protected SignerBackend sse_decode_signer_backend(SseDeserializer deserializer); @@ -661,6 +695,10 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_UnsignedEvent( UnsignedEvent self, SseSerializer serializer); + @protected + void sse_encode_Map_String_String( + Map self, SseSerializer serializer); + @protected void sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_Client( @@ -721,6 +759,9 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_UnsignedEvent( UnsignedEvent self, SseSerializer serializer); + @protected + void sse_encode_Set_String(Set self, SseSerializer serializer); + @protected void sse_encode_String(String self, SseSerializer serializer); @@ -757,9 +798,21 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { void sse_encode_list_prim_u_8_strict( Uint8List self, SseSerializer serializer); + @protected + void sse_encode_list_record_string_string( + List<(String, String)> self, SseSerializer serializer); + @protected void sse_encode_opt_String(String? self, SseSerializer serializer); + @protected + void sse_encode_record_string_string( + (String, String) self, SseSerializer serializer); + + @protected + void sse_encode_send_event_output( + SendEventOutput self, SseSerializer serializer); + @protected void sse_encode_signer_backend(SignerBackend self, SseSerializer serializer); diff --git a/lib/src/rust/frb_generated.web.dart b/lib/src/rust/frb_generated.web.dart index 12e8d8a..ef49118 100644 --- a/lib/src/rust/frb_generated.web.dart +++ b/lib/src/rust/frb_generated.web.dart @@ -9,6 +9,7 @@ import 'api/client.dart'; import 'api/client/builder.dart'; import 'api/client/options.dart'; +import 'api/client/output.dart'; import 'api/protocol/event.dart'; import 'api/protocol/event/builder.dart'; import 'api/protocol/event/tag.dart'; @@ -193,6 +194,9 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { dco_decode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_UnsignedEvent( dynamic raw); + @protected + Map dco_decode_Map_String_String(dynamic raw); + @protected Client dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_Client( @@ -252,6 +256,9 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_UnsignedEvent( dynamic raw); + @protected + Set dco_decode_Set_String(dynamic raw); + @protected String dco_decode_String(dynamic raw); @@ -284,9 +291,18 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { @protected Uint8List dco_decode_list_prim_u_8_strict(dynamic raw); + @protected + List<(String, String)> dco_decode_list_record_string_string(dynamic raw); + @protected String? dco_decode_opt_String(dynamic raw); + @protected + (String, String) dco_decode_record_string_string(dynamic raw); + + @protected + SendEventOutput dco_decode_send_event_output(dynamic raw); + @protected SignerBackend dco_decode_signer_backend(dynamic raw); @@ -426,6 +442,10 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { sse_decode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_UnsignedEvent( SseDeserializer deserializer); + @protected + Map sse_decode_Map_String_String( + SseDeserializer deserializer); + @protected Client sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_Client( @@ -485,6 +505,9 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_UnsignedEvent( SseDeserializer deserializer); + @protected + Set sse_decode_Set_String(SseDeserializer deserializer); + @protected String sse_decode_String(SseDeserializer deserializer); @@ -518,9 +541,20 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { @protected Uint8List sse_decode_list_prim_u_8_strict(SseDeserializer deserializer); + @protected + List<(String, String)> sse_decode_list_record_string_string( + SseDeserializer deserializer); + @protected String? sse_decode_opt_String(SseDeserializer deserializer); + @protected + (String, String) sse_decode_record_string_string( + SseDeserializer deserializer); + + @protected + SendEventOutput sse_decode_send_event_output(SseDeserializer deserializer); + @protected SignerBackend sse_decode_signer_backend(SseDeserializer deserializer); @@ -663,6 +697,10 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_UnsignedEvent( UnsignedEvent self, SseSerializer serializer); + @protected + void sse_encode_Map_String_String( + Map self, SseSerializer serializer); + @protected void sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_Client( @@ -723,6 +761,9 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_UnsignedEvent( UnsignedEvent self, SseSerializer serializer); + @protected + void sse_encode_Set_String(Set self, SseSerializer serializer); + @protected void sse_encode_String(String self, SseSerializer serializer); @@ -759,9 +800,21 @@ abstract class NostrSdkApiImplPlatform extends BaseApiImpl { void sse_encode_list_prim_u_8_strict( Uint8List self, SseSerializer serializer); + @protected + void sse_encode_list_record_string_string( + List<(String, String)> self, SseSerializer serializer); + @protected void sse_encode_opt_String(String? self, SseSerializer serializer); + @protected + void sse_encode_record_string_string( + (String, String) self, SseSerializer serializer); + + @protected + void sse_encode_send_event_output( + SendEventOutput self, SseSerializer serializer); + @protected void sse_encode_signer_backend(SignerBackend self, SseSerializer serializer); diff --git a/rust/src/api/client/mod.rs b/rust/src/api/client/mod.rs index 74f4c78..5dad6c1 100644 --- a/rust/src/api/client/mod.rs +++ b/rust/src/api/client/mod.rs @@ -8,8 +8,10 @@ use nostr_sdk::prelude::*; pub mod builder; pub mod options; +pub mod output; use self::builder::_ClientBuilder; +use self::output::SendEventOutput; use super::protocol::event::_Event; use super::protocol::event::builder::_EventBuilder; @@ -60,9 +62,9 @@ impl _Client { /// /// Send `Event` to all relays with `WRITE` flag. /// If `gossip` option is enabled, the event will be sent also to NIP65 relays (automatically discovered). - pub async fn send_event(&self, event: _Event) -> Result { + pub async fn send_event(&self, event: _Event) -> Result { let output = self.inner.send_event(event.inner).await?; - Ok(output.id().to_string()) + Ok(output.into()) } /// Send event @@ -70,8 +72,8 @@ impl _Client { /// Take an [`EventBuilder`], sign it by using the [`NostrSigner`] and broadcast to relays (check [`Client::send_event`] from more details). /// /// Return an error if the [`NostrSigner`] is not set. - pub async fn send_event_builder(&self, builder: _EventBuilder) -> Result { + pub async fn send_event_builder(&self, builder: _EventBuilder) -> Result { let output = self.inner.send_event_builder(builder.inner).await?; - Ok(output.id().to_string()) + Ok(output.into()) } } diff --git a/rust/src/api/client/output.rs b/rust/src/api/client/output.rs new file mode 100644 index 0000000..a0fff37 --- /dev/null +++ b/rust/src/api/client/output.rs @@ -0,0 +1,33 @@ +// Copyright (c) 2022-2023 Yuki Kishimoto +// Copyright (c) 2023-2024 Rust Nostr Developers +// Distributed under the MIT software license + +use std::collections::{HashMap, HashSet}; + +use flutter_rust_bridge::frb; +use nostr_sdk::prelude::*; + +/// Output +#[frb] +pub struct SendEventOutput { + /// Event ID + pub id: String, + /// Set of relays that success + pub success: HashSet, + /// Map of relays that failed, with related errors. + pub failed: HashMap, +} + +impl From> for SendEventOutput { + fn from(output: Output) -> Self { + Self { + id: output.id().to_string(), + success: output.success.into_iter().map(|u| u.to_string()).collect(), + failed: output + .failed + .into_iter() + .map(|(u, e)| (u.to_string(), e)) + .collect(), + } + } +} diff --git a/rust/src/frb_generated.rs b/rust/src/frb_generated.rs index 522c898..5a5dff2 100644 --- a/rust/src/frb_generated.rs +++ b/rust/src/frb_generated.rs @@ -4383,6 +4383,14 @@ impl SseDecode for _UnsignedEvent { } } +impl SseDecode for std::collections::HashMap { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut inner = >::sse_decode(deserializer); + return inner.into_iter().collect(); + } +} + impl SseDecode for RustOpaqueMoi> { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -4495,6 +4503,14 @@ impl SseDecode } } +impl SseDecode for std::collections::HashSet { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut inner = >::sse_decode(deserializer); + return inner.into_iter().collect(); + } +} + impl SseDecode for String { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -4590,6 +4606,18 @@ impl SseDecode for Vec { } } +impl SseDecode for Vec<(String, String)> { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut len_ = ::sse_decode(deserializer); + let mut ans_ = vec![]; + for idx_ in 0..len_ { + ans_.push(<(String, String)>::sse_decode(deserializer)); + } + return ans_; + } +} + impl SseDecode for Option { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -4601,6 +4629,29 @@ impl SseDecode for Option { } } +impl SseDecode for (String, String) { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut var_field0 = ::sse_decode(deserializer); + let mut var_field1 = ::sse_decode(deserializer); + return (var_field0, var_field1); + } +} + +impl SseDecode for crate::api::client::output::SendEventOutput { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut var_id = ::sse_decode(deserializer); + let mut var_success = >::sse_decode(deserializer); + let mut var_failed = >::sse_decode(deserializer); + return crate::api::client::output::SendEventOutput { + id: var_id, + success: var_success, + failed: var_failed, + }; + } +} + impl SseDecode for crate::api::protocol::signer::SignerBackend { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -5218,6 +5269,28 @@ impl flutter_rust_bridge::IntoIntoDart flutter_rust_bridge::for_generated::DartAbi { + [ + self.id.into_into_dart().into_dart(), + self.success.into_into_dart().into_dart(), + self.failed.into_into_dart().into_dart(), + ] + .into_dart() + } +} +impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive + for crate::api::client::output::SendEventOutput +{ +} +impl flutter_rust_bridge::IntoIntoDart + for crate::api::client::output::SendEventOutput +{ + fn into_into_dart(self) -> crate::api::client::output::SendEventOutput { + self + } +} +// Codec=Dco (DartCObject based), see doc to use other codecs impl flutter_rust_bridge::IntoDart for crate::api::protocol::signer::SignerBackend { fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { match self { @@ -5346,6 +5419,13 @@ impl SseEncode for _UnsignedEvent { } } +impl SseEncode for std::collections::HashMap { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + >::sse_encode(self.into_iter().collect(), serializer); + } +} + impl SseEncode for RustOpaqueMoi> { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -5470,6 +5550,13 @@ impl SseEncode } } +impl SseEncode for std::collections::HashSet { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + >::sse_encode(self.into_iter().collect(), serializer); + } +} + impl SseEncode for String { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -5559,6 +5646,16 @@ impl SseEncode for Vec { } } +impl SseEncode for Vec<(String, String)> { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.len() as _, serializer); + for item in self { + <(String, String)>::sse_encode(item, serializer); + } + } +} + impl SseEncode for Option { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -5569,6 +5666,23 @@ impl SseEncode for Option { } } +impl SseEncode for (String, String) { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.0, serializer); + ::sse_encode(self.1, serializer); + } +} + +impl SseEncode for crate::api::client::output::SendEventOutput { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.id, serializer); + >::sse_encode(self.success, serializer); + >::sse_encode(self.failed, serializer); + } +} + impl SseEncode for crate::api::protocol::signer::SignerBackend { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {