-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add wallet state #6763
Merged
SWvheerden
merged 2 commits into
tari-project:development
from
SWvheerden:sw_add_wallet_state
Jan 27, 2025
Merged
feat: add wallet state #6763
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,8 @@ use minotari_app_grpc::tari_rpc::{ | |
GetAddressResponse, | ||
GetBalanceRequest, | ||
GetBalanceResponse, | ||
GetStateRequest, | ||
GetStateResponse, | ||
GetCompletedTransactionsRequest, | ||
GetCompletedTransactionsResponse, | ||
GetConnectivityRequest, | ||
|
@@ -122,7 +124,7 @@ use tokio::{ | |
use tonic::{Request, Response, Status}; | ||
|
||
use crate::{ | ||
grpc::{convert_to_transaction_event, get_balance_debounced::GetBalanceDebounced, TransactionWrapper}, | ||
grpc::{convert_to_transaction_event, wallet_debouncer::WalletDebouncer, TransactionWrapper}, | ||
notifier::{CANCELLED, CONFIRMATION, MINED, QUEUED, RECEIVED, SENT}, | ||
}; | ||
|
||
|
@@ -146,23 +148,24 @@ async fn send_transaction_event( | |
pub struct WalletGrpcServer { | ||
wallet: WalletSqlite, | ||
rules: ConsensusManager, | ||
get_balance_debounced: Arc<Mutex<GetBalanceDebounced>>, | ||
debouncer: Arc<Mutex<WalletDebouncer>>, | ||
} | ||
|
||
impl WalletGrpcServer { | ||
#[allow(dead_code)] | ||
pub fn new(wallet: WalletSqlite) -> Result<Self, ConsensusBuilderError> { | ||
let rules = ConsensusManager::builder(wallet.network.as_network()).build()?; | ||
let get_balance = GetBalanceDebounced::new( | ||
let debouncer = WalletDebouncer::new( | ||
wallet.output_manager_service.clone(), | ||
wallet.transaction_service.clone(), | ||
wallet.wallet_connectivity.clone(), | ||
wallet.utxo_scanner_service.clone(), | ||
wallet.comms.shutdown_signal(), | ||
); | ||
Ok(Self { | ||
wallet, | ||
rules, | ||
get_balance_debounced: Arc::new(Mutex::new(get_balance)), | ||
debouncer: Arc::new(Mutex::new(debouncer)), | ||
}) | ||
} | ||
|
||
|
@@ -281,16 +284,57 @@ impl wallet_server::Wallet for WalletGrpcServer { | |
async fn get_balance(&self, _request: Request<GetBalanceRequest>) -> Result<Response<GetBalanceResponse>, Status> { | ||
let start = std::time::Instant::now(); | ||
let balance = { | ||
let mut get_balance = self.get_balance_debounced.lock().await; | ||
let mut get_balance = self.debouncer.lock().await; | ||
match get_balance.get_balance().await { | ||
Ok(b) => b, | ||
Err(e) => return Err(Status::not_found(format!("GetBalanceDebounced error! {}", e))), | ||
Err(e) => return Err(Status::not_found(format!("WalletDebouncer error! {}", e))), | ||
} | ||
}; | ||
trace!(target: LOG_TARGET, "'get_balance' completed in {:.2?}", start.elapsed()); | ||
Ok(Response::new(balance)) | ||
} | ||
|
||
async fn get_state(&self, _request: Request<GetStateRequest>) -> Result<Response<GetStateResponse>, Status> { | ||
let start = std::time::Instant::now(); | ||
let (balance, scanned_height) = { | ||
let mut debouncer = self.debouncer.lock().await; | ||
let balance = match debouncer.get_balance().await { | ||
Ok(b) => b, | ||
Err(e) => return Err(Status::not_found(format!("WalletDebouncer error! {}", e))), | ||
}; | ||
let scanned_height = debouncer.get_scanned_height().await; | ||
(Some(balance), scanned_height) | ||
}; | ||
|
||
|
||
let status = self | ||
.comms() | ||
.connectivity() | ||
.get_connectivity_status() | ||
.await | ||
.map_err(|err| Status::internal(err.to_string()))?; | ||
let mut base_node_service = self.wallet.base_node_service.clone(); | ||
|
||
let network = Some(tari_rpc::NetworkStatusResponse { | ||
status: tari_rpc::ConnectivityStatus::from(status) as i32, | ||
avg_latency_ms: base_node_service | ||
.get_base_node_latency() | ||
.await | ||
.map_err(|err| Status::internal(err.to_string()))? | ||
.map(|d| u32::try_from(d.as_millis()).unwrap_or(u32::MAX)) | ||
.unwrap_or_default(), | ||
num_node_connections: u32::try_from(status.num_connected_nodes()) | ||
.map_err(|_| Status::internal("Count not convert u64 to usize".to_string()))?, | ||
}); | ||
|
||
trace!(target: LOG_TARGET, "'get_state' completed in {:.2?}", start.elapsed()); | ||
Ok(Response::new(GetStateResponse { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fmt ok? |
||
scanned_height, | ||
balance, | ||
network, | ||
})) | ||
} | ||
|
||
async fn get_unspent_amounts( | ||
&self, | ||
_: Request<tari_rpc::Empty>, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmt ok?