Skip to content

Commit d51c0dc

Browse files
committed
run cargo fmt
1 parent 208491f commit d51c0dc

File tree

4 files changed

+88
-34
lines changed

4 files changed

+88
-34
lines changed

electrs_macros/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use proc_macro::TokenStream;
22

3-
43
#[proc_macro_attribute]
54
#[cfg(feature = "otlp-tracing")]
65
pub fn trace(attr: TokenStream, item: TokenStream) -> TokenStream {
@@ -32,4 +31,4 @@ pub fn trace(attr: TokenStream, item: TokenStream) -> TokenStream {
3231
#[cfg(not(feature = "otlp-tracing"))]
3332
pub fn trace(_attr: TokenStream, item: TokenStream) -> TokenStream {
3433
item
35-
}
34+
}

src/new_index/mempool.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use itertools::{Either, Itertools};
33

44
#[cfg(not(feature = "liquid"))]
55
use bitcoin::consensus::encode::serialize;
6+
use electrs_macros::trace;
67
#[cfg(feature = "liquid")]
78
use elements::{encode::serialize, AssetId};
89

@@ -11,7 +12,6 @@ use std::iter::FromIterator;
1112
use std::sync::{Arc, RwLock};
1213
use std::time::{Duration, Instant};
1314

14-
use electrs_macros::trace;
1515
use crate::chain::{deserialize, BlockHash, Network, OutPoint, Transaction, TxOut, Txid};
1616
use crate::config::Config;
1717
use crate::daemon::Daemon;
@@ -516,7 +516,12 @@ impl Mempool {
516516
daemon: &Daemon,
517517
tip: &BlockHash,
518518
) -> Result<bool> {
519-
let _timer = mempool.read().unwrap().latency.with_label_values(&["update"]).start_timer();
519+
let _timer = mempool
520+
.read()
521+
.unwrap()
522+
.latency
523+
.with_label_values(&["update"])
524+
.start_timer();
520525

521526
// Continuously attempt to fetch mempool transactions until we're able to get them in full
522527
let mut fetched_txs = HashMap::<Txid, Transaction>::new();
@@ -554,9 +559,18 @@ impl Mempool {
554559
{
555560
let mempool = mempool.read().unwrap();
556561

557-
mempool.count.with_label_values(&["all_txs"]).set(all_txids.len() as f64);
558-
mempool.count.with_label_values(&["fetched_txs"]).set((indexed_txids.len() + fetched_txs.len()) as f64);
559-
mempool.count.with_label_values(&["missing_txs"]).set(new_txids.len() as f64);
562+
mempool
563+
.count
564+
.with_label_values(&["all_txs"])
565+
.set(all_txids.len() as f64);
566+
mempool
567+
.count
568+
.with_label_values(&["fetched_txs"])
569+
.set((indexed_txids.len() + fetched_txs.len()) as f64);
570+
mempool
571+
.count
572+
.with_label_values(&["missing_txs"])
573+
.set(new_txids.len() as f64);
560574
}
561575

562576
let new_txs = daemon.gettransactions_available(&new_txids)?;

src/rest.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
21
use crate::chain::{
32
address, BlockHash, Network, OutPoint, Script, Sequence, Transaction, TxIn, TxMerkleNode,
43
TxOut, Txid,
54
};
65
use crate::config::Config;
76
use crate::errors;
87
use crate::new_index::{compute_script_hash, Query, SpendingInput, Utxo};
8+
#[cfg(feature = "liquid")]
9+
use crate::util::optional_value_for_newer_blocks;
910
use crate::util::{
1011
create_socket, electrum_merkle, extract_tx_prevouts, get_innerscripts, get_tx_fee, has_prevout,
1112
is_coinbase, BlockHeaderMeta, BlockId, FullHash, ScriptToAddr, ScriptToAsm, TransactionStatus,
1213
DEFAULT_BLOCKHASH,
1314
};
14-
#[cfg(feature = "liquid")]
15-
use crate::util::optional_value_for_newer_blocks;
1615
#[cfg(not(feature = "liquid"))]
1716
use bitcoin::consensus::encode;
1817

@@ -186,14 +185,18 @@ impl TransactionValue {
186185
status: Some(TransactionStatus::from(blockid)),
187186

188187
#[cfg(feature = "liquid")]
189-
discount_vsize: optional_value_for_newer_blocks(blockid,
190-
START_OF_LIQUID_DISCOUNT_CT_POLICY,
191-
tx.discount_vsize()),
188+
discount_vsize: optional_value_for_newer_blocks(
189+
blockid,
190+
START_OF_LIQUID_DISCOUNT_CT_POLICY,
191+
tx.discount_vsize(),
192+
),
192193

193194
#[cfg(feature = "liquid")]
194-
discount_weight: optional_value_for_newer_blocks(blockid,
195-
START_OF_LIQUID_DISCOUNT_CT_POLICY,
196-
tx.discount_weight()),
195+
discount_weight: optional_value_for_newer_blocks(
196+
blockid,
197+
START_OF_LIQUID_DISCOUNT_CT_POLICY,
198+
tx.discount_weight(),
199+
),
197200
}
198201
}
199202
}

src/util/transaction.rs

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ impl From<Option<BlockId>> for TransactionStatus {
4545
}
4646
}
4747

48-
4948
#[cfg(feature = "liquid")]
50-
pub fn optional_value_for_newer_blocks(block_id: Option<BlockId>,
51-
check_time: u32,
52-
value: usize) -> Option<usize> {
49+
pub fn optional_value_for_newer_blocks(
50+
block_id: Option<BlockId>,
51+
check_time: u32,
52+
value: usize,
53+
) -> Option<usize> {
5354
match block_id {
5455
// use the provided value only if it was after the "activation" time
5556
Some(b) if b.time >= check_time => Some(value),
@@ -132,13 +133,12 @@ where
132133
s.end()
133134
}
134135

135-
136136
#[cfg(all(test, feature = "liquid"))]
137137
mod test {
138+
use super::optional_value_for_newer_blocks;
139+
use crate::util::BlockId;
138140
use bitcoin::hashes::Hash;
139141
use elements::BlockHash;
140-
use crate::util::BlockId;
141-
use super::optional_value_for_newer_blocks;
142142

143143
#[test]
144144
fn opt_value_newer_block() {
@@ -149,20 +149,58 @@ mod test {
149149

150150
// unconfirmed block should include the value
151151
let block_id = None;
152-
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), Some(value));
152+
assert_eq!(
153+
optional_value_for_newer_blocks(block_id, check_time, value),
154+
Some(value)
155+
);
153156

154157
// block time before check_time should NOT include the value
155-
let block_id = Some(BlockId{ height, hash, time: 0 });
156-
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), None);
157-
let block_id = Some(BlockId{ height, hash, time: 31 });
158-
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), None);
158+
let block_id = Some(BlockId {
159+
height,
160+
hash,
161+
time: 0,
162+
});
163+
assert_eq!(
164+
optional_value_for_newer_blocks(block_id, check_time, value),
165+
None
166+
);
167+
let block_id = Some(BlockId {
168+
height,
169+
hash,
170+
time: 31,
171+
});
172+
assert_eq!(
173+
optional_value_for_newer_blocks(block_id, check_time, value),
174+
None
175+
);
159176

160177
// block time on or after check_time should include the value
161-
let block_id = Some(BlockId{ height, hash, time: 32 });
162-
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), Some(value));
163-
let block_id = Some(BlockId{ height, hash, time: 33 });
164-
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), Some(value));
165-
let block_id = Some(BlockId{ height, hash, time: 333 });
166-
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), Some(value));
178+
let block_id = Some(BlockId {
179+
height,
180+
hash,
181+
time: 32,
182+
});
183+
assert_eq!(
184+
optional_value_for_newer_blocks(block_id, check_time, value),
185+
Some(value)
186+
);
187+
let block_id = Some(BlockId {
188+
height,
189+
hash,
190+
time: 33,
191+
});
192+
assert_eq!(
193+
optional_value_for_newer_blocks(block_id, check_time, value),
194+
Some(value)
195+
);
196+
let block_id = Some(BlockId {
197+
height,
198+
hash,
199+
time: 333,
200+
});
201+
assert_eq!(
202+
optional_value_for_newer_blocks(block_id, check_time, value),
203+
Some(value)
204+
);
167205
}
168206
}

0 commit comments

Comments
 (0)