summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine A <>2023-10-06 03:58:16 +0200
committerAntoine A <>2023-10-06 03:58:16 +0200
commitc3f80619983e4eb80897c87add51bc70594e4b54 (patch)
tree5cb0ee4462cadeea7d230041e3dbbdc8936c0718
parent2e685701559118da856a0cde10849d82a112c9c7 (diff)
downloaddepolymerization-c3f80619983e4eb80897c87add51bc70594e4b54.tar.gz
depolymerization-c3f80619983e4eb80897c87add51bc70594e4b54.tar.bz2
depolymerization-c3f80619983e4eb80897c87add51bc70594e4b54.zip
Clean code
-rw-r--r--Cargo.lock40
-rw-r--r--btc-wire/src/btc_config.rs2
-rw-r--r--btc-wire/src/loops/analysis.rs2
-rw-r--r--btc-wire/src/loops/worker.rs2
-rw-r--r--btc-wire/src/main.rs5
-rw-r--r--btc-wire/src/rpc.rs2
-rw-r--r--eth-wire/src/lib.rs2
-rw-r--r--eth-wire/src/loops/worker.rs17
-rw-r--r--instrumentation/src/gateway.rs3
-rw-r--r--instrumentation/src/main.rs5
-rw-r--r--instrumentation/src/utils.rs14
11 files changed, 50 insertions, 44 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d81fc47..efe2b0c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -103,7 +103,7 @@ checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.37",
+ "syn 2.0.38",
]
[[package]]
@@ -223,9 +223,9 @@ checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec"
[[package]]
name = "byteorder"
-version = "1.4.3"
+version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
+checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "bytes"
@@ -325,7 +325,7 @@ dependencies = [
"heck",
"proc-macro2",
"quote",
- "syn 2.0.37",
+ "syn 2.0.38",
]
[[package]]
@@ -578,7 +578,7 @@ dependencies = [
"proc-macro2",
"quote",
"strsim",
- "syn 2.0.37",
+ "syn 2.0.38",
]
[[package]]
@@ -589,7 +589,7 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5"
dependencies = [
"darling_core",
"quote",
- "syn 2.0.37",
+ "syn 2.0.38",
]
[[package]]
@@ -849,7 +849,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.37",
+ "syn 2.0.38",
]
[[package]]
@@ -1425,7 +1425,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.37",
+ "syn 2.0.38",
]
[[package]]
@@ -1713,9 +1713,9 @@ checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6"
[[package]]
name = "rustix"
-version = "0.38.15"
+version = "0.38.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d2f9da0cbd88f9f09e7814e388301c8414c51c62aa6ce1e4b5c551d49d96e531"
+checksum = "f25469e9ae0f3d0047ca8b93fc56843f38e6774f0914a107ff8b41be8be8e0b7"
dependencies = [
"bitflags 2.4.0",
"errno",
@@ -1814,7 +1814,7 @@ checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.37",
+ "syn 2.0.38",
]
[[package]]
@@ -1836,7 +1836,7 @@ checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.37",
+ "syn 2.0.38",
]
[[package]]
@@ -1877,7 +1877,7 @@ dependencies = [
"darling",
"proc-macro2",
"quote",
- "syn 2.0.37",
+ "syn 2.0.38",
]
[[package]]
@@ -1986,9 +1986,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "2.0.37"
+version = "2.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8"
+checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b"
dependencies = [
"proc-macro2",
"quote",
@@ -2034,7 +2034,7 @@ checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.37",
+ "syn 2.0.38",
]
[[package]]
@@ -2130,7 +2130,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.37",
+ "syn 2.0.38",
]
[[package]]
@@ -2199,7 +2199,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.37",
+ "syn 2.0.38",
]
[[package]]
@@ -2376,7 +2376,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
- "syn 2.0.37",
+ "syn 2.0.38",
"wasm-bindgen-shared",
]
@@ -2398,7 +2398,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.37",
+ "syn 2.0.38",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
diff --git a/btc-wire/src/btc_config.rs b/btc-wire/src/btc_config.rs
index 58d85fe..85c96f4 100644
--- a/btc-wire/src/btc_config.rs
+++ b/btc-wire/src/btc_config.rs
@@ -83,7 +83,7 @@ impl BitcoinConfig {
Network::Testnet => conf.section(Some("test")),
Network::Signet => conf.section(Some("signet")),
Network::Regtest => conf.section(Some("regtest")),
- _ => unimplemented!()
+ _ => unimplemented!(),
};
let port = if let Some(addr) = section.and_then(|s| s.get("rpcport")) {
diff --git a/btc-wire/src/loops/analysis.rs b/btc-wire/src/loops/analysis.rs
index d2081d5..5d71758 100644
--- a/btc-wire/src/loops/analysis.rs
+++ b/btc-wire/src/loops/analysis.rs
@@ -24,7 +24,7 @@ pub fn analysis(rpc: &mut Rpc, current: u32, max: u32) -> LoopResult<u32> {
let fork = rpc
.get_chain_tips()?
.into_iter()
- .filter_map(|t| (t.status == ChainTipsStatus::ValidFork).then(|| t.length))
+ .filter_map(|t| (t.status == ChainTipsStatus::ValidFork).then_some(t.length))
.max()
.unwrap_or(0) as u32;
// If new fork is bigger than what current confirmation delay protect against
diff --git a/btc-wire/src/loops/worker.rs b/btc-wire/src/loops/worker.rs
index 3cd2aec..b26b902 100644
--- a/btc-wire/src/loops/worker.rs
+++ b/btc-wire/src/loops/worker.rs
@@ -176,7 +176,7 @@ fn sync_chain(
BlockHash,
) = {
// Get all transactions made since this block
- let list = rpc.list_since_block(Some(&last_hash), conf_delay as u32)?;
+ let list = rpc.list_since_block(Some(&last_hash), conf_delay)?;
// Only keep ids and category
let txs = list
.transactions
diff --git a/btc-wire/src/main.rs b/btc-wire/src/main.rs
index edb82e5..d6c8e45 100644
--- a/btc-wire/src/main.rs
+++ b/btc-wire/src/main.rs
@@ -101,7 +101,10 @@ fn init(config: Option<PathBuf>, init: Init) -> LoopResult<()> {
// Create wallet
let passwd = password();
let created = match rpc.create_wallet(WIRE_WALLET_NAME, &passwd) {
- Err(rpc::Error::RPC { code, .. }) if code == ErrorCode::RpcWalletError => false,
+ Err(rpc::Error::RPC {
+ code: ErrorCode::RpcWalletError,
+ ..
+ }) => false,
Err(e) => panic!("{}", e),
Ok(_) => true,
};
diff --git a/btc-wire/src/rpc.rs b/btc-wire/src/rpc.rs
index 711cb39..83c55ad 100644
--- a/btc-wire/src/rpc.rs
+++ b/btc-wire/src/rpc.rs
@@ -356,7 +356,7 @@ impl Rpc {
add_inputs: true,
inputs,
subtract_fee_from_outputs: if subtract_fee {
- (0..nb_outputs).into_iter().collect()
+ (0..nb_outputs).collect()
} else {
vec![]
},
diff --git a/eth-wire/src/lib.rs b/eth-wire/src/lib.rs
index 71ab818..6f3031b 100644
--- a/eth-wire/src/lib.rs
+++ b/eth-wire/src/lib.rs
@@ -119,7 +119,7 @@ pub trait RpcExtended: RpcClient {
txs.into_iter()
.filter_map(|tx| {
(tx.from == Some(*address) || tx.to == Some(*address))
- .then(|| SyncTransaction { tx, confirmations })
+ .then_some(SyncTransaction { tx, confirmations })
})
.collect()
};
diff --git a/eth-wire/src/loops/worker.rs b/eth-wire/src/loops/worker.rs
index 81eb59c..9139137 100644
--- a/eth-wire/src/loops/worker.rs
+++ b/eth-wire/src/loops/worker.rs
@@ -199,13 +199,16 @@ fn sync_chain_removed(
// Only keep incoming transaction that are not reconfirmed
// TODO study risk of accepting only mined transactions for faster recovery
- for tx in removed.iter().filter_map(|sync_tx| {
- (sync_tx.tx.to == Some(*addr)
- && txs
- .iter()
- .all(|it| it.tx.hash != sync_tx.tx.hash || it.confirmations < min_confirmation))
- .then(|| &sync_tx.tx)
- }) {
+ for tx in removed
+ .iter()
+ .filter(|sync_tx| {
+ sync_tx.tx.to == Some(*addr)
+ && txs
+ .iter()
+ .all(|it| it.tx.hash != sync_tx.tx.hash || it.confirmations < min_confirmation)
+ })
+ .map(|s| &s.tx)
+ {
match InMetadata::decode(&tx.input) {
Ok(metadata) => match metadata {
InMetadata::Credit { reserve_pub } => {
diff --git a/instrumentation/src/gateway.rs b/instrumentation/src/gateway.rs
index 3f24dab..e783303 100644
--- a/instrumentation/src/gateway.rs
+++ b/instrumentation/src/gateway.rs
@@ -194,8 +194,7 @@ pub fn api(ctx: TestCtx) {
// Compression bomb
let mut compressor = Compressor::new(CompressionLvl::best());
- let mut compressed = Vec::new();
- compressed.resize(compressor.deflate_compress_bound(big_hello.len()), 0);
+ let mut compressed = vec![0u8; compressor.deflate_compress_bound(big_hello.len())];
let size = compressor
.deflate_compress(big_hello.as_bytes(), &mut compressed)
.unwrap();
diff --git a/instrumentation/src/main.rs b/instrumentation/src/main.rs
index 5990c12..f196d7d 100644
--- a/instrumentation/src/main.rs
+++ b/instrumentation/src/main.rs
@@ -87,11 +87,11 @@ pub fn main() {
build_bin(&p, name, Some("fail"), &format!("{name}-fail"));
}
p.finish_and_clear();
-
+
// Run tests
let m = MultiProgress::new();
let start_style =
- &ProgressStyle::with_template("{prefix:.magenta} {elapsed:.dim}").unwrap();
+ &ProgressStyle::with_template("{prefix:.magenta} {msg} {elapsed:.dim}").unwrap();
let ok_style =
&ProgressStyle::with_template("{prefix:.magenta} {msg:.green} {elapsed:.dim}")
.unwrap();
@@ -110,6 +110,7 @@ pub fn main() {
let pb = m.add(ProgressBar::new_spinner());
pb.set_style(start_style.clone());
pb.set_prefix(*name);
+ pb.set_message("RUN");
pb.enable_steady_tick(Duration::from_millis(1000));
let join = s.spawn(move || {
let start = Instant::now();
diff --git a/instrumentation/src/utils.rs b/instrumentation/src/utils.rs
index 158876b..835764a 100644
--- a/instrumentation/src/utils.rs
+++ b/instrumentation/src/utils.rs
@@ -20,7 +20,7 @@ use std::{
io::Write as _,
net::{Ipv4Addr, SocketAddrV4, TcpListener, TcpStream},
ops::{Deref, DerefMut},
- path::PathBuf,
+ path::{Path, PathBuf},
process::{Child, Command, Stdio},
str::FromStr,
sync::{Arc, Mutex},
@@ -194,7 +194,7 @@ pub fn retry_opt<T>(mut lambda: impl FnMut() -> Option<T>) -> T {
}
pub fn retry(mut lambda: impl FnMut() -> bool) {
- retry_opt(|| lambda().then(|| ()))
+ retry_opt(|| lambda().then_some(()))
}
#[derive(Clone)]
@@ -206,12 +206,12 @@ pub struct TestCtx {
impl TestCtx {
pub fn new(name: &str) -> Self {
// Create log dir
- let log_dir = format!("log/{name}").into();
+ let log_dir = format!("log/{name}");
std::fs::remove_dir_all(&log_dir).ok();
std::fs::create_dir_all(&log_dir).unwrap();
// Generate password
let pwd: String = (0..30).map(|_| fastrand::alphanumeric()).collect();
- std::env::set_var("PASSWORD", &pwd);
+ std::env::set_var("PASSWORD", pwd);
Self {
log_dir,
@@ -315,7 +315,7 @@ impl TalerCtx {
),
)
.unwrap();
- let db = TalerCtx::start_db(&db_dir, &ctx);
+ let db = TalerCtx::start_db(&db_dir, ctx);
retry(|| {
let mut psql = ChildGuard(
Command::new("psql")
@@ -325,7 +325,7 @@ impl TalerCtx {
std::fs::File::options()
.append(true)
.create(true)
- .open(&ctx.log("postgres"))
+ .open(ctx.log("postgres"))
.unwrap(),
)
.stdin(Stdio::piped())
@@ -430,7 +430,7 @@ impl TalerCtx {
/* ----- Database ----- */
- fn start_db(db_dir: &PathBuf, ctx: &TestCtx) -> ChildGuard {
+ fn start_db(db_dir: &Path, ctx: &TestCtx) -> ChildGuard {
cmd_redirect(
"postgres",
&["-D", db_dir.to_string_lossy().as_ref()],