From 41233c91241b7e434a41003548b37d4fd07aea87 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 22 Nov 2024 18:12:10 -0800 Subject: [PATCH] Run clippy on CI (#27) --- .github/workflows/ci.yaml | 3 ++ README.md | 54 +++----------------------- client/src/client.rs | 75 ++++++++++++++++-------------------- client/src/error.rs | 2 - client/src/lib.rs | 1 - client/src/queryable.rs | 1 - integration_test/src/main.rs | 56 +++++++++++++-------------- json/src/lib.rs | 12 +++--- justfile | 10 +---- 9 files changed, 77 insertions(+), 137 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1a156776..cce86ea6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -31,6 +31,9 @@ jobs: - uses: Swatinem/rust-cache@v2 + - name: Clippy + run: cargo clippy --all --all-targets + - name: Format run: cargo fmt --all -- --check diff --git a/README.md b/README.md index 278a8fdb..2f59ee3d 100644 --- a/README.md +++ b/README.md @@ -1,50 +1,6 @@ -[![Status](https://travis-ci.org/rust-bitcoin/rust-bitcoincore-rpc.png?branch=master)](https://travis-ci.org/rust-bitcoin/rust-bitcoincore-rpc) +`ord-bitcoincore-rpc` +===================== -# Rust RPC client for Bitcoin Core JSON-RPC - -This is a Rust RPC client library for calling the Bitcoin Core JSON-RPC API. It provides a layer of abstraction over -[rust-jsonrpc](https://github.com/apoelstra/rust-jsonrpc) and makes it easier to talk to the Bitcoin JSON-RPC interface - -This git package compiles into two crates. -1. [bitcoincore-rpc](https://crates.io/crates/bitcoincore-rpc) - contains an implementation of an rpc client that exposes -the Bitcoin Core JSON-RPC APIs as rust functions. - -2. [bitcoincore-rpc-json](https://crates.io/crates/bitcoincore-rpc-json) - contains rust data structures that represent -the json responses from the Bitcoin Core JSON-RPC APIs. bitcoincore-rpc depends on this. - -# Usage -Given below is an example of how to connect to the Bitcoin Core JSON-RPC for a Bitcoin Core node running on `localhost` -and print out the hash of the latest block. - -It assumes that the node has password authentication setup, the RPC interface is enabled at port `8332` and the node -is set up to accept RPC connections. - -```rust -extern crate bitcoincore_rpc; - -use bitcoincore_rpc::{Auth, Client, RpcApi}; - -fn main() { - - let rpc = Client::new("http://localhost:8332", - Auth::UserPass("".to_string(), - "".to_string())).unwrap(); - let best_block_hash = rpc.get_best_block_hash().unwrap(); - println!("best block hash: {}", best_block_hash); -} -``` - -See `client/examples/` for more usage examples. - -# Supported Bitcoin Core Versions -The following versions are officially supported and automatically tested: -* 0.18.0 -* 0.18.1 -* 0.19.0.1 -* 0.19.1 -* 0.20.0 -* 0.20.1 -* 0.21.0 - -# Minimum Supported Rust Version (MSRV) -This library should always compile with any combination of features on **Rust 1.56.1**. +This crate is a fork of +[rust-bitcoin/rust-bitcoincore-rpc](https://github.com/rust-bitcoin/rust-bitcoincore-rpc) +for use in [ord](https://github.com/ordinals/ord/). diff --git a/client/src/client.rs b/client/src/client.rs index b6f35e10..b4d3f212 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -18,9 +18,6 @@ use std::{fmt, result}; use crate::bitcoin; use crate::bitcoin::consensus::encode; use bitcoin::hex::DisplayHex; -use jsonrpc; -use serde; -use serde_json; use crate::bitcoin::address::{NetworkChecked, NetworkUnchecked}; use crate::bitcoin::hashes::hex::FromHex; @@ -55,11 +52,11 @@ impl From for JsonOutPoint { } } -impl Into for JsonOutPoint { - fn into(self) -> OutPoint { +impl From for OutPoint { + fn from(outpoint: JsonOutPoint) -> OutPoint { OutPoint { - txid: self.txid, - vout: self.vout, + txid: outpoint.txid, + vout: outpoint.vout, } } } @@ -113,9 +110,9 @@ fn empty_obj() -> serde_json::Value { /// /// Elements of `args` without corresponding `defaults` value, won't /// be substituted, because they are required. -fn handle_defaults<'a, 'b>( +fn handle_defaults<'a>( args: &'a mut [serde_json::Value], - defaults: &'b [serde_json::Value], + defaults: &[serde_json::Value], ) -> &'a [serde_json::Value] { assert!(args.len() >= defaults.len()); @@ -231,7 +228,7 @@ pub trait RpcApi: Sized { &self, id: &>::Id, ) -> Result { - T::query(&self, &id) + T::query(self, id) } fn get_network_info(&self) -> Result { @@ -378,9 +375,9 @@ pub trait RpcApi: Sized { self.call( "getblocktemplate", &[into_json(Argument { - mode: mode, - rules: rules, - capabilities: capabilities, + mode, + rules, + capabilities, })?], ) } @@ -419,7 +416,7 @@ pub trait RpcApi: Sized { type_: json::SoftforkType::Buried, bip9: None, height: None, - active: active, + active, }, ); } @@ -532,7 +529,7 @@ pub trait RpcApi: Sized { } fn get_balances(&self) -> Result { - Ok(self.call("getbalances", &[])?) + self.call("getbalances", &[]) } fn get_received_by_address(&self, address: &Address, minconf: Option) -> Result { @@ -670,7 +667,7 @@ pub trait RpcApi: Sized { req: &[json::ImportDescriptors], ) -> Result> { let json_request = serde_json::to_value(req)?; - self.call("importdescriptors", handle_defaults(&mut [json_request.into()], &[null()])) + self.call("importdescriptors", handle_defaults(&mut [json_request], &[null()])) } fn set_label(&self, address: &Address, label: &str) -> Result<()> { @@ -703,18 +700,14 @@ pub trait RpcApi: Sized { /// To unlock, use [unlock_unspent]. fn lock_unspent(&self, outputs: &[OutPoint]) -> Result { - let outputs: Vec<_> = outputs - .into_iter() - .map(|o| serde_json::to_value(JsonOutPoint::from(*o)).unwrap()) - .collect(); + let outputs: Vec<_> = + outputs.iter().map(|o| serde_json::to_value(JsonOutPoint::from(*o)).unwrap()).collect(); self.call("lockunspent", &[false.into(), outputs.into()]) } fn unlock_unspent(&self, outputs: &[OutPoint]) -> Result { - let outputs: Vec<_> = outputs - .into_iter() - .map(|o| serde_json::to_value(JsonOutPoint::from(*o)).unwrap()) - .collect(); + let outputs: Vec<_> = + outputs.iter().map(|o| serde_json::to_value(JsonOutPoint::from(*o)).unwrap()).collect(); self.call("lockunspent", &[true.into(), outputs.into()]) } @@ -864,7 +857,7 @@ pub trait RpcApi: Sized { rawtxs: &[R], ) -> Result> { let hexes: Vec = - rawtxs.to_vec().into_iter().map(|r| r.raw_hex().into()).collect(); + rawtxs.iter().cloned().map(|r| r.raw_hex().into()).collect(); self.call("testmempoolaccept", &[hexes.into()]) } @@ -958,6 +951,7 @@ pub trait RpcApi: Sized { self.call("getchaintips", &[]) } + #[allow(clippy::too_many_arguments)] fn send_to_address( &self, address: &Address, @@ -991,22 +985,22 @@ pub trait RpcApi: Sized { /// Attempts to add a node to the addnode list. /// 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). fn add_node(&self, addr: &str) -> Result<()> { - self.call("addnode", &[into_json(&addr)?, into_json("add")?]) + self.call("addnode", &[into_json(addr)?, into_json("add")?]) } /// Attempts to remove a node from the addnode list. fn remove_node(&self, addr: &str) -> Result<()> { - self.call("addnode", &[into_json(&addr)?, into_json("remove")?]) + self.call("addnode", &[into_json(addr)?, into_json("remove")?]) } /// Attempts to connect to a node without permanently adding it to the addnode list. fn onetry_node(&self, addr: &str) -> Result<()> { - self.call("addnode", &[into_json(&addr)?, into_json("onetry")?]) + self.call("addnode", &[into_json(addr)?, into_json("onetry")?]) } /// Immediately disconnects from the specified peer node. fn disconnect_node(&self, addr: &str) -> Result<()> { - self.call("disconnectnode", &[into_json(&addr)?]) + self.call("disconnectnode", &[into_json(addr)?]) } fn disconnect_node_by_id(&self, node_id: u32) -> Result<()> { @@ -1016,7 +1010,7 @@ pub trait RpcApi: Sized { /// Returns information about the given added node, or all added nodes (note that onetry addnodes are not listed here) fn get_added_node_info(&self, node: Option<&str>) -> Result> { if let Some(addr) = node { - self.call("getaddednodeinfo", &[into_json(&addr)?]) + self.call("getaddednodeinfo", &[into_json(addr)?]) } else { self.call("getaddednodeinfo", &[]) } @@ -1028,7 +1022,7 @@ pub trait RpcApi: Sized { count: Option, ) -> Result> { let cnt = count.unwrap_or(1); - self.call("getnodeaddresses", &[into_json(&cnt)?]) + self.call("getnodeaddresses", &[into_json(cnt)?]) } /// List all banned IPs/Subnets. @@ -1045,18 +1039,18 @@ pub trait RpcApi: Sized { fn add_ban(&self, subnet: &str, bantime: u64, absolute: bool) -> Result<()> { self.call( "setban", - &[into_json(&subnet)?, into_json("add")?, into_json(&bantime)?, into_json(&absolute)?], + &[into_json(subnet)?, into_json("add")?, into_json(bantime)?, into_json(absolute)?], ) } /// Attempts to remove an IP/Subnet from the banned list. fn remove_ban(&self, subnet: &str) -> Result<()> { - self.call("setban", &[into_json(&subnet)?, into_json("remove")?]) + self.call("setban", &[into_json(subnet)?, into_json("remove")?]) } /// Disable/enable all p2p network activity. fn set_network_active(&self, state: bool) -> Result { - self.call("setnetworkactive", &[into_json(&state)?]) + self.call("setnetworkactive", &[into_json(state)?]) } /// Returns data about each connected network node as an array of @@ -1098,7 +1092,7 @@ pub trait RpcApi: Sized { /// # Arguments /// /// 1. `timeout`: Time in milliseconds to wait for a response. 0 - /// indicates no timeout. + /// indicates no timeout. fn wait_for_new_block(&self, timeout: u64) -> Result { self.call("waitfornewblock", &[into_json(timeout)?]) } @@ -1110,7 +1104,7 @@ pub trait RpcApi: Sized { /// /// 1. `blockhash`: Block hash to wait for. /// 2. `timeout`: Time in milliseconds to wait for a response. 0 - /// indicates no timeout. + /// indicates no timeout. fn wait_for_block( &self, blockhash: &bitcoin::BlockHash, @@ -1256,10 +1250,10 @@ pub trait RpcApi: Sized { /// Submit a block as a hex string fn submit_block_hex(&self, block_hex: &str) -> Result<()> { - match self.call("submitblock", &[into_json(&block_hex)?]) { + match self.call("submitblock", &[into_json(block_hex)?]) { Ok(serde_json::Value::Null) => Ok(()), Ok(res) => Err(Error::ReturnedError(res.to_string())), - Err(err) => Err(err.into()), + Err(err) => Err(err), } } @@ -1321,7 +1315,7 @@ impl RpcApi for Client { args: &[serde_json::Value], ) -> Result { let raw = serde_json::value::to_raw_value(args)?; - let req = self.client.build_request(&cmd, Some(&*raw)); + let req = self.client.build_request(cmd, Some(&*raw)); if log_enabled!(Debug) { debug!(target: "bitcoincore_rpc", "JSON-RPC request: {} {}", cmd, serde_json::Value::from(args)); } @@ -1360,12 +1354,11 @@ fn log_response(cmd: &str, resp: &Result) { mod tests { use super::*; use crate::bitcoin; - use serde_json; #[test] fn test_raw_tx() { use crate::bitcoin::consensus::encode; - let client = Client::new("http://localhost/".into(), Auth::None).unwrap(); + let client = Client::new("http://localhost/", Auth::None).unwrap(); let tx: bitcoin::Transaction = encode::deserialize(&Vec::::from_hex("0200000001586bd02815cf5faabfec986a4e50d25dbee089bd2758621e61c5fab06c334af0000000006b483045022100e85425f6d7c589972ee061413bcf08dc8c8e589ce37b217535a42af924f0e4d602205c9ba9cb14ef15513c9d946fa1c4b797883e748e8c32171bdf6166583946e35c012103dae30a4d7870cd87b45dd53e6012f71318fdd059c1c2623b8cc73f8af287bb2dfeffffff021dc4260c010000001976a914f602e88b2b5901d8aab15ebe4a97cf92ec6e03b388ac00e1f505000000001976a914687ffeffe8cf4e4c038da46a9b1d37db385a472d88acfd211500").unwrap()).unwrap(); assert!(client.send_raw_transaction(&tx).is_err()); diff --git a/client/src/error.rs b/client/src/error.rs index 02a04d52..ae1584c1 100644 --- a/client/src/error.rs +++ b/client/src/error.rs @@ -13,8 +13,6 @@ use std::{error, fmt, io}; use crate::bitcoin; use crate::bitcoin::hashes::hex; use crate::bitcoin::secp256k1; -use jsonrpc; -use serde_json; /// The error type for errors produced in this library. #[derive(Debug)] diff --git a/client/src/lib.rs b/client/src/lib.rs index abcffe0d..ba725564 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -18,7 +18,6 @@ #[macro_use] extern crate log; -#[allow(unused)] #[macro_use] // `macro_use` is needed for v1.24.0 compilation. extern crate serde; diff --git a/client/src/queryable.rs b/client/src/queryable.rs index 6052f7e8..380dd835 100644 --- a/client/src/queryable.rs +++ b/client/src/queryable.rs @@ -9,7 +9,6 @@ // use crate::bitcoin; -use serde_json; use crate::client::Result; use crate::client::RpcApi; diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index 415ac032..ecba8323 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -109,21 +109,21 @@ fn sbtc>(btc: F) -> SignedAmount { } fn get_testdir() -> String { - return std::env::var("TESTDIR").expect("TESTDIR must be set"); + std::env::var("TESTDIR").expect("TESTDIR must be set") } fn get_rpc_url() -> String { - return std::env::var("RPC_URL").expect("RPC_URL must be set"); + std::env::var("RPC_URL").expect("RPC_URL must be set") } fn get_auth() -> bitcoincore_rpc::Auth { if let Ok(cookie) = std::env::var("RPC_COOKIE") { - return Auth::CookieFile(cookie.into()); + Auth::CookieFile(cookie.into()) } else if let Ok(user) = std::env::var("RPC_USER") { - return Auth::UserPass(user, std::env::var("RPC_PASS").unwrap_or_default()); + Auth::UserPass(user, std::env::var("RPC_PASS").unwrap_or_default()) } else { panic!("Either RPC_COOKIE or RPC_USER + RPC_PASS must be set."); - }; + } } fn new_wallet_client(wallet_name: &str) -> Client { @@ -393,7 +393,7 @@ fn test_get_address_info(cl: &Client) { fn test_set_label(cl: &Client) { let addr = cl.get_new_address(Some("label"), None).unwrap().assume_checked(); let info = cl.get_address_info(&addr).unwrap(); - if version() >= 0_20_00_00 { + if version() >= 20_00_00 { assert!(info.label.is_none()); assert_eq!(info.labels[0], json::GetAddressInfoResultLabel::Simple("label".into())); } else { @@ -409,7 +409,7 @@ fn test_set_label(cl: &Client) { cl.set_label(&addr, "other").unwrap(); let info = cl.get_address_info(&addr).unwrap(); - if version() >= 0_20_00_00 { + if version() >= 20_00_00 { assert!(info.label.is_none()); assert_eq!(info.labels[0], json::GetAddressInfoResultLabel::Simple("other".into())); } else { @@ -603,7 +603,7 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) { ..Default::default() }; let unspent = cl.list_unspent(Some(6), None, None, None, Some(options)).unwrap(); - let unspent = unspent.into_iter().nth(0).unwrap(); + let unspent = unspent.into_iter().next().unwrap(); let tx = Transaction { version: transaction::Version::ONE, @@ -639,7 +639,7 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) { lock_time: LockTime::ZERO, input: vec![TxIn { previous_output: OutPoint { - txid: txid, + txid, vout: 0, }, script_sig: ScriptBuf::new(), @@ -681,7 +681,7 @@ fn test_create_raw_transaction(cl: &Client) { ..Default::default() }; let unspent = cl.list_unspent(Some(6), None, None, None, Some(options)).unwrap(); - let unspent = unspent.into_iter().nth(0).unwrap(); + let unspent = unspent.into_iter().next().unwrap(); let input = json::CreateRawTransactionInput { txid: unspent.txid, @@ -704,7 +704,7 @@ fn test_decode_raw_transaction(cl: &Client) { ..Default::default() }; let unspent = cl.list_unspent(Some(6), None, None, None, Some(options)).unwrap(); - let unspent = unspent.into_iter().nth(0).unwrap(); + let unspent = unspent.into_iter().next().unwrap(); let input = json::CreateRawTransactionInput { txid: unspent.txid, @@ -773,7 +773,7 @@ fn test_test_mempool_accept(cl: &Client) { ..Default::default() }; let unspent = cl.list_unspent(Some(6), None, None, None, Some(options)).unwrap(); - let unspent = unspent.into_iter().nth(0).unwrap(); + let unspent = unspent.into_iter().next().unwrap(); let input = json::CreateRawTransactionInput { txid: unspent.txid, @@ -801,7 +801,7 @@ fn test_wallet_create_funded_psbt(cl: &Client) { ..Default::default() }; let unspent = cl.list_unspent(Some(6), None, None, None, Some(options)).unwrap(); - let unspent = unspent.into_iter().nth(0).unwrap(); + let unspent = unspent.into_iter().next().unwrap(); let input = json::CreateRawTransactionInput { txid: unspent.txid, @@ -859,7 +859,7 @@ fn test_wallet_process_psbt(cl: &Client) { ..Default::default() }; let unspent = cl.list_unspent(Some(6), None, None, None, Some(options)).unwrap(); - let unspent = unspent.into_iter().nth(0).unwrap(); + let unspent = unspent.into_iter().next().unwrap(); let input = json::CreateRawTransactionInput { txid: unspent.txid, vout: unspent.vout, @@ -915,7 +915,7 @@ fn test_combine_psbt(cl: &Client) { ..Default::default() }; let unspent = cl.list_unspent(Some(6), None, None, None, Some(options)).unwrap(); - let unspent = unspent.into_iter().nth(0).unwrap(); + let unspent = unspent.into_iter().next().unwrap(); let input = json::CreateRawTransactionInput { txid: unspent.txid, vout: unspent.vout, @@ -937,7 +937,7 @@ fn test_combine_raw_transaction(cl: &Client) { ..Default::default() }; let unspent = cl.list_unspent(Some(6), None, None, None, Some(options)).unwrap(); - let unspent = unspent.into_iter().nth(0).unwrap(); + let unspent = unspent.into_iter().next().unwrap(); let input = json::CreateRawTransactionInput { txid: unspent.txid, vout: unspent.vout, @@ -958,7 +958,7 @@ fn test_create_psbt(cl: &Client) { ..Default::default() }; let unspent = cl.list_unspent(Some(6), None, None, None, Some(options)).unwrap(); - let unspent = unspent.into_iter().nth(0).unwrap(); + let unspent = unspent.into_iter().next().unwrap(); let input = json::CreateRawTransactionInput { txid: unspent.txid, @@ -977,7 +977,7 @@ fn test_finalize_psbt(cl: &Client) { ..Default::default() }; let unspent = cl.list_unspent(Some(6), None, None, None, Some(options)).unwrap(); - let unspent = unspent.into_iter().nth(0).unwrap(); + let unspent = unspent.into_iter().next().unwrap(); let input = json::CreateRawTransactionInput { txid: unspent.txid, vout: unspent.vout, @@ -1036,7 +1036,7 @@ fn test_import_address(cl: &Client) { inner: secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng()), compressed: true, }; - let addr = Address::p2pkh(&sk.public_key(&SECP), Network::Regtest); + let addr = Address::p2pkh(sk.public_key(&SECP), Network::Regtest); cl.import_address(&addr, None, None).unwrap(); cl.import_address(&addr, Some("l"), None).unwrap(); cl.import_address(&addr, None, Some(false)).unwrap(); @@ -1048,7 +1048,7 @@ fn test_import_address_script(cl: &Client) { inner: secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng()), compressed: true, }; - let addr = Address::p2pkh(&sk.public_key(&SECP), Network::Regtest); + let addr = Address::p2pkh(sk.public_key(&SECP), Network::Regtest); cl.import_address_script(&addr.script_pubkey(), None, None, None).unwrap(); cl.import_address_script(&addr.script_pubkey(), Some("l"), None, None).unwrap(); cl.import_address_script(&addr.script_pubkey(), None, Some(false), None).unwrap(); @@ -1061,7 +1061,7 @@ fn test_estimate_smart_fee(cl: &Client) { // With a fresh node, we can't get fee estimates. if let Some(errors) = res.errors { - if errors == &["Insufficient data or no feerate found"] { + if errors == ["Insufficient data or no feerate found"] { println!("Cannot test estimate_smart_fee because no feerate found!"); return; } else { @@ -1074,7 +1074,7 @@ fn test_estimate_smart_fee(cl: &Client) { } fn test_ping(cl: &Client) { - let _ = cl.ping().unwrap(); + cl.ping().unwrap(); } fn test_get_peer_info(cl: &Client) { @@ -1187,7 +1187,7 @@ fn test_create_wallet(cl: &Client) { // Main wallet created for tests assert!(loaded_wallet_list.iter().any(|w| w == "testwallet")); - loaded_wallet_list.retain(|w| w != "testwallet" && w != ""); + loaded_wallet_list.retain(|w| w != "testwallet" && w.is_empty()); // Created wallets assert!(loaded_wallet_list.iter().zip(wallet_names).all(|(a, b)| a == b)); @@ -1345,7 +1345,7 @@ fn test_wait_for_new_block(cl: &Client) { let height = cl.get_block_count().unwrap(); let hash = cl.get_block_hash(height).unwrap(); - assert!(cl.wait_for_new_block(std::u64::MAX).is_err()); // JSON integer out of range + assert!(cl.wait_for_new_block(u64::MAX).is_err()); // JSON integer out of range assert_eq!( cl.wait_for_new_block(100).unwrap(), json::BlockRef { @@ -1359,7 +1359,7 @@ fn test_wait_for_block(cl: &Client) { let height = cl.get_block_count().unwrap(); let hash = cl.get_block_hash(height).unwrap(); - assert!(cl.wait_for_block(&hash, std::u64::MAX).is_err()); // JSON integer out of range + assert!(cl.wait_for_block(&hash, u64::MAX).is_err()); // JSON integer out of range assert_eq!( cl.wait_for_block(&hash, 0).unwrap(), json::BlockRef { @@ -1377,9 +1377,9 @@ fn test_get_descriptor_info(cl: &Client) { res.descriptor, r"pkh(02e96fe52ef0e22d2f131dd425ce1893073a3c6ad20e8cac36726393dfb4856a4c)#62k9sn4x" ); - assert_eq!(res.is_range, false); - assert_eq!(res.is_solvable, true); - assert_eq!(res.has_private_keys, true); + assert!(!res.is_range); + assert!(res.is_solvable); + assert!(res.has_private_keys); // Checksum introduced in: https://github.com/bitcoin/bitcoin/commit/26d3fad1093dfc697048313be7a96c9adf723654 if version() >= 190000 { diff --git a/json/src/lib.rs b/json/src/lib.rs index f47b9da2..135652f9 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -18,8 +18,6 @@ #![allow(deprecated)] // Because of `GetPeerInfoResultNetwork::Unroutable`. pub extern crate bitcoin; -#[allow(unused)] -#[macro_use] // `macro_use` is needed for v1.24.0 compilation. extern crate serde; extern crate serde_json; @@ -54,7 +52,7 @@ pub mod serde_hex { pub fn deserialize<'de, D: Deserializer<'de>>(d: D) -> Result, D::Error> { let hex_str: String = ::serde::Deserialize::deserialize(d)?; - Ok(FromHex::from_hex(&hex_str).map_err(D::Error::custom)?) + FromHex::from_hex(&hex_str).map_err(D::Error::custom) } pub mod opt { @@ -646,7 +644,7 @@ impl GetRawTransactionResult { } pub fn transaction(&self) -> Result { - Ok(encode::deserialize(&self.hex)?) + encode::deserialize(&self.hex) } } @@ -715,7 +713,7 @@ pub struct GetTransactionResult { impl GetTransactionResult { pub fn transaction(&self) -> Result { - Ok(encode::deserialize(&self.hex)?) + encode::deserialize(&self.hex) } } @@ -828,7 +826,7 @@ pub struct SignRawTransactionResult { impl SignRawTransactionResult { pub fn transaction(&self) -> Result { - Ok(encode::deserialize(&self.hex)?) + encode::deserialize(&self.hex) } } @@ -1162,7 +1160,7 @@ impl<'a> serde::Serialize for ImportMultiRequestScriptPubkey<'a> { S: serde::Serializer, { match *self { - ImportMultiRequestScriptPubkey::Address(ref addr) => { + ImportMultiRequestScriptPubkey::Address(addr) => { #[derive(Serialize)] struct Tmp<'a> { pub address: &'a Address, diff --git a/justfile b/justfile index 68e181d5..7e3b26d4 100644 --- a/justfile +++ b/justfile @@ -1,26 +1,20 @@ -default: - @just --list +watch +args='test': + cargo watch --clear --exec '{{args}}' -# Cargo build everything. build: cargo build --workspace --all-targets -# Cargo check everything. check: cargo check --workspace --all-targets -# Lint everything. lint: cargo clippy --workspace --all-targets -# Run the formatter. fmt: cargo fmt --all -# Check the formatting. format: cargo fmt --all --check -# Test the workspace. test: cargo test --workspace --all-targets