@ -1,12 +1,11 @@
use crate ::bitcoin ::{ Address , PublicKey , PunishTimelock , Transaction , TxCancel } ;
use crate ::bitcoin ::{ self , Address , PunishTimelock , Transaction , TxCancel } ;
use ::bitcoin ::util ::bip143 ::SigHashCache ;
use ::bitcoin ::{ SigHash , SigHashType } ;
use anyhow ::Result ;
use ecdsa_fun ::Signature ;
use anyhow ::{ Context , Result } ;
use miniscript ::{ Descriptor , DescriptorTrait } ;
use std ::collections ::HashMap ;
#[ derive( Debug)]
#[ derive( Clone, Debug)]
pub struct TxPunish {
inner : Transaction ,
digest : SigHash ,
@ -39,22 +38,20 @@ impl TxPunish {
self . digest
}
pub fn add_signatures (
pub fn complete (
self ,
( A , sig_a ) : ( PublicKey , Signature ) ,
( B , sig_b ) : ( PublicKey , Signature ) ,
tx_punish_sig_bob : bitcoin ::Signature ,
a : bitcoin ::SecretKey ,
B : bitcoin ::PublicKey ,
) -> Result < Transaction > {
let sig_a = a . sign ( self . digest ( ) ) ;
let sig_b = tx_punish_sig_bob ;
let satisfier = {
let mut satisfier = HashMap ::with_capacity ( 2 ) ;
let A = ::bitcoin ::PublicKey {
compressed : true ,
key : A . 0. into ( ) ,
} ;
let B = ::bitcoin ::PublicKey {
compressed : true ,
key : B . 0. into ( ) ,
} ;
let A = a . public ( ) . into ( ) ;
let B = B . into ( ) ;
// The order in which these are inserted doesn't matter
satisfier . insert ( A , ( sig_a . into ( ) , ::bitcoin ::SigHashType ::All ) ) ;
@ -65,7 +62,8 @@ impl TxPunish {
let mut tx_punish = self . inner ;
self . cancel_output_descriptor
. satisfy ( & mut tx_punish . input [ 0 ] , satisfier ) ? ;
. satisfy ( & mut tx_punish . input [ 0 ] , satisfier )
. context ( "Failed to satisfy inputs with given signatures" ) ? ;
Ok ( tx_punish )
}