@@ -416,35 +416,32 @@ private class ZmqWatcher(nodeParams: NodeParams, blockHeight: AtomicLong, client
416
416
private def checkConfirmed (w : WatchConfirmed [_ <: WatchConfirmedTriggered ]): Future [Unit ] = {
417
417
log.debug(" checking confirmations of txid={}" , w.txId)
418
418
419
- def checkConfirmationProof (): Future [Unit ] = {
420
- client.getTxConfirmationProof(w.txId).map(headerInfos => {
421
- if (nodeParams.chainHash == Block .LivenetGenesisBlock .hash) {
422
- // 0x1715a35cL = 387294044 = difficulty of block 600000
423
- val minDiff = Try (context.system.settings.config.getLong(" eclair.bitcoind.min-difficulty" )).getOrElse(0x1715a35cL)
424
- require(headerInfos.forall(hi => hi.header.bits < minDiff))
425
- }
426
- })
419
+ val defaultMinDifficultyTarget = nodeParams.chainHash match {
420
+ case Block .LivenetGenesisBlock .hash => 0x1715a35cL // 0x1715a35cL = 387294044 = difficulty target of block 600000
421
+ case Block .TestnetGenesisBlock .hash => 0x1d00ffffL
422
+ case _ => 0x207fffffL
427
423
}
428
424
429
- // NB: this is very inefficient since internally we call `getrawtransaction` three times, but it doesn't really
430
- // matter because this only happens once, when the watched transaction has reached min_depth
425
+ val minDifficultyTarget = Try (context.system.settings.config.getLong( " eclair.bitcoind.min-difficulty-target " )).getOrElse(defaultMinDifficultyTarget)
426
+
431
427
client.getTxConfirmations(w.txId).flatMap {
432
428
case Some (confirmations) if confirmations >= w.minDepth =>
433
- checkConfirmationProof().andThen(_ =>
434
- client.getTransaction(w.txId).flatMap { tx =>
435
- client.getTransactionShortId(w.txId).map {
436
- case (height, index) => w match {
437
- case w : WatchFundingConfirmed => context.self ! TriggerEvent (w.replyTo, w, WatchFundingConfirmedTriggered (height, index, tx))
438
- case w : WatchFundingDeeplyBuried => context.self ! TriggerEvent (w.replyTo, w, WatchFundingDeeplyBuriedTriggered (height, index, tx))
439
- case w : WatchTxConfirmed => context.self ! TriggerEvent (w.replyTo, w, WatchTxConfirmedTriggered (height, index, tx))
440
- case w : WatchParentTxConfirmed => context.self ! TriggerEvent (w.replyTo, w, WatchParentTxConfirmedTriggered (height, index, tx))
441
- case w : WatchAlternativeCommitTxConfirmed => context.self ! TriggerEvent (w.replyTo, w, WatchAlternativeCommitTxConfirmedTriggered (height, index, tx))
442
- }
443
- }
429
+ for {
430
+ proof <- client.getTxConfirmationProof(w.txId)
431
+ _ = require(proof.confirmations >= confirmations)
432
+ _ = require(proof.headerInfos.forall(hi => hi.header.bits <= minDifficultyTarget))
433
+ height = BlockHeight (proof.height)
434
+ tx <- client.getTransaction(w.txId)
435
+ } yield {
436
+ w match {
437
+ case w : WatchFundingConfirmed => context.self ! TriggerEvent (w.replyTo, w, WatchFundingConfirmedTriggered (height, proof.txIndex, tx))
438
+ case w : WatchFundingDeeplyBuried => context.self ! TriggerEvent (w.replyTo, w, WatchFundingDeeplyBuriedTriggered (height, proof.txIndex, tx))
439
+ case w : WatchTxConfirmed => context.self ! TriggerEvent (w.replyTo, w, WatchTxConfirmedTriggered (height, proof.txIndex, tx))
440
+ case w : WatchParentTxConfirmed => context.self ! TriggerEvent (w.replyTo, w, WatchParentTxConfirmedTriggered (height, proof.txIndex, tx))
441
+ case w : WatchAlternativeCommitTxConfirmed => context.self ! TriggerEvent (w.replyTo, w, WatchAlternativeCommitTxConfirmedTriggered (height, proof.txIndex, tx))
444
442
}
445
- )
446
- case _ => Future .successful((): Unit )
443
+ }
444
+ case _ => Future .successful(())
447
445
}
448
446
}
449
-
450
447
}
0 commit comments