@ -4,6 +4,7 @@ use crate::bitcoin::{
use crate ::env ::Config ;
use crate ::monero ::wallet ::{ TransferRequest , WatchRequest } ;
use crate ::monero ::TransferProof ;
use crate ::monero_ext ::ScalarExt ;
use crate ::protocol ::alice ::{ Message1 , Message3 } ;
use crate ::protocol ::bob ::{ Message0 , Message2 , Message4 } ;
use crate ::protocol ::CROSS_CURVE_PROOF_SYSTEM ;
@ -76,18 +77,18 @@ impl fmt::Display for AliceState {
#[ derive(Clone, Debug, PartialEq) ]
pub struct State0 {
pub a : bitcoin ::SecretKey ,
pub s_a : monero ::Scalar ,
pub v_a : monero ::PrivateViewKey ,
pub ( crate ) S_a_monero : monero ::PublicKey ,
pub ( crate ) S_a_bitcoin : bitcoin ::PublicKey ,
pub dleq_proof_s_a : CrossCurveDLEQProof ,
pub btc : bitcoin ::Amount ,
pub xmr : monero ::Amount ,
pub cancel_timelock : CancelTimelock ,
pub punish_timelock : PunishTimelock ,
pub redeem_address : bitcoin ::Address ,
pub punish_address : bitcoin ::Address ,
a : bitcoin ::SecretKey ,
s_a : monero ::Scalar ,
v_a : monero ::PrivateViewKey ,
S_a_monero : monero ::PublicKey ,
S_a_bitcoin : bitcoin ::PublicKey ,
dleq_proof_s_a : CrossCurveDLEQProof ,
btc : bitcoin ::Amount ,
xmr : monero ::Amount ,
cancel_timelock : CancelTimelock ,
punish_timelock : PunishTimelock ,
redeem_address : bitcoin ::Address ,
punish_address : bitcoin ::Address ,
}
impl State0 {
@ -292,23 +293,23 @@ impl State2 {
#[ derive(Clone, Debug, Deserialize, Serialize, PartialEq) ]
pub struct State3 {
pub a : bitcoin ::SecretKey ,
pub B : bitcoin ::PublicKey ,
pub s_a : monero ::Scalar ,
pub S_b_monero : monero ::PublicKey ,
pub S_b_bitcoin : bitcoin ::PublicKey ,
a : bitcoin ::SecretKey ,
B : bitcoin ::PublicKey ,
s_a : monero ::Scalar ,
S_b_monero : monero ::PublicKey ,
S_b_bitcoin : bitcoin ::PublicKey ,
pub v : monero ::PrivateViewKey ,
#[ serde(with = " ::bitcoin::util::amount::serde::as_sat " ) ]
pub btc : bitcoin ::Amount ,
pub xmr : monero ::Amount ,
btc : bitcoin ::Amount ,
xmr : monero ::Amount ,
pub cancel_timelock : CancelTimelock ,
pub punish_timelock : PunishTimelock ,
pub refund_address : bitcoin ::Address ,
pub redeem_address : bitcoin ::Address ,
pub punish_address : bitcoin ::Address ,
refund_address : bitcoin ::Address ,
redeem_address : bitcoin ::Address ,
punish_address : bitcoin ::Address ,
pub tx_lock : bitcoin ::TxLock ,
pub tx_punish_sig_bob : bitcoin ::Signature ,
pub tx_cancel_sig_bob : bitcoin ::Signature ,
tx_punish_sig_bob : bitcoin ::Signature ,
tx_cancel_sig_bob : bitcoin ::Signature ,
}
impl State3 {
@ -364,15 +365,48 @@ impl State3 {
TxCancel ::new ( & self . tx_lock , self . cancel_timelock , self . a . public ( ) , self . B )
}
pub fn tx_punish ( & self ) -> TxPunish {
pub fn tx_refund ( & self ) -> TxRefund {
bitcoin ::TxRefund ::new ( & self . tx_cancel ( ) , & self . refund_address )
}
pub fn extract_monero_private_key (
& self ,
published_refund_tx : bitcoin ::Transaction ,
) -> Result < monero ::PrivateKey > {
self . tx_refund ( ) . extract_monero_private_key (
published_refund_tx ,
self . s_a ,
self . a . clone ( ) ,
self . S_b_bitcoin ,
)
}
pub fn signed_redeem_transaction (
& self ,
sig : bitcoin ::EncryptedSignature ,
) -> Result < bitcoin ::Transaction > {
bitcoin ::TxRedeem ::new ( & self . tx_lock , & self . redeem_address )
. complete ( sig , self . a . clone ( ) , self . s_a . to_secpfun_scalar ( ) , self . B )
. context ( "Failed to complete Bitcoin redeem transaction" )
}
pub fn signed_cancel_transaction ( & self ) -> Result < bitcoin ::Transaction > {
self . tx_cancel ( )
. complete_as_alice ( self . a . clone ( ) , self . B , self . tx_cancel_sig_bob . clone ( ) )
. context ( "Failed to complete Bitcoin cancel transaction" )
}
pub fn signed_punish_transaction ( & self ) -> Result < bitcoin ::Transaction > {
self . tx_punish ( )
. complete ( self . tx_punish_sig_bob . clone ( ) , self . a . clone ( ) , self . B )
. context ( "Failed to complete Bitcoin punish transaction" )
}
fn tx_punish ( & self ) -> TxPunish {
bitcoin ::TxPunish ::new (
& self . tx_cancel ( ) ,
& self . punish_address ,
self . punish_timelock ,
)
}
pub fn tx_refund ( & self ) -> TxRefund {
bitcoin ::TxRefund ::new ( & self . tx_cancel ( ) , & self . refund_address )
}
}