Skip to content

Commit

Permalink
if you set max_outputs to 2 on init_send_tx you get a panic. Fix #34
Browse files Browse the repository at this point in the history
  • Loading branch information
bayk committed Aug 30, 2024
1 parent b23463a commit b465967
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
30 changes: 30 additions & 0 deletions api/src/owner_rpc_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,36 @@ pub trait OwnerRpcV2: Sync + Send {
}
# "#
# ,false, 4, false, false, false, false, false);
#
# // Testing low 'max_outputs' value. Expecting to get error that slate is too large
# grin_wallet_api::doctest_helper_json_rpc_owner_assert_response!(
# r#"
{
"jsonrpc": "2.0",
"method": "init_send_tx",
"params": {
"args": {
"amount": "20000000",
"minimum_confirmations": 2,
"max_outputs": 2
}
},
"id": 1
}
# "#
# ,
# r#"
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"Err": {
"TooLargeSlate": 2
}
}
}
# "#
# ,false, 4, false, false, false, false, false);
```
*/

Expand Down
10 changes: 6 additions & 4 deletions libwallet/src/internal/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,10 +864,12 @@ where
// amount, the wallet should allow going over it to satisfy what the user
// wants to send. So the wallet considers max_outputs more of a soft limit.
if eligible.len() > max_outputs {
for window in eligible.windows(max_outputs) {
let windowed_eligibles = window.to_vec();
if let Some(outputs) = select_from(amount, select_all, windowed_eligibles) {
return (max_available, outputs);
if max_outputs > 0 {
for window in eligible.windows(max_outputs) {
let windowed_eligibles = window.to_vec();
if let Some(outputs) = select_from(amount, select_all, windowed_eligibles) {
return (max_available, outputs);
}
}
}
// Not exist in any window of which total amount >= amount.
Expand Down

0 comments on commit b465967

Please sign in to comment.