-
Notifications
You must be signed in to change notification settings - Fork 6
wallet daemon: sign / sign_transactions improvements #173
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
wallet daemon: sign / sign_transactions improvements #173
Conversation
wallet/grpc/server/src/service.rs
Outdated
| if !is_send_all { | ||
| // Calculating minimum set of UTXO's | ||
| let mut selected_utxos = Vec::new(); | ||
| let mut accumulated_amount = 0u64; | ||
| let target_amount = amount + MAX_COMMISSION_GAP; | ||
|
|
||
| for utxo in sorted_utxos.iter() { | ||
| selected_utxos.push(utxo.clone()); | ||
| accumulated_amount += utxo.amount; | ||
|
|
||
| // Stop | ||
| if accumulated_amount >= target_amount { | ||
| break; | ||
| } | ||
| if selected_utxos.len() >= MAX_UTXOS_FOR_SINGLE_TX { | ||
| log::warn!("Reached maximum UTXO limit ({}) to avoid mass overflow", MAX_UTXOS_FOR_SINGLE_TX); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| info!( | ||
| "Selected {} UTXOs out of {} total, covering {} sompi", | ||
| selected_utxos.len(), | ||
| sorted_utxos.len(), | ||
| accumulated_amount | ||
| ); | ||
| sorted_utxos = selected_utxos; | ||
| } else { | ||
| if sorted_utxos.len() > MAX_UTXOS_FOR_SINGLE_TX { | ||
| log::info!( | ||
| "Too many UTXOs ({}), selecting {} largest UTXOs to avoid mass limit", | ||
| sorted_utxos.len(), | ||
| MAX_UTXOS_FOR_SINGLE_TX | ||
| ); | ||
| sorted_utxos.truncate(MAX_UTXOS_FOR_SINGLE_TX); | ||
| } | ||
| } |
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.
i dont think this logic is needed. generator handles mass internally and can issue multiple transactions
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.
fixed
wallet/grpc/server/src/service.rs
Outdated
| let mut sorted_utxos = utxos; | ||
| sorted_utxos.sort_by(|a, b| b.amount.cmp(&a.amount)); |
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.
sorted_utxos.sort_unstable_by_key(|a|Reverse(a.amount))
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.
fixed
wallet/grpc/server/src/service.rs
Outdated
|
|
||
| let utxos = account.clone().get_utxos(search_addresses, None).await.map_err(|err| Status::internal(err.to_string()))?; | ||
|
|
||
| info!("Found {} UTXOs with total value {} sompi", utxos.len(), utxos.iter().map(|utxo| utxo.amount).sum::<u64>()); |
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.
the value claculated below again. put the sum into some variable
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.
fixed
wallet/grpc/server/src/service.rs
Outdated
| None // Search UTXO from all addresses in wallet | ||
| } else { | ||
| info!("Searching UTXOs in specified addresses: {:?}", from_addresses); | ||
| Some(from_addresses.clone()) |
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.
unnecessary clone
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.
fixed
wallet/grpc/server/Cargo.toml
Outdated
|
|
||
| tokio.workspace = true | ||
| tonic.workspace = true | ||
| log = "0.4.22" |
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.
use workspace deps
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.
fixed
e57c38f to
0eb670f
Compare
0eb670f to
d10a46e
Compare
No description provided.