Skip to content

Commit 08d7816

Browse files
committed
chore: remove all frb from ltbl-ffi
1 parent a02504e commit 08d7816

28 files changed

+13799
-28262
lines changed

example/integration_test/bolt11_test.dart

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void main() {
4343
await core.init();
4444

4545
final aliceConfig = await initLdkConfig('alice',
46-
ldk.SocketAddress.hostname(addr: "0.0.0.0", port: 3001));
46+
ldk.AddressHostname(addr: "0.0.0.0", port: 3001).asSocket());
4747
debugPrint("Creating Alice builder...");
4848
final aliceBuilder = await ldk.Builder.fromConfig(config: aliceConfig)
4949
.setEntropyBip39Mnemonic(
@@ -59,7 +59,7 @@ void main() {
5959
await aliceNode.start();
6060
debugPrint("Alice node started successfully!");
6161
final bobConfig = await initLdkConfig(
62-
'bob', ldk.SocketAddress.hostname(addr: "0.0.0.0", port: 3002));
62+
'bob', ldk.AddressHostname(addr: "0.0.0.0", port: 3002).asSocket());
6363

6464
debugPrint("Creating Bob builder...");
6565
final bobBuilder = ldk.Builder.fromConfig(config: bobConfig)
@@ -126,7 +126,7 @@ void main() {
126126

127127
debugPrint("Opening channel from aliceNode to bobNode");
128128
final bobNodeId = await bobNode.nodeId();
129-
debugPrint("Bob's node ID: ${bobNodeId.hex}");
129+
debugPrint("Bob's node ID: ${bobNodeId.toString()}");
130130

131131
// Check if nodes can see each other
132132
final bobListeningAddresses = await bobNode.listeningAddresses();
@@ -142,7 +142,7 @@ void main() {
142142
channelAmountSats: BigInt.from(fundingAmountSat),
143143
pushToCounterpartyMsat: BigInt.from(pushMsat),
144144
);
145-
debugPrint("Channel created; id: ${userChannelId.data}");
145+
debugPrint("Channel created; id: ${await userChannelId.asVec()}");
146146

147147
// Wait a moment for the funding transaction to be broadcast
148148
await Future.delayed(const Duration(seconds: 2));
@@ -173,14 +173,16 @@ void main() {
173173
final channels = await aliceNode.listChannels();
174174
debugPrint("Alice has ${channels.length} channels");
175175

176-
final bobChannels = channels.where((e) => e.counterpartyNodeId.hex == bobNodeId.hex).toList();
176+
final bobChannels = channels.where((e) => e.counterpartyNodeId.toString() == bobNodeId.toString()).toList();
177+
178+
debugPrint("Alice has ${bobChannels.length} channels with Bob");
177179

178180
if (bobChannels.isNotEmpty) {
179181
final channel = bobChannels.first;
180182
debugPrint("Channel state: usable=${channel.isUsable}, ready=${channel.isChannelReady}, confirmations=${channel.confirmations}");
181183
debugPrint("Channel funding: ${channel.channelValueSats}sats, outbound capacity: ${channel.outboundCapacityMsat}msat");
182-
debugPrint("Channel ID: ${channel.channelId.data}, User Channel ID: ${channel.userChannelId.data}");
183-
184+
debugPrint("Channel ID: ${await channel.channelId.asBytes()}, User Channel ID: ${await channel.userChannelId.asVec()}");
185+
184186
// If channel has 0 confirmations, generate more blocks
185187
if (channel.confirmations == 0 && channelAttempts % 10 == 0) {
186188
debugPrint("Channel still has 0 confirmations, generating more blocks...");
@@ -209,7 +211,7 @@ void main() {
209211
debugPrint("Channel not ready after timeout! Checking final state...");
210212
final finalChannels = await aliceNode.listChannels();
211213
for (final channel in finalChannels) {
212-
debugPrint("Final channel state: counterparty=${channel.counterpartyNodeId.hex}, usable=${channel.isUsable}, ready=${channel.isChannelReady}");
214+
debugPrint("Final channel state: counterparty=${channel.counterpartyNodeId.toString()}, usable=${channel.isUsable}, ready=${channel.isChannelReady}");
213215
}
214216
}
215217

@@ -218,18 +220,18 @@ void main() {
218220
debugPrint("Alice has ${alicePeers.length} peers and ${aliceChannels.length} channels");
219221

220222
for (final peer in alicePeers) {
221-
debugPrint("Alice peer: ${peer.nodeId.hex}, connected: ${peer.isConnected}");
223+
debugPrint("Alice peer: ${peer.nodeId.toString()}, connected: ${peer.isConnected}");
222224
}
223225

224226
expect(
225-
(alicePeers.where((e) => e.nodeId.hex == bobNodeId.hex)).toList().isNotEmpty,
227+
(alicePeers.where((e) => e.nodeId.toString() == bobNodeId.toString())).toList().isNotEmpty,
226228
equals(true));
227229

228230
// Generate more blocks to ensure channel is well-confirmed
229231
await regTestClient.generate(5, await aliceNodeAddress.asString());
230232
expect(
231233
(aliceChannels
232-
.where((e) => e.counterpartyNodeId.hex == bobNodeId.hex))
234+
.where((e) => e.counterpartyNodeId.toString() == bobNodeId.toString()))
233235
.where((f) => f.isUsable && f.isChannelReady)
234236
.toList() !=
235237
[],
@@ -250,11 +252,11 @@ void main() {
250252
description: "BOLT11 payment test 1",
251253
expirySecs: 3600,
252254
);
253-
debugPrint("Invoice created: ${invoice1.signedRawInvoice}");
255+
debugPrint("Invoice created: ${invoice1.toString()}");
254256

255257
debugPrint("Alice sending payment to Bob's invoice...");
256258
final payment1Id = await aliceBolt11Handler.send(invoice: invoice1);
257-
debugPrint("Payment 1 successful: ${payment1Id.data}");
259+
debugPrint("Payment 1 successful: ${payment1Id.toVec()}");
258260

259261
// Wait for payment to be recorded
260262
await Future.delayed(const Duration(milliseconds: 500));
@@ -285,11 +287,11 @@ void main() {
285287
description: "BOLT11 payment test 2",
286288
expirySecs: 3600,
287289
);
288-
debugPrint("Second invoice created: ${invoice2.signedRawInvoice}");
290+
debugPrint("Second invoice created: ${invoice2.toString()}");
289291

290292
debugPrint("Alice sending second payment...");
291293
final payment2Id = await aliceBolt11Handler.send(invoice: invoice2);
292-
debugPrint("Payment 2 successful: ${payment2Id.data}");
294+
debugPrint("Payment 2 successful: ${payment2Id.toVec()}");
293295

294296
// Wait for payment to be recorded
295297
await Future.delayed(const Duration(milliseconds: 500));
@@ -303,9 +305,9 @@ void main() {
303305
expect(finalAlicePayments.length >= 2, true);
304306

305307
// Verify specific payments exist in Alice's list
306-
final payment1Match = finalAlicePayments.where((p) => listEquals(p.id.data, payment1Id.data)).toList();
307-
final payment2Match = finalAlicePayments.where((p) => listEquals(p.id.data, payment2Id.data)).toList();
308-
308+
final payment1Match = finalAlicePayments.where((p) => listEquals(p.id.toVec(), payment1Id.toVec())).toList();
309+
final payment2Match = finalAlicePayments.where((p) => listEquals(p.id.toVec(), payment2Id.toVec())).toList();
310+
309311
debugPrint("Payment 1 found in Alice's list: ${payment1Match.length == 1}");
310312
debugPrint("Payment 2 found in Alice's list: ${payment2Match.length == 1}");
311313

example/integration_test/bolt12_test.dart

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void main() {
4747
await core.init();
4848

4949
final aliceConfig = await initLdkConfig('alice',
50-
ldk.SocketAddress.hostname(addr: "0.0.0.0", port: 3003));
50+
ldk.AddressHostname(addr: "0.0.0.0", port: 3003).asSocket());
5151
debugPrint("Creating Alice builder...");
5252
final aliceBuilder = await ldk.Builder.fromConfig(config: aliceConfig)
5353
.setEntropyBip39Mnemonic(
@@ -65,7 +65,7 @@ void main() {
6565
await aliceNode.start();
6666
debugPrint("Alice node started successfully!");
6767
final bobConfig = await initLdkConfig(
68-
'bob', ldk.SocketAddress.hostname(addr: "0.0.0.0", port: 3004));
68+
'bob', ldk.AddressHostname(addr: "0.0.0.0", port: 3004).asSocket());
6969

7070
debugPrint("Creating Bob builder...");
7171
final bobBuilder = ldk.Builder.fromConfig(config: bobConfig)
@@ -132,7 +132,7 @@ void main() {
132132

133133
debugPrint("Opening channel from aliceNode to bobNode");
134134
final bobNodeId = await bobNode.nodeId();
135-
debugPrint("Bob's node ID: ${bobNodeId.hex}");
135+
debugPrint("Bob's node ID: ${bobNodeId.toString()}");
136136

137137
// Check if nodes can see each other
138138
final bobListeningAddresses = await bobNode.listeningAddresses();
@@ -148,8 +148,8 @@ void main() {
148148
channelAmountSats: BigInt.from(fundingAmountSat),
149149
pushToCounterpartyMsat: BigInt.from(pushMsat),
150150
);
151-
debugPrint("Channel created; id: ${userChannelId.data}");
152-
151+
debugPrint("Channel created; id: ${await userChannelId.asVec()}");
152+
153153
// Wait a moment for the funding transaction to be broadcast
154154
await Future.delayed(const Duration(seconds: 2));
155155
debugPrint("Waiting for funding transaction to be broadcast...");
@@ -179,14 +179,14 @@ void main() {
179179
final channels = await aliceNode.listChannels();
180180
debugPrint("Alice has ${channels.length} channels");
181181

182-
final bobChannels = channels.where((e) => e.counterpartyNodeId.hex == bobNodeId.hex).toList();
182+
final bobChannels = channels.where((e) => e.counterpartyNodeId.toString() == bobNodeId.toString()).toList();
183183

184184
if (bobChannels.isNotEmpty) {
185185
final channel = bobChannels.first;
186186
debugPrint("Channel state: usable=${channel.isUsable}, ready=${channel.isChannelReady}, confirmations=${channel.confirmations}");
187187
debugPrint("Channel funding: ${channel.channelValueSats}sats, outbound capacity: ${channel.outboundCapacityMsat}msat");
188-
debugPrint("Channel ID: ${channel.channelId.data}, User Channel ID: ${channel.userChannelId.data}");
189-
188+
debugPrint("Channel ID: ${await channel.channelId.asBytes()}, User Channel ID: ${await channel.userChannelId.asVec()}");
189+
190190
// If channel has 0 confirmations, generate more blocks
191191
if (channel.confirmations == 0 && channelAttempts % 10 == 0) {
192192
debugPrint("Channel still has 0 confirmations, generating more blocks...");
@@ -215,7 +215,7 @@ void main() {
215215
debugPrint("Channel not ready after timeout! Checking final state...");
216216
final finalChannels = await aliceNode.listChannels();
217217
for (final channel in finalChannels) {
218-
debugPrint("Final channel state: counterparty=${channel.counterpartyNodeId.hex}, usable=${channel.isUsable}, ready=${channel.isChannelReady}");
218+
debugPrint("Final channel state: counterparty=${channel.counterpartyNodeId.toString()}, usable=${channel.isUsable}, ready=${channel.isChannelReady}");
219219
}
220220
}
221221

@@ -224,18 +224,18 @@ void main() {
224224
debugPrint("Alice has ${alicePeers.length} peers and ${aliceChannels.length} channels");
225225

226226
for (final peer in alicePeers) {
227-
debugPrint("Alice peer: ${peer.nodeId.hex}, connected: ${peer.isConnected}");
227+
debugPrint("Alice peer: ${peer.nodeId.toString()}, connected: ${peer.isConnected}");
228228
}
229229

230230
expect(
231-
(alicePeers.where((e) => e.nodeId.hex == bobNodeId.hex)).toList().isNotEmpty,
231+
(alicePeers.where((e) => e.nodeId.toString() == bobNodeId.toString())).toList().isNotEmpty,
232232
equals(true));
233233

234234
// Generate more blocks to ensure channel is well-confirmed
235235
await regTestClient.generate(5, await aliceNodeAddress.asString());
236236
expect(
237237
(aliceChannels
238-
.where((e) => e.counterpartyNodeId.hex == bobNodeId.hex))
238+
.where((e) => e.counterpartyNodeId.toString() == bobNodeId.toString()))
239239
.where((f) => f.isUsable && f.isChannelReady)
240240
.toList() !=
241241
[],
@@ -259,7 +259,7 @@ void main() {
259259
final offer1 = await bobNodeBol12Handler.receive(
260260
amountMsat: payment1ExpectedAmountMsat, description: "payment_1");
261261
final payment1Id = await aliceNodeBol12Handler.send(offer: offer1);
262-
debugPrint("payment_1 successful: ${payment1Id.data.toString()}");
262+
debugPrint("payment_1 successful: ${payment1Id.toVec().toString()}");
263263

264264
// Wait a moment for the payment to be fully recorded
265265
await Future.delayed(const Duration(milliseconds: 500));
@@ -276,7 +276,7 @@ void main() {
276276
debugPrint("Offer2 created, now sending payment of ${payment2ExpectedAmountMsat}msat");
277277
final payment2Id = await aliceNodeBol12Handler.sendUsingAmount(
278278
offer: offer2, amountMsat: BigInt.from(payment2ExpectedAmountMsat));
279-
debugPrint("payment_2 successful: ${payment2Id.data.toString()}");
279+
debugPrint("payment_2 successful: ${payment2Id.toVec().toString()}");
280280

281281
// Wait a moment for the payment to be recorded
282282
await Future.delayed(const Duration(milliseconds: 500));
@@ -286,20 +286,20 @@ void main() {
286286
debugPrint("Alice now has ${allAlicePayments.length} total payments:");
287287
for (int i = 0; i < allAlicePayments.length; i++) {
288288
final payment = allAlicePayments[i];
289-
debugPrint(" Payment $i: ID=${payment.id.data}, amount=${payment.amountMsat}msat, status=${payment.status}");
289+
debugPrint(" Payment $i: ID=${payment.id.toVec()}, amount=${payment.amountMsat}msat, status=${payment.status}");
290290
}
291291

292292
// Check if payment2Id exists in the list
293-
final matchingPayments = allAlicePayments.where((e) => listEquals(e.id.data, payment2Id.data)).toList();
294-
debugPrint("Looking for payment with ID: ${payment2Id.data}");
293+
final matchingPayments = allAlicePayments.where((e) => listEquals(e.id.toVec(), payment2Id.toVec())).toList();
294+
debugPrint("Looking for payment with ID: ${payment2Id.toVec()}");
295295
debugPrint("Found ${matchingPayments.length} matching payments");
296296

297297
if (matchingPayments.isEmpty) {
298298
debugPrint("ERROR: payment_2 not found in Alice's payment list!");
299-
debugPrint("Expected payment ID: ${payment2Id.data}");
299+
debugPrint("Expected payment ID: ${payment2Id.toVec()}");
300300
debugPrint("All payment IDs in Alice's list:");
301301
for (int i = 0; i < allAlicePayments.length; i++) {
302-
debugPrint(" Payment $i ID: ${allAlicePayments[i].id.data}");
302+
debugPrint(" Payment $i ID: ${allAlicePayments[i].id.toVec()}");
303303
}
304304
}
305305

@@ -314,10 +314,10 @@ void main() {
314314
final bobNodePayment3Id = (await bobNode.listPayments())
315315
.firstWhere((p) => p.amountMsat == BigInt.from(overPaidAmount))
316316
.id;
317-
debugPrint("Bob's payment 3 ID: ${bobNodePayment3Id.data}");
317+
debugPrint("Bob's payment 3 ID: ${bobNodePayment3Id.toVec()}");
318318
expect(
319319
((await bobNode.listPayments()).where(
320-
(e) => listEquals(e.id.data, bobNodePayment3Id.data)))
320+
(e) => listEquals(e.id.toVec(), bobNodePayment3Id.toVec())))
321321
.length ==
322322
1,
323323
true);

example/lib/providers/wallet_provider.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ class WalletNotifier extends StateNotifier<WalletState> {
3838
.setChainSourceEsplora(
3939
esploraServerUrl: 'https://mutinynet.ltbl.io/api/')
4040
.setListeningAddresses(
41-
[ldk.SocketAddress.hostname(addr: '0.0.0.0', port: port)])
41+
[ldk.AddressHostname(addr: '0.0.0.0', port: port).asSocket()])
4242
.setLiquiditySourceLsps2(
43-
address: ldk.SocketAddress.hostname(
44-
addr: '192.243.215.101', port: 27110),
43+
address: ldk.AddressHostname(
44+
addr: '192.243.215.101',
45+
port: 27110,
46+
).asSocket(),
4547
publicKey: ldk.PublicKey(
4648
hex:
4749
'02764a0e09f2e8ec67708f11d853191e8ba4a7f06db1330fd0250ab3de10590a8e'),
@@ -196,7 +198,7 @@ class WalletNotifier extends StateNotifier<WalletState> {
196198
description: description,
197199
expirySecs: expirySecs,
198200
);
199-
return invoice.signedRawInvoice;
201+
return invoice.toString();
200202
} catch (e) {
201203
throw Exception('Failed to create invoice: $e');
202204
}
@@ -230,7 +232,7 @@ class WalletNotifier extends StateNotifier<WalletState> {
230232

231233
try {
232234
final socketAddress =
233-
ldk.SocketAddress.hostname(addr: address, port: port);
235+
ldk.AddressHostname(addr: address, port: port).asSocket();
234236
final publicKey = ldk.PublicKey(hex: nodeId);
235237

236238
await state.node!.openChannel(

example/lib/screens/dashboard_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
275275
const Spacer(),
276276
if (walletState.nodeId != null)
277277
Text(
278-
'ID: ${walletState.nodeId!.hex.substring(0, 8)}...',
278+
'ID: ${walletState.nodeId!.toString().substring(0, 8)}...',
279279
style: GoogleFonts.nunito(
280280
color: Colors.grey[600],
281281
fontSize: 12,

example/lib/screens/lightning_screen.dart

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_riverpod/flutter_riverpod.dart';
33
import 'package:google_fonts/google_fonts.dart';
4+
import 'package:ldk_node/src/generated/api/extensions.dart';
45
import 'package:ldk_node/src/generated/third_party/shared.dart';
56
import '../providers/wallet_provider.dart';
67
import 'package:qr_flutter/qr_flutter.dart';
@@ -346,15 +347,40 @@ class _LightningScreenState extends ConsumerState<LightningScreen>
346347

347348
void _showNodeInfoDialog() async {
348349
final walletState = ref.read(walletProvider);
349-
final nodeId = walletState.nodeId?.hex ?? 'Unavailable';
350+
final nodeId = walletState.nodeId?.toString() ?? 'Unavailable';
350351
String host = 'Unavailable';
351352
String port = 'Unavailable';
352353
if (walletState.node != null) {
353354
final addresses = await walletState.node!.listeningAddresses();
354355
if (addresses != null && addresses.isNotEmpty) {
355356
final addr = addresses.first;
356-
host = await addr.addr();
357-
port = await addr.port().toString();
357+
switch (addr.addressType()) {
358+
case SocketAddressType.tcpIpV4:
359+
// Assuming addr has field0 (List<int>) and field1 (int) for tcpIpV4
360+
final address_converted = addr.toTcpIpV4()!;
361+
host = address_converted.addr.join('.');
362+
port = address_converted.port.toString();
363+
break;
364+
case SocketAddressType.tcpIpV6:
365+
final address_converted = addr.toTcpIpV6()!;
366+
host = address_converted.addr.join(':');
367+
port = address_converted.port.toString();
368+
break;
369+
case SocketAddressType.onionV2:
370+
host = 'Onion V2';
371+
port = 'N/A';
372+
break;
373+
case SocketAddressType.onionV3:
374+
final address_converted = addr.toOnionV3()!;
375+
host = 'Onion V3';
376+
port = address_converted.port.toString();
377+
break;
378+
case SocketAddressType.hostname:
379+
final address_converted = addr.toHostname()!;
380+
host = address_converted.addr;
381+
port = address_converted.port.toString();
382+
break;
383+
}
358384
}
359385
}
360386
showDialog(

example/lib/screens/transaction_detail_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class TransactionDetailScreen extends ConsumerWidget {
284284
}
285285

286286
String _formatPaymentId() {
287-
final bytes = payment.id.data;
287+
final bytes = payment.id.toVec();
288288
return bytes
289289
.map((b) => b.toRadixString(16).padLeft(2, '0'))
290290
.join('')

0 commit comments

Comments
 (0)