mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-11-17 15:26:14 +00:00
Move generation of keys inside State0::new
The event loop will now use this function so I want to simplify its usage to avoid having to instantiate too many items to use it.
This commit is contained in:
parent
788445964a
commit
fd084b764d
@ -175,30 +175,20 @@ impl Builder {
|
|||||||
btc_to_swap: bitcoin::Amount,
|
btc_to_swap: bitcoin::Amount,
|
||||||
xmr_to_swap: monero::Amount,
|
xmr_to_swap: monero::Amount,
|
||||||
) -> Result<AliceState> {
|
) -> Result<AliceState> {
|
||||||
let rng = &mut OsRng;
|
|
||||||
|
|
||||||
let amounts = SwapAmounts {
|
let amounts = SwapAmounts {
|
||||||
btc: btc_to_swap,
|
btc: btc_to_swap,
|
||||||
xmr: xmr_to_swap,
|
xmr: xmr_to_swap,
|
||||||
};
|
};
|
||||||
|
|
||||||
let a = bitcoin::SecretKey::new_random(rng);
|
|
||||||
let s_a = cross_curve_dleq::Scalar::random(rng);
|
|
||||||
let v_a = monero::PrivateViewKey::new_random(rng);
|
|
||||||
let redeem_address = self.bitcoin_wallet.new_address().await?;
|
|
||||||
let punish_address = redeem_address.clone();
|
|
||||||
let state0 = State0::new(
|
let state0 = State0::new(
|
||||||
a,
|
|
||||||
s_a,
|
|
||||||
v_a,
|
|
||||||
amounts.btc,
|
amounts.btc,
|
||||||
amounts.xmr,
|
amounts.xmr,
|
||||||
self.execution_params.bitcoin_cancel_timelock,
|
self.execution_params.bitcoin_cancel_timelock,
|
||||||
self.execution_params.bitcoin_punish_timelock,
|
self.execution_params.bitcoin_punish_timelock,
|
||||||
redeem_address,
|
self.bitcoin_wallet.as_ref(),
|
||||||
punish_address,
|
&mut OsRng,
|
||||||
rng,
|
)
|
||||||
);
|
.await?;
|
||||||
|
|
||||||
Ok(AliceState::Started { amounts, state0 })
|
Ok(AliceState::Started { amounts, state0 })
|
||||||
}
|
}
|
||||||
|
@ -101,25 +101,25 @@ pub struct State0 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl State0 {
|
impl State0 {
|
||||||
#[allow(clippy::too_many_arguments)]
|
pub async fn new<R>(
|
||||||
pub fn new<R>(
|
|
||||||
a: bitcoin::SecretKey,
|
|
||||||
s_a: cross_curve_dleq::Scalar,
|
|
||||||
v_a: monero::PrivateViewKey,
|
|
||||||
btc: bitcoin::Amount,
|
btc: bitcoin::Amount,
|
||||||
xmr: monero::Amount,
|
xmr: monero::Amount,
|
||||||
cancel_timelock: Timelock,
|
cancel_timelock: Timelock,
|
||||||
punish_timelock: Timelock,
|
punish_timelock: Timelock,
|
||||||
redeem_address: bitcoin::Address,
|
bitcoin_wallet: &bitcoin::Wallet,
|
||||||
punish_address: bitcoin::Address,
|
|
||||||
rng: &mut R,
|
rng: &mut R,
|
||||||
) -> Self
|
) -> Result<Self>
|
||||||
where
|
where
|
||||||
R: RngCore + CryptoRng,
|
R: RngCore + CryptoRng,
|
||||||
{
|
{
|
||||||
|
let a = bitcoin::SecretKey::new_random(rng);
|
||||||
|
let s_a = cross_curve_dleq::Scalar::random(rng);
|
||||||
|
let v_a = monero::PrivateViewKey::new_random(rng);
|
||||||
|
let redeem_address = bitcoin_wallet.new_address().await?;
|
||||||
|
let punish_address = redeem_address.clone();
|
||||||
let dleq_proof_s_a = cross_curve_dleq::Proof::new(rng, &s_a);
|
let dleq_proof_s_a = cross_curve_dleq::Proof::new(rng, &s_a);
|
||||||
|
|
||||||
Self {
|
Ok(Self {
|
||||||
a,
|
a,
|
||||||
s_a,
|
s_a,
|
||||||
v_a,
|
v_a,
|
||||||
@ -130,7 +130,7 @@ impl State0 {
|
|||||||
xmr,
|
xmr,
|
||||||
cancel_timelock,
|
cancel_timelock,
|
||||||
punish_timelock,
|
punish_timelock,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn receive(self, msg: Message0) -> Result<State1> {
|
pub fn receive(self, msg: Message0) -> Result<State1> {
|
||||||
|
Loading…
Reference in New Issue
Block a user