@@ -568,7 +568,7 @@ object Transactions {
568
568
def makeClaimP2WPKHOutputTx (commitTx : Transaction , localDustLimit : Satoshi , localPaymentPubkey : PublicKey , localFinalScriptPubKey : ByteVector , feeratePerKw : FeeratePerKw ): Either [TxGenerationSkipped , ClaimP2WPKHOutputTx ] = {
569
569
val redeemScript = Script .pay2pkh(localPaymentPubkey)
570
570
val pubkeyScript = write(pay2wpkh(localPaymentPubkey))
571
- findPubKeyScriptIndex(commitTx, pubkeyScript, amount_opt = None ) match {
571
+ findPubKeyScriptIndex(commitTx, pubkeyScript) match {
572
572
case Left (skip) => Left (skip)
573
573
case Right (outputIndex) =>
574
574
val input = InputInfo (OutPoint (commitTx, outputIndex), commitTx.txOut(outputIndex), write(redeemScript))
@@ -594,7 +594,7 @@ object Transactions {
594
594
def makeClaimRemoteDelayedOutputTx (commitTx : Transaction , localDustLimit : Satoshi , localPaymentPubkey : PublicKey , localFinalScriptPubKey : ByteVector , feeratePerKw : FeeratePerKw ): Either [TxGenerationSkipped , ClaimRemoteDelayedOutputTx ] = {
595
595
val redeemScript = toRemoteDelayed(localPaymentPubkey)
596
596
val pubkeyScript = write(pay2wsh(redeemScript))
597
- findPubKeyScriptIndex(commitTx, pubkeyScript, amount_opt = None ) match {
597
+ findPubKeyScriptIndex(commitTx, pubkeyScript) match {
598
598
case Left (skip) => Left (skip)
599
599
case Right (outputIndex) =>
600
600
val input = InputInfo (OutPoint (commitTx, outputIndex), commitTx.txOut(outputIndex), write(redeemScript))
@@ -620,7 +620,7 @@ object Transactions {
620
620
def makeClaimLocalDelayedOutputTx (commitTx : Transaction , localDustLimit : Satoshi , localRevocationPubkey : PublicKey , toLocalDelay : CltvExpiryDelta , localDelayedPaymentPubkey : PublicKey , localFinalScriptPubKey : ByteVector , feeratePerKw : FeeratePerKw ): Either [TxGenerationSkipped , ClaimLocalDelayedOutputTx ] = {
621
621
val redeemScript = toLocalDelayed(localRevocationPubkey, toLocalDelay, localDelayedPaymentPubkey)
622
622
val pubkeyScript = write(pay2wsh(redeemScript))
623
- findPubKeyScriptIndex(commitTx, pubkeyScript, amount_opt = None ) match {
623
+ findPubKeyScriptIndex(commitTx, pubkeyScript) match {
624
624
case Left (skip) => Left (skip)
625
625
case Right (outputIndex) =>
626
626
val input = InputInfo (OutPoint (commitTx, outputIndex), commitTx.txOut(outputIndex), write(redeemScript))
@@ -646,7 +646,7 @@ object Transactions {
646
646
private def makeClaimAnchorOutputTx (commitTx : Transaction , fundingPubkey : PublicKey ): Either [TxGenerationSkipped , (InputInfo , Transaction )] = {
647
647
val redeemScript = anchor(fundingPubkey)
648
648
val pubkeyScript = write(pay2wsh(redeemScript))
649
- findPubKeyScriptIndex(commitTx, pubkeyScript, amount_opt = None ) match {
649
+ findPubKeyScriptIndex(commitTx, pubkeyScript) match {
650
650
case Left (skip) => Left (skip)
651
651
case Right (outputIndex) =>
652
652
val input = InputInfo (OutPoint (commitTx, outputIndex), commitTx.txOut(outputIndex), write(redeemScript))
@@ -668,12 +668,12 @@ object Transactions {
668
668
makeClaimAnchorOutputTx(commitTx, remoteFundingPubkey).map { case (input, tx) => ClaimRemoteAnchorOutputTx (input, tx) }
669
669
}
670
670
671
- def makeClaimHtlcDelayedOutputPenaltyTx (htlcTx : Transaction , localDustLimit : Satoshi , localRevocationPubkey : PublicKey , toLocalDelay : CltvExpiryDelta , localDelayedPaymentPubkey : PublicKey , localFinalScriptPubKey : ByteVector , feeratePerKw : FeeratePerKw ): Either [TxGenerationSkipped , ClaimHtlcDelayedOutputPenaltyTx ] = {
671
+ def makeClaimHtlcDelayedOutputPenaltyTxs (htlcTx : Transaction , localDustLimit : Satoshi , localRevocationPubkey : PublicKey , toLocalDelay : CltvExpiryDelta , localDelayedPaymentPubkey : PublicKey , localFinalScriptPubKey : ByteVector , feeratePerKw : FeeratePerKw ): Seq [ Either [TxGenerationSkipped , ClaimHtlcDelayedOutputPenaltyTx ] ] = {
672
672
val redeemScript = toLocalDelayed(localRevocationPubkey, toLocalDelay, localDelayedPaymentPubkey)
673
673
val pubkeyScript = write(pay2wsh(redeemScript))
674
- findPubKeyScriptIndex (htlcTx, pubkeyScript, amount_opt = None ) match {
675
- case Left (skip) => Left (skip)
676
- case Right (outputIndex ) =>
674
+ findPubKeyScriptIndexes (htlcTx, pubkeyScript) match {
675
+ case Left (skip) => Seq ( Left (skip) )
676
+ case Right (outputIndexes ) => outputIndexes.map(outputIndex => {
677
677
val input = InputInfo (OutPoint (htlcTx, outputIndex), htlcTx.txOut(outputIndex), write(redeemScript))
678
678
// unsigned transaction
679
679
val tx = Transaction (
@@ -691,13 +691,14 @@ object Transactions {
691
691
val tx1 = tx.copy(txOut = tx.txOut.head.copy(amount = amount) :: Nil )
692
692
Right (ClaimHtlcDelayedOutputPenaltyTx (input, tx1))
693
693
}
694
+ })
694
695
}
695
696
}
696
697
697
698
def makeMainPenaltyTx (commitTx : Transaction , localDustLimit : Satoshi , remoteRevocationPubkey : PublicKey , localFinalScriptPubKey : ByteVector , toRemoteDelay : CltvExpiryDelta , remoteDelayedPaymentPubkey : PublicKey , feeratePerKw : FeeratePerKw ): Either [TxGenerationSkipped , MainPenaltyTx ] = {
698
699
val redeemScript = toLocalDelayed(remoteRevocationPubkey, toRemoteDelay, remoteDelayedPaymentPubkey)
699
700
val pubkeyScript = write(pay2wsh(redeemScript))
700
- findPubKeyScriptIndex(commitTx, pubkeyScript, amount_opt = None ) match {
701
+ findPubKeyScriptIndex(commitTx, pubkeyScript) match {
701
702
case Left (skip) => Left (skip)
702
703
case Right (outputIndex) =>
703
704
val input = InputInfo (OutPoint (commitTx, outputIndex), commitTx.txOut(outputIndex), write(redeemScript))
@@ -760,21 +761,30 @@ object Transactions {
760
761
txIn = TxIn (commitTxInput.outPoint, ByteVector .empty, sequence = 0xffffffffL) :: Nil ,
761
762
txOut = toLocalOutput_opt.toSeq ++ toRemoteOutput_opt.toSeq ++ Nil ,
762
763
lockTime = 0 ))
763
- val toLocalOutput = findPubKeyScriptIndex(tx, localScriptPubKey, None ).map(index => OutputInfo (index, toLocalAmount, localScriptPubKey)).toOption
764
+ val toLocalOutput = findPubKeyScriptIndex(tx, localScriptPubKey).map(index => OutputInfo (index, toLocalAmount, localScriptPubKey)).toOption
764
765
ClosingTx (commitTxInput, tx, toLocalOutput)
765
766
}
766
767
767
- def findPubKeyScriptIndex (tx : Transaction , pubkeyScript : ByteVector , amount_opt : Option [Satoshi ]): Either [TxGenerationSkipped , Int ] = {
768
- val outputIndex = tx.txOut
769
- .zipWithIndex
770
- .indexWhere { case (txOut, _) => amount_opt.forall(_ == txOut.amount) && txOut.publicKeyScript == pubkeyScript }
768
+ def findPubKeyScriptIndex (tx : Transaction , pubkeyScript : ByteVector ): Either [TxGenerationSkipped , Int ] = {
769
+ val outputIndex = tx.txOut.indexWhere(_.publicKeyScript == pubkeyScript)
771
770
if (outputIndex >= 0 ) {
772
771
Right (outputIndex)
773
772
} else {
774
773
Left (OutputNotFound )
775
774
}
776
775
}
777
776
777
+ def findPubKeyScriptIndexes (tx : Transaction , pubkeyScript : ByteVector ): Either [TxGenerationSkipped , Seq [Int ]] = {
778
+ val outputIndexes = tx.txOut.zipWithIndex.collect {
779
+ case (txOut, index) if txOut.publicKeyScript == pubkeyScript => index
780
+ }
781
+ if (outputIndexes.nonEmpty) {
782
+ Right (outputIndexes)
783
+ } else {
784
+ Left (OutputNotFound )
785
+ }
786
+ }
787
+
778
788
/**
779
789
* Default public key used for fee estimation
780
790
*/
0 commit comments