Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate code and lint import #3124

Merged
merged 13 commits into from
Feb 27, 2024
4 changes: 2 additions & 2 deletions crates/ordinals/src/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ mod tests {
assert_eq!(Epoch::from(Sat(1)), 0);
assert_eq!(Epoch::from(Epoch(1).starting_sat()), 1);
assert_eq!(Epoch::from(Epoch(1).starting_sat() + 1), 1);
assert_eq!(Epoch::from(Sat(u64::max_value())), 33);
assert_eq!(Epoch::from(Sat(u64::MAX)), 33);
}

#[test]
Expand All @@ -237,6 +237,6 @@ mod tests {
#[test]
fn first_post_subsidy() {
assert_eq!(Epoch::FIRST_POST_SUBSIDY.subsidy(), 0);
assert!((Epoch(Epoch::FIRST_POST_SUBSIDY.0 - 1)).subsidy() > 0);
assert!(Epoch(Epoch::FIRST_POST_SUBSIDY.0 - 1).subsidy() > 0);
}
}
2 changes: 1 addition & 1 deletion crates/ordinals/src/height.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ mod tests {
u64::from(SUBSIDY_HALVING_INTERVAL) * 5000000000 + 2500000000
);
assert_eq!(
Height(u32::max_value()).starting_sat(),
Height(u32::MAX).starting_sat(),
*Epoch::STARTING_SATS.last().unwrap()
);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/test-bitcoincore-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub struct TransactionTemplate<'a> {

#[derive(Serialize, Deserialize)]
pub struct JsonOutPoint {
txid: bitcoin::Txid,
txid: Txid,
vout: u32,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/test-bitcoincore-rpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl Api for Server {
.utxos
.get(&OutPoint { txid, vout })
.map(|&value| GetTxOutResult {
bestblock: bitcoin::BlockHash::all_zeros(),
bestblock: BlockHash::all_zeros(),
confirmations: 0,
value,
script_pub_key: GetRawTransactionResultVoutScriptPubKey {
Expand Down Expand Up @@ -651,7 +651,7 @@ impl Api for Server {
&self,
_label: Option<String>,
_address_type: Option<bitcoincore_rpc::json::AddressType>,
) -> Result<bitcoin::Address, jsonrpc_core::Error> {
) -> Result<Address, jsonrpc_core::Error> {
let secp256k1 = Secp256k1::new();
let key_pair = KeyPair::new(&secp256k1, &mut rand::thread_rng());
let (public_key, _parity) = XOnlyPublicKey::from_keypair(&key_pair);
Expand Down
2 changes: 1 addition & 1 deletion src/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Decimal {
}

impl Display for Decimal {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let magnitude = 10u128.pow(self.scale.into());

let integer = self.value / magnitude;
Expand Down
6 changes: 3 additions & 3 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ impl Index {
};

self
.get_children_by_sequence_number_paginated(sequence_number, usize::max_value(), 0)
.get_children_by_sequence_number_paginated(sequence_number, usize::MAX, 0)
.map(|(children, _more)| children)
}

Expand Down Expand Up @@ -1885,7 +1885,7 @@ impl Index {
Some(sat) => {
if self.index_sats {
// unbound inscriptions should not be assigned to a sat
assert!(satpoint.outpoint != unbound_outpoint());
assert_ne!(satpoint.outpoint, unbound_outpoint());

assert!(rtx
.open_multimap_table(SAT_TO_SEQUENCE_NUMBER)
Expand Down Expand Up @@ -1913,7 +1913,7 @@ impl Index {
}
None => {
if self.index_sats {
assert!(satpoint.outpoint == unbound_outpoint())
assert_eq!(satpoint.outpoint, unbound_outpoint())
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/index/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl Entry for OutPoint {
type Value = OutPointValue;

fn load(value: Self::Value) -> Self {
Decodable::consensus_decode(&mut io::Cursor::new(value)).unwrap()
Decodable::consensus_decode(&mut Cursor::new(value)).unwrap()
}

fn store(self) -> Self::Value {
Expand All @@ -342,7 +342,7 @@ impl Entry for SatPoint {
type Value = SatPointValue;

fn load(value: Self::Value) -> Self {
Decodable::consensus_decode(&mut io::Cursor::new(value)).unwrap()
Decodable::consensus_decode(&mut Cursor::new(value)).unwrap()
}

fn store(self) -> Self::Value {
Expand Down
7 changes: 2 additions & 5 deletions src/index/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ impl Fetcher {

log::info!("failed to fetch raw transactions, retrying: {}", error);

tokio::time::sleep(tokio::time::Duration::from_millis(
100 * u64::pow(2, retries),
))
.await;
tokio::time::sleep(Duration::from_millis(100 * u64::pow(2, retries))).await;
retries += 1;
continue;
}
Expand Down Expand Up @@ -113,7 +110,7 @@ impl Fetcher {
.map_err(|e| anyhow!("Result for batched JSON-RPC response not valid hex: {e}"))
})
.and_then(|hex| {
bitcoin::consensus::deserialize(&hex).map_err(|e| {
consensus::deserialize(&hex).map_err(|e| {
anyhow!("Result for batched JSON-RPC response not valid bitcoin tx: {e}")
})
})
Expand Down
4 changes: 2 additions & 2 deletions src/index/reorg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ pub(crate) enum ReorgError {
Unrecoverable,
}

impl fmt::Display for ReorgError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
impl Display for ReorgError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
ReorgError::Recoverable { height, depth } => {
write!(f, "{depth} block deep reorg detected at height {height}")
Expand Down
35 changes: 16 additions & 19 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,20 @@ impl<'index> Updater<'_> {
let mut wtx = self.index.begin_write()?;
let starting_height = u32::try_from(self.index.client.get_block_count()?).unwrap() + 1;

wtx
.open_table(WRITE_TRANSACTION_STARTING_BLOCK_COUNT_TO_TIMESTAMP)?
.insert(
&self.height,
&SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.map(|duration| duration.as_millis())
.unwrap_or(0),
)?;
let write_height_to_ts = |wtx: &mut WriteTransaction, height: &u32| {
wtx
.open_table(WRITE_TRANSACTION_STARTING_BLOCK_COUNT_TO_TIMESTAMP)
.expect("open table failed")
.insert(
height,
&SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.map(|duration| duration.as_millis())
.unwrap_or(0),
)
.expect("insert height failed");
};
write_height_to_ts(&mut wtx, &self.height);
lugondev marked this conversation as resolved.
Show resolved Hide resolved

let mut progress_bar = if cfg!(test)
|| log_enabled!(log::Level::Info)
Expand Down Expand Up @@ -128,15 +133,7 @@ impl<'index> Updater<'_> {
// write transaction
break;
}
wtx
.open_table(WRITE_TRANSACTION_STARTING_BLOCK_COUNT_TO_TIMESTAMP)?
.insert(
&self.height,
&SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.map(|duration| duration.as_millis())
.unwrap_or(0),
)?;
write_height_to_ts(&mut wtx, &self.height);
lugondev marked this conversation as resolved.
Show resolved Hide resolved
}

if SHUTTING_DOWN.load(atomic::Ordering::Relaxed) {
Expand Down Expand Up @@ -257,7 +254,7 @@ impl<'index> Updater<'_> {
// else runs a request, we keep this to 12.
const PARALLEL_REQUESTS: usize = 12;

std::thread::spawn(move || {
thread::spawn(move || {
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
Expand Down
4 changes: 2 additions & 2 deletions src/index/updater/rune_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {
mint.limit.unwrap_or(runes::MAX_LIMIT)
}
} else {
u128::max_value()
u128::MAX
},
divisibility: etching.divisibility,
id: u128::from(self.height) << 16 | u128::from(index),
Expand Down Expand Up @@ -307,7 +307,7 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {
mint.limit.unwrap_or(runes::MAX_LIMIT)
}
} else {
u128::max_value()
u128::MAX
} - balance,
symbol,
timestamp: self.timestamp,
Expand Down
32 changes: 16 additions & 16 deletions src/inscriptions/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,11 @@ mod tests {
#[test]
fn ignore_key_path_spends() {
assert_eq!(
parse(&[Witness::from_slice(&[bitcoin::script::Builder::new()
.push_opcode(bitcoin::opcodes::OP_FALSE)
.push_opcode(bitcoin::opcodes::all::OP_IF)
parse(&[Witness::from_slice(&[script::Builder::new()
.push_opcode(opcodes::OP_FALSE)
.push_opcode(opcodes::all::OP_IF)
.push_slice(PROTOCOL_ID)
.push_opcode(bitcoin::opcodes::all::OP_ENDIF)
.push_opcode(opcodes::all::OP_ENDIF)
.into_script()
.into_bytes()])]),
Vec::new()
Expand All @@ -298,11 +298,11 @@ mod tests {
fn ignore_key_path_spends_with_annex() {
assert_eq!(
parse(&[Witness::from_slice(&[
bitcoin::script::Builder::new()
.push_opcode(bitcoin::opcodes::OP_FALSE)
.push_opcode(bitcoin::opcodes::all::OP_IF)
script::Builder::new()
.push_opcode(opcodes::OP_FALSE)
.push_opcode(opcodes::all::OP_IF)
.push_slice(PROTOCOL_ID)
.push_opcode(bitcoin::opcodes::all::OP_ENDIF)
.push_opcode(opcodes::all::OP_ENDIF)
.into_script()
.into_bytes(),
vec![0x50]
Expand All @@ -315,11 +315,11 @@ mod tests {
fn parse_from_tapscript() {
assert_eq!(
parse(&[Witness::from_slice(&[
bitcoin::script::Builder::new()
.push_opcode(bitcoin::opcodes::OP_FALSE)
.push_opcode(bitcoin::opcodes::all::OP_IF)
script::Builder::new()
.push_opcode(opcodes::OP_FALSE)
.push_opcode(opcodes::all::OP_IF)
.push_slice(PROTOCOL_ID)
.push_opcode(bitcoin::opcodes::all::OP_ENDIF)
.push_opcode(opcodes::all::OP_ENDIF)
.into_script()
.into_bytes(),
Vec::new()
Expand All @@ -332,11 +332,11 @@ mod tests {

#[test]
fn ignore_unparsable_scripts() {
let mut script_bytes = bitcoin::script::Builder::new()
.push_opcode(bitcoin::opcodes::OP_FALSE)
.push_opcode(bitcoin::opcodes::all::OP_IF)
let mut script_bytes = script::Builder::new()
.push_opcode(opcodes::OP_FALSE)
.push_opcode(opcodes::all::OP_IF)
.push_slice(PROTOCOL_ID)
.push_opcode(bitcoin::opcodes::all::OP_ENDIF)
.push_opcode(opcodes::all::OP_ENDIF)
.into_script()
.into_bytes();
script_bytes.push(0x01);
Expand Down
11 changes: 4 additions & 7 deletions src/inscriptions/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,19 @@ mod tests {
fn for_extension() {
assert_eq!(
Media::content_type_for_path(Path::new("pepe.jpg")).unwrap(),
("image/jpeg", BrotliEncoderMode::BROTLI_MODE_GENERIC)
("image/jpeg", BROTLI_MODE_GENERIC)
);
assert_eq!(
Media::content_type_for_path(Path::new("pepe.jpeg")).unwrap(),
("image/jpeg", BrotliEncoderMode::BROTLI_MODE_GENERIC)
("image/jpeg", BROTLI_MODE_GENERIC)
);
assert_eq!(
Media::content_type_for_path(Path::new("pepe.JPG")).unwrap(),
("image/jpeg", BrotliEncoderMode::BROTLI_MODE_GENERIC)
("image/jpeg", BROTLI_MODE_GENERIC)
);
assert_eq!(
Media::content_type_for_path(Path::new("pepe.txt")).unwrap(),
(
"text/plain;charset=utf-8",
BrotliEncoderMode::BROTLI_MODE_TEXT
)
("text/plain;charset=utf-8", BROTLI_MODE_TEXT)
);
assert_regex_match!(
Media::content_type_for_path(Path::new("pepe.foo")).unwrap_err(),
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ type Result<T = (), E = Error> = std::result::Result<T, E>;

static SHUTTING_DOWN: AtomicBool = AtomicBool::new(false);
static LISTENERS: Mutex<Vec<axum_server::Handle>> = Mutex::new(Vec::new());
static INDEXER: Mutex<Option<thread::JoinHandle<()>>> = Mutex::new(Option::None);
static INDEXER: Mutex<Option<thread::JoinHandle<()>>> = Mutex::new(None);

const TARGET_POSTAGE: Amount = Amount::from_sat(10_000);

Expand Down Expand Up @@ -183,7 +183,7 @@ fn unbound_outpoint() -> OutPoint {
}
}

pub fn parse_ord_server_args(args: &str) -> (Options, crate::subcommand::server::Server) {
pub fn parse_ord_server_args(args: &str) -> (Options, subcommand::server::Server) {
match Arguments::try_parse_from(args.split_whitespace()) {
Ok(arguments) => match arguments.subcommand {
Subcommand::Server(server) => (arguments.options, server),
Expand Down
1 change: 1 addition & 0 deletions src/object.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
lugondev marked this conversation as resolved.
Show resolved Hide resolved
use bitcoin::hashes::Hash;

#[derive(Debug, PartialEq, Clone)]
pub enum Object {
Expand Down
2 changes: 1 addition & 1 deletion src/outgoing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum Outgoing {
}

impl Display for Outgoing {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::Amount(amount) => write!(f, "{}", amount.to_string().to_lowercase()),
Self::InscriptionId(inscription_id) => inscription_id.fmt(f),
Expand Down
Loading
Loading