@@ -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);
0 commit comments