@@ -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