Skip to content

Commit 4c133ec

Browse files
authored
Merge pull request #280 from relaystr/chore-dart-format-11-11-25
chore: dart format
2 parents 68d019d + e86de7c commit 4c133ec

10 files changed

Lines changed: 103 additions & 45 deletions

File tree

packages/ndk/lib/domain_layer/usecases/broadcast/broadcast.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class Broadcast {
6868
final signer =
6969
nostrEvent.sig == '' ? _checkSinger(customSigner: customSigner) : null;
7070

71-
final cleanedSpecificRelays = specificRelays != null ? cleanRelayUrls(specificRelays.toList()) : null;
71+
final cleanedSpecificRelays =
72+
specificRelays != null ? cleanRelayUrls(specificRelays.toList()) : null;
7273

7374
return _engine.handleEventBroadcast(
7475
nostrEvent: nostrEvent,
@@ -127,7 +128,8 @@ class Broadcast {
127128
}
128129

129130
if (idsToDelete.isEmpty) {
130-
throw ArgumentError("At least one eventId must be provided for deletion.");
131+
throw ArgumentError(
132+
"At least one eventId must be provided for deletion.");
131133
}
132134

133135
Nip01Event event = Nip01Event(

packages/ndk/lib/domain_layer/usecases/jit_engine/jit_engine.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class JitEngine with Logger implements NetworkEngine {
7070

7171
if (requestState.request.explicitRelays != null &&
7272
requestState.request.explicitRelays!.isNotEmpty) {
73-
final cleanedExplicitRelays = cleanRelayUrls(requestState.request.explicitRelays!.toList());
73+
final cleanedExplicitRelays =
74+
cleanRelayUrls(requestState.request.explicitRelays!.toList());
7475
RelayJitRequestSpecificStrategy.handleRequest(
7576
relayManager: relayManagerLight,
7677
requestState: requestState,

packages/ndk/lib/domain_layer/usecases/nwc/nostr_wallet_connect_uri.dart

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ class NostrWalletConnectUri extends Equatable {
7272
String? secret = parsedUri.queryParameters['secret'];
7373
String? lud16 = parsedUri.queryParameters['lud16'];
7474

75-
if (pubkey.isEmpty || secret == null || parsedUri.scheme != 'nostr+walletconnect') {
76-
throw Exception("Required fields (scheme, pubkey, secret) are missing or incorrect in the connection URI.");
75+
if (pubkey.isEmpty ||
76+
secret == null ||
77+
parsedUri.scheme != 'nostr+walletconnect') {
78+
throw Exception(
79+
"Required fields (scheme, pubkey, secret) are missing or incorrect in the connection URI.");
7780
}
7881

7982
// Parse relays - support both single relay and comma-separated relays
@@ -83,7 +86,11 @@ class NostrWalletConnectUri extends Equatable {
8386
List<String>? relayParams = parsedUri.queryParametersAll['relay'];
8487
if (relayParams != null) {
8588
for (var relay in relayParams) {
86-
List<String> commaSeparatedRelays = relay.split(',').map((r) => r.trim()).where((r) => r.isNotEmpty).toList();
89+
List<String> commaSeparatedRelays = relay
90+
.split(',')
91+
.map((r) => r.trim())
92+
.where((r) => r.isNotEmpty)
93+
.toList();
8794
for (String relay in commaSeparatedRelays) {
8895
if (!relaysList.contains(relay)) {
8996
relaysList.add(relay);
@@ -95,8 +102,11 @@ class NostrWalletConnectUri extends Equatable {
95102
// Check for comma-separated relays in a single parameter
96103
String? relaysParam = parsedUri.queryParameters['relays'];
97104
if (relaysParam != null) {
98-
List<String> commaSeparatedRelays =
99-
relaysParam.split(',').map((r) => r.trim()).where((r) => r.isNotEmpty).toList();
105+
List<String> commaSeparatedRelays = relaysParam
106+
.split(',')
107+
.map((r) => r.trim())
108+
.where((r) => r.isNotEmpty)
109+
.toList();
100110
for (String relay in commaSeparatedRelays) {
101111
if (!relaysList.contains(relay)) {
102112
relaysList.add(relay);

packages/ndk/lib/domain_layer/usecases/nwc/nwc.dart

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ class Nwc {
109109

110110
await _subscribeToNotificationsAndResponses(connection);
111111

112-
if (doGetInfoMethod && (ignoreCapabilitiesCheck ||
113-
connection.permissions.contains(NwcMethod.GET_INFO.name))) {
112+
if (doGetInfoMethod &&
113+
(ignoreCapabilitiesCheck ||
114+
connection.permissions.contains(NwcMethod.GET_INFO.name))) {
114115
try {
115116
await getInfo(connection, timeout: timeout).then((info) {
116117
connection.info = info;
@@ -145,7 +146,8 @@ class Nwc {
145146
connection.subscription = _requests.subscription(
146147
name:
147148
"nwc-sub-${connection.useETagForEachRequest ? "notifs-only" : ""}",
148-
explicitRelays: connection.uri.relays.map((r) => Uri.decodeFull(r)).toList(),
149+
explicitRelays:
150+
connection.uri.relays.map((r) => Uri.decodeFull(r)).toList(),
149151
filters: [
150152
Filter(
151153
kinds: kindsToSubscribe,
@@ -298,7 +300,8 @@ class Nwc {
298300
);
299301
dedicatedResponse = _requests.subscription(
300302
name: "nwc-response-",
301-
explicitRelays: connection.uri.relays.map((r) => Uri.decodeFull(r)).toList(),
303+
explicitRelays:
304+
connection.uri.relays.map((r) => Uri.decodeFull(r)).toList(),
302305
filters: [responseFilter],
303306
cacheRead: false,
304307
cacheWrite: false);
@@ -323,7 +326,8 @@ class Nwc {
323326

324327
final bResponse = _broadcast.broadcast(
325328
nostrEvent: event,
326-
specificRelays: connection.uri.relays.map((r) => Uri.decodeFull(r)).toList(),
329+
specificRelays:
330+
connection.uri.relays.map((r) => Uri.decodeFull(r)).toList(),
327331
customSigner: connection.signer,
328332
);
329333
await bResponse.broadcastDoneFuture;
@@ -375,8 +379,10 @@ class Nwc {
375379
}
376380

377381
/// Does a `get_balance` request
378-
Future<GetBalanceResponse> getBalance(NwcConnection connection, {Duration? timeout}) async {
379-
return _executeRequest<GetBalanceResponse>(connection, GetBalanceRequest(), timeout: timeout);
382+
Future<GetBalanceResponse> getBalance(NwcConnection connection,
383+
{Duration? timeout}) async {
384+
return _executeRequest<GetBalanceResponse>(connection, GetBalanceRequest(),
385+
timeout: timeout);
380386
}
381387

382388
/// Does a `get_balance` request

packages/ndk/lib/shared/logger/log_level.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// Log levels for the NDK logger.
2-
///
2+
///
33
/// Defines the severity levels for logging messages.
44
enum LogLevel {
55
/// Log everything - lowest priority

packages/ndk/test/relays/requests_test.dart

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ void main() async {
131131
await relay1.stopServer();
132132
});
133133

134-
test('Subscription processes events immediately without stream closing', () async {
134+
test('Subscription processes events immediately without stream closing',
135+
() async {
135136
// This test would FAIL with the previous VerifyEventStream implementation
136137
// because events would remain stuck in buffer until stream closes
137138
MockRelay relay1 = MockRelay(name: "relay 1", explicitPort: 6060);
@@ -143,9 +144,11 @@ void main() async {
143144
engine: NdkEngine.RELAY_SETS,
144145
bootstrapRelays: [relay1.url],
145146
));
146-
ndk.accounts.loginPrivateKey(pubkey: key1.publicKey, privkey: key1.privateKey!);
147+
ndk.accounts
148+
.loginPrivateKey(pubkey: key1.publicKey, privkey: key1.privateKey!);
147149

148-
final filter = Filter(kinds: [Nip01Event.kTextNodeKind], authors: [key1.publicKey]);
150+
final filter =
151+
Filter(kinds: [Nip01Event.kTextNodeKind], authors: [key1.publicKey]);
149152

150153
// Use subscription instead of query - this creates a long-lived stream
151154
final subscription = ndk.requests.subscription(filters: [filter]);
@@ -160,7 +163,8 @@ void main() async {
160163
await Future.delayed(Duration(milliseconds: 200));
161164

162165
expect(receivedEvents.length, equals(1),
163-
reason: 'Subscription should process events immediately without waiting for stream to close');
166+
reason:
167+
'Subscription should process events immediately without waiting for stream to close');
164168
expect(receivedEvents[0].content, contains('key1'));
165169

166170
// Clean up
@@ -171,7 +175,8 @@ void main() async {
171175
await relay1.stopServer();
172176
});
173177

174-
test('Subscription handles continuous events from non-closing stream', () async {
178+
test('Subscription handles continuous events from non-closing stream',
179+
() async {
175180
// This test simulates a real-world scenario where a subscription
176181
// receives events continuously without the stream ever closing
177182
MockRelay relay1 = MockRelay(name: "relay 1", explicitPort: 6060);
@@ -191,10 +196,17 @@ void main() async {
191196
engine: NdkEngine.RELAY_SETS,
192197
bootstrapRelays: [relay1.url],
193198
));
194-
ndk.accounts.loginPrivateKey(pubkey: key1.publicKey, privkey: key1.privateKey!);
199+
ndk.accounts
200+
.loginPrivateKey(pubkey: key1.publicKey, privkey: key1.privateKey!);
195201

196-
final filter = Filter(
197-
kinds: [Nip01Event.kTextNodeKind], authors: [key1.publicKey, key2.publicKey, key3.publicKey, key4.publicKey]);
202+
final filter = Filter(kinds: [
203+
Nip01Event.kTextNodeKind
204+
], authors: [
205+
key1.publicKey,
206+
key2.publicKey,
207+
key3.publicKey,
208+
key4.publicKey
209+
]);
198210

199211
final subscription = ndk.requests.subscription(filters: [filter]);
200212

@@ -208,11 +220,14 @@ void main() async {
208220
// because they would get stuck in the verification buffer
209221
await Future.delayed(Duration(milliseconds: 300));
210222

211-
expect(receivedEvents.length, equals(4), reason: 'Subscription should process all matching events immediately');
223+
expect(receivedEvents.length, equals(4),
224+
reason:
225+
'Subscription should process all matching events immediately');
212226

213227
// Verify we got events from different authors (showing parallel processing worked)
214228
final uniqueAuthors = receivedEvents.map((e) => e.pubKey).toSet();
215-
expect(uniqueAuthors.length, greaterThan(1), reason: 'Should receive events from multiple authors');
229+
expect(uniqueAuthors.length, greaterThan(1),
230+
reason: 'Should receive events from multiple authors');
216231

217232
// Clean up
218233
await streamSubscription.cancel();

packages/ndk/test/usecases/broadcast_jit_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ void main() async {
127127
Filter(authors: [event1.pubKey], kinds: [Nip01Event.kTextNodeKind])
128128
]).future;
129129

130-
response1 = ndk.broadcast.broadcastDeletion(eventIds: [event1.id, event2.id]);
130+
response1 =
131+
ndk.broadcast.broadcastDeletion(eventIds: [event1.id, event2.id]);
131132
await response1.broadcastDoneFuture;
132133

133134
list = await ndk.requests.query(filters: [
@@ -136,7 +137,8 @@ void main() async {
136137
expect(list, isEmpty);
137138
});
138139

139-
test('broadcast deletion with empty eventIds throws ArgumentError', () async {
140+
test('broadcast deletion with empty eventIds throws ArgumentError',
141+
() async {
140142
ndk.accounts
141143
.loginPrivateKey(pubkey: key0.publicKey, privkey: key0.privateKey!);
142144
expect(

packages/ndk/test/usecases/broadcast_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ void main() async {
129129
Filter(authors: [event1.pubKey], kinds: [Nip01Event.kTextNodeKind])
130130
]).future;
131131

132-
response1 = ndk.broadcast.broadcastDeletion(eventIds: [event1.id, event2.id]);
132+
response1 =
133+
ndk.broadcast.broadcastDeletion(eventIds: [event1.id, event2.id]);
133134
await response1.broadcastDoneFuture;
134135

135136
list = await ndk.requests.query(filters: [
@@ -166,7 +167,8 @@ void main() async {
166167
expect(list.first.content, reaction);
167168
});
168169

169-
test('broadcast deletion with empty eventIds throws ArgumentError', () async {
170+
test('broadcast deletion with empty eventIds throws ArgumentError',
171+
() async {
170172
ndk.accounts
171173
.loginPrivateKey(pubkey: key0.publicKey, privkey: key0.privateKey!);
172174
expect(

packages/ndk/test/usecases/nwc/nostr_wallet_connect_uri_test.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ void main() {
3131
]));
3232
expect(nostrUri.secret, equals('secret123'));
3333
});
34-
test('should parse a connection URI with multiple individual relay parameters', () {
34+
test(
35+
'should parse a connection URI with multiple individual relay parameters',
36+
() {
3537
final uri =
3638
'nostr+walletconnect://pubkey123?relay=wss://relay1.example.com&relay=wss://relay2.example.com&relay=wss://relay3.example.com&secret=secret123';
3739
final nostrUri = NostrWalletConnectUri.parseConnectionUri(uri);
@@ -75,7 +77,8 @@ void main() {
7577
});
7678

7779
test('should throw an exception for missing required fields', () {
78-
final uri = 'nostr+walletconnect://pubkey123?relays=wss://relay.example.com';
80+
final uri =
81+
'nostr+walletconnect://pubkey123?relays=wss://relay.example.com';
7982

8083
expect(
8184
() => NostrWalletConnectUri.parseConnectionUri(uri),

packages/ndk/test/verifiers/verify_event_stream_test.dart

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,25 @@ void main() {
225225

226226
await Future.delayed(Duration(milliseconds: 50));
227227

228-
expect(resultList.length, equals(1), reason: 'First event should be processed immediately');
228+
expect(resultList.length, equals(1),
229+
reason: 'First event should be processed immediately');
229230
expect(resultList[0].content, equals('content1'));
230231

231232
controller.add(createMockEvent('2'));
232233

233234
await Future.delayed(Duration(milliseconds: 50));
234235

235-
expect(resultList.length, equals(2), reason: 'Second event should be processed immediately');
236+
expect(resultList.length, equals(2),
237+
reason: 'Second event should be processed immediately');
236238
expect(resultList[1].content, equals('content2'));
237239

238240
await subscription.cancel();
239241
await controller.close();
240242
});
241243

242-
test('should process events from non-closing stream with fewer events than maxConcurrent', () async {
244+
test(
245+
'should process events from non-closing stream with fewer events than maxConcurrent',
246+
() async {
243247
final controller = StreamController<Nip01Event>();
244248
final resultList = <Nip01Event>[];
245249

@@ -259,7 +263,9 @@ void main() {
259263

260264
await Future.delayed(Duration(milliseconds: 100));
261265

262-
expect(resultList.length, equals(3), reason: 'All events should be processed even when count < maxConcurrent');
266+
expect(resultList.length, equals(3),
267+
reason:
268+
'All events should be processed even when count < maxConcurrent');
263269

264270
await subscription.cancel();
265271
await controller.close();
@@ -286,8 +292,10 @@ void main() {
286292

287293
await Future.delayed(Duration(milliseconds: 50));
288294

289-
expect(resultList.length, equals(1), reason: 'Fast event should complete first');
290-
expect(resultList[0].content, equals('contentfast'), reason: 'Fast event should be yielded before slow event');
295+
expect(resultList.length, equals(1),
296+
reason: 'Fast event should complete first');
297+
expect(resultList[0].content, equals('contentfast'),
298+
reason: 'Fast event should be yielded before slow event');
291299

292300
await Future.delayed(Duration(milliseconds: 80));
293301

@@ -298,7 +306,8 @@ void main() {
298306
await controller.close();
299307
});
300308

301-
test('should handle continuous stream of events without blocking', () async {
309+
test('should handle continuous stream of events without blocking',
310+
() async {
302311
final controller = StreamController<Nip01Event>();
303312
final resultList = <Nip01Event>[];
304313

@@ -319,19 +328,23 @@ void main() {
319328

320329
if (i >= 2) {
321330
expect(resultList.length, greaterThan(0),
322-
reason: 'Events should be processed continuously, not waiting for stream end');
331+
reason:
332+
'Events should be processed continuously, not waiting for stream end');
323333
}
324334
}
325335

326336
await Future.delayed(Duration(milliseconds: 100));
327337

328-
expect(resultList.length, equals(10), reason: 'All events should be processed from continuous stream');
338+
expect(resultList.length, equals(10),
339+
reason: 'All events should be processed from continuous stream');
329340

330341
await subscription.cancel();
331342
await controller.close();
332343
});
333344

334-
test('should not deadlock when maxConcurrent is reached with non-closing stream', () async {
345+
test(
346+
'should not deadlock when maxConcurrent is reached with non-closing stream',
347+
() async {
335348
final controller = StreamController<Nip01Event>();
336349
final resultList = <Nip01Event>[];
337350

@@ -352,13 +365,15 @@ void main() {
352365

353366
await Future.delayed(Duration(milliseconds: 200));
354367

355-
expect(resultList.length, equals(4), reason: 'Should process all events without deadlocking');
368+
expect(resultList.length, equals(4),
369+
reason: 'Should process all events without deadlocking');
356370

357371
await subscription.cancel();
358372
await controller.close();
359373
});
360374

361-
test('should yield events immediately upon verification completion', () async {
375+
test('should yield events immediately upon verification completion',
376+
() async {
362377
final controller = StreamController<Nip01Event>();
363378
final resultTimes = <DateTime>[];
364379

@@ -386,7 +401,9 @@ void main() {
386401

387402
for (int i = 0; i < resultTimes.length; i++) {
388403
final timeDiff = resultTimes[i].difference(startTime).inMilliseconds;
389-
expect(timeDiff, lessThan(200), reason: 'Event $i should be processed within 200ms, was ${timeDiff}ms');
404+
expect(timeDiff, lessThan(200),
405+
reason:
406+
'Event $i should be processed within 200ms, was ${timeDiff}ms');
390407
}
391408

392409
await subscription.cancel();

0 commit comments

Comments
 (0)