From 20fdb034790eb7ba5cb0f8316e132cc0d1bb1d6d Mon Sep 17 00:00:00 2001 From: Stan Bondi Date: Fri, 29 Jul 2022 09:49:35 +0400 Subject: [PATCH] fix(wallet): implement `check_for_updates` in wallet grpc --- .../tari_base_node/src/commands/cli_loop.rs | 2 +- .../src/commands/command/version.rs | 2 +- .../src/grpc/base_node_grpc_server.rs | 2 +- .../src/grpc/wallet_grpc_server.rs | 27 ++++++++---------- base_layer/p2p/src/auto_update/service.rs | 13 ++++++--- meta/hashes.txt | 5 ++++ meta/hashes.txt.sig | Bin 566 -> 985 bytes 7 files changed, 29 insertions(+), 22 deletions(-) diff --git a/applications/tari_base_node/src/commands/cli_loop.rs b/applications/tari_base_node/src/commands/cli_loop.rs index 8107f23fea..9d8798603f 100644 --- a/applications/tari_base_node/src/commands/cli_loop.rs +++ b/applications/tari_base_node/src/commands/cli_loop.rs @@ -117,7 +117,7 @@ impl CliLoop { async fn watch_loop(&mut self) { if let Some(command) = self.watch_task.take() { let mut interrupt = signal::ctrl_c().fuse().boxed(); - let mut software_update_notif = self.context.software_updater.new_update_notifier().clone(); + let mut software_update_notif = self.context.software_updater.update_notifier().clone(); let config = self.context.config.clone(); let line = command.line(); let interval = command diff --git a/applications/tari_base_node/src/commands/command/version.rs b/applications/tari_base_node/src/commands/command/version.rs index 677c3657ea..6c69c96af7 100644 --- a/applications/tari_base_node/src/commands/command/version.rs +++ b/applications/tari_base_node/src/commands/command/version.rs @@ -45,7 +45,7 @@ impl CommandContext { println!("Author: {}", consts::APP_AUTHOR); println!("Avx2: {}", if cfg!(feature = "avx2") { "enabled" } else { "disabled" }); - if let Some(ref update) = *self.software_updater.new_update_notifier().borrow() { + if let Some(ref update) = *self.software_updater.update_notifier().borrow() { println!( "Version {} of the {} is available: {} (sha: {})", update.version(), diff --git a/applications/tari_base_node/src/grpc/base_node_grpc_server.rs b/applications/tari_base_node/src/grpc/base_node_grpc_server.rs index b1d138d8ed..3859312589 100644 --- a/applications/tari_base_node/src/grpc/base_node_grpc_server.rs +++ b/applications/tari_base_node/src/grpc/base_node_grpc_server.rs @@ -1563,7 +1563,7 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer { ) -> Result, Status> { let mut resp = tari_rpc::SoftwareUpdate::default(); - if let Some(ref update) = *self.software_updater.new_update_notifier().borrow() { + if let Some(ref update) = *self.software_updater.update_notifier().borrow() { resp.has_update = true; resp.version = update.version().to_string(); resp.sha = update.to_hash_hex(); diff --git a/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs b/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs index 0531ab90b9..433d05030c 100644 --- a/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs +++ b/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs @@ -193,21 +193,18 @@ impl wallet_server::Wallet for WalletGrpcServer { &self, _: Request, ) -> Result, Status> { - todo!("reimplement updates") - // let mut resp = tari_rpc::SoftwareUpdate::default(); - // - // if let Some(ref update) = *self - // .wallet - // .get_software_updater() - // .map(|su| su.new_update_notifier().borrow()) - // { - // resp.has_update = true; - // resp.version = update.version().to_string(); - // resp.sha = update.to_hash_hex(); - // resp.download_url = update.download_url().to_string(); - // } - // - // Ok(Response::new(resp)) + let mut resp = tari_rpc::SoftwareUpdate::default(); + + if let Some(ref updater) = self.wallet.get_software_updater() { + if let Some(ref update) = *updater.latest_update() { + resp.has_update = true; + resp.version = update.version().to_string(); + resp.sha = update.to_hash_hex(); + resp.download_url = update.download_url().to_string(); + } + } + + Ok(Response::new(resp)) } async fn identify(&self, _: Request) -> Result, Status> { diff --git a/base_layer/p2p/src/auto_update/service.rs b/base_layer/p2p/src/auto_update/service.rs index 9c332e5dfc..8bed655a91 100644 --- a/base_layer/p2p/src/auto_update/service.rs +++ b/base_layer/p2p/src/auto_update/service.rs @@ -45,7 +45,7 @@ pub type SoftwareUpdateNotifier = watch::Receiver>; #[derive(Clone)] pub struct SoftwareUpdaterHandle { - new_update_notifier: SoftwareUpdateNotifier, + update_notifier: SoftwareUpdateNotifier, request_tx: mpsc::Sender>>, } @@ -53,8 +53,13 @@ impl SoftwareUpdaterHandle { /// Returns watch notifier that emits a value whenever a new software update is detected. /// First the current SoftwareUpdate (if any) is emitted. Thereafter, only software updates with a greater version /// number are emitted. - pub fn new_update_notifier(&self) -> &SoftwareUpdateNotifier { - &self.new_update_notifier + pub fn update_notifier(&self) -> &SoftwareUpdateNotifier { + &self.update_notifier + } + + /// Returns the latest update or None if the updater has not retrieved the latest update yet. + pub fn latest_update(&self) -> watch::Ref<'_, Option> { + self.update_notifier.borrow() } /// Returns watch notifier that triggers after a check for software updates @@ -177,7 +182,7 @@ impl ServiceInitializer for SoftwareUpdaterService { let (request_tx, request_rx) = mpsc::channel(1); context.register_handle(SoftwareUpdaterHandle { - new_update_notifier: new_update_notif.clone(), + update_notifier: new_update_notif.clone(), request_tx, }); context.spawn_until_shutdown(move |_| service.run(request_rx, notifier, new_update_notif)); diff --git a/meta/hashes.txt b/meta/hashes.txt index 3c7df39762..f5f8d8d901 100644 --- a/meta/hashes.txt +++ b/meta/hashes.txt @@ -2,3 +2,8 @@ 6e77da12535e0ed7851761ae6c6729f2dd3ae8050840e8c08e10e279dadfde8a osx/tari_base_node-0.8.10-65fc65a-release.pkg fa2623588f0891caa39344d4b1b6ca1ba6256fede52b0f7cb96b285a125dff6d linux/tari_base_node-ubuntu-18.04-x64-0.8.10-65fc65a-release.zip 952b04d1f79d5712133d78fbc0f2dbfb80dac199c782ac7884ec36c10f4bd623 windows/tari_base_node-Windows-0.8.11-3b00f2d-release.exe + +## Console wallet (these need updating) +6e77da12535e0ed7851761ae6c6729f2dd3ae8050840e8c08e10e279dadfde8a osx/console_wallet-0.8.10-65fc65a-release.pkg +fa2623588f0891caa39344d4b1b6ca1ba6256fede52b0f7cb96b285a125dff6d linux/console_wallet-ubuntu-18.04-x64-0.8.10-65fc65a-release.zip +952b04d1f79d5712133d78fbc0f2dbfb80dac199c782ac7884ec36c10f4bd623 windows/console_wallet-Windows-0.8.11-3b00f2d-release.exe diff --git a/meta/hashes.txt.sig b/meta/hashes.txt.sig index 4bc8c465cdb413d64a070e81d240cfa2d97ef53f..89657f7ba355a37ff42bd15e80e6c99110c4525b 100644 GIT binary patch literal 985 zcmV;~119{V0h_?f%)rGc(Ynzyz=tb^aV@h-5?4lIaYkyfUP(ns(&JhwWn~4Y#Nt#1 zzx0D`vMrKCFrWO`y1{Riv$%%=^mc}L~DJDsVNoL83hDnKLMy6(IsVS+Z zMo9)~=E+HxW=TdCrXUxlq@|gqC@AD)=9OaDSejItS5m5LXrX6dqFZ5Rg3Ae2nFU;y zAfruE4AX$VFf}(cGBh>@`a3Nt*#PL>q_iXpgOtQ%LrcqKa|@$HAYoyWnrv*AY-o^X zl9U2;yn;e`W?o8uc`>>p!Xd&CyA5@XlMFy6!tGA2Naf-J2EKECUU7a-szP~UPEKlx zf<_52Zc-KUQd3hDN()jFOEUA)HK`OY$q=jJAy&~NUeIhDn0P^R1QGGl$z;sJz{tfQ zE2hX|Ts`sq(T_~EU2nhH!txO-6Da2}aB&L2M4H?A|JSX3`taVr3G34mcD&%Iv(kCP zHF3S%GKNWue3Un%&R@E)^Sb$0K5i=4Kx#>XRqWTzm0R-U`X2SGscb zZ#hqJT)UX?TRbhn`{vgVANOuHZ+P34P@3_(ed#V2)phnfE^8eg%~&os<4o1;EW@pQ zJFl$zd-tK`rjrX^N=6@_&Hq`IHE5A+f*0Rr0n>}iSp*j!biUlIyQs6izkH^u#iAL> HqI@0z%gXaj literal 566 zcmV-60?GY}0y6{v0SEvc79j*Pdy((O@dAB{?e;wwg|SIcObTQL0$|#>Z2$@h5EzBA zNl;7*WHnz8|8PH4H(OJI*ex8Ms}E+1BWk&RGHln)yLWP;{cVLtpV=@u+(0XI0BC}^ z`dMue^VTGi`Hiz#f>3kD;~f*((z+{$eQ%V`%*tqGuN5GR@xlJT9 zYNvR33iCR;JVrq+4uB#deraQ<<+C!nXRmhYL^3{k^ehtm!EyJJFUa!VDp|G63>wPj z%c+mgJ#k3)n$(8vfddr}-`j@Fl@NP-WS#N=yaQ+yAB4Irb|PXVwIJ}(c&H^Y(L#is z{Na*&ralOS+oxW4>94&ST+eR$htz2_gmENcbc5Cw zzw$B!zYDgQr>0vg$Nigk1DIxwy<9<2d%-ELyDlE#r(RWy-#|l_bj9j#haF-ykqV2= zHrs4;@EB`Wo_3}gEX#&6O9KIn+WNrX53-E8-UIi}wPdh)a3-)mY7e(FA>rQ}S)ODP zs>%y|W2hJryc*XDKS|j1)RkY~{gfg(ha(yTk&b%FgYohv)mQ`0=^wo9e1oj+YI~*m ziW8#Y`2&HD<