Skip to content

Commit f327fc8

Browse files
committed
fix: resolve all non-result_large_err clippy warnings
- Fix mismatched_lifetime_syntaxes: add explicit '_ to Cow<str> - Fix deref_addrof: remove unnecessary & on already-reference args - Fix useless_conversion: remove redundant .into() calls - Fix len_zero: use .is_empty() instead of .len() > 0 - Fix cmp_owned: compare BigDecimal directly with integer literal - Fix from_over_into: convert Into impl to From impl for Balance - Fix is_multiple_of: use .is_multiple_of() instead of modulo - Fix large_enum_variant: box ServerInfo and ServerState in XRPLResult - Fix unreachable_code and remove #[allow] directives in asynch/mod.rs
1 parent cc0d491 commit f327fc8

File tree

9 files changed

+104
-45
lines changed

9 files changed

+104
-45
lines changed

src/asynch/mod.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,33 @@ pub mod transaction;
1111
#[cfg(feature = "helpers")]
1212
pub mod wallet;
1313

14-
#[allow(unused_imports)]
15-
#[allow(clippy::needless_return)]
16-
#[allow(unused_variables)]
17-
async fn wait_seconds(seconds: u64) {
18-
use core::time::Duration;
19-
14+
async fn wait_seconds(_seconds: u64) {
2015
#[cfg(feature = "tokio-rt")]
2116
{
22-
tokio::time::sleep(tokio::time::Duration::from_secs(seconds)).await;
23-
return;
17+
tokio::time::sleep(tokio::time::Duration::from_secs(_seconds)).await;
2418
}
2519
#[cfg(feature = "embassy-rt")]
2620
{
2721
embassy_time::Timer::after_secs(1).await;
28-
return;
2922
}
3023
#[cfg(feature = "actix-rt")]
3124
{
32-
actix_rt::time::sleep(Duration::from_secs(seconds)).await;
33-
return;
25+
use core::time::Duration;
26+
actix_rt::time::sleep(Duration::from_secs(_seconds)).await;
3427
}
3528
#[cfg(feature = "async-std-rt")]
3629
{
37-
async_std::task::sleep(Duration::from_secs(seconds)).await;
38-
return;
30+
use core::time::Duration;
31+
async_std::task::sleep(Duration::from_secs(_seconds)).await;
3932
}
4033
#[cfg(feature = "futures-rt")]
4134
{
42-
futures_timer::Delay::new(Duration::from_secs(seconds)).await;
43-
return;
35+
use core::time::Duration;
36+
futures_timer::Delay::new(Duration::from_secs(_seconds)).await;
4437
}
4538
#[cfg(feature = "smol-rt")]
4639
{
47-
smol::Timer::after(Duration::from_secs(seconds)).await;
48-
return;
40+
use core::time::Duration;
41+
smol::Timer::after(Duration::from_secs(_seconds)).await;
4942
}
5043
}

src/asynch/transaction/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ where
6161
let serialized_bytes = hex::decode(serialized_for_signing)?;
6262
let signature = keypairs_sign(&serialized_bytes, &wallet.private_key)?;
6363
let signer = Signer::new(
64-
wallet.classic_address.clone().into(),
65-
signature.into(),
66-
wallet.public_key.clone().into(),
64+
wallet.classic_address.clone(),
65+
signature,
66+
wallet.public_key.clone(),
6767
);
6868
transaction.get_mut_common_fields().signers = Some(vec![signer]);
6969

src/cli/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,15 +480,15 @@ pub fn execute_command(command: &Commands) -> Result<(), CliError> {
480480
WalletCommands::Validate { address } => {
481481
use crate::core::addresscodec::{is_valid_classic_address, is_valid_xaddress};
482482

483-
let is_valid_classic = is_valid_classic_address(&address);
484-
let is_valid_x = is_valid_xaddress(&address);
483+
let is_valid_classic = is_valid_classic_address(address);
484+
let is_valid_x = is_valid_xaddress(address);
485485

486486
if is_valid_classic {
487487
alloc::println!("Valid classic address: {}", address);
488488
Ok(())
489489
} else if is_valid_x {
490490
use crate::core::addresscodec::xaddress_to_classic_address;
491-
let (classic_address, tag, is_test) = xaddress_to_classic_address(&address)?;
491+
let (classic_address, tag, is_test) = xaddress_to_classic_address(address)?;
492492
alloc::println!("Valid X-address: {}", address);
493493
alloc::println!(" Classic address: {}", classic_address);
494494
alloc::println!(" Destination tag: {:?}", tag);
@@ -786,10 +786,10 @@ pub fn execute_command(command: &Commands) -> Result<(), CliError> {
786786
use crate::wallet::Wallet;
787787

788788
// Create wallet from seed
789-
let wallet = Wallet::new(&seed, 0)?;
789+
let wallet = Wallet::new(seed, 0)?;
790790

791791
// Parse the JSON
792-
let json_value: Value = serde_json::from_str(&json)?;
792+
let json_value: Value = serde_json::from_str(json)?;
793793

794794
use crate::asynch::transaction::sign;
795795

src/core/binarycodec/types/vector256.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl Serialize for Vector256 {
6666
where
6767
S: Serializer,
6868
{
69-
if self.0.len() % _HASH_LENGTH_BYTES != 0 {
69+
if !self.0.len().is_multiple_of(_HASH_LENGTH_BYTES) {
7070
Err(S::Error::custom(XRPLVectorException::InvalidVector256Bytes))
7171
} else {
7272
let mut sequence = serializer.serialize_seq(None)?;

src/models/results/mod.rs

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ pub enum XRPLResult<'a> {
141141
PathFind(path_find::PathFind<'a>),
142142
Random(random::Random<'a>),
143143
RipplePathFind(ripple_path_find::RipplePathFind<'a>),
144-
ServerInfo(server_info::ServerInfo<'a>),
145-
ServerState(server_state::ServerState<'a>),
144+
ServerInfo(Box<server_info::ServerInfo<'a>>),
145+
ServerState(Box<server_state::ServerState<'a>>),
146146
Submit(submit::Submit<'a>),
147147
SubmitMultisigned(submit_multisigned::SubmitMultisigned<'a>),
148148
TransactionEntry(transaction_entry::TransactionEntry<'a>),
@@ -190,8 +190,16 @@ impl_from_result!(no_ripple_check, NoRippleCheck);
190190
impl_from_result!(path_find, PathFind);
191191
impl_from_result!(random, Random);
192192
impl_from_result!(ripple_path_find, RipplePathFind);
193-
impl_from_result!(server_info, ServerInfo);
194-
impl_from_result!(server_state, ServerState);
193+
impl<'a> From<server_info::ServerInfo<'a>> for XRPLResult<'a> {
194+
fn from(value: server_info::ServerInfo<'a>) -> Self {
195+
XRPLResult::ServerInfo(Box::new(value))
196+
}
197+
}
198+
impl<'a> From<server_state::ServerState<'a>> for XRPLResult<'a> {
199+
fn from(value: server_state::ServerState<'a>) -> Self {
200+
XRPLResult::ServerState(Box::new(value))
201+
}
202+
}
195203
impl_from_result!(submit, Submit);
196204
impl_from_result!(submit_multisigned, SubmitMultisigned);
197205
impl_from_result!(transaction_entry, TransactionEntry);
@@ -256,8 +264,34 @@ impl_try_from_result!(no_ripple_check, NoRippleCheck, NoRippleCheck);
256264
impl_try_from_result!(path_find, PathFind, PathFind);
257265
impl_try_from_result!(random, Random, Random);
258266
impl_try_from_result!(ripple_path_find, RipplePathFind, RipplePathFind);
259-
impl_try_from_result!(server_info, ServerInfo, ServerInfo);
260-
impl_try_from_result!(server_state, ServerState, ServerState);
267+
impl<'a> TryFrom<XRPLResult<'a>> for server_info::ServerInfo<'a> {
268+
type Error = XRPLModelException;
269+
270+
fn try_from(result: XRPLResult<'a>) -> XRPLModelResult<Self> {
271+
match result {
272+
XRPLResult::ServerInfo(value) => Ok(*value),
273+
res => Err(XRPLResultException::UnexpectedResultType(
274+
"ServerInfo".to_string(),
275+
res.get_name(),
276+
)
277+
.into()),
278+
}
279+
}
280+
}
281+
impl<'a> TryFrom<XRPLResult<'a>> for server_state::ServerState<'a> {
282+
type Error = XRPLModelException;
283+
284+
fn try_from(result: XRPLResult<'a>) -> XRPLModelResult<Self> {
285+
match result {
286+
XRPLResult::ServerState(value) => Ok(*value),
287+
res => Err(XRPLResultException::UnexpectedResultType(
288+
"ServerState".to_string(),
289+
res.get_name(),
290+
)
291+
.into()),
292+
}
293+
}
294+
}
261295
impl_try_from_result!(submit, Submit, Submit);
262296
impl_try_from_result!(submit_multisigned, SubmitMultisigned, SubmitMultisigned);
263297
impl_try_from_result!(transaction_entry, TransactionEntry, TransactionEntry);
@@ -407,8 +441,40 @@ impl_try_from_response!(path_find, PathFind, PathFind);
407441
impl_try_from_response!(ping, Ping, Ping);
408442
impl_try_from_response!(random, Random, Random);
409443
impl_try_from_response!(ripple_path_find, RipplePathFind, RipplePathFind);
410-
impl_try_from_response!(server_info, ServerInfo, ServerInfo);
411-
impl_try_from_response!(server_state, ServerState, ServerState);
444+
impl<'a> TryFrom<XRPLResponse<'a>> for server_info::ServerInfo<'a> {
445+
type Error = XRPLModelException;
446+
447+
fn try_from(response: XRPLResponse<'a>) -> XRPLModelResult<Self> {
448+
match response.result {
449+
Some(result) => match result {
450+
XRPLResult::ServerInfo(value) => Ok(*value),
451+
res => Err(XRPLResultException::UnexpectedResultType(
452+
"ServerInfo".to_string(),
453+
res.get_name(),
454+
)
455+
.into()),
456+
},
457+
None => Err(XRPLModelException::MissingField("result".to_string())),
458+
}
459+
}
460+
}
461+
impl<'a> TryFrom<XRPLResponse<'a>> for server_state::ServerState<'a> {
462+
type Error = XRPLModelException;
463+
464+
fn try_from(response: XRPLResponse<'a>) -> XRPLModelResult<Self> {
465+
match response.result {
466+
Some(result) => match result {
467+
XRPLResult::ServerState(value) => Ok(*value),
468+
res => Err(XRPLResultException::UnexpectedResultType(
469+
"ServerState".to_string(),
470+
res.get_name(),
471+
)
472+
.into()),
473+
},
474+
None => Err(XRPLModelException::MissingField("result".to_string())),
475+
}
476+
}
477+
}
412478
impl_try_from_response!(submit, Submit, Submit);
413479
impl_try_from_response!(submit_multisigned, SubmitMultisigned, SubmitMultisigned);
414480
impl_try_from_response!(transaction_entry, TransactionEntry, TransactionEntry);

src/models/transactions/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ where
271271
if let Some(signers) = &self.signers {
272272
signers
273273
.iter()
274-
.all(|signer| signer.txn_signature.len() > 0 && signer.signing_pub_key.len() > 0)
274+
.all(|signer| !signer.txn_signature.is_empty() && !signer.signing_pub_key.is_empty())
275275
} else {
276276
self.txn_signature.is_some() && self.signing_pub_key.is_some()
277277
}
@@ -602,7 +602,7 @@ where
602602

603603
/// Hashes the Transaction object as the ledger does. Only valid for signed
604604
/// Transaction objects.
605-
fn get_hash(&self) -> XRPLModelResult<Cow<str>>
605+
fn get_hash(&self) -> XRPLModelResult<Cow<'_, str>>
606606
where
607607
Self: Serialize + DeserializeOwned + Debug + Clone,
608608
{

src/utils/parse_nftoken_id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn unscramble_taxon(taxon: u64, token_seq: u64) -> u64 {
5252
/// | `---> TransferFee: 1337.0 bps or 13.37%
5353
/// |
5454
/// `---> Flags: 11 -> lsfBurnable, lsfOnlyXRP and lsfTransferable
55-
pub fn parse_nftoken_id(nft_id: Cow<str>) -> XRPLUtilsResult<NFTokenId<'_>> {
55+
pub fn parse_nftoken_id(nft_id: Cow<'_, str>) -> XRPLUtilsResult<NFTokenId<'_>> {
5656
const EXPECTED_LEN: usize = 64;
5757

5858
if nft_id.len() != EXPECTED_LEN {

src/utils/txn_parser/get_final_balances.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn compute_final_balance(node: &NormalizedNode) -> XRPLUtilsResult<Option<BigDec
2626
value = get_value(&balance.clone().into())?;
2727
}
2828
}
29-
if value == BigDecimal::from(0) {
29+
if value == 0 {
3030
return Ok(None);
3131
}
3232
Ok(Some(value))

src/utils/txn_parser/utils/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ impl<'a: 'b, 'b> From<Amount<'a>> for Balance<'b> {
3636
}
3737
}
3838

39-
impl<'a> Into<Amount<'a>> for Balance<'a> {
40-
fn into(self) -> Amount<'a> {
41-
if self.currency == "XRP" {
42-
Amount::XRPAmount(self.value.into())
39+
impl<'a> From<Balance<'a>> for Amount<'a> {
40+
fn from(balance: Balance<'a>) -> Self {
41+
if balance.currency == "XRP" {
42+
Amount::XRPAmount(balance.value.into())
4343
} else {
4444
Amount::IssuedCurrencyAmount(crate::models::IssuedCurrencyAmount {
45-
currency: self.currency,
46-
value: self.value,
47-
issuer: self.issuer.unwrap_or("".into()),
45+
currency: balance.currency,
46+
value: balance.value,
47+
issuer: balance.issuer.unwrap_or("".into()),
4848
})
4949
}
5050
}

0 commit comments

Comments
 (0)