Skip to content

Commit afd525b

Browse files
Additional clippy warning fixes
- Remove redundant closure in get_transaction_are_locked - Fix useless type conversion (remove .into() on string literal) - Change &Vec to &[T] for better performance in function signature - Remove unnecessary reference taking in pattern matching - Fix remaining needless borrows in node management functions - Verified remaining "redundant imports" are actually used (false positives) Further reduces clippy warnings across the codebase
1 parent 8c53c7d commit afd525b

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

rpc-client/src/client.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,9 @@ pub trait RpcApi: Sized {
510510

511511
fn get_transaction_are_locked(
512512
&self,
513-
tx_ids: &Vec<dashcore::Txid>,
513+
tx_ids: &[dashcore::Txid],
514514
) -> Result<Vec<Option<json::GetTransactionLockedResult>>> {
515-
let transaction_ids_json =
516-
tx_ids.iter().map(|tx_id| into_json(tx_id)).collect::<Result<Vec<Value>>>()?;
515+
let transaction_ids_json = tx_ids.iter().map(into_json).collect::<Result<Vec<Value>>>()?;
517516
let args = [transaction_ids_json.into()];
518517
self.call("gettxchainlocks", &args)
519518
}
@@ -891,22 +890,22 @@ pub trait RpcApi: Sized {
891890
/// Attempts to add a node to the addnode list.
892891
/// Nodes added using addnode (or -connect) are protected from DoS disconnection and are not required to be full nodes/support SegWit as other outbound peers are (though such peers will not be synced from).
893892
fn add_node(&self, addr: &str) -> Result<()> {
894-
self.call("addnode", &[into_json(&addr)?, into_json("add")?])
893+
self.call("addnode", &[into_json(addr)?, into_json("add")?])
895894
}
896895

897896
/// Attempts to remove a node from the addnode list.
898897
fn remove_node(&self, addr: &str) -> Result<()> {
899-
self.call("addnode", &[into_json(&addr)?, into_json("remove")?])
898+
self.call("addnode", &[into_json(addr)?, into_json("remove")?])
900899
}
901900

902901
/// Attempts to connect to a node without permanently adding it to the addnode list.
903902
fn onetry_node(&self, addr: &str) -> Result<()> {
904-
self.call("addnode", &[into_json(&addr)?, into_json("onetry")?])
903+
self.call("addnode", &[into_json(addr)?, into_json("onetry")?])
905904
}
906905

907906
/// Immediately disconnects from the specified peer node.
908907
fn disconnect_node(&self, addr: &str) -> Result<()> {
909-
self.call("disconnectnode", &[into_json(&addr)?])
908+
self.call("disconnectnode", &[into_json(addr)?])
910909
}
911910

912911
fn disconnect_node_by_id(&self, node_id: u32) -> Result<()> {
@@ -916,7 +915,7 @@ pub trait RpcApi: Sized {
916915
/// Returns information about the given added node, or all added nodes (note that onetry addnodes are not listed here)
917916
fn get_added_node_info(&self, node: Option<&str>) -> Result<Vec<json::GetAddedNodeInfoResult>> {
918917
if let Some(addr) = node {
919-
self.call("getaddednodeinfo", &[into_json(&addr)?])
918+
self.call("getaddednodeinfo", &[into_json(addr)?])
920919
} else {
921920
self.call("getaddednodeinfo", &[])
922921
}
@@ -928,7 +927,7 @@ pub trait RpcApi: Sized {
928927
count: Option<usize>,
929928
) -> Result<Vec<json::GetNodeAddressesResult>> {
930929
let cnt = count.unwrap_or(1);
931-
self.call("getnodeaddresses", &[into_json(&cnt)?])
930+
self.call("getnodeaddresses", &[into_json(cnt)?])
932931
}
933932

934933
/// List all banned IPs/Subnets.
@@ -945,18 +944,18 @@ pub trait RpcApi: Sized {
945944
fn add_ban(&self, subnet: &str, bantime: u64, absolute: bool) -> Result<()> {
946945
self.call(
947946
"setban",
948-
&[into_json(&subnet)?, into_json("add")?, into_json(&bantime)?, into_json(&absolute)?],
947+
&[into_json(subnet)?, into_json("add")?, into_json(bantime)?, into_json(absolute)?],
949948
)
950949
}
951950

952951
/// Attempts to remove an IP/Subnet from the banned list.
953952
fn remove_ban(&self, subnet: &str) -> Result<()> {
954-
self.call("setban", &[into_json(&subnet)?, into_json("remove")?])
953+
self.call("setban", &[into_json(subnet)?, into_json("remove")?])
955954
}
956955

957956
/// Disable/enable all p2p network activity.
958957
fn set_network_active(&self, state: bool) -> Result<bool> {
959-
self.call("setnetworkactive", &[into_json(&state)?])
958+
self.call("setnetworkactive", &[into_json(state)?])
960959
}
961960

962961
/// Returns data about each connected network node as an array of
@@ -1738,7 +1737,7 @@ mod tests {
17381737
#[test]
17391738
fn test_raw_tx() {
17401739
use dashcore::consensus::encode;
1741-
let client = Client::new("http://localhost/".into(), Auth::None).unwrap();
1740+
let client = Client::new("http://localhost/", Auth::None).unwrap();
17421741
let tx: Transaction = encode::deserialize(&Vec::<u8>::from_hex("0200000001586bd02815cf5faabfec986a4e50d25dbee089bd2758621e61c5fab06c334af0000000006b483045022100e85425f6d7c589972ee061413bcf08dc8c8e589ce37b217535a42af924f0e4d602205c9ba9cb14ef15513c9d946fa1c4b797883e748e8c32171bdf6166583946e35c012103dae30a4d7870cd87b45dd53e6012f71318fdd059c1c2623b8cc73f8af287bb2dfeffffff021dc4260c010000001976a914f602e88b2b5901d8aab15ebe4a97cf92ec6e03b388ac00e1f505000000001976a914687ffeffe8cf4e4c038da46a9b1d37db385a472d88acfd211500").unwrap()).unwrap();
17431742

17441743
assert!(client.send_raw_transaction(&tx).is_err());

rpc-json/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ impl<'a> serde::Serialize for ImportMultiRequestScriptPubkey<'a> {
10541054
S: Serializer,
10551055
{
10561056
match *self {
1057-
ImportMultiRequestScriptPubkey::Address(ref addr) => {
1057+
ImportMultiRequestScriptPubkey::Address(addr) => {
10581058
#[derive(Serialize)]
10591059
struct Tmp<'a> {
10601060
pub address: &'a Address,

0 commit comments

Comments
 (0)