@@ -45,7 +45,7 @@ import {
4545// Step 13: Initialize networking ✅
4646// Step 14: Connect and Disconnect Blocks ✅
4747// Step 15: Handle LDK Events [WIP]
48- // Step 16: Initialize routing ProbabilisticScorer
48+ // Step 16: Initialize routing ProbabilisticScorer [Not sure if required]
4949// Step 17: Create InvoicePayer ✅
5050// Step 18: Persist ChannelManager and NetworkGraph
5151// Step 19: Background Processing
@@ -231,29 +231,35 @@ class LightningManager {
231231 }
232232
233233 /**
234- * Fetches current best block and sends to LDK.
235- * Updates both channelManager and chainMonitor .
234+ * Fetches current best block and sends to LDK to update both channelManager and chainMonitor .
235+ * Also watches transactions and outputs for confirmed and unconfirmed transactions and updated LDK .
236236 * @returns {Promise<Err<string> | Ok<string>> }
237237 */
238238 async syncLdk ( ) {
239239 const { bestblockhash, blocks } = await regtestBestBlock ( ) ;
240240
241- if ( this . currentBlockHash === bestblockhash ) {
242- return ; //No need to update
243- }
241+ //Don't update unnecessarily
242+ if ( this . currentBlockHash !== bestblockhash ) {
243+ const header = await regtestBlockHeaderHex ( bestblockhash ) ;
244+ const syncToTip = await ldk . syncToTip ( {
245+ header,
246+ height : blocks
247+ } ) ;
248+ if ( syncToTip . isErr ( ) ) {
249+ return syncToTip ;
250+ }
244251
245- const header = await regtestBlockHeaderHex ( bestblockhash ) ;
246- const syncToTip = await ldk . syncToTip ( {
247- header,
248- height : blocks
249- } ) ;
250- if ( syncToTip . isErr ( ) ) {
251- return syncToTip ;
252+ this . currentBlockHash = bestblockhash ;
252253 }
253254
254- this . currentBlockHash = bestblockhash ;
255-
256- //TODO fetch latest data for watchTxs and watchOutputs. Feed to transactions_confirmed() and transactions_confirmed()
255+ //TODO fetch latest data for watchTxs and watchOutputs. Feed any updates to LDK.
256+ // const setRes = await ldk.setTxConfirmed({
257+ // header: 'hex_encoded_header',
258+ // height: 1,
259+ // transaction: 'hex_encoded_tx',
260+ // pos: 1
261+ // });
262+ // const unsetRes = await ldk.setTxUnconfirmed({ txId: 'set_me' });
257263
258264 return ok ( `Synced to block ${ blocks } ` ) ;
259265 }
@@ -314,7 +320,7 @@ class LightningManager {
314320 }
315321
316322 private onChannelManagerPaymentPathSuccessful ( res : TChannelManagerPaymentPathSuccessful ) {
317- //Nothing to here. Optionally notify user?
323+ //Nothing to do here. Optionally notify user?
318324 console . log ( `onChannelManagerPaymentPathSuccessful: ${ JSON . stringify ( res ) } ` ) ; //TODO
319325 }
320326
0 commit comments