Skip to content

Commit 4d9f010

Browse files
committed
Update ldk_node.dart
1 parent d920a4a commit 4d9f010

File tree

3 files changed

+48
-55
lines changed

3 files changed

+48
-55
lines changed

CHANGELOG.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
11
## [0.3.0]
2-
Updated `flutter_rust_bridge` to `2.0.0`.
3-
#### APIs added
4-
- `buildWithFsStore` method is added in the `Builder` class allowing to use the filesystem storage backend.
5-
- Exposed `setLiquiditySourceLsps2` method to `Builder` to configure the `Node` instance to source the inbound liquidity.
6-
- `nextEventAsync` method is added to `Node` class that allows polling the event queue asynchronously.
7-
- `status` method has been added to `Node` allowing to retrieve information about the Node's status.
8-
- `config` method added to get the config with which the `Node` was initialized.
9-
- The payment APIs have been restructured to use per-type (bolt11, onchain, bolt12) payment handlers which can be accessed via `node.{type}Payment`.
10-
- Support for sourcing inbound liquidity via LSPS2 just-in-time (JIT) channels has been added.
11-
- Support for creating and paying BOLT12 offers and refunds has been added.
12-
- Added `networkGraph` handler method allowing to query the network graph.
13-
- Added `forceCloseChannel` to `Node` class.
14-
#### API changed
15-
- All available balances outside of channel balances are now exposed via a unified `listBalances` interface method.
16-
#### Fixed
17-
Persisted peers are now correctly reconnected after startup.
182

193
## [0.2.2-dev]
204
Updated Rust and Flutter dependencies.

example/lib/main.dart

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,46 @@ class _MyAppState extends State<MyApp> {
3636
'http://10.0.2.2:30000'
3737
: 'http://127.0.0.1:30000';*/
3838

39+
3940
@override
4041
void initState() {
4142
initAliceNode();
4243
super.initState();
4344
}
4445

45-
Future<ldk.Builder> createBuilder(
46-
String path, ldk.SocketAddress address, String mnemonic) async {
46+
Future<ldk.Config> initLdkConfig(
47+
String path, ldk.SocketAddress address) async {
4748
final directory = await getApplicationDocumentsDirectory();
48-
final nodeStorageDir = "${directory.path}/ldk_cache/$path";
49-
print(nodeStorageDir);
50-
// For a node on the mutiny network with default config and service
51-
ldk.Builder builder = ldk.Builder.mutinynet()
52-
.setEntropyBip39Mnemonic(mnemonic: ldk.Mnemonic(seedPhrase: mnemonic))
53-
.setEsploraServer(esploraUrl)
54-
.setStorageDirPath(nodeStorageDir)
55-
.setListeningAddresses([address]);
56-
return builder;
49+
final nodePath = "${directory.path}/ldk_cache/$path";
50+
final config = ldk.Config(
51+
probingLiquidityLimitMultiplier: BigInt.from(3),
52+
trustedPeers0Conf: [],
53+
storageDirPath: nodePath,
54+
network: ldk.Network.regtest,
55+
listeningAddresses: [address],
56+
onchainWalletSyncIntervalSecs: BigInt.from(60),
57+
walletSyncIntervalSecs: BigInt.from(20),
58+
feeRateCacheUpdateIntervalSecs: BigInt.from(600),
59+
logLevel: ldk.LogLevel.debug,
60+
defaultCltvExpiryDelta: 144);
61+
return config;
62+
}
63+
64+
closeChannel() async {
65+
await aliceNode.closeChannel(
66+
userChannelId: userChannelId!, counterpartyNodeId: bobNodeId!);
5767
}
5868

5969
Future initAliceNode() async {
60-
aliceNode = await (await createBuilder(
61-
'alice_mutinynet',
62-
ldk.SocketAddress.hostname(addr: "0.0.0.0", port: 3003),
63-
"cart super leaf clinic pistol plug replace close super tooth wealth usage"))
70+
final aliceConfig = await initLdkConfig('alice_mutinynet',
71+
ldk.SocketAddress.hostname(addr: "0.0.0.0", port: 3003));
72+
ldk.Builder aliceBuilder = ldk.Builder.fromConfig(config: aliceConfig);
73+
aliceNode = await aliceBuilder
74+
.setEntropyBip39Mnemonic(
75+
mnemonic: ldk.Mnemonic(
76+
seedPhrase:
77+
"cart super leaf clinic pistol plug replace close super tooth wealth usage"))
78+
.setEsploraServer(esploraUrl)
6479
.build();
6580
await startNode(aliceNode);
6681
final res = await aliceNode.nodeId();
@@ -70,11 +85,22 @@ class _MyAppState extends State<MyApp> {
7085
});
7186
}
7287

88+
startNode(ldk.Node node) async {
89+
try {
90+
node.start();
91+
} on ldk.NodeException catch (e) {
92+
print(e.toString());
93+
}
94+
}
95+
7396
initBobNode() async {
74-
bobNode = await (await createBuilder(
75-
'bob_mutinynet',
76-
ldk.SocketAddress.hostname(addr: "0.0.0.0", port: 3004),
77-
"puppy interest whip tonight dad never sudden response push zone pig patch"))
97+
ldk.Builder bobBuilder = ldk.Builder
98+
.mutinynet(); // For a node on the mutiny network with default config and services
99+
bobNode = await bobBuilder
100+
.setEntropyBip39Mnemonic(
101+
mnemonic: ldk.Mnemonic(
102+
seedPhrase:
103+
'puppy interest whip tonight dad never sudden response push zone pig patch'))
78104
.build();
79105
await startNode(bobNode);
80106
final res = await bobNode.nodeId();
@@ -84,14 +110,6 @@ class _MyAppState extends State<MyApp> {
84110
});
85111
}
86112

87-
startNode(ldk.Node node) async {
88-
try {
89-
node.start();
90-
} on ldk.NodeException catch (e) {
91-
print(e.toString());
92-
}
93-
}
94-
95113
totalOnchainBalanceSats() async {
96114
final alice = await aliceNode.listBalances();
97115
final bob = await bobNode.listBalances();
@@ -122,7 +140,7 @@ class _MyAppState extends State<MyApp> {
122140
for (var e in res) {
123141
print("nodeId: ${aliceNodeId!.hex}");
124142
print("userChannelId: ${e.userChannelId.data}");
125-
print("confirmations required: ${e.confirmationsRequired}");
143+
print("channelId: ${e.channelId.data}");
126144
print("isChannelReady: ${e.isChannelReady}");
127145
print("isUsable: ${e.isUsable}");
128146
print("outboundCapacityMsat: ${e.outboundCapacityMsat}");
@@ -187,15 +205,6 @@ class _MyAppState extends State<MyApp> {
187205
}
188206
}
189207

190-
closeChannel() async {
191-
await aliceNode.closeChannel(
192-
userChannelId: userChannelId!,
193-
counterpartyNodeId: ldk.PublicKey(
194-
hex:
195-
'02465ed5be53d04fde66c9418ff14a5f2267723810176c9212b722e542dc1afb1b',
196-
));
197-
}
198-
199208
connectOpenChannel() async {
200209
final funding_amount_sat = 80000;
201210
final push_msat = (funding_amount_sat / 2) * 1000;
@@ -223,9 +232,8 @@ class _MyAppState extends State<MyApp> {
223232
amountMsat: BigInt.from(25000 * 1000),
224233
description: 'asdf',
225234
expirySecs: 9217);
226-
print(invoice!.signedRawInvoice);
227235
setState(() {
228-
displayText = invoice!.signedRawInvoice;
236+
displayText = invoice.toString();
229237
});
230238
final paymentId = await aliceBolt11Handler.send(invoice: invoice!);
231239
final res = await aliceNode.payment(paymentId: paymentId);

lib/ldk_node.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ export './src/generated/api/types.dart'
2929
GossipSourceConfig,
3030
EntropySourceConfig_SeedFile;
3131
export 'src/root.dart';
32+
export 'src/generated/lib.dart' show U8Array4, U8Array12, U8Array64, U8Array32;
3233
export 'src/utils/utils.dart'
3334
hide ExceptionBase, mapLdkBuilderError, mapLdkNodeError, Frb;

0 commit comments

Comments
 (0)