@@ -416,35 +416,30 @@ 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 minDifficultyTarget = nodeParams.chainHash match {
420
+ case Block .LivenetGenesisBlock .hash => Try (context.system.settings.config.getLong(" eclair.bitcoind.min-difficulty-target" )).getOrElse(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
431
425
client.getTxConfirmations(w.txId).flatMap {
432
426
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
- }
427
+ for {
428
+ proof <- client.getTxConfirmationProof(w.txId)
429
+ _ = require(proof.confirmations >= confirmations)
430
+ _ = require(proof.headerInfos.forall(hi => hi.header.bits <= minDifficultyTarget))
431
+ height = BlockHeight (proof.height)
432
+ tx <- client.getTransaction(w.txId)
433
+ } yield {
434
+ w match {
435
+ case w : WatchFundingConfirmed => context.self ! TriggerEvent (w.replyTo, w, WatchFundingConfirmedTriggered (height, proof.txIndex, tx))
436
+ case w : WatchFundingDeeplyBuried => context.self ! TriggerEvent (w.replyTo, w, WatchFundingDeeplyBuriedTriggered (height, proof.txIndex, tx))
437
+ case w : WatchTxConfirmed => context.self ! TriggerEvent (w.replyTo, w, WatchTxConfirmedTriggered (height, proof.txIndex, tx))
438
+ case w : WatchParentTxConfirmed => context.self ! TriggerEvent (w.replyTo, w, WatchParentTxConfirmedTriggered (height, proof.txIndex, tx))
439
+ case w : WatchAlternativeCommitTxConfirmed => context.self ! TriggerEvent (w.replyTo, w, WatchAlternativeCommitTxConfirmedTriggered (height, proof.txIndex, tx))
444
440
}
445
- )
446
- case _ => Future .successful((): Unit )
441
+ }
442
+ case _ => Future .successful(())
447
443
}
448
444
}
449
-
450
445
}
0 commit comments