Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tonic = { workspace = true }
tonic-health = { workspace = true }
# needs to line up with jsonrpsee tower version...
tower = { workspace = true }
tower-http = { workspace = true, features = ["request-id", "trace"] }
tower-http = { workspace = true, features = ["cors", "request-id", "trace"] }
tracing = { workspace = true }
tracing-appender = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter", "json"] }
Expand Down
65 changes: 36 additions & 29 deletions app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,30 +287,29 @@ impl App {
Ok(())
}

pub fn get_new_main_address(
pub async fn get_new_main_address_async(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd prefer to explicitly name get_new_main_address as blocking - I think names like

pub async fn get_new_main_address(..)

pub fn get_new_main_address_blocking(..)

would be better

&self,
) -> Result<bitcoin::Address<bitcoin::address::NetworkChecked>, Error> {
let Some(miner) = self.miner.as_ref() else {
return Err(Error::NoCusfMainchainWalletClient);
};
let address = self.runtime.block_on({
let miner = miner.clone();
async move {
let mut miner_write = miner.write().await;
let cusf_mainchain = &mut miner_write.cusf_mainchain;
let mainchain_info = cusf_mainchain.get_chain_info().await?;
let cusf_mainchain_wallet =
&mut miner_write.cusf_mainchain_wallet;
let res = cusf_mainchain_wallet
.create_new_address()
.await?
.require_network(mainchain_info.network)
.unwrap();
drop(miner_write);
Result::<_, Error>::Ok(res)
}
})?;
Ok(address)
let mut miner_write = miner.write().await;
let cusf_mainchain = &mut miner_write.cusf_mainchain;
let mainchain_info = cusf_mainchain.get_chain_info().await?;
let cusf_mainchain_wallet = &mut miner_write.cusf_mainchain_wallet;
let res = cusf_mainchain_wallet
.create_new_address()
.await?
.require_network(mainchain_info.network)
.unwrap();
drop(miner_write);
Ok(res)
}

pub fn get_new_main_address(
&self,
) -> Result<bitcoin::Address<bitcoin::address::NetworkChecked>, Error> {
self.runtime.block_on(self.get_new_main_address_async())
}

const EMPTY_BLOCK_BMM_BRIBE: bitcoin::Amount =
Expand Down Expand Up @@ -531,7 +530,7 @@ impl App {
Ok(())
}

pub fn deposit(
pub async fn deposit_async(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd prefer to explicitly name deposit as blocking - I think names like

pub async fn deposit(..)

pub fn deposit_blocking(..)

would be better

&self,
address: Address,
amount: bitcoin::Amount,
Expand All @@ -540,15 +539,23 @@ impl App {
let Some(miner) = self.miner.as_ref() else {
return Err(Error::NoCusfMainchainWalletClient);
};
self.runtime.block_on(async {
let mut miner_write = miner.write().await;
let txid = miner_write
.cusf_mainchain_wallet
.create_deposit_tx(address, amount.to_sat(), fee.to_sat())
.await?;
drop(miner_write);
Ok(txid)
})
let mut miner_write = miner.write().await;
let txid = miner_write
.cusf_mainchain_wallet
.create_deposit_tx(address, amount.to_sat(), fee.to_sat())
.await?;
drop(miner_write);
Ok(txid)
}

pub fn deposit(
&self,
address: Address,
amount: bitcoin::Amount,
fee: bitcoin::Amount,
) -> Result<bitcoin::Txid, Error> {
self.runtime
.block_on(self.deposit_async(address, amount, fee))
}
}

Expand Down
10 changes: 8 additions & 2 deletions app/gui/coins/transfer_receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Receive {
};
let address = app
.wallet
.get_new_address()
.get_address_or_new()
.map_err(anyhow::Error::from)
.inspect_err(|err| tracing::error!("{err:#}"));
Self {
Expand All @@ -122,7 +122,13 @@ impl Receive {
.add_enabled(app.is_some(), Button::new("generate"))
.clicked()
{
*self = Self::new(app)
let address = app
.unwrap()
.wallet
.get_new_address()
.map_err(anyhow::Error::from)
.inspect_err(|err| tracing::error!("{err:#}"));
self.address = Some(address);
}
}
}
Expand Down
32 changes: 14 additions & 18 deletions app/gui/coins/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl TxBuilder {
ui.separator();
ui.monospace(format!("Total: {value_in}"));
ui.separator();
egui::Grid::new("utxos").striped(true).show(ui, |ui| {
egui::Grid::new("spent_utxos").striped(true).show(ui, |ui| {
ui.monospace("kind");
ui.monospace("outpoint");
ui.monospace("value");
Expand Down Expand Up @@ -111,33 +111,29 @@ impl TxBuilder {
ui: &mut egui::Ui,
) -> anyhow::Result<()> {
egui::ScrollArea::horizontal().show(ui, |ui| {
egui::SidePanel::left("spend_utxo")
.exact_width(250.)
.resizable(false)
.show_inside(ui, |ui| {
ui.horizontal(|ui| {
ui.vertical(|ui| {
ui.set_width(250.0);
self.utxo_selector.show(app, ui, &mut self.base_tx);
});
egui::SidePanel::left("value_in")
.exact_width(250.)
.resizable(false)
.show_inside(ui, |ui| {
ui.separator();
ui.vertical(|ui| {
ui.set_width(250.0);
let () = self.show_value_in(app, ui);
});
egui::SidePanel::left("value_out")
.exact_width(250.)
.resizable(false)
.show_inside(ui, |ui| {
ui.separator();
ui.vertical(|ui| {
ui.set_width(250.0);
let () = self.show_value_out(ui);
});
egui::SidePanel::left("create_utxo")
.exact_width(450.)
.resizable(false)
.show_separator_line(false)
.show_inside(ui, |ui| {
ui.separator();
ui.vertical(|ui| {
ui.set_width(450.0);
self.utxo_creator.show(app, ui, &mut self.base_tx);
ui.separator();
self.tx_creator.show(app, ui, &mut self.base_tx).unwrap();
});
});
});
Ok(())
}
Expand Down
Loading