Skip to content

Commit c530901

Browse files
committed
Remove handle_defaults
This function is left over from `bitcoincore-rpc`, we don't need to handle defaults like this - just remove the function.
1 parent 34c4c69 commit c530901

File tree

14 files changed

+14
-62
lines changed

14 files changed

+14
-62
lines changed

client/src/client_sync/mod.rs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -184,54 +184,6 @@ fn empty_arr() -> serde_json::Value { serde_json::Value::Array(vec![]) }
184184
#[allow(dead_code)] // TODO: Remove this if unused still when we are done.
185185
fn empty_obj() -> serde_json::Value { serde_json::Value::Object(Default::default()) }
186186

187-
/// Handle default values in the argument list.
188-
///
189-
/// Substitute `Value::Null`s with corresponding values from `defaults` table, except when they are
190-
/// trailing, in which case just skip them altogether in returned list.
191-
///
192-
/// Note, that `defaults` corresponds to the last elements of `args`.
193-
///
194-
/// ```norust
195-
/// arg1 arg2 arg3 arg4
196-
/// def1 def2
197-
/// ```
198-
///
199-
/// Elements of `args` without corresponding `defaults` value, won't be substituted, because they
200-
/// are required.
201-
#[allow(dead_code)] // TODO: Remove this if unused still when we are done.
202-
fn handle_defaults<'a>(
203-
args: &'a mut [serde_json::Value],
204-
defaults: &[serde_json::Value],
205-
) -> &'a [serde_json::Value] {
206-
assert!(args.len() >= defaults.len());
207-
208-
// Pass over the optional arguments in backwards order, filling in defaults after the first
209-
// non-null optional argument has been observed.
210-
let mut first_non_null_optional_idx = None;
211-
for i in 0..defaults.len() {
212-
let args_i = args.len() - 1 - i;
213-
let defaults_i = defaults.len() - 1 - i;
214-
if args[args_i] == serde_json::Value::Null {
215-
if first_non_null_optional_idx.is_some() {
216-
if defaults[defaults_i] == serde_json::Value::Null {
217-
panic!("Missing `default` for argument idx {}", args_i);
218-
}
219-
args[args_i] = defaults[defaults_i].clone();
220-
}
221-
} else if first_non_null_optional_idx.is_none() {
222-
first_non_null_optional_idx = Some(args_i);
223-
}
224-
}
225-
226-
let required_num = args.len() - defaults.len();
227-
228-
if let Some(i) = first_non_null_optional_idx {
229-
&args[..i + 1]
230-
} else {
231-
&args[..required_num]
232-
}
233-
}
234-
235187
/// Convert a possible-null result into an `Option`.
236188
#[allow(dead_code)] // TODO: Remove this if unused still when we are done.
237189
fn opt_result<T: for<'a> serde::de::Deserialize<'a>>(

client/src/client_sync/v17/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use bitcoin::address::{Address, NetworkChecked};
1515
use bitcoin::{Amount, Block, BlockHash, Txid};
1616
use serde::{Deserialize, Serialize};
1717

18-
use crate::client_sync::{handle_defaults, into_json};
18+
use crate::client_sync::into_json;
1919
use crate::types::v17::*;
2020

2121
crate::define_jsonrpc_minreq_client!("v17");

client/src/client_sync/v17/wallet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ macro_rules! impl_client_v17__sendtoaddress {
103103
address: &Address<NetworkChecked>,
104104
amount: Amount,
105105
) -> Result<SendToAddress> {
106-
let mut args = [address.to_string().into(), into_json(amount.to_btc())?];
107-
self.call("sendtoaddress", handle_defaults(&mut args, &["".into(), "".into()]))
106+
let args = [address.to_string().into(), into_json(amount.to_btc())?];
107+
self.call("sendtoaddress", &args)
108108
}
109109
}
110110
};

client/src/client_sync/v18.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use bitcoin::address::{Address, NetworkChecked};
88
use bitcoin::{Amount, Block, BlockHash, Txid};
99

10-
use crate::client_sync::{handle_defaults, into_json};
10+
use crate::client_sync::into_json;
1111
use crate::types::v18::*;
1212

1313
crate::define_jsonrpc_minreq_client!("v18");

client/src/client_sync/v19/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod wallet;
99
use bitcoin::address::{Address, NetworkChecked};
1010
use bitcoin::{Amount, Block, BlockHash, Txid};
1111

12-
use crate::client_sync::{handle_defaults, into_json};
12+
use crate::client_sync::into_json;
1313
use crate::types::v19::*;
1414

1515
crate::define_jsonrpc_minreq_client!("v19");

client/src/client_sync/v20.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use bitcoin::address::{Address, NetworkChecked};
88
use bitcoin::{Amount, Block, BlockHash, Txid};
99

10-
use crate::client_sync::{handle_defaults, into_json};
10+
use crate::client_sync::into_json;
1111
use crate::types::v20::*;
1212

1313
crate::define_jsonrpc_minreq_client!("v20");

client/src/client_sync/v21.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use bitcoin::address::{Address, NetworkChecked};
88
use bitcoin::{Amount, Block, BlockHash, Txid};
99

10-
use crate::client_sync::{handle_defaults, into_json};
10+
use crate::client_sync::into_json;
1111
use crate::types::v21::*;
1212

1313
crate::define_jsonrpc_minreq_client!("v21");

client/src/client_sync/v22/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod wallet;
99
use bitcoin::address::{Address, NetworkChecked};
1010
use bitcoin::{Amount, Block, BlockHash, Txid};
1111

12-
use crate::client_sync::{handle_defaults, into_json};
12+
use crate::client_sync::into_json;
1313
use crate::types::v22::*;
1414

1515
crate::define_jsonrpc_minreq_client!("v22");

client/src/client_sync/v23.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use bitcoin::address::{Address, NetworkChecked};
88
use bitcoin::{Amount, Block, BlockHash, Txid};
99
use serde::{Deserialize, Serialize};
1010

11-
use crate::client_sync::{handle_defaults, into_json};
11+
use crate::client_sync::into_json;
1212
use crate::types::v23::*;
1313

1414
crate::define_jsonrpc_minreq_client!("v23");

client/src/client_sync/v24.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use bitcoin::address::{Address, NetworkChecked};
88
use bitcoin::{Amount, Block, BlockHash, Txid};
99

10-
use crate::client_sync::{handle_defaults, into_json};
10+
use crate::client_sync::into_json;
1111
use crate::types::v24::*;
1212

1313
crate::define_jsonrpc_minreq_client!("v24");

0 commit comments

Comments
 (0)