Pass address/fees into State0 instead of passing in the wallet.

This commit is contained in:
Philipp Hoenisch 2021-05-03 16:32:52 +10:00
parent 14c5a4f025
commit 77f6f11a7f
No known key found for this signature in database
GPG Key ID: E5F8E74C672BC666
2 changed files with 25 additions and 12 deletions

View File

@ -1,4 +1,5 @@
use crate::asb::Rate;
use crate::bitcoin::TX_PUNISH_ESTIMATED_WEIGHT;
use crate::database::Database;
use crate::env::Config;
use crate::monero::BalanceTooLow;
@ -161,8 +162,26 @@ where
continue;
}
}
// TODO: This should be cleaned up.
let tx_redeem_fee = self.bitcoin_wallet
.estimate_fee(bitcoin::TxRedeem::weight())
.await.unwrap();
let tx_punish_fee = self.bitcoin_wallet
.estimate_fee(TX_PUNISH_ESTIMATED_WEIGHT)
.await.unwrap();
let redeem_address = self.bitcoin_wallet.new_address().await.unwrap();
let punish_address = self.bitcoin_wallet.new_address().await.unwrap();
let state0 = match State0::new(btc, xmr, self.env_config, self.bitcoin_wallet.as_ref(), &mut OsRng).await {
let state0 = match State0::new(
btc,
xmr,
self.env_config,
redeem_address,
punish_address,
tx_redeem_fee,
tx_punish_fee,
&mut OsRng
) {
Ok(state) => state,
Err(e) => {
tracing::warn!(%peer, "Failed to make State0 for execution setup: {:#}", e);

View File

@ -1,6 +1,5 @@
use crate::bitcoin::{
current_epoch, CancelTimelock, ExpiredTimelocks, PunishTimelock, TxCancel, TxPunish, TxRefund,
TX_PUNISH_ESTIMATED_WEIGHT, TX_REDEEM_ESTIMATED_WEIGHT,
};
use crate::env::Config;
use crate::monero::wallet::{TransferRequest, WatchRequest};
@ -114,11 +113,14 @@ pub struct State0 {
}
impl State0 {
pub async fn new<R>(
pub fn new<R>(
btc: bitcoin::Amount,
xmr: monero::Amount,
env_config: Config,
bitcoin_wallet: &bitcoin::Wallet,
redeem_address: bitcoin::Address,
punish_address: bitcoin::Address,
tx_redeem_fee: bitcoin::Amount,
tx_punish_fee: bitcoin::Amount,
rng: &mut R,
) -> Result<Self>
where
@ -126,18 +128,10 @@ impl State0 {
{
let a = bitcoin::SecretKey::new_random(rng);
let v_a = monero::PrivateViewKey::new_random(rng);
let redeem_address = bitcoin_wallet.new_address().await?;
let punish_address = bitcoin_wallet.new_address().await?;
let s_a = monero::Scalar::random(rng);
let (dleq_proof_s_a, (S_a_bitcoin, S_a_monero)) = CROSS_CURVE_PROOF_SYSTEM.prove(&s_a, rng);
let tx_redeem_fee = bitcoin_wallet
.estimate_fee(TX_REDEEM_ESTIMATED_WEIGHT)
.await?;
let tx_punish_fee = bitcoin_wallet
.estimate_fee(TX_PUNISH_ESTIMATED_WEIGHT)
.await?;
Ok(Self {
a,
s_a,