Skip to content

Commit

Permalink
chore: remove From impls for tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
jinsankim committed Feb 20, 2023
1 parent 231f460 commit acb0d81
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
25 changes: 13 additions & 12 deletions crates/net/network/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ pub struct NewPooledTransactionHashes {
pub hashes: Vec<H256>,
}

impl NewPooledTransactionHashes {
pub fn new(hashes: Vec<TxHash>, types: Vec<TxType>, sizes: Vec<usize>) -> Self {
NewPooledTransactionHashes {
types: Some(types.into_iter().map(|t| t as u8).collect()),
sizes: Some(sizes),
hashes,
}
}
}

impl From<NewPooledTransactionHashes66> for NewPooledTransactionHashes {
fn from(msg: NewPooledTransactionHashes66) -> Self {
NewPooledTransactionHashes { types: None, sizes: None, hashes: msg.0 }
Expand All @@ -66,21 +76,12 @@ impl From<NewPooledTransactionHashes68> for NewPooledTransactionHashes {
}
}

impl From<(Vec<TxHash>, Vec<TxType>, Vec<usize>)> for NewPooledTransactionHashes {
fn from((hashes, types, sizes): (Vec<TxHash>, Vec<TxType>, Vec<usize>)) -> Self {
NewPooledTransactionHashes {
types: Some(types.into_iter().map(|t| t as u8).collect()),
sizes: Some(sizes),
hashes,
}
}
}

impl From<Vec<PooledTransactionHash>> for NewPooledTransactionHashes {
fn from(value: Vec<PooledTransactionHash>) -> Self {
let (hashes, (types, sizes)) =
let (hashes, (types, sizes)): (Vec<TxHash>, (Vec<TxType>, Vec<usize>)) =
value.into_iter().map(|v| (v.hash, (v.tx_type, v.size))).unzip();
(hashes, types, sizes).into()

NewPooledTransactionHashes::new(hashes, types, sizes)
}
}

Expand Down
5 changes: 4 additions & 1 deletion crates/net/network/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ where
let (types, sizes) = full.iter().map(|tx| (tx.tx_type(), tx.length())).unzip();

// send hashes of transactions
self.network.send_transactions_hashes(*peer_id, (hashes, types, sizes).into());
self.network.send_transactions_hashes(
*peer_id,
NewPooledTransactionHashes::new(hashes, types, sizes),
);
} else {
// send full transactions
self.network.send_transactions(*peer_id, full);
Expand Down

0 comments on commit acb0d81

Please sign in to comment.