Skip to content

Commit a63db29

Browse files
Merge pull request #52 from LtbLightning/minor-fixes
Minor fixes
2 parents a3beecd + 2566e7f commit a63db29

File tree

2 files changed

+55
-47
lines changed

2 files changed

+55
-47
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
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.
218

319
## [0.2.2-dev]
420
Updated Rust and Flutter dependencies.

example/lib/main.dart

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

39-
4039
@override
4140
void initState() {
4241
initAliceNode();
4342
super.initState();
4443
}
4544

46-
Future<ldk.Config> initLdkConfig(
47-
String path, ldk.SocketAddress address) async {
45+
Future<ldk.Builder> createBuilder(
46+
String path, ldk.SocketAddress address, String mnemonic) async {
4847
final directory = await getApplicationDocumentsDirectory();
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!);
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;
6757
}
6858

6959
Future initAliceNode() async {
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)
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"))
7964
.build();
8065
await startNode(aliceNode);
8166
final res = await aliceNode.nodeId();
@@ -85,22 +70,11 @@ class _MyAppState extends State<MyApp> {
8570
});
8671
}
8772

88-
startNode(ldk.Node node) async {
89-
try {
90-
node.start();
91-
} on ldk.NodeException catch (e) {
92-
print(e.toString());
93-
}
94-
}
95-
9673
initBobNode() async {
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'))
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"))
10478
.build();
10579
await startNode(bobNode);
10680
final res = await bobNode.nodeId();
@@ -110,6 +84,14 @@ class _MyAppState extends State<MyApp> {
11084
});
11185
}
11286

87+
startNode(ldk.Node node) async {
88+
try {
89+
node.start();
90+
} on ldk.NodeException catch (e) {
91+
print(e.toString());
92+
}
93+
}
94+
11395
totalOnchainBalanceSats() async {
11496
final alice = await aliceNode.listBalances();
11597
final bob = await bobNode.listBalances();
@@ -140,7 +122,7 @@ class _MyAppState extends State<MyApp> {
140122
for (var e in res) {
141123
print("nodeId: ${aliceNodeId!.hex}");
142124
print("userChannelId: ${e.userChannelId.data}");
143-
print("channelId: ${e.channelId.data}");
125+
print("confirmations required: ${e.confirmationsRequired}");
144126
print("isChannelReady: ${e.isChannelReady}");
145127
print("isUsable: ${e.isUsable}");
146128
print("outboundCapacityMsat: ${e.outboundCapacityMsat}");
@@ -205,6 +187,15 @@ class _MyAppState extends State<MyApp> {
205187
}
206188
}
207189

190+
closeChannel() async {
191+
await aliceNode.closeChannel(
192+
userChannelId: userChannelId!,
193+
counterpartyNodeId: ldk.PublicKey(
194+
hex:
195+
'02465ed5be53d04fde66c9418ff14a5f2267723810176c9212b722e542dc1afb1b',
196+
));
197+
}
198+
208199
connectOpenChannel() async {
209200
final funding_amount_sat = 80000;
210201
final push_msat = (funding_amount_sat / 2) * 1000;
@@ -232,8 +223,9 @@ class _MyAppState extends State<MyApp> {
232223
amountMsat: BigInt.from(25000 * 1000),
233224
description: 'asdf',
234225
expirySecs: 9217);
226+
print(invoice!.signedRawInvoice);
235227
setState(() {
236-
displayText = invoice.toString();
228+
displayText = invoice!.signedRawInvoice;
237229
});
238230
final paymentId = await aliceBolt11Handler.send(invoice: invoice!);
239231
final res = await aliceNode.payment(paymentId: paymentId);

0 commit comments

Comments
 (0)