force wallet refresh from gui before balance checks

This commit is contained in:
creating2morrow 2023-07-03 19:26:35 -04:00
parent 7e18e68a11
commit 943980eb8d
3 changed files with 85 additions and 5 deletions

View file

@ -79,6 +79,7 @@ enum RpcFields {
Make,
Open,
Prepare,
Refresh,
SignMultisig,
SubmitMultisig,
SweepAll,
@ -108,6 +109,7 @@ impl RpcFields {
RpcFields::Make => String::from("make_multisig"),
RpcFields::Open => String::from("open_wallet"),
RpcFields::Prepare => String::from("prepare_multisig"),
RpcFields::Refresh => String::from("refresh"),
RpcFields::SignMultisig => String::from("sign_multisig"),
RpcFields::SubmitMultisig => String::from("submit_multisig"),
RpcFields::SweepAll => String::from("sweep_all"),
@ -152,7 +154,7 @@ impl LockTimeLimit {
}
}
/// Start monerod from the -`-monero-location` flag
/// Start monerod from the `--monero-location` flag
///
/// default: /home/$USER/monero-xxx-xxx
pub fn start_daemon() {
@ -1153,6 +1155,35 @@ pub async fn create_address() -> reqres::XmrRpcCreateAddressResponse {
}
}
/// Performs the xmr rpc 'create_address' method
pub async fn refresh() -> reqres::XmrRpcRefreshResponse {
info!("executing {}", RpcFields::Refresh.value());
let client = reqwest::Client::new();
let host = get_rpc_host();
let req = reqres::XmrRpcRequest {
jsonrpc: RpcFields::JsonRpcVersion.value(),
id: RpcFields::Id.value(),
method: RpcFields::Refresh.value(),
};
let login: RpcLogin = get_rpc_creds();
match client
.post(host)
.json(&req)
.send_with_digest_auth(&login.username, &login.credential)
.await
{
Ok(response) => {
let res = response.json::<reqres::XmrRpcRefreshResponse>().await;
debug!("{} response: {:?}", RpcFields::Refresh.value(), res);
match res {
Ok(res) => res,
_ => Default::default(),
}
}
Err(_) => Default::default(),
}
}
// Daemon requests
//-------------------------------------------------------------------
@ -1179,7 +1210,7 @@ pub async fn get_info() -> reqres::XmrDaemonGetInfoResponse {
}
}
/// Performs the xmr daemon 'get_info' method
/// Performs the xmr daemon 'get_info' method for proxied daemons
pub async fn p_get_info() -> Result<reqres::XmrDaemonGetInfoResponse, Box<dyn Error>> {
info!("fetching proxy daemon info");
let host = utils::get_i2p_http_proxy();

View file

@ -505,6 +505,7 @@ pub struct XmrRpcDescribeTranferResult {
pub struct KeyImageList {
key_images: Vec<String>,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct XmrRpcSweepAllResult {
pub amount_list: Vec<u128>,
@ -524,6 +525,12 @@ pub struct XmrRpcCreateAddressResult {
pub addresses: Vec<String>,
}
#[derive(Deserialize, Debug)]
pub struct XmrRpcRefreshResult {
pub blocks_fetched: u64,
pub received_money: bool,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct XmrDaemonGetInfoResult {
pub adjusted_time: u64,
@ -1088,6 +1095,22 @@ impl Default for XmrRpcCreateAddressResponse {
}
}
}
#[derive(Deserialize, Debug)]
pub struct XmrRpcRefreshResponse {
pub result: XmrRpcRefreshResult,
}
impl Default for XmrRpcRefreshResponse {
fn default() -> Self {
XmrRpcRefreshResponse {
result: XmrRpcRefreshResult {
blocks_fetched: 0,
received_money: false,
},
}
}
}
// END XMR Structs
/// Container for the message decryption
@ -1186,6 +1209,9 @@ pub struct MultisigInfoRequest {
pub contact: String,
/// Send empty array on prepare info request
pub info: Vec<String>,
/// flag for mediator to create create multisig wallet for order
pub init_mediator: bool,
/// valid values are found in lines 21-26 of market.rs
pub msig_type: String,
pub orid: String,
}
@ -1195,6 +1221,7 @@ impl Default for MultisigInfoRequest {
MultisigInfoRequest {
contact: utils::empty_string(),
info: Vec::new(),
init_mediator: false,
msig_type: utils::empty_string(),
orid: utils::empty_string(),
}

View file

@ -14,6 +14,8 @@ use std::{
};
pub struct HomeApp {
/// blocks fetched during last wallet refresh
blocks_fetched: u64,
connections: utils::Connections,
core_timeout_tx: Sender<bool>,
core_timeout_rx: Receiver<bool>,
@ -43,6 +45,8 @@ pub struct HomeApp {
xmr_rpc_ver_rx: Receiver<reqres::XmrRpcVersionResponse>,
can_refresh_tx: Sender<bool>,
can_refresh_rx: Receiver<bool>,
wallet_refresh_tx: Sender<reqres::XmrRpcRefreshResponse>,
wallet_refresh_rx: Receiver<reqres::XmrRpcRefreshResponse>,
pub qr: egui_extras::RetainedImage,
// application state set
s_xmr_address: reqres::XmrRpcAddressResponse,
@ -58,6 +62,7 @@ pub struct HomeApp {
impl Default for HomeApp {
fn default() -> Self {
let blocks_fetched = 0;
let connections = Default::default();
let has_install_failed = false;
let installations = Default::default();
@ -75,6 +80,7 @@ impl Default for HomeApp {
let (xmr_rpc_ver_tx, xmr_rpc_ver_rx) = std::sync::mpsc::channel();
let (xmr_address_tx, xmr_address_rx) = std::sync::mpsc::channel();
let (xmr_balance_tx, xmr_balance_rx) = std::sync::mpsc::channel();
let (wallet_refresh_tx, wallet_refresh_rx) = std::sync::mpsc::channel();
let (can_refresh_tx, can_refresh_rx) = std::sync::mpsc::channel();
let (i2p_status_tx, i2p_status_rx) = std::sync::mpsc::channel();
let (installation_tx, installation_rx) = std::sync::mpsc::channel();
@ -92,6 +98,7 @@ impl Default for HomeApp {
let logo_i2p =
egui_extras::RetainedImage::from_image_bytes("./assets/i2p.png", &c_i2p_logo).unwrap();
Self {
blocks_fetched,
connections,
core_timeout_rx,
core_timeout_tx,
@ -121,6 +128,8 @@ impl Default for HomeApp {
can_refresh_rx,
can_refresh_tx,
qr: egui_extras::RetainedImage::from_image_bytes("qr.png", &contents).unwrap(),
wallet_refresh_rx,
wallet_refresh_tx,
// state of self defaults
s_xmr_address,
s_xmr_balance,
@ -144,6 +153,9 @@ impl eframe::App for HomeApp {
if let Ok(address) = self.xmr_address_rx.try_recv() {
self.s_xmr_address = address;
}
if let Ok(wallet_refresh) = self.wallet_refresh_rx.try_recv() {
self.blocks_fetched = wallet_refresh.result.blocks_fetched;
}
if let Ok(balance) = self.xmr_balance_rx.try_recv() {
self.s_xmr_balance = balance;
}
@ -356,7 +368,12 @@ impl eframe::App for HomeApp {
if !self.is_updated {
if !self.is_init {
send_ver_req(self.xmr_rpc_ver_tx.clone(), ctx.clone());
send_wallet_req(self.xmr_address_tx.clone(), self.xmr_balance_tx.clone(), ctx.clone());
send_wallet_req(
self.xmr_address_tx.clone(),
self.xmr_balance_tx.clone(),
self.wallet_refresh_tx.clone(),
ctx.clone()
);
send_i2p_status_req(self.i2p_status_tx.clone(), ctx.clone());
send_xmrd_get_info_req(self.xmrd_get_info_tx.clone(), ctx.clone());
}
@ -396,14 +413,15 @@ impl eframe::App for HomeApp {
ui.horizontal(|ui| {
self.logo_xmr.show(ui);
let address = &self.s_xmr_address.result.address;
let blocks_fetched = self.blocks_fetched;
let unlocked_balance = self.s_xmr_balance.result.unlocked_balance;
let locked_balance = self.s_xmr_balance.result.balance - unlocked_balance;
let unlock_time = self.s_xmr_balance.result.blocks_to_unlock * crate::BLOCK_TIME_IN_SECS_EST;
let xmrd_info: &reqres::XmrDaemonGetInfoResult = &self.s_xmrd_get_info.result;
let free_space = xmrd_info.free_space / crate::BYTES_IN_GB;
let db_size = xmrd_info.database_size / crate::BYTES_IN_GB;
ui.label(format!("- rpc version: {}\n- address: {}\n- balance: {} piconero(s)\n- locked balance: {} piconero(s)\n- unlock time (secs): {}\n- daemon info\n\t- net type: {}\n\t- current hash: {}\n\t- height: {}\n\t- synced: {}\n\t- blockchain size : ~{} GB\n\t- free space : ~{} GB\n\t- version: {}\n",
self.s_xmr_rpc_ver.result.version, address, unlocked_balance, locked_balance,
ui.label(format!("- rpc version: {}\n- blocks fetched: {}\n- address: {}\n- balance: {} piconero(s)\n- locked balance: {} piconero(s)\n- unlock time (secs): {}\n- daemon info\n\t- net type: {}\n\t- current hash: {}\n\t- height: {}\n\t- synced: {}\n\t- blockchain size : ~{} GB\n\t- free space : ~{} GB\n\t- version: {}\n",
self.s_xmr_rpc_ver.result.version, blocks_fetched, address, unlocked_balance, locked_balance,
unlock_time, xmrd_info.nettype, xmrd_info.top_block_hash, xmrd_info.height, xmrd_info.synchronized,
db_size, free_space, xmrd_info.version));
});
@ -462,6 +480,7 @@ fn send_ver_req(tx: Sender<reqres::XmrRpcVersionResponse>, ctx: egui::Context) {
fn send_wallet_req(
address_tx: Sender<reqres::XmrRpcAddressResponse>,
balance_tx: Sender<reqres::XmrRpcBalanceResponse>,
wallet_refresh_tx: Sender<reqres::XmrRpcRefreshResponse>,
ctx: egui::Context,
) {
tokio::spawn(async move {
@ -470,10 +489,13 @@ fn send_wallet_req(
std::env::var(neveko_core::MONERO_WALLET_PASSWORD).unwrap_or(String::from("password"));
monero::open_wallet(&wallet_name, &wallet_password).await;
let address: reqres::XmrRpcAddressResponse = monero::get_address().await;
// hope this fixes wallet not refreshing on initial startup bug
let refresh: reqres::XmrRpcRefreshResponse = monero::refresh().await;
let balance: reqres::XmrRpcBalanceResponse = monero::get_balance().await;
monero::close_wallet(&wallet_name, &wallet_password).await;
let _ = address_tx.send(address);
let _ = balance_tx.send(balance);
let _ = wallet_refresh_tx.send(refresh);
ctx.request_repaint();
});
}