Skip to content

Commit b6fe16d

Browse files
committed
Add SendEventOutput
1 parent 6305585 commit b6fe16d

File tree

10 files changed

+447
-15
lines changed

10 files changed

+447
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
* Expose `UnsignedEvent` ([Yuki Kishimoto])
4343
* Expose `EventBuilder` ([Yuki Kishimoto])
4444
* Expose `Client::send_event_builder` ([Yuki Kishimoto])
45+
* Add `SendEventOutput` ([Yuki Kishimoto])
4546

4647
### Fixed
4748

lib/nostr_sdk.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export 'src/rust/api/protocol/signer.dart';
1313
export 'src/rust/api/relay/options.dart';
1414
export 'src/rust/api/client.dart';
1515
export 'src/rust/api/client/options.dart';
16+
export 'src/rust/api/client/output.dart';

lib/src/rust/api/client.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import '../frb_generated.dart';
77
import 'client/builder.dart';
8+
import 'client/output.dart';
89
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
910
import 'protocol/event.dart';
1011
import 'protocol/event/builder.dart';
@@ -37,12 +38,12 @@ abstract class Client implements RustOpaqueInterface {
3738
///
3839
/// Send `Event` to all relays with `WRITE` flag.
3940
/// If `gossip` option is enabled, the event will be sent also to NIP65 relays (automatically discovered).
40-
Future<String> sendEvent({required Event event});
41+
Future<SendEventOutput> sendEvent({required Event event});
4142

4243
/// Send event
4344
///
4445
/// Take an [`EventBuilder`], sign it by using the [`NostrSigner`] and broadcast to relays (check [`Client::send_event`] from more details).
4546
///
4647
/// Return an error if the [`NostrSigner`] is not set.
47-
Future<String> sendEventBuilder({required EventBuilder builder});
48+
Future<SendEventOutput> sendEventBuilder({required EventBuilder builder});
4849
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This file is automatically generated, so please do not edit it.
2+
// Generated by `flutter_rust_bridge`@ 2.0.0.
3+
4+
// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import
5+
6+
import '../../frb_generated.dart';
7+
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
8+
9+
// 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`
10+
11+
/// Output
12+
class SendEventOutput {
13+
/// Event ID
14+
final String id;
15+
16+
/// Set of relays that success
17+
final Set<String> success;
18+
19+
/// Map of relays that failed, with related errors.
20+
final Map<String, String> failed;
21+
22+
const SendEventOutput({
23+
required this.id,
24+
required this.success,
25+
required this.failed,
26+
});
27+
28+
@override
29+
int get hashCode => id.hashCode ^ success.hashCode ^ failed.hashCode;
30+
31+
@override
32+
bool operator ==(Object other) =>
33+
identical(this, other) ||
34+
other is SendEventOutput &&
35+
runtimeType == other.runtimeType &&
36+
id == other.id &&
37+
success == other.success &&
38+
failed == other.failed;
39+
}

lib/src/rust/frb_generated.dart

Lines changed: 144 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import 'api/client.dart';
77
import 'api/client/builder.dart';
88
import 'api/client/options.dart';
9+
import 'api/client/output.dart';
910
import 'api/protocol/event.dart';
1011
import 'api/protocol/event/builder.dart';
1112
import 'api/protocol/event/tag.dart';
@@ -92,10 +93,10 @@ abstract class NostrSdkApi extends BaseApi {
9293

9394
Client crateApiClientClientNew();
9495

95-
Future<String> crateApiClientClientSendEvent(
96+
Future<SendEventOutput> crateApiClientClientSendEvent(
9697
{required Client that, required Event event});
9798

98-
Future<String> crateApiClientClientSendEventBuilder(
99+
Future<SendEventOutput> crateApiClientClientSendEventBuilder(
99100
{required Client that, required EventBuilder builder});
100101

101102
Client crateApiClientBuilderClientBuilderBuild({required ClientBuilder that});
@@ -539,7 +540,7 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi {
539540
);
540541

541542
@override
542-
Future<String> crateApiClientClientSendEvent(
543+
Future<SendEventOutput> crateApiClientClientSendEvent(
543544
{required Client that, required Event event}) {
544545
return handler.executeNormal(NormalTask(
545546
callFfi: (port_) {
@@ -552,7 +553,7 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi {
552553
funcId: 6, port: port_);
553554
},
554555
codec: SseCodec(
555-
decodeSuccessData: sse_decode_String,
556+
decodeSuccessData: sse_decode_send_event_output,
556557
decodeErrorData: sse_decode_AnyhowException,
557558
),
558559
constMeta: kCrateApiClientClientSendEventConstMeta,
@@ -568,7 +569,7 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi {
568569
);
569570

570571
@override
571-
Future<String> crateApiClientClientSendEventBuilder(
572+
Future<SendEventOutput> crateApiClientClientSendEventBuilder(
572573
{required Client that, required EventBuilder builder}) {
573574
return handler.executeNormal(NormalTask(
574575
callFfi: (port_) {
@@ -581,7 +582,7 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi {
581582
funcId: 7, port: port_);
582583
},
583584
codec: SseCodec(
584-
decodeSuccessData: sse_decode_String,
585+
decodeSuccessData: sse_decode_send_event_output,
585586
decodeErrorData: sse_decode_AnyhowException,
586587
),
587588
constMeta: kCrateApiClientClientSendEventBuilderConstMeta,
@@ -3053,6 +3054,13 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi {
30533054
return UnsignedEventImpl.frbInternalDcoDecode(raw as List<dynamic>);
30543055
}
30553056

3057+
@protected
3058+
Map<String, String> dco_decode_Map_String_String(dynamic raw) {
3059+
// Codec=Dco (DartCObject based), see doc to use other codecs
3060+
return Map.fromEntries(dco_decode_list_record_string_string(raw)
3061+
.map((e) => MapEntry(e.$1, e.$2)));
3062+
}
3063+
30563064
@protected
30573065
Client
30583066
dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_Client(
@@ -3148,6 +3156,12 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi {
31483156
return UnsignedEventImpl.frbInternalDcoDecode(raw as List<dynamic>);
31493157
}
31503158

3159+
@protected
3160+
Set<String> dco_decode_Set_String(dynamic raw) {
3161+
// Codec=Dco (DartCObject based), see doc to use other codecs
3162+
return Set.from(dco_decode_list_String(raw));
3163+
}
3164+
31513165
@protected
31523166
String dco_decode_String(dynamic raw) {
31533167
// Codec=Dco (DartCObject based), see doc to use other codecs
@@ -3226,12 +3240,44 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi {
32263240
return raw as Uint8List;
32273241
}
32283242

3243+
@protected
3244+
List<(String, String)> dco_decode_list_record_string_string(dynamic raw) {
3245+
// Codec=Dco (DartCObject based), see doc to use other codecs
3246+
return (raw as List<dynamic>).map(dco_decode_record_string_string).toList();
3247+
}
3248+
32293249
@protected
32303250
String? dco_decode_opt_String(dynamic raw) {
32313251
// Codec=Dco (DartCObject based), see doc to use other codecs
32323252
return raw == null ? null : dco_decode_String(raw);
32333253
}
32343254

3255+
@protected
3256+
(String, String) dco_decode_record_string_string(dynamic raw) {
3257+
// Codec=Dco (DartCObject based), see doc to use other codecs
3258+
final arr = raw as List<dynamic>;
3259+
if (arr.length != 2) {
3260+
throw Exception('Expected 2 elements, got ${arr.length}');
3261+
}
3262+
return (
3263+
dco_decode_String(arr[0]),
3264+
dco_decode_String(arr[1]),
3265+
);
3266+
}
3267+
3268+
@protected
3269+
SendEventOutput dco_decode_send_event_output(dynamic raw) {
3270+
// Codec=Dco (DartCObject based), see doc to use other codecs
3271+
final arr = raw as List<dynamic>;
3272+
if (arr.length != 3)
3273+
throw Exception('unexpected arr length: expect 3 but see ${arr.length}');
3274+
return SendEventOutput(
3275+
id: dco_decode_String(arr[0]),
3276+
success: dco_decode_Set_String(arr[1]),
3277+
failed: dco_decode_Map_String_String(arr[2]),
3278+
);
3279+
}
3280+
32353281
@protected
32363282
SignerBackend dco_decode_signer_backend(dynamic raw) {
32373283
// Codec=Dco (DartCObject based), see doc to use other codecs
@@ -3502,6 +3548,14 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi {
35023548
sse_decode_usize(deserializer), sse_decode_i_32(deserializer));
35033549
}
35043550

3551+
@protected
3552+
Map<String, String> sse_decode_Map_String_String(
3553+
SseDeserializer deserializer) {
3554+
// Codec=Sse (Serialization based), see doc to use other codecs
3555+
var inner = sse_decode_list_record_string_string(deserializer);
3556+
return Map.fromEntries(inner.map((e) => MapEntry(e.$1, e.$2)));
3557+
}
3558+
35053559
@protected
35063560
Client
35073561
sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_Client(
@@ -3609,6 +3663,13 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi {
36093663
sse_decode_usize(deserializer), sse_decode_i_32(deserializer));
36103664
}
36113665

3666+
@protected
3667+
Set<String> sse_decode_Set_String(SseDeserializer deserializer) {
3668+
// Codec=Sse (Serialization based), see doc to use other codecs
3669+
var inner = sse_decode_list_String(deserializer);
3670+
return Set.from(inner);
3671+
}
3672+
36123673
@protected
36133674
String sse_decode_String(SseDeserializer deserializer) {
36143675
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -3703,6 +3764,19 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi {
37033764
return deserializer.buffer.getUint8List(len_);
37043765
}
37053766

3767+
@protected
3768+
List<(String, String)> sse_decode_list_record_string_string(
3769+
SseDeserializer deserializer) {
3770+
// Codec=Sse (Serialization based), see doc to use other codecs
3771+
3772+
var len_ = sse_decode_i_32(deserializer);
3773+
var ans_ = <(String, String)>[];
3774+
for (var idx_ = 0; idx_ < len_; ++idx_) {
3775+
ans_.add(sse_decode_record_string_string(deserializer));
3776+
}
3777+
return ans_;
3778+
}
3779+
37063780
@protected
37073781
String? sse_decode_opt_String(SseDeserializer deserializer) {
37083782
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -3714,6 +3788,25 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi {
37143788
}
37153789
}
37163790

3791+
@protected
3792+
(String, String) sse_decode_record_string_string(
3793+
SseDeserializer deserializer) {
3794+
// Codec=Sse (Serialization based), see doc to use other codecs
3795+
var var_field0 = sse_decode_String(deserializer);
3796+
var var_field1 = sse_decode_String(deserializer);
3797+
return (var_field0, var_field1);
3798+
}
3799+
3800+
@protected
3801+
SendEventOutput sse_decode_send_event_output(SseDeserializer deserializer) {
3802+
// Codec=Sse (Serialization based), see doc to use other codecs
3803+
var var_id = sse_decode_String(deserializer);
3804+
var var_success = sse_decode_Set_String(deserializer);
3805+
var var_failed = sse_decode_Map_String_String(deserializer);
3806+
return SendEventOutput(
3807+
id: var_id, success: var_success, failed: var_failed);
3808+
}
3809+
37173810
@protected
37183811
SignerBackend sse_decode_signer_backend(SseDeserializer deserializer) {
37193812
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -3995,6 +4088,14 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi {
39954088
serializer);
39964089
}
39974090

4091+
@protected
4092+
void sse_encode_Map_String_String(
4093+
Map<String, String> self, SseSerializer serializer) {
4094+
// Codec=Sse (Serialization based), see doc to use other codecs
4095+
sse_encode_list_record_string_string(
4096+
self.entries.map((e) => (e.key, e.value)).toList(), serializer);
4097+
}
4098+
39984099
@protected
39994100
void
40004101
sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInner_Client(
@@ -4107,6 +4208,12 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi {
41074208
serializer);
41084209
}
41094210

4211+
@protected
4212+
void sse_encode_Set_String(Set<String> self, SseSerializer serializer) {
4213+
// Codec=Sse (Serialization based), see doc to use other codecs
4214+
sse_encode_list_String(self.toList(), serializer);
4215+
}
4216+
41104217
@protected
41114218
void sse_encode_String(String self, SseSerializer serializer) {
41124219
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -4195,6 +4302,16 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi {
41954302
serializer.buffer.putUint8List(self);
41964303
}
41974304

4305+
@protected
4306+
void sse_encode_list_record_string_string(
4307+
List<(String, String)> self, SseSerializer serializer) {
4308+
// Codec=Sse (Serialization based), see doc to use other codecs
4309+
sse_encode_i_32(self.length, serializer);
4310+
for (final item in self) {
4311+
sse_encode_record_string_string(item, serializer);
4312+
}
4313+
}
4314+
41984315
@protected
41994316
void sse_encode_opt_String(String? self, SseSerializer serializer) {
42004317
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -4205,6 +4322,23 @@ class NostrSdkApiImpl extends NostrSdkApiImplPlatform implements NostrSdkApi {
42054322
}
42064323
}
42074324

4325+
@protected
4326+
void sse_encode_record_string_string(
4327+
(String, String) self, SseSerializer serializer) {
4328+
// Codec=Sse (Serialization based), see doc to use other codecs
4329+
sse_encode_String(self.$1, serializer);
4330+
sse_encode_String(self.$2, serializer);
4331+
}
4332+
4333+
@protected
4334+
void sse_encode_send_event_output(
4335+
SendEventOutput self, SseSerializer serializer) {
4336+
// Codec=Sse (Serialization based), see doc to use other codecs
4337+
sse_encode_String(self.id, serializer);
4338+
sse_encode_Set_String(self.success, serializer);
4339+
sse_encode_Map_String_String(self.failed, serializer);
4340+
}
4341+
42084342
@protected
42094343
void sse_encode_signer_backend(SignerBackend self, SseSerializer serializer) {
42104344
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -4327,15 +4461,16 @@ class ClientImpl extends RustOpaque implements Client {
43274461
///
43284462
/// Send `Event` to all relays with `WRITE` flag.
43294463
/// If `gossip` option is enabled, the event will be sent also to NIP65 relays (automatically discovered).
4330-
Future<String> sendEvent({required Event event}) => NostrSdk.instance.api
4331-
.crateApiClientClientSendEvent(that: this, event: event);
4464+
Future<SendEventOutput> sendEvent({required Event event}) =>
4465+
NostrSdk.instance.api
4466+
.crateApiClientClientSendEvent(that: this, event: event);
43324467

43334468
/// Send event
43344469
///
43354470
/// Take an [`EventBuilder`], sign it by using the [`NostrSigner`] and broadcast to relays (check [`Client::send_event`] from more details).
43364471
///
43374472
/// Return an error if the [`NostrSigner`] is not set.
4338-
Future<String> sendEventBuilder({required EventBuilder builder}) =>
4473+
Future<SendEventOutput> sendEventBuilder({required EventBuilder builder}) =>
43394474
NostrSdk.instance.api
43404475
.crateApiClientClientSendEventBuilder(that: this, builder: builder);
43414476
}

0 commit comments

Comments
 (0)