From 03162853f123fa9215be00412e0c1afe75bd9c0a Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Tue, 3 Sep 2024 12:40:54 +0800 Subject: [PATCH 01/30] add btc domain indexer --- src/index/updater.rs | 2 +- src/okx/datastore/ord/btc_domain.rs | 96 ++++++++++++++++++++++++++++ src/okx/datastore/ord/collections.rs | 2 + src/okx/datastore/ord/mod.rs | 1 + src/okx/protocol/mod.rs | 7 +- src/okx/protocol/ord/btc_domain.rs | 88 +++++++++++++++++++++++++ src/okx/protocol/ord/mod.rs | 1 + src/okx/protocol/protocol_manager.rs | 10 ++- src/options.rs | 5 ++ 9 files changed, 209 insertions(+), 3 deletions(-) create mode 100644 src/okx/datastore/ord/btc_domain.rs create mode 100644 src/okx/protocol/ord/btc_domain.rs diff --git a/src/index/updater.rs b/src/index/updater.rs index fd0eb18b73..6bde56f72a 100644 --- a/src/index/updater.rs +++ b/src/index/updater.rs @@ -646,7 +646,7 @@ impl<'index> Updater<'_> { // Create a protocol manager to index the block of bitmap data. let config = ProtocolConfig::new_with_options(&index.options); - ProtocolManager::new(config).index_block(&mut context, &block, operations)?; + ProtocolManager::new(config).index_block(&mut context, &block, operations, domain_list)?; if index.index_runes && self.height >= self.index.options.first_rune_height() { let mut outpoint_to_rune_balances = wtx.open_table(OUTPOINT_TO_RUNE_BALANCES)?; diff --git a/src/okx/datastore/ord/btc_domain.rs b/src/okx/datastore/ord/btc_domain.rs new file mode 100644 index 0000000000..de83394774 --- /dev/null +++ b/src/okx/datastore/ord/btc_domain.rs @@ -0,0 +1,96 @@ +use {super::*, anyhow::anyhow, regex::Regex}; + +const BTC_DOMAIN_KEY: &str = r"BTC_DOMAIN"; + +pub struct District { + pub name: String, + pub domain: String, +} + +const DEFAULT_DOMAIN_LIST: [&'static str; 4] = ["btc", "unisat", "sats", "x"]; +impl District { + pub fn parse(bytes: &[u8], domain_list: &[String]) -> Result { + let domains = if domain_list.is_empty() { + DEFAULT_DOMAIN_LIST.iter().join("|") + } else { + domain_list.iter().join("|") + }; + let pattern = format!(r"^(?.*)\.(?[{domains}])$"); + let content = std::str::from_utf8(bytes)?; + let re = Regex::new(&pattern).unwrap(); + if let Some(capture) = re.captures(content) { + let name = &capture["name"]; + let domain = &capture["domain"]; + Ok(Self { + name: name.to_string(), + domain: domain.to_string(), + }) + } else { + Err(anyhow!("No match found.")) + } + } + + pub fn to_collection_key(&self) -> String { + format!("{}_{}_{}", BTC_DOMAIN_KEY, self.name, self.domain) + } + + /// 为.btc域名项目的6位纯数字域名提供额外的图片展示 + pub fn btc_block_height(&self) -> Option { + if self.name.len() == 6 && self.domain == "btc" { + if let Ok(block_height) = self.name.parse::() { + Some(block_height) + } else { + None + } + } else { + None + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use bech32::ToBase32; + + #[test] + fn validate_regex() { + let domain_list = vec![]; + let district = District::parse("0.bitmap".as_bytes(), &domain_list); + assert!(district.is_err()); + + let district = District::parse("01.btc".as_bytes(), &domain_list).unwrap(); + assert_eq!(district.domain, "btc"); + assert_eq!(district.name, "01"); + assert_eq!(district.btc_block_height(), None); + + let district = District::parse("123456.btc".as_bytes(), &domain_list).unwrap(); + assert_eq!(district.btc_block_height(), Some(123456)); + let district = District::parse("100000.btc".as_bytes(), &domain_list).unwrap(); + assert_eq!(district.btc_block_height(), Some(100000)); + let district = District::parse("000001.btc".as_bytes(), &domain_list).unwrap(); + assert_eq!(district.btc_block_height(), Some(1)); + + let district = District::parse("1234567.btc".as_bytes(), &domain_list).unwrap(); + assert_eq!(district.btc_block_height(), None); + + let district = District::parse("abc.btc".as_bytes(), &domain_list).unwrap(); + assert_eq!(district.domain, "btc"); + assert_eq!(district.name, "abc"); + + for d in DEFAULT_DOMAIN_LIST { + let s = format!("abc.{d}"); + let district = District::parse(s.as_bytes(), &domain_list).unwrap(); + assert!(DEFAULT_DOMAIN_LIST.contains(&district.domain.as_str())); + assert_eq!(district.name, "abc"); + } + // new domain list + let domain_list = vec!["aaa".to_string(), "bbb".to_string()]; + let district = District::parse("abc.aaa".as_bytes(), &domain_list).unwrap(); + assert_eq!(district.name, "abc"); + assert_eq!(district.domain, "aaa"); + + let district = District::parse("abc.btc".as_bytes(), &domain_list); + assert!(district.is_err()); + } +} diff --git a/src/okx/datastore/ord/collections.rs b/src/okx/datastore/ord/collections.rs index 196eceb929..b1084738e1 100644 --- a/src/okx/datastore/ord/collections.rs +++ b/src/okx/datastore/ord/collections.rs @@ -6,6 +6,7 @@ use std::fmt::Display; pub enum CollectionKind { BitMap, BRC20, + Domain, } impl Display for CollectionKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -14,6 +15,7 @@ impl Display for CollectionKind { "{}", match self { CollectionKind::BitMap => String::from("bitmap"), + CollectionKind::Domain => String::from("domain"), CollectionKind::BRC20 => String::from("brc20"), } ) diff --git a/src/okx/datastore/ord/mod.rs b/src/okx/datastore/ord/mod.rs index 3fe3b28afb..798c404b90 100644 --- a/src/okx/datastore/ord/mod.rs +++ b/src/okx/datastore/ord/mod.rs @@ -8,6 +8,7 @@ use { }; pub mod bitmap; +pub mod btc_domain; pub mod collections; pub mod operation; pub mod redb; diff --git a/src/okx/protocol/mod.rs b/src/okx/protocol/mod.rs index 947ef633a9..7b3e11b67d 100644 --- a/src/okx/protocol/mod.rs +++ b/src/okx/protocol/mod.rs @@ -19,12 +19,15 @@ pub struct ChainContext { pub blockheight: u32, pub blocktime: u32, } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone)] pub struct ProtocolConfig { first_inscription_height: u32, first_brc20_height: Option, enable_ord_receipts: bool, enable_index_bitmap: bool, + // 支持btc域名解析 + enable_index_domain: bool, + btc_domain_list: Vec, } impl ProtocolConfig { @@ -38,6 +41,8 @@ impl ProtocolConfig { }, enable_ord_receipts: options.enable_save_ord_receipts, enable_index_bitmap: options.enable_index_bitmap, + enable_index_domain: options.enable_index_domain, + btc_domain_list: options.btc_domain_list.clone(), } } } diff --git a/src/okx/protocol/ord/btc_domain.rs b/src/okx/protocol/ord/btc_domain.rs new file mode 100644 index 0000000000..38045a2127 --- /dev/null +++ b/src/okx/protocol/ord/btc_domain.rs @@ -0,0 +1,88 @@ +use crate::okx::datastore::ord::{OrdReader, OrdReaderWriter}; +use crate::okx::protocol::context::Context; +use { + crate::{ + okx::datastore::ord::{ + btc_domain::District, + collections::CollectionKind, + operation::{Action, InscriptionOp}, + }, + Inscription, InscriptionId, Result, + }, + anyhow::anyhow, + bitcoin::Txid, + std::collections::HashMap, +}; + +pub fn index_btc_domain( + context: &mut Context, + operations: &HashMap>, + domain_list: &[String], +) -> Result { + let mut count = 0; + + // ignore transferred or cursed inscriptions. + let mut positive_inscriptions = operations + .values() + .flatten() + .filter(|op| { + !op.inscription_number.unwrap().is_negative() && matches!(op.action, Action::New { .. }) + }) + .cloned() + .collect::>(); + + // sort by inscription number. + positive_inscriptions.sort_by_key(|op| op.inscription_number.unwrap()); + + for op in positive_inscriptions.into_iter() { + match op.action { + Action::New { inscription, .. } => { + if let Some((inscription_id, district)) = + index_district(context, inscription, op.inscription_id, domain_list)? + { + let key = district.to_collection_key(); + context.set_inscription_by_collection_key(&key, &inscription_id)?; + context.add_inscription_attributes(&inscription_id, CollectionKind::Domain)?; + count += 1; + } + } + _ => unreachable!(), + } + } + Ok(count) +} + +fn index_district( + context: &mut Context, + inscription: Inscription, + inscription_id: InscriptionId, + domain_list: &[String], +) -> Result> { + if let Some(content) = inscription.body() { + if let Ok(district) = District::parse(content, domain_list) { + if let Some(h) = district.btc_block_height() { + if h > context.chain_conf.blockheight { + return Ok(None); + } + } + let collection_key = district.to_collection_key(); + + if context + .get_collection_inscription_id(&collection_key) + .map_err(|e| { + anyhow!("failed to get collection inscription! key: {collection_key} error: {e}") + })? + .is_none() + { + log::info!( + "found valid btc domain district! {}.{} inscription_id {}", + district.name, + district.domain, + inscription_id, + ); + return Ok(Some((inscription_id, district))); + } + } + } + Ok(None) +} diff --git a/src/okx/protocol/ord/mod.rs b/src/okx/protocol/ord/mod.rs index 163f8968d3..04822a3ef6 100644 --- a/src/okx/protocol/ord/mod.rs +++ b/src/okx/protocol/ord/mod.rs @@ -1 +1,2 @@ pub mod bitmap; +pub mod btc_domain; diff --git a/src/okx/protocol/protocol_manager.rs b/src/okx/protocol/protocol_manager.rs index e3a4d0ab66..d4f93a8b70 100644 --- a/src/okx/protocol/protocol_manager.rs +++ b/src/okx/protocol/protocol_manager.rs @@ -21,7 +21,7 @@ impl ProtocolManager { // Need three datastore, and they're all in the same write transaction. pub fn new(config: ProtocolConfig) -> Self { Self { - config, + config: config.clone(), call_man: CallManager::new(), resolve_man: MsgResolveManager::new(config), } @@ -78,9 +78,17 @@ impl ProtocolManager { let bitmap_start = Instant::now(); let mut bitmap_count = 0; + let mut btc_domain_count = 0; if self.config.enable_index_bitmap { bitmap_count = ord_proto::bitmap::index_bitmap(context, &operations)?; } + if self.config.enable_index_domain { + btc_domain_count = ord_proto::btc_domain::index_btc_domain( + context, + &operations, + &self.config.btc_domain_list, + )?; + } let cost4 = bitmap_start.elapsed().as_millis(); log::info!( diff --git a/src/options.rs b/src/options.rs index a7854ccfca..0be404c5f1 100644 --- a/src/options.rs +++ b/src/options.rs @@ -81,9 +81,14 @@ pub struct Options { pub(crate) enable_save_ord_receipts: bool, #[arg(long, help = "Enable Index Bitmap Collection.")] pub(crate) enable_index_bitmap: bool, + #[arg(long, help = "Enable Index BTC domain Collection.")] + pub(crate) enable_index_domain: bool, // OKX defined options. #[arg(long, help = "Enable Index all of BRC20 Protocol")] pub(crate) enable_index_brc20: bool, + #[arg(long, use_value_delimiter=true, value_delimiter = ",", num_args=0.., + help = "BTC domain list, if empty, use default [btc,unisat,sats,x]")] + pub(crate) btc_domain_list: Vec, #[arg( long, help = "Don't look for BRC20 messages below ." From f1a7c83617d2f805f786e777178ff7928732555c Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Tue, 3 Sep 2024 14:52:53 +0800 Subject: [PATCH 02/30] fix error --- src/index/updater.rs | 2 +- src/okx/datastore/ord/btc_domain.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index/updater.rs b/src/index/updater.rs index 6bde56f72a..fd0eb18b73 100644 --- a/src/index/updater.rs +++ b/src/index/updater.rs @@ -646,7 +646,7 @@ impl<'index> Updater<'_> { // Create a protocol manager to index the block of bitmap data. let config = ProtocolConfig::new_with_options(&index.options); - ProtocolManager::new(config).index_block(&mut context, &block, operations, domain_list)?; + ProtocolManager::new(config).index_block(&mut context, &block, operations)?; if index.index_runes && self.height >= self.index.options.first_rune_height() { let mut outpoint_to_rune_balances = wtx.open_table(OUTPOINT_TO_RUNE_BALANCES)?; diff --git a/src/okx/datastore/ord/btc_domain.rs b/src/okx/datastore/ord/btc_domain.rs index de83394774..b387c75c8f 100644 --- a/src/okx/datastore/ord/btc_domain.rs +++ b/src/okx/datastore/ord/btc_domain.rs @@ -11,9 +11,9 @@ const DEFAULT_DOMAIN_LIST: [&'static str; 4] = ["btc", "unisat", "sats", "x"]; impl District { pub fn parse(bytes: &[u8], domain_list: &[String]) -> Result { let domains = if domain_list.is_empty() { - DEFAULT_DOMAIN_LIST.iter().join("|") + DEFAULT_DOMAIN_LIST.join("|") } else { - domain_list.iter().join("|") + domain_list.join("|") }; let pattern = format!(r"^(?.*)\.(?[{domains}])$"); let content = std::str::from_utf8(bytes)?; From 167ad72a1bb2f10d55b3b7d693a6cb6ad2279dd3 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Tue, 3 Sep 2024 14:53:56 +0800 Subject: [PATCH 03/30] update time crate --- Cargo.lock | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a861684728..57dc0b0d81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2192,6 +2192,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" version = "0.1.45" @@ -3580,13 +3586,14 @@ dependencies = [ [[package]] name = "time" -version = "0.3.31" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", "libc", + "num-conv", "num_threads", "powerfmt", "serde", @@ -3602,10 +3609,11 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ + "num-conv", "time-core", ] From efd9d06f1a45cb22694d6efa75e4370b9efe62d6 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Tue, 3 Sep 2024 16:32:17 +0800 Subject: [PATCH 04/30] add domain/:base64_domain interface --- src/index.rs | 2 ++ src/index/rtx.rs | 19 +++++++++++++++++++ src/okx/datastore/ord/btc_domain.rs | 24 ++++++++++++------------ src/okx/protocol/ord/btc_domain.rs | 6 +++--- src/okx/protocol/protocol_manager.rs | 3 ++- src/options.rs | 2 +- src/subcommand/server.rs | 4 ++++ src/subcommand/server/ord/inscription.rs | 24 ++++++++++++++++++++++++ 8 files changed, 67 insertions(+), 17 deletions(-) diff --git a/src/index.rs b/src/index.rs index 29d00ed454..62c95e333a 100644 --- a/src/index.rs +++ b/src/index.rs @@ -228,6 +228,7 @@ pub struct Index { path: PathBuf, started: DateTime, unrecoverably_reorged: AtomicBool, + pub domain_list: Vec, } impl Index { @@ -422,6 +423,7 @@ impl Index { path, started: Utc::now(), unrecoverably_reorged: AtomicBool::new(false), + domain_list: options.btc_domain_list.clone(), }) } diff --git a/src/index/rtx.rs b/src/index/rtx.rs index 1f76f25a79..829314c6c1 100644 --- a/src/index/rtx.rs +++ b/src/index/rtx.rs @@ -1,4 +1,7 @@ use super::*; +use crate::okx::datastore::ord::btc_domain::BtcDomain; +use base64::prelude::BASE64_STANDARD; +use base64::Engine; pub(crate) struct Rtx<'a>(pub(crate) redb::ReadTransaction<'a>); @@ -174,6 +177,22 @@ impl Rtx<'_> { get_collection_inscription_id(&table, &district.to_collection_key()) } + pub(crate) fn domain_district_to_inscription_id( + &self, + base64_domain: &str, + domain_list: &[String], + ) -> Result> { + let domain_raw = BASE64_STANDARD + .decode(base64_domain.as_bytes()) + .map_err(|e| { + log::error!("can't decode base64 domain: {base64_domain}, error: {e:?}"); + e + })?; + let domain = BtcDomain::parse(&domain_raw, &domain_list)?; + let table = self.0.open_table(COLLECTIONS_KEY_TO_INSCRIPTION_ID)?; + get_collection_inscription_id(&table, &domain.to_collection_key()) + } + pub(crate) fn ord_transaction_id_to_inscription_operations( &self, txid: Txid, diff --git a/src/okx/datastore/ord/btc_domain.rs b/src/okx/datastore/ord/btc_domain.rs index b387c75c8f..d4d0329628 100644 --- a/src/okx/datastore/ord/btc_domain.rs +++ b/src/okx/datastore/ord/btc_domain.rs @@ -2,13 +2,13 @@ use {super::*, anyhow::anyhow, regex::Regex}; const BTC_DOMAIN_KEY: &str = r"BTC_DOMAIN"; -pub struct District { +pub struct BtcDomain { pub name: String, pub domain: String, } const DEFAULT_DOMAIN_LIST: [&'static str; 4] = ["btc", "unisat", "sats", "x"]; -impl District { +impl BtcDomain { pub fn parse(bytes: &[u8], domain_list: &[String]) -> Result { let domains = if domain_list.is_empty() { DEFAULT_DOMAIN_LIST.join("|") @@ -56,41 +56,41 @@ mod tests { #[test] fn validate_regex() { let domain_list = vec![]; - let district = District::parse("0.bitmap".as_bytes(), &domain_list); + let district = BtcDomain::parse("0.bitmap".as_bytes(), &domain_list); assert!(district.is_err()); - let district = District::parse("01.btc".as_bytes(), &domain_list).unwrap(); + let district = BtcDomain::parse("01.btc".as_bytes(), &domain_list).unwrap(); assert_eq!(district.domain, "btc"); assert_eq!(district.name, "01"); assert_eq!(district.btc_block_height(), None); - let district = District::parse("123456.btc".as_bytes(), &domain_list).unwrap(); + let district = BtcDomain::parse("123456.btc".as_bytes(), &domain_list).unwrap(); assert_eq!(district.btc_block_height(), Some(123456)); - let district = District::parse("100000.btc".as_bytes(), &domain_list).unwrap(); + let district = BtcDomain::parse("100000.btc".as_bytes(), &domain_list).unwrap(); assert_eq!(district.btc_block_height(), Some(100000)); - let district = District::parse("000001.btc".as_bytes(), &domain_list).unwrap(); + let district = BtcDomain::parse("000001.btc".as_bytes(), &domain_list).unwrap(); assert_eq!(district.btc_block_height(), Some(1)); - let district = District::parse("1234567.btc".as_bytes(), &domain_list).unwrap(); + let district = BtcDomain::parse("1234567.btc".as_bytes(), &domain_list).unwrap(); assert_eq!(district.btc_block_height(), None); - let district = District::parse("abc.btc".as_bytes(), &domain_list).unwrap(); + let district = BtcDomain::parse("abc.btc".as_bytes(), &domain_list).unwrap(); assert_eq!(district.domain, "btc"); assert_eq!(district.name, "abc"); for d in DEFAULT_DOMAIN_LIST { let s = format!("abc.{d}"); - let district = District::parse(s.as_bytes(), &domain_list).unwrap(); + let district = BtcDomain::parse(s.as_bytes(), &domain_list).unwrap(); assert!(DEFAULT_DOMAIN_LIST.contains(&district.domain.as_str())); assert_eq!(district.name, "abc"); } // new domain list let domain_list = vec!["aaa".to_string(), "bbb".to_string()]; - let district = District::parse("abc.aaa".as_bytes(), &domain_list).unwrap(); + let district = BtcDomain::parse("abc.aaa".as_bytes(), &domain_list).unwrap(); assert_eq!(district.name, "abc"); assert_eq!(district.domain, "aaa"); - let district = District::parse("abc.btc".as_bytes(), &domain_list); + let district = BtcDomain::parse("abc.btc".as_bytes(), &domain_list); assert!(district.is_err()); } } diff --git a/src/okx/protocol/ord/btc_domain.rs b/src/okx/protocol/ord/btc_domain.rs index 38045a2127..6c3a06ff00 100644 --- a/src/okx/protocol/ord/btc_domain.rs +++ b/src/okx/protocol/ord/btc_domain.rs @@ -3,7 +3,7 @@ use crate::okx::protocol::context::Context; use { crate::{ okx::datastore::ord::{ - btc_domain::District, + btc_domain::BtcDomain, collections::CollectionKind, operation::{Action, InscriptionOp}, }, @@ -57,9 +57,9 @@ fn index_district( inscription: Inscription, inscription_id: InscriptionId, domain_list: &[String], -) -> Result> { +) -> Result> { if let Some(content) = inscription.body() { - if let Ok(district) = District::parse(content, domain_list) { + if let Ok(district) = BtcDomain::parse(content, domain_list) { if let Some(h) = district.btc_block_height() { if h > context.chain_conf.blockheight { return Ok(None); diff --git a/src/okx/protocol/protocol_manager.rs b/src/okx/protocol/protocol_manager.rs index d4f93a8b70..dbf9fde300 100644 --- a/src/okx/protocol/protocol_manager.rs +++ b/src/okx/protocol/protocol_manager.rs @@ -92,11 +92,12 @@ impl ProtocolManager { let cost4 = bitmap_start.elapsed().as_millis(); log::info!( - "Protocol Manager indexed block {} with ord inscriptions {}, messages {}, bitmap {} in {} ms, {}/{}/{}/{}", + "Protocol Manager indexed block {} with ord inscriptions {}, messages {}, bitmap {}, btc domain {}, in {} ms, {}/{}/{}/{}", context.chain_conf.blockheight, inscriptions_size, messages_size, bitmap_count, + btc_domain_count, start.elapsed().as_millis(), cost1/1000, cost2/1000, diff --git a/src/options.rs b/src/options.rs index 0be404c5f1..8ab260327f 100644 --- a/src/options.rs +++ b/src/options.rs @@ -86,7 +86,7 @@ pub struct Options { // OKX defined options. #[arg(long, help = "Enable Index all of BRC20 Protocol")] pub(crate) enable_index_brc20: bool, - #[arg(long, use_value_delimiter=true, value_delimiter = ",", num_args=0.., + #[arg(long, use_value_delimiter=true, value_delimiter = ',', num_args=0.., help = "BTC domain list, if empty, use default [btc,unisat,sats,x]")] pub(crate) btc_domain_list: Vec, #[arg( diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 8705e410c5..39eaff837d 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -309,6 +309,10 @@ impl Server { "/ord/debug/bitmap/district/:number", get(ord::ord_debug_bitmap_district), ) + .route( + "/ord/debug/domain/:base64_domain", + get(ord::ord_debug_domain_district), + ) .route("/brc20/tick/:tick", get(brc20::brc20_tick_info)) .route("/brc20/tick", get(brc20::brc20_all_tick_info)) .route( diff --git a/src/subcommand/server/ord/inscription.rs b/src/subcommand/server/ord/inscription.rs index 0ac551596a..22a56c052a 100644 --- a/src/subcommand/server/ord/inscription.rs +++ b/src/subcommand/server/ord/inscription.rs @@ -248,6 +248,30 @@ pub(crate) async fn ord_debug_bitmap_district( Ok(Json(ApiResponse::ok(inscription_id))) } +// ord/debug/domain/:base64_domain +pub(crate) async fn ord_debug_domain_district( + Extension(index): Extension>, + Path(base64_domain): Path, +) -> ApiResult { + log::debug!( + "rpc: get ord_debug_bitmap_district: base64_domain:{}", + base64_domain + ); + + let rtx = index.begin_read()?; + let inscription_id = rtx + .domain_district_to_inscription_id(&base64_domain, &index.domain_list)? + .ok_or_api_not_found(format!("district {base64_domain} not found."))?; + + log::debug!( + "rpc: get ord_debug_bitmap_district: {:?} {:?}", + base64_domain, + inscription_id + ); + + Ok(Json(ApiResponse::ok(inscription_id))) +} + #[cfg(test)] mod tests { use super::*; From 5bc469414ac90f0fd081dbc5bc37ee629ac8d1a7 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Tue, 3 Sep 2024 16:37:41 +0800 Subject: [PATCH 05/30] add unit test for domain_list options --- src/options.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/options.rs b/src/options.rs index 8ab260327f..3c55242333 100644 --- a/src/options.rs +++ b/src/options.rs @@ -905,4 +905,13 @@ mod tests { "cookie file `/foo/bar/baz/qux/.cookie` does not exist" ); } + + #[test] + fn test_domain_list() { + let arguments = Arguments::try_parse_from(["ord", "--btc_domain_list", "aaa, bbb"]).unwrap(); + assert_eq!( + arguments.options.btc_domain_list, + vec!["aaa".to_string(), "bbb".to_string()] + ); + } } From b34afeb54a26da1ea1dd8ee82783442796ed8e4f Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Tue, 3 Sep 2024 16:44:47 +0800 Subject: [PATCH 06/30] update validate regex unit test --- src/okx/datastore/ord/btc_domain.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/okx/datastore/ord/btc_domain.rs b/src/okx/datastore/ord/btc_domain.rs index d4d0329628..d9d7e7edba 100644 --- a/src/okx/datastore/ord/btc_domain.rs +++ b/src/okx/datastore/ord/btc_domain.rs @@ -63,6 +63,9 @@ mod tests { assert_eq!(district.domain, "btc"); assert_eq!(district.name, "01"); assert_eq!(district.btc_block_height(), None); + let district = BtcDomain::parse("btc.com/01?.btc.btc".as_bytes(), &domain_list).unwrap(); + assert_eq!(district.domain, "btc"); + assert_eq!(district.name, "btc.com/01?.btc"); let district = BtcDomain::parse("123456.btc".as_bytes(), &domain_list).unwrap(); assert_eq!(district.btc_block_height(), Some(123456)); From 5e7f72c2101b080c684872f916a8626b635d6c95 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Tue, 3 Sep 2024 16:58:57 +0800 Subject: [PATCH 07/30] fix domain regex pattern --- src/okx/datastore/ord/btc_domain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/okx/datastore/ord/btc_domain.rs b/src/okx/datastore/ord/btc_domain.rs index d9d7e7edba..fc9c755fc3 100644 --- a/src/okx/datastore/ord/btc_domain.rs +++ b/src/okx/datastore/ord/btc_domain.rs @@ -15,7 +15,7 @@ impl BtcDomain { } else { domain_list.join("|") }; - let pattern = format!(r"^(?.*)\.(?[{domains}])$"); + let pattern = format!(r"^(?.+)\.(?{domains})$"); let content = std::str::from_utf8(bytes)?; let re = Regex::new(&pattern).unwrap(); if let Some(capture) = re.captures(content) { From 403d9acf41eb3c5df11d54ebf4ca700cc2af23e5 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Tue, 3 Sep 2024 17:29:32 +0800 Subject: [PATCH 08/30] fix domain unit test --- src/options.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/options.rs b/src/options.rs index 3c55242333..b0f1f84b62 100644 --- a/src/options.rs +++ b/src/options.rs @@ -87,7 +87,7 @@ pub struct Options { #[arg(long, help = "Enable Index all of BRC20 Protocol")] pub(crate) enable_index_brc20: bool, #[arg(long, use_value_delimiter=true, value_delimiter = ',', num_args=0.., - help = "BTC domain list, if empty, use default [btc,unisat,sats,x]")] + help = "BTC domain list, default are btc,unisat,sats,x")] pub(crate) btc_domain_list: Vec, #[arg( long, @@ -908,7 +908,12 @@ mod tests { #[test] fn test_domain_list() { - let arguments = Arguments::try_parse_from(["ord", "--btc_domain_list", "aaa, bbb"]).unwrap(); + let arguments = Arguments::try_parse_from([ + "ord", + "--btc-domain-list=aaa,bbb", + "index", + "update" + ]).unwrap(); assert_eq!( arguments.options.btc_domain_list, vec!["aaa".to_string(), "bbb".to_string()] From a5bc13bc96c85d310401e468d89d6c1b65854646 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Tue, 3 Sep 2024 18:41:11 +0800 Subject: [PATCH 09/30] remove block height check for btc --- src/okx/protocol/ord/btc_domain.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/okx/protocol/ord/btc_domain.rs b/src/okx/protocol/ord/btc_domain.rs index 6c3a06ff00..c06e433ddb 100644 --- a/src/okx/protocol/ord/btc_domain.rs +++ b/src/okx/protocol/ord/btc_domain.rs @@ -38,7 +38,7 @@ pub fn index_btc_domain( match op.action { Action::New { inscription, .. } => { if let Some((inscription_id, district)) = - index_district(context, inscription, op.inscription_id, domain_list)? + index_domain(context, inscription, op.inscription_id, domain_list)? { let key = district.to_collection_key(); context.set_inscription_by_collection_key(&key, &inscription_id)?; @@ -52,7 +52,7 @@ pub fn index_btc_domain( Ok(count) } -fn index_district( +fn index_domain( context: &mut Context, inscription: Inscription, inscription_id: InscriptionId, @@ -60,11 +60,13 @@ fn index_district( ) -> Result> { if let Some(content) = inscription.body() { if let Ok(district) = BtcDomain::parse(content, domain_list) { - if let Some(h) = district.btc_block_height() { - if h > context.chain_conf.blockheight { - return Ok(None); - } - } + // TODO: 当前高度为800000,若mint了900000.btc,则在到达900000高度时开图 + // TODO: 当前高度为800000,若mint了700000.btc,则直接开图,图片内容= 700000.bimap + // if let Some(h) = district.btc_block_height() { + // if h > context.chain_conf.blockheight { + // return Ok(None); + // } + // } let collection_key = district.to_collection_key(); if context From aab8320434be3449d16a49812661294f9068df5a Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Wed, 4 Sep 2024 09:51:50 +0800 Subject: [PATCH 10/30] update log --- src/subcommand/server/ord/inscription.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subcommand/server/ord/inscription.rs b/src/subcommand/server/ord/inscription.rs index 22a56c052a..c2543d1297 100644 --- a/src/subcommand/server/ord/inscription.rs +++ b/src/subcommand/server/ord/inscription.rs @@ -254,7 +254,7 @@ pub(crate) async fn ord_debug_domain_district( Path(base64_domain): Path, ) -> ApiResult { log::debug!( - "rpc: get ord_debug_bitmap_district: base64_domain:{}", + "rpc: get ord_debug_domain_district: base64_domain:{}", base64_domain ); From 76ee15f256e5e251d520677d47d47bd4ae21a991 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Wed, 4 Sep 2024 10:27:11 +0800 Subject: [PATCH 11/30] update comment --- src/okx/datastore/ord/btc_domain.rs | 2 +- src/okx/protocol/ord/btc_domain.rs | 4 ++-- src/options.rs | 8 ++------ 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/okx/datastore/ord/btc_domain.rs b/src/okx/datastore/ord/btc_domain.rs index fc9c755fc3..972b580e90 100644 --- a/src/okx/datastore/ord/btc_domain.rs +++ b/src/okx/datastore/ord/btc_domain.rs @@ -34,7 +34,7 @@ impl BtcDomain { format!("{}_{}_{}", BTC_DOMAIN_KEY, self.name, self.domain) } - /// 为.btc域名项目的6位纯数字域名提供额外的图片展示 + /// need image display if the domain name of "*.btc" is 6-digit pub fn btc_block_height(&self) -> Option { if self.name.len() == 6 && self.domain == "btc" { if let Ok(block_height) = self.name.parse::() { diff --git a/src/okx/protocol/ord/btc_domain.rs b/src/okx/protocol/ord/btc_domain.rs index c06e433ddb..bca6294011 100644 --- a/src/okx/protocol/ord/btc_domain.rs +++ b/src/okx/protocol/ord/btc_domain.rs @@ -60,8 +60,8 @@ fn index_domain( ) -> Result> { if let Some(content) = inscription.body() { if let Ok(district) = BtcDomain::parse(content, domain_list) { - // TODO: 当前高度为800000,若mint了900000.btc,则在到达900000高度时开图 - // TODO: 当前高度为800000,若mint了700000.btc,则直接开图,图片内容= 700000.bimap + // TODO: if current block height is 800000,and mint 900000.btc,need display image at block height 900000 + // TODO: if current block height is 800000,and mint 700000.btc,need to display image directly, the image content = 700000.bimap // if let Some(h) = district.btc_block_height() { // if h > context.chain_conf.blockheight { // return Ok(None); diff --git a/src/options.rs b/src/options.rs index b0f1f84b62..b7feb4d4ed 100644 --- a/src/options.rs +++ b/src/options.rs @@ -908,12 +908,8 @@ mod tests { #[test] fn test_domain_list() { - let arguments = Arguments::try_parse_from([ - "ord", - "--btc-domain-list=aaa,bbb", - "index", - "update" - ]).unwrap(); + let arguments = + Arguments::try_parse_from(["ord", "--btc-domain-list=aaa,bbb", "index", "update"]).unwrap(); assert_eq!( arguments.options.btc_domain_list, vec!["aaa".to_string(), "bbb".to_string()] From 53e42c8df1d77b91d77d10d7a82c3ad5c2c899b9 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Wed, 4 Sep 2024 10:32:17 +0800 Subject: [PATCH 12/30] fix unit test error --- src/okx/datastore/ord/redb/table.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/okx/datastore/ord/redb/table.rs b/src/okx/datastore/ord/redb/table.rs index ba5e0df347..8bfe99919d 100644 --- a/src/okx/datastore/ord/redb/table.rs +++ b/src/okx/datastore/ord/redb/table.rs @@ -158,7 +158,7 @@ mod tests { let mut table = wtx.open_table(ORD_TX_TO_OPERATIONS).unwrap(); let txid = Txid::from_str("b61b0172d95e266c18aea0c624db987e971a5d6d4ebc2aaed85da4642d635735").unwrap(); - let operation = InscriptionOp { + let mut operation = InscriptionOp { txid, action: Action::New { cursed: false, @@ -182,6 +182,10 @@ mod tests { save_transaction_operations(&mut table, &txid, &[operation.clone()]).unwrap(); + // skip the inscription + if let Action::New { inscription, .. } = &mut operation.action { + *inscription = crate::Inscription::default(); + } assert_eq!( get_transaction_operations(&table, &txid).unwrap(), Some(vec![operation]) From 27608239e43589cb9c35f17dd58c885634708e03 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Fri, 6 Sep 2024 11:29:31 +0800 Subject: [PATCH 13/30] check domain name --- src/okx/datastore/ord/btc_domain.rs | 49 ++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/src/okx/datastore/ord/btc_domain.rs b/src/okx/datastore/ord/btc_domain.rs index 972b580e90..1c751d5b13 100644 --- a/src/okx/datastore/ord/btc_domain.rs +++ b/src/okx/datastore/ord/btc_domain.rs @@ -18,16 +18,28 @@ impl BtcDomain { let pattern = format!(r"^(?.+)\.(?{domains})$"); let content = std::str::from_utf8(bytes)?; let re = Regex::new(&pattern).unwrap(); - if let Some(capture) = re.captures(content) { + if let Some(capture) = re.captures(&content.to_lowercase()) { let name = &capture["name"]; let domain = &capture["domain"]; - Ok(Self { - name: name.to_string(), - domain: domain.to_string(), - }) - } else { - Err(anyhow!("No match found.")) + if Self::is_name_valid(name) { + return Ok(Self { + name: name.to_string(), + domain: domain.to_string(), + }) + } + } + Err(anyhow!("No match found.")) + } + + fn is_name_valid(name: &str) -> bool { + let pattern = r"[\.[:space:]]"; + let re = Regex::new(pattern).unwrap(); + if re.captures(name) { + return false } + // check if it's json format + let value: Result = serde_json::from_str(name); + return value.is_err() } pub fn to_collection_key(&self) -> String { @@ -56,16 +68,29 @@ mod tests { #[test] fn validate_regex() { let domain_list = vec![]; - let district = BtcDomain::parse("0.bitmap".as_bytes(), &domain_list); - assert!(district.is_err()); + let invalid_domains = [ + "abc.bitmap", + "btc.com.btc", + "hi.jack.btc", + " jack.btc", + "jack.btc ", + "hi jack.btc", + " jack.btc ", + "jack.btc\n", + "\njack.btc", + "hi\njack.btc", + "\njack.btc\n", + r#"{ "p":"sns", "op":"reg", "name":"jack.btc"}"#, + ]; + for domain in invalid_domains { + let district = BtcDomain::parse(domain.as_bytes(), &domain_list); + assert!(district.is_err()); + } let district = BtcDomain::parse("01.btc".as_bytes(), &domain_list).unwrap(); assert_eq!(district.domain, "btc"); assert_eq!(district.name, "01"); assert_eq!(district.btc_block_height(), None); - let district = BtcDomain::parse("btc.com/01?.btc.btc".as_bytes(), &domain_list).unwrap(); - assert_eq!(district.domain, "btc"); - assert_eq!(district.name, "btc.com/01?.btc"); let district = BtcDomain::parse("123456.btc".as_bytes(), &domain_list).unwrap(); assert_eq!(district.btc_block_height(), Some(123456)); From 77eb918d676fb55a586abe65774a57a9957080e9 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Fri, 6 Sep 2024 11:31:06 +0800 Subject: [PATCH 14/30] fix comment --- src/okx/protocol/mod.rs | 1 - src/okx/protocol/ord/btc_domain.rs | 7 ------- 2 files changed, 8 deletions(-) diff --git a/src/okx/protocol/mod.rs b/src/okx/protocol/mod.rs index 7b3e11b67d..a7a0c4a829 100644 --- a/src/okx/protocol/mod.rs +++ b/src/okx/protocol/mod.rs @@ -25,7 +25,6 @@ pub struct ProtocolConfig { first_brc20_height: Option, enable_ord_receipts: bool, enable_index_bitmap: bool, - // 支持btc域名解析 enable_index_domain: bool, btc_domain_list: Vec, } diff --git a/src/okx/protocol/ord/btc_domain.rs b/src/okx/protocol/ord/btc_domain.rs index bca6294011..408a245f09 100644 --- a/src/okx/protocol/ord/btc_domain.rs +++ b/src/okx/protocol/ord/btc_domain.rs @@ -60,13 +60,6 @@ fn index_domain( ) -> Result> { if let Some(content) = inscription.body() { if let Ok(district) = BtcDomain::parse(content, domain_list) { - // TODO: if current block height is 800000,and mint 900000.btc,need display image at block height 900000 - // TODO: if current block height is 800000,and mint 700000.btc,need to display image directly, the image content = 700000.bimap - // if let Some(h) = district.btc_block_height() { - // if h > context.chain_conf.blockheight { - // return Ok(None); - // } - // } let collection_key = district.to_collection_key(); if context From 062528dc1b0cc92e1aaee11f586e03f9a0b8786b Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Fri, 6 Sep 2024 11:39:18 +0800 Subject: [PATCH 15/30] fix compile error --- src/okx/datastore/ord/btc_domain.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/okx/datastore/ord/btc_domain.rs b/src/okx/datastore/ord/btc_domain.rs index 1c751d5b13..78633d41a9 100644 --- a/src/okx/datastore/ord/btc_domain.rs +++ b/src/okx/datastore/ord/btc_domain.rs @@ -34,7 +34,7 @@ impl BtcDomain { fn is_name_valid(name: &str) -> bool { let pattern = r"[\.[:space:]]"; let re = Regex::new(pattern).unwrap(); - if re.captures(name) { + if re.captures(name).is_some() { return false } // check if it's json format @@ -87,10 +87,18 @@ mod tests { assert!(district.is_err()); } - let district = BtcDomain::parse("01.btc".as_bytes(), &domain_list).unwrap(); - assert_eq!(district.domain, "btc"); - assert_eq!(district.name, "01"); - assert_eq!(district.btc_block_height(), None); + let valid_domains = [ + "01.btc", + "123456.btc", + "Jack.btc", + "JACK.BTC", + "jack.BtC", + "比特币.btc", + "😀.btc", + ]; + let district = BtcDomain::parse("01.btc".as_bytes(), &domain_list); + assert!(district.is_ok()); + let district = BtcDomain::parse("123456.btc".as_bytes(), &domain_list).unwrap(); assert_eq!(district.btc_block_height(), Some(123456)); @@ -117,8 +125,5 @@ mod tests { let district = BtcDomain::parse("abc.aaa".as_bytes(), &domain_list).unwrap(); assert_eq!(district.name, "abc"); assert_eq!(district.domain, "aaa"); - - let district = BtcDomain::parse("abc.btc".as_bytes(), &domain_list); - assert!(district.is_err()); } } From 9324eacc42232bd0e9d09f52ff932d150ae890e9 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Fri, 6 Sep 2024 11:53:37 +0800 Subject: [PATCH 16/30] fix valid name error --- src/okx/datastore/ord/btc_domain.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/okx/datastore/ord/btc_domain.rs b/src/okx/datastore/ord/btc_domain.rs index 78633d41a9..8ee2433822 100644 --- a/src/okx/datastore/ord/btc_domain.rs +++ b/src/okx/datastore/ord/btc_domain.rs @@ -38,8 +38,11 @@ impl BtcDomain { return false } // check if it's json format - let value: Result = serde_json::from_str(name); - return value.is_err() + if name.contains("{") { + let value: Result = serde_json::from_str(name); + return value.is_err() + } + true } pub fn to_collection_key(&self) -> String { From bfe976b408f38bd5185eeeb90fce6e91fb9cd7bf Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Tue, 10 Sep 2024 12:10:30 +0800 Subject: [PATCH 17/30] cargo fmt --- src/okx/datastore/ord/btc_domain.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/okx/datastore/ord/btc_domain.rs b/src/okx/datastore/ord/btc_domain.rs index 8ee2433822..5e9ea4ff97 100644 --- a/src/okx/datastore/ord/btc_domain.rs +++ b/src/okx/datastore/ord/btc_domain.rs @@ -25,7 +25,7 @@ impl BtcDomain { return Ok(Self { name: name.to_string(), domain: domain.to_string(), - }) + }); } } Err(anyhow!("No match found.")) @@ -35,12 +35,12 @@ impl BtcDomain { let pattern = r"[\.[:space:]]"; let re = Regex::new(pattern).unwrap(); if re.captures(name).is_some() { - return false + return false; } // check if it's json format if name.contains("{") { - let value: Result = serde_json::from_str(name); - return value.is_err() + let value: Result = serde_json::from_str(name); + return value.is_err(); } true } @@ -102,7 +102,6 @@ mod tests { let district = BtcDomain::parse("01.btc".as_bytes(), &domain_list); assert!(district.is_ok()); - let district = BtcDomain::parse("123456.btc".as_bytes(), &domain_list).unwrap(); assert_eq!(district.btc_block_height(), Some(123456)); let district = BtcDomain::parse("100000.btc".as_bytes(), &domain_list).unwrap(); From b727373eb0c8681d47a1e541e647dc4e187166b8 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Tue, 10 Sep 2024 12:14:43 +0800 Subject: [PATCH 18/30] fix unit test --- src/okx/datastore/ord/btc_domain.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/okx/datastore/ord/btc_domain.rs b/src/okx/datastore/ord/btc_domain.rs index 5e9ea4ff97..7f308f78e5 100644 --- a/src/okx/datastore/ord/btc_domain.rs +++ b/src/okx/datastore/ord/btc_domain.rs @@ -7,7 +7,7 @@ pub struct BtcDomain { pub domain: String, } -const DEFAULT_DOMAIN_LIST: [&'static str; 4] = ["btc", "unisat", "sats", "x"]; +const DEFAULT_DOMAIN_LIST: [&str; 4] = ["btc", "unisat", "sats", "x"]; impl BtcDomain { pub fn parse(bytes: &[u8], domain_list: &[String]) -> Result { let domains = if domain_list.is_empty() { @@ -99,8 +99,10 @@ mod tests { "比特币.btc", "😀.btc", ]; - let district = BtcDomain::parse("01.btc".as_bytes(), &domain_list); - assert!(district.is_ok()); + for domain in valid_domains { + let district = BtcDomain::parse(domain.as_bytes(), &domain_list); + assert!(district.is_ok()); + } let district = BtcDomain::parse("123456.btc".as_bytes(), &domain_list).unwrap(); assert_eq!(district.btc_block_height(), Some(123456)); From 8ea7c013e4a0c8071a4740cfa543ec76dce2342b Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Tue, 10 Sep 2024 18:19:10 +0800 Subject: [PATCH 19/30] fix unit test --- src/okx/datastore/ord/btc_domain.rs | 31 ++++++++++++++++------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/okx/datastore/ord/btc_domain.rs b/src/okx/datastore/ord/btc_domain.rs index 7f308f78e5..ba789d6d12 100644 --- a/src/okx/datastore/ord/btc_domain.rs +++ b/src/okx/datastore/ord/btc_domain.rs @@ -31,8 +31,10 @@ impl BtcDomain { Err(anyhow!("No match found.")) } + /// check the name is valid or not + /// https://docs.btcname.id/docs/overview/chapter-4-thinking-about-.btc-domain-name/calibration-rules fn is_name_valid(name: &str) -> bool { - let pattern = r"[\.[:space:]]"; + let pattern = r"[\.[:space:]\\]"; let re = Regex::new(pattern).unwrap(); if re.captures(name).is_some() { return false; @@ -49,24 +51,23 @@ impl BtcDomain { format!("{}_{}_{}", BTC_DOMAIN_KEY, self.name, self.domain) } - /// need image display if the domain name of "*.btc" is 6-digit - pub fn btc_block_height(&self) -> Option { - if self.name.len() == 6 && self.domain == "btc" { - if let Ok(block_height) = self.name.parse::() { - Some(block_height) - } else { - None - } - } else { - None - } - } + // need image display if the domain name of "*.btc" is 6-digit + // pub fn btc_block_height(&self) -> Option { + // if self.name.len() == 6 && self.domain == "btc" { + // if let Ok(block_height) = self.name.parse::() { + // Some(block_height) + // } else { + // None + // } + // } else { + // None + // } + // } } #[cfg(test)] mod tests { use super::*; - use bech32::ToBase32; #[test] fn validate_regex() { @@ -83,6 +84,8 @@ mod tests { "\njack.btc", "hi\njack.btc", "\njack.btc\n", + "\\jack.btc", + "\tjack.btc", r#"{ "p":"sns", "op":"reg", "name":"jack.btc"}"#, ]; for domain in invalid_domains { From 2675e377a050da4042d8e85435b623254f29158d Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Tue, 10 Sep 2024 18:34:15 +0800 Subject: [PATCH 20/30] fix check domain name method --- src/okx/datastore/ord/btc_domain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/okx/datastore/ord/btc_domain.rs b/src/okx/datastore/ord/btc_domain.rs index ba789d6d12..a30f594b80 100644 --- a/src/okx/datastore/ord/btc_domain.rs +++ b/src/okx/datastore/ord/btc_domain.rs @@ -34,7 +34,7 @@ impl BtcDomain { /// check the name is valid or not /// https://docs.btcname.id/docs/overview/chapter-4-thinking-about-.btc-domain-name/calibration-rules fn is_name_valid(name: &str) -> bool { - let pattern = r"[\.[:space:]\\]"; + let pattern = r"[\.\n ]"; let re = Regex::new(pattern).unwrap(); if re.captures(name).is_some() { return false; From 73016cfb6a82230baf1ed819850a870e6258aca8 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Tue, 10 Sep 2024 18:35:34 +0800 Subject: [PATCH 21/30] update unit test --- src/okx/datastore/ord/btc_domain.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/okx/datastore/ord/btc_domain.rs b/src/okx/datastore/ord/btc_domain.rs index a30f594b80..00b5dad3e9 100644 --- a/src/okx/datastore/ord/btc_domain.rs +++ b/src/okx/datastore/ord/btc_domain.rs @@ -84,8 +84,6 @@ mod tests { "\njack.btc", "hi\njack.btc", "\njack.btc\n", - "\\jack.btc", - "\tjack.btc", r#"{ "p":"sns", "op":"reg", "name":"jack.btc"}"#, ]; for domain in invalid_domains { @@ -101,6 +99,8 @@ mod tests { "jack.BtC", "比特币.btc", "😀.btc", + "\\jack.btc", + "\tjack.btc", ]; for domain in valid_domains { let district = BtcDomain::parse(domain.as_bytes(), &domain_list); @@ -108,14 +108,14 @@ mod tests { } let district = BtcDomain::parse("123456.btc".as_bytes(), &domain_list).unwrap(); - assert_eq!(district.btc_block_height(), Some(123456)); + // assert_eq!(district.btc_block_height(), Some(123456)); let district = BtcDomain::parse("100000.btc".as_bytes(), &domain_list).unwrap(); - assert_eq!(district.btc_block_height(), Some(100000)); + // assert_eq!(district.btc_block_height(), Some(100000)); let district = BtcDomain::parse("000001.btc".as_bytes(), &domain_list).unwrap(); - assert_eq!(district.btc_block_height(), Some(1)); + // assert_eq!(district.btc_block_height(), Some(1)); let district = BtcDomain::parse("1234567.btc".as_bytes(), &domain_list).unwrap(); - assert_eq!(district.btc_block_height(), None); + // assert_eq!(district.btc_block_height(), None); let district = BtcDomain::parse("abc.btc".as_bytes(), &domain_list).unwrap(); assert_eq!(district.domain, "btc"); From 857c335811bfe745e8d9e059882b5ce210887eec Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Thu, 12 Sep 2024 12:45:58 +0800 Subject: [PATCH 22/30] cargo clippy --- src/index/rtx.rs | 2 +- src/index/updater/inscription_updater.rs | 2 +- src/index/updater/rune_updater.rs | 4 +- src/inscriptions/envelope.rs | 2 +- src/okx/datastore/brc20/mod.rs | 32 +++---- src/okx/datastore/ord/mod.rs | 18 ++-- src/okx/lru.rs | 8 +- src/okx/protocol/context.rs | 104 +++++++++++------------ src/subcommand/server.rs | 32 +++---- src/subcommand/server/api.rs | 14 +-- src/subcommand/wallet/inscribe/batch.rs | 4 +- src/templates.rs | 4 - src/templates/inscription.rs | 6 +- 13 files changed, 114 insertions(+), 118 deletions(-) diff --git a/src/index/rtx.rs b/src/index/rtx.rs index 829314c6c1..9874c99708 100644 --- a/src/index/rtx.rs +++ b/src/index/rtx.rs @@ -188,7 +188,7 @@ impl Rtx<'_> { log::error!("can't decode base64 domain: {base64_domain}, error: {e:?}"); e })?; - let domain = BtcDomain::parse(&domain_raw, &domain_list)?; + let domain = BtcDomain::parse(&domain_raw, domain_list)?; let table = self.0.open_table(COLLECTIONS_KEY_TO_INSCRIPTION_ID)?; get_collection_inscription_id(&table, &domain.to_collection_key()) } diff --git a/src/index/updater/inscription_updater.rs b/src/index/updater/inscription_updater.rs index 6342dd522d..43082a491d 100644 --- a/src/index/updater/inscription_updater.rs +++ b/src/index/updater/inscription_updater.rs @@ -275,7 +275,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> { hidden: inscription.payload.hidden(), parent: inscription.payload.parent(), pointer: inscription.payload.pointer(), - reinscription: inscribed_offsets.get(&offset).is_some(), + reinscription: inscribed_offsets.contains_key(&offset), unbound, inscription: inscription.payload.clone(), vindicated: curse.is_some() && jubilant, diff --git a/src/index/updater/rune_updater.rs b/src/index/updater/rune_updater.rs index c3ec79e410..0c1d02cd5b 100644 --- a/src/index/updater/rune_updater.rs +++ b/src/index/updater/rune_updater.rs @@ -131,7 +131,7 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> { limit } } else { - u128::max_value() + u128::MAX }, deadline: etching.deadline, divisibility: etching.divisibility, @@ -314,7 +314,7 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> { limit } } else { - u128::max_value() + u128::MAX } - balance, end: end.and_then(|end| (!burn).then_some(end)), symbol, diff --git a/src/inscriptions/envelope.rs b/src/inscriptions/envelope.rs index 76836f7733..d146284873 100644 --- a/src/inscriptions/envelope.rs +++ b/src/inscriptions/envelope.rs @@ -736,7 +736,7 @@ mod tests { fn chunked_data_is_parsable() { let mut witness = Witness::new(); - witness.push(&inscription("foo", [1; 1040]).append_reveal_script(script::Builder::new())); + witness.push(inscription("foo", [1; 1040]).append_reveal_script(script::Builder::new())); witness.push([]); diff --git a/src/okx/datastore/brc20/mod.rs b/src/okx/datastore/brc20/mod.rs index 04f9a17097..dccfb589db 100644 --- a/src/okx/datastore/brc20/mod.rs +++ b/src/okx/datastore/brc20/mod.rs @@ -18,7 +18,7 @@ use std::fmt::{Debug, Display}; pub trait Brc20Reader { type Error: Debug + Display; - fn get_balances(&self, script_key: &ScriptKey) -> Result, Self::Error>; + // fn get_balances(&self, script_key: &ScriptKey) -> Result, Self::Error>; fn get_balance( &self, script_key: &ScriptKey, @@ -26,27 +26,27 @@ pub trait Brc20Reader { ) -> Result, Self::Error>; fn get_token_info(&self, tick: &Tick) -> Result, Self::Error>; - fn get_tokens_info(&self) -> Result, Self::Error>; + // fn get_tokens_info(&self) -> Result, Self::Error>; - fn get_transaction_receipts(&self, txid: &Txid) -> Result>, Self::Error>; + // fn get_transaction_receipts(&self, txid: &Txid) -> Result>, Self::Error>; fn get_transferable_assets_by_satpoint( &self, satpoint: &SatPoint, ) -> Result, Self::Error>; - fn get_transferable_assets_by_account( - &self, - script: &ScriptKey, - ) -> Result, Self::Error>; - fn get_transferable_assets_by_account_ticker( - &self, - script: &ScriptKey, - tick: &Tick, - ) -> Result, Self::Error>; - fn get_transferable_assets_by_outpoint( - &self, - outpoint: OutPoint, - ) -> Result, Self::Error>; + // fn get_transferable_assets_by_account( + // &self, + // script: &ScriptKey, + // ) -> Result, Self::Error>; + // fn get_transferable_assets_by_account_ticker( + // &self, + // script: &ScriptKey, + // tick: &Tick, + // ) -> Result, Self::Error>; + // fn get_transferable_assets_by_outpoint( + // &self, + // outpoint: OutPoint, + // ) -> Result, Self::Error>; } pub trait Brc20ReaderWriter: Brc20Reader { diff --git a/src/okx/datastore/ord/mod.rs b/src/okx/datastore/ord/mod.rs index 798c404b90..4a9e739db2 100644 --- a/src/okx/datastore/ord/mod.rs +++ b/src/okx/datastore/ord/mod.rs @@ -26,15 +26,15 @@ pub trait OrdReader { chain: Chain, ) -> Result; - fn get_transaction_operations( - &self, - txid: &Txid, - ) -> Result>, Self::Error>; - - fn get_collections_of_inscription( - &self, - inscription_id: &InscriptionId, - ) -> Result>, Self::Error>; + // fn get_transaction_operations( + // &self, + // txid: &Txid, + // ) -> Result>, Self::Error>; + + // fn get_collections_of_inscription( + // &self, + // inscription_id: &InscriptionId, + // ) -> Result>, Self::Error>; fn get_collection_inscription_id( &self, diff --git a/src/okx/lru.rs b/src/okx/lru.rs index f2ebac3c89..51d1cee3d8 100644 --- a/src/okx/lru.rs +++ b/src/okx/lru.rs @@ -21,10 +21,10 @@ where } } - pub fn get(&self, key: &Q) -> Option<&V> + pub fn get(&self, key: &Q) -> Option<&V> where K: Borrow, - Q: Hash + Eq, + Q: Hash + Eq + ?Sized, { if let Some(v) = self.new_cache.get(key) { Some(v) @@ -33,10 +33,10 @@ where } } - pub fn contains(&self, key: &Q) -> bool + pub fn contains(&self, key: &Q) -> bool where K: Borrow, - Q: Hash + Eq, + Q: Hash + Eq + ?Sized, { if self.new_cache.contains_key(key) { true diff --git a/src/okx/protocol/context.rs b/src/okx/protocol/context.rs index bdf0d7406b..c0307286d7 100644 --- a/src/okx/protocol/context.rs +++ b/src/okx/protocol/context.rs @@ -102,19 +102,19 @@ impl<'a, 'db, 'txn> OrdReader for Context<'a, 'db, 'txn> { } } - fn get_transaction_operations( - &self, - txid: &Txid, - ) -> crate::Result>, Self::Error> { - get_transaction_operations(self.ORD_TX_TO_OPERATIONS, txid) - } + // fn get_transaction_operations( + // &self, + // txid: &Txid, + // ) -> crate::Result>, Self::Error> { + // get_transaction_operations(self.ORD_TX_TO_OPERATIONS, txid) + // } - fn get_collections_of_inscription( - &self, - inscription_id: &InscriptionId, - ) -> crate::Result>, Self::Error> { - get_collections_of_inscription(self.COLLECTIONS_INSCRIPTION_ID_TO_KINDS, inscription_id) - } + // fn get_collections_of_inscription( + // &self, + // inscription_id: &InscriptionId, + // ) -> crate::Result>, Self::Error> { + // get_collections_of_inscription(self.COLLECTIONS_INSCRIPTION_ID_TO_KINDS, inscription_id) + // } fn get_collection_inscription_id( &self, @@ -157,9 +157,9 @@ impl<'a, 'db, 'txn> OrdReaderWriter for Context<'a, 'db, 'txn> { impl<'a, 'db, 'txn> Brc20Reader for Context<'a, 'db, 'txn> { type Error = anyhow::Error; - fn get_balances(&self, script_key: &ScriptKey) -> crate::Result, Self::Error> { - get_balances(self.BRC20_BALANCES, script_key) - } + // fn get_balances(&self, script_key: &ScriptKey) -> crate::Result, Self::Error> { + // get_balances(self.BRC20_BALANCES, script_key) + // } fn get_balance( &self, @@ -173,40 +173,40 @@ impl<'a, 'db, 'txn> Brc20Reader for Context<'a, 'db, 'txn> { get_token_info(self.BRC20_TOKEN, tick) } - fn get_tokens_info(&self) -> crate::Result, Self::Error> { - get_tokens_info(self.BRC20_TOKEN) - } + // fn get_tokens_info(&self) -> crate::Result, Self::Error> { + // get_tokens_info(self.BRC20_TOKEN) + // } - fn get_transaction_receipts( - &self, - txid: &Txid, - ) -> crate::Result>, Self::Error> { - get_transaction_receipts(self.BRC20_EVENTS, txid) - } + // fn get_transaction_receipts( + // &self, + // txid: &Txid, + // ) -> crate::Result>, Self::Error> { + // get_transaction_receipts(self.BRC20_EVENTS, txid) + // } - fn get_transferable_assets_by_account( - &self, - script: &ScriptKey, - ) -> crate::Result, Self::Error> { - get_transferable_assets_by_account( - self.BRC20_ADDRESS_TICKER_TO_TRANSFERABLE_ASSETS, - self.BRC20_SATPOINT_TO_TRANSFERABLE_ASSETS, - script, - ) - } + // fn get_transferable_assets_by_account( + // &self, + // script: &ScriptKey, + // ) -> crate::Result, Self::Error> { + // get_transferable_assets_by_account( + // self.BRC20_ADDRESS_TICKER_TO_TRANSFERABLE_ASSETS, + // self.BRC20_SATPOINT_TO_TRANSFERABLE_ASSETS, + // script, + // ) + // } - fn get_transferable_assets_by_account_ticker( - &self, - script: &ScriptKey, - tick: &Tick, - ) -> crate::Result, Self::Error> { - get_transferable_assets_by_account_ticker( - self.BRC20_ADDRESS_TICKER_TO_TRANSFERABLE_ASSETS, - self.BRC20_SATPOINT_TO_TRANSFERABLE_ASSETS, - script, - tick, - ) - } + // fn get_transferable_assets_by_account_ticker( + // &self, + // script: &ScriptKey, + // tick: &Tick, + // ) -> crate::Result, Self::Error> { + // get_transferable_assets_by_account_ticker( + // self.BRC20_ADDRESS_TICKER_TO_TRANSFERABLE_ASSETS, + // self.BRC20_SATPOINT_TO_TRANSFERABLE_ASSETS, + // script, + // tick, + // ) + // } fn get_transferable_assets_by_satpoint( &self, @@ -215,12 +215,12 @@ impl<'a, 'db, 'txn> Brc20Reader for Context<'a, 'db, 'txn> { get_transferable_assets_by_satpoint(self.BRC20_SATPOINT_TO_TRANSFERABLE_ASSETS, satpoint) } - fn get_transferable_assets_by_outpoint( - &self, - outpoint: OutPoint, - ) -> crate::Result, Self::Error> { - get_transferable_assets_by_outpoint(self.BRC20_SATPOINT_TO_TRANSFERABLE_ASSETS, outpoint) - } + // fn get_transferable_assets_by_outpoint( + // &self, + // outpoint: OutPoint, + // ) -> crate::Result, Self::Error> { + // get_transferable_assets_by_outpoint(self.BRC20_SATPOINT_TO_TRANSFERABLE_ASSETS, outpoint) + // } } impl<'a, 'db, 'txn> Brc20ReaderWriter for Context<'a, 'db, 'txn> { diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 39eaff837d..7d0900d143 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -120,22 +120,22 @@ struct Search { #[folder = "static"] struct StaticAssets; -struct StaticHtml { - title: &'static str, - html: &'static str, -} - -impl PageContent for StaticHtml { - fn title(&self) -> String { - self.title.into() - } -} - -impl Display for StaticHtml { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - f.write_str(self.html) - } -} +// struct StaticHtml { +// title: &'static str, +// html: &'static str, +// } +// +// impl PageContent for StaticHtml { +// fn title(&self) -> String { +// self.title.into() +// } +// } +// +// impl Display for StaticHtml { +// fn fmt(&self, f: &mut Formatter) -> fmt::Result { +// f.write_str(self.html) +// } +// } #[derive(Debug, Parser)] pub(crate) struct Server { diff --git a/src/subcommand/server/api.rs b/src/subcommand/server/api.rs index a5079a6026..607b40f007 100644 --- a/src/subcommand/server/api.rs +++ b/src/subcommand/server/api.rs @@ -1,12 +1,12 @@ use {super::*, utoipa::IntoParams}; -#[derive(Deserialize, IntoParams)] -pub struct Pagination { - /// Start index of the result. - pub start: Option, - /// Limit of the result. - pub limit: Option, -} +// #[derive(Deserialize, IntoParams)] +// pub struct Pagination { +// /// Start index of the result. +// pub start: Option, +// /// Limit of the result. +// pub limit: Option, +// } pub(crate) type ApiResult = Result>, ApiError>; diff --git a/src/subcommand/wallet/inscribe/batch.rs b/src/subcommand/wallet/inscribe/batch.rs index 1024097825..1ae029e54d 100644 --- a/src/subcommand/wallet/inscribe/batch.rs +++ b/src/subcommand/wallet/inscribe/batch.rs @@ -409,7 +409,7 @@ impl Batch { ); witness.push(reveal_script); - witness.push(&control_block.serialize()); + witness.push(control_block.serialize()); let recovery_key_pair = key_pair.tap_tweak(&secp256k1, taproot_spend_info.merkle_root()); @@ -507,7 +507,7 @@ impl Batch { .to_vec(), ); txin.witness.push(script); - txin.witness.push(&control_block.serialize()); + txin.witness.push(control_block.serialize()); } else { txin.witness = Witness::from_slice(&[&[0; SCHNORR_SIGNATURE_SIZE]]); } diff --git a/src/templates.rs b/src/templates.rs index fc9385d7b7..9e6c50db07 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -90,10 +90,6 @@ pub(crate) trait PageContent: Display + 'static { { PageHtml::new(self, server_config) } - - fn preview_image_url(&self) -> Option> { - None - } } #[cfg(test)] diff --git a/src/templates/inscription.rs b/src/templates/inscription.rs index 2470424a35..c0e2046eb3 100644 --- a/src/templates/inscription.rs +++ b/src/templates/inscription.rs @@ -46,9 +46,9 @@ impl PageContent for InscriptionHtml { format!("Inscription {}", self.inscription_number) } - fn preview_image_url(&self) -> Option> { - Some(Trusted(format!("/content/{}", self.inscription_id))) - } + // fn preview_image_url(&self) -> Option> { + // Some(Trusted(format!("/content/{}", self.inscription_id))) + // } } #[cfg(test)] From 16f810ab6073c51ac4fe69f7e80780cc4016d111 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Thu, 12 Sep 2024 12:50:35 +0800 Subject: [PATCH 23/30] update clippy --- src/okx/datastore/brc20/mod.rs | 2 +- src/okx/protocol/context.rs | 14 +++++--------- src/runes/rune.rs | 2 +- src/subcommand/server/api.rs | 2 +- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/okx/datastore/brc20/mod.rs b/src/okx/datastore/brc20/mod.rs index dccfb589db..749c1c394e 100644 --- a/src/okx/datastore/brc20/mod.rs +++ b/src/okx/datastore/brc20/mod.rs @@ -12,7 +12,7 @@ pub use self::{ }; use super::ScriptKey; use crate::{Result, SatPoint}; -use bitcoin::{OutPoint, Txid}; +use bitcoin::Txid; use std::fmt::{Debug, Display}; pub trait Brc20Reader { diff --git a/src/okx/protocol/context.rs b/src/okx/protocol/context.rs index c0307286d7..72d4f81b17 100644 --- a/src/okx/protocol/context.rs +++ b/src/okx/protocol/context.rs @@ -7,12 +7,9 @@ use crate::{ datastore::{ brc20::{ redb::table::{ - get_balance, get_balances, get_token_info, get_tokens_info, get_transaction_receipts, - get_transferable_assets_by_account, get_transferable_assets_by_account_ticker, - get_transferable_assets_by_outpoint, get_transferable_assets_by_satpoint, - insert_token_info, insert_transferable_asset, remove_transferable_asset, - save_transaction_receipts, update_burned_token_info, update_mint_token_info, - update_token_balance, + get_balance, get_token_info, get_transferable_assets_by_satpoint, insert_token_info, + insert_transferable_asset, remove_transferable_asset, save_transaction_receipts, + update_burned_token_info, update_mint_token_info, update_token_balance, }, Balance, Brc20Reader, Brc20ReaderWriter, Receipt, Tick, TokenInfo, TransferableLog, }, @@ -20,9 +17,8 @@ use crate::{ collections::CollectionKind, redb::table::{ add_inscription_attributes, get_collection_inscription_id, - get_collections_of_inscription, get_inscription_number_by_sequence_number, - get_transaction_operations, get_txout_by_outpoint, save_transaction_operations, - set_inscription_by_collection_key, + get_inscription_number_by_sequence_number, get_txout_by_outpoint, + save_transaction_operations, set_inscription_by_collection_key, }, InscriptionOp, OrdReader, OrdReaderWriter, }, diff --git a/src/runes/rune.rs b/src/runes/rune.rs index 8321c81680..5be13c15fe 100644 --- a/src/runes/rune.rs +++ b/src/runes/rune.rs @@ -95,7 +95,7 @@ impl<'de> Deserialize<'de> for Rune { impl Display for Rune { fn fmt(&self, f: &mut Formatter) -> fmt::Result { let mut n = self.0; - if n == u128::max_value() { + if n == u128::MAX { return write!(f, "BCGDENLQRQWDSLRUGSNLBTMFIJAV"); } diff --git a/src/subcommand/server/api.rs b/src/subcommand/server/api.rs index 607b40f007..49e8a7de21 100644 --- a/src/subcommand/server/api.rs +++ b/src/subcommand/server/api.rs @@ -1,4 +1,4 @@ -use {super::*, utoipa::IntoParams}; +use super::*; // #[derive(Deserialize, IntoParams)] // pub struct Pagination { From 23193a36eb51e823467b508865f57c62dce0ee1c Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Thu, 12 Sep 2024 13:55:52 +0800 Subject: [PATCH 24/30] update btc domain to btc name --- src/index/rtx.rs | 14 ++--- .../ord/{btc_domain.rs => btc_name.rs} | 53 +++++-------------- src/okx/datastore/ord/collections.rs | 4 +- src/okx/datastore/ord/mod.rs | 2 +- .../ord/{btc_domain.rs => btc_name.rs} | 28 +++++----- src/okx/protocol/ord/mod.rs | 2 +- src/okx/protocol/protocol_manager.rs | 2 +- src/subcommand/server.rs | 2 +- src/subcommand/server/ord/inscription.rs | 8 +-- 9 files changed, 41 insertions(+), 74 deletions(-) rename src/okx/datastore/ord/{btc_domain.rs => btc_name.rs} (57%) rename src/okx/protocol/ord/{btc_domain.rs => btc_name.rs} (73%) diff --git a/src/index/rtx.rs b/src/index/rtx.rs index 9874c99708..38791431ea 100644 --- a/src/index/rtx.rs +++ b/src/index/rtx.rs @@ -1,6 +1,5 @@ use super::*; -use crate::okx::datastore::ord::btc_domain::BtcDomain; -use base64::prelude::BASE64_STANDARD; +use crate::okx::datastore::ord::btc_name::BtcName; use base64::Engine; pub(crate) struct Rtx<'a>(pub(crate) redb::ReadTransaction<'a>); @@ -179,16 +178,11 @@ impl Rtx<'_> { pub(crate) fn domain_district_to_inscription_id( &self, - base64_domain: &str, + btc_name: &str, domain_list: &[String], ) -> Result> { - let domain_raw = BASE64_STANDARD - .decode(base64_domain.as_bytes()) - .map_err(|e| { - log::error!("can't decode base64 domain: {base64_domain}, error: {e:?}"); - e - })?; - let domain = BtcDomain::parse(&domain_raw, domain_list)?; + let btc_name_raw = btc_name.as_bytes().to_vec(); + let domain = BtcName::parse(&btc_name_raw, domain_list)?; let table = self.0.open_table(COLLECTIONS_KEY_TO_INSCRIPTION_ID)?; get_collection_inscription_id(&table, &domain.to_collection_key()) } diff --git a/src/okx/datastore/ord/btc_domain.rs b/src/okx/datastore/ord/btc_name.rs similarity index 57% rename from src/okx/datastore/ord/btc_domain.rs rename to src/okx/datastore/ord/btc_name.rs index 00b5dad3e9..7d1f49d8e8 100644 --- a/src/okx/datastore/ord/btc_domain.rs +++ b/src/okx/datastore/ord/btc_name.rs @@ -1,14 +1,14 @@ use {super::*, anyhow::anyhow, regex::Regex}; -const BTC_DOMAIN_KEY: &str = r"BTC_DOMAIN"; +const BTC_DOMAIN_KEY: &str = r"BTC_NAME"; -pub struct BtcDomain { +pub struct BtcName { pub name: String, pub domain: String, } const DEFAULT_DOMAIN_LIST: [&str; 4] = ["btc", "unisat", "sats", "x"]; -impl BtcDomain { +impl BtcName { pub fn parse(bytes: &[u8], domain_list: &[String]) -> Result { let domains = if domain_list.is_empty() { DEFAULT_DOMAIN_LIST.join("|") @@ -50,19 +50,6 @@ impl BtcDomain { pub fn to_collection_key(&self) -> String { format!("{}_{}_{}", BTC_DOMAIN_KEY, self.name, self.domain) } - - // need image display if the domain name of "*.btc" is 6-digit - // pub fn btc_block_height(&self) -> Option { - // if self.name.len() == 6 && self.domain == "btc" { - // if let Ok(block_height) = self.name.parse::() { - // Some(block_height) - // } else { - // None - // } - // } else { - // None - // } - // } } #[cfg(test)] @@ -87,8 +74,8 @@ mod tests { r#"{ "p":"sns", "op":"reg", "name":"jack.btc"}"#, ]; for domain in invalid_domains { - let district = BtcDomain::parse(domain.as_bytes(), &domain_list); - assert!(district.is_err()); + let btc_name = BtcName::parse(domain.as_bytes(), &domain_list); + assert!(btc_name.is_err()); } let valid_domains = [ @@ -103,34 +90,20 @@ mod tests { "\tjack.btc", ]; for domain in valid_domains { - let district = BtcDomain::parse(domain.as_bytes(), &domain_list); - assert!(district.is_ok()); + let btc_name = BtcName::parse(domain.as_bytes(), &domain_list); + assert!(btc_name.is_ok()); } - let district = BtcDomain::parse("123456.btc".as_bytes(), &domain_list).unwrap(); - // assert_eq!(district.btc_block_height(), Some(123456)); - let district = BtcDomain::parse("100000.btc".as_bytes(), &domain_list).unwrap(); - // assert_eq!(district.btc_block_height(), Some(100000)); - let district = BtcDomain::parse("000001.btc".as_bytes(), &domain_list).unwrap(); - // assert_eq!(district.btc_block_height(), Some(1)); - - let district = BtcDomain::parse("1234567.btc".as_bytes(), &domain_list).unwrap(); - // assert_eq!(district.btc_block_height(), None); - - let district = BtcDomain::parse("abc.btc".as_bytes(), &domain_list).unwrap(); - assert_eq!(district.domain, "btc"); - assert_eq!(district.name, "abc"); - for d in DEFAULT_DOMAIN_LIST { let s = format!("abc.{d}"); - let district = BtcDomain::parse(s.as_bytes(), &domain_list).unwrap(); - assert!(DEFAULT_DOMAIN_LIST.contains(&district.domain.as_str())); - assert_eq!(district.name, "abc"); + let btc_name = BtcName::parse(s.as_bytes(), &domain_list).unwrap(); + assert!(DEFAULT_DOMAIN_LIST.contains(&btc_name.domain.as_str())); + assert_eq!(btc_name.name, "abc"); } // new domain list let domain_list = vec!["aaa".to_string(), "bbb".to_string()]; - let district = BtcDomain::parse("abc.aaa".as_bytes(), &domain_list).unwrap(); - assert_eq!(district.name, "abc"); - assert_eq!(district.domain, "aaa"); + let btc_name = BtcName::parse("abc.aaa".as_bytes(), &domain_list).unwrap(); + assert_eq!(btc_name.name, "abc"); + assert_eq!(btc_name.domain, "aaa"); } } diff --git a/src/okx/datastore/ord/collections.rs b/src/okx/datastore/ord/collections.rs index b1084738e1..b9cc96c527 100644 --- a/src/okx/datastore/ord/collections.rs +++ b/src/okx/datastore/ord/collections.rs @@ -6,7 +6,7 @@ use std::fmt::Display; pub enum CollectionKind { BitMap, BRC20, - Domain, + BtcName, } impl Display for CollectionKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -15,7 +15,7 @@ impl Display for CollectionKind { "{}", match self { CollectionKind::BitMap => String::from("bitmap"), - CollectionKind::Domain => String::from("domain"), + CollectionKind::BtcName => String::from("btc_name"), CollectionKind::BRC20 => String::from("brc20"), } ) diff --git a/src/okx/datastore/ord/mod.rs b/src/okx/datastore/ord/mod.rs index 4a9e739db2..7359a9edbd 100644 --- a/src/okx/datastore/ord/mod.rs +++ b/src/okx/datastore/ord/mod.rs @@ -8,7 +8,7 @@ use { }; pub mod bitmap; -pub mod btc_domain; +pub mod btc_name; pub mod collections; pub mod operation; pub mod redb; diff --git a/src/okx/protocol/ord/btc_domain.rs b/src/okx/protocol/ord/btc_name.rs similarity index 73% rename from src/okx/protocol/ord/btc_domain.rs rename to src/okx/protocol/ord/btc_name.rs index 408a245f09..fcabdd9566 100644 --- a/src/okx/protocol/ord/btc_domain.rs +++ b/src/okx/protocol/ord/btc_name.rs @@ -3,7 +3,7 @@ use crate::okx::protocol::context::Context; use { crate::{ okx::datastore::ord::{ - btc_domain::BtcDomain, + btc_name::BtcName, collections::CollectionKind, operation::{Action, InscriptionOp}, }, @@ -14,7 +14,7 @@ use { std::collections::HashMap, }; -pub fn index_btc_domain( +pub fn index_btc_name( context: &mut Context, operations: &HashMap>, domain_list: &[String], @@ -37,12 +37,12 @@ pub fn index_btc_domain( for op in positive_inscriptions.into_iter() { match op.action { Action::New { inscription, .. } => { - if let Some((inscription_id, district)) = - index_domain(context, inscription, op.inscription_id, domain_list)? + if let Some((inscription_id, btc_name)) = + do_index_btc_name(context, inscription, op.inscription_id, domain_list)? { - let key = district.to_collection_key(); + let key = btc_name.to_collection_key(); context.set_inscription_by_collection_key(&key, &inscription_id)?; - context.add_inscription_attributes(&inscription_id, CollectionKind::Domain)?; + context.add_inscription_attributes(&inscription_id, CollectionKind::BtcName)?; count += 1; } } @@ -52,15 +52,15 @@ pub fn index_btc_domain( Ok(count) } -fn index_domain( +fn do_index_btc_name( context: &mut Context, inscription: Inscription, inscription_id: InscriptionId, domain_list: &[String], -) -> Result> { +) -> Result> { if let Some(content) = inscription.body() { - if let Ok(district) = BtcDomain::parse(content, domain_list) { - let collection_key = district.to_collection_key(); + if let Ok(btc_name) = BtcName::parse(content, domain_list) { + let collection_key = btc_name.to_collection_key(); if context .get_collection_inscription_id(&collection_key) @@ -70,12 +70,12 @@ fn index_domain( .is_none() { log::info!( - "found valid btc domain district! {}.{} inscription_id {}", - district.name, - district.domain, + "found valid btc domain btc_name! {}.{} inscription_id {}", + btc_name.name, + btc_name.domain, inscription_id, ); - return Ok(Some((inscription_id, district))); + return Ok(Some((inscription_id, btc_name))); } } } diff --git a/src/okx/protocol/ord/mod.rs b/src/okx/protocol/ord/mod.rs index 04822a3ef6..5bccfb9974 100644 --- a/src/okx/protocol/ord/mod.rs +++ b/src/okx/protocol/ord/mod.rs @@ -1,2 +1,2 @@ pub mod bitmap; -pub mod btc_domain; +pub mod btc_name; diff --git a/src/okx/protocol/protocol_manager.rs b/src/okx/protocol/protocol_manager.rs index dbf9fde300..39b06456f7 100644 --- a/src/okx/protocol/protocol_manager.rs +++ b/src/okx/protocol/protocol_manager.rs @@ -83,7 +83,7 @@ impl ProtocolManager { bitmap_count = ord_proto::bitmap::index_bitmap(context, &operations)?; } if self.config.enable_index_domain { - btc_domain_count = ord_proto::btc_domain::index_btc_domain( + btc_domain_count = ord_proto::btc_name::index_btc_name( context, &operations, &self.config.btc_domain_list, diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 7d0900d143..9b0a36dfba 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -310,7 +310,7 @@ impl Server { get(ord::ord_debug_bitmap_district), ) .route( - "/ord/debug/domain/:base64_domain", + "/ord/debug/domain/:btc_name", get(ord::ord_debug_domain_district), ) .route("/brc20/tick/:tick", get(brc20::brc20_tick_info)) diff --git a/src/subcommand/server/ord/inscription.rs b/src/subcommand/server/ord/inscription.rs index c2543d1297..7c46ebbd32 100644 --- a/src/subcommand/server/ord/inscription.rs +++ b/src/subcommand/server/ord/inscription.rs @@ -251,21 +251,21 @@ pub(crate) async fn ord_debug_bitmap_district( // ord/debug/domain/:base64_domain pub(crate) async fn ord_debug_domain_district( Extension(index): Extension>, - Path(base64_domain): Path, + Path(btc_name): Path, ) -> ApiResult { log::debug!( "rpc: get ord_debug_domain_district: base64_domain:{}", - base64_domain + btc_name ); let rtx = index.begin_read()?; let inscription_id = rtx - .domain_district_to_inscription_id(&base64_domain, &index.domain_list)? + .domain_district_to_inscription_id(&btc_name, &index.domain_list)? .ok_or_api_not_found(format!("district {base64_domain} not found."))?; log::debug!( "rpc: get ord_debug_bitmap_district: {:?} {:?}", - base64_domain, + btc_name, inscription_id ); From 15a037bc016a8398dac74cd70fc31820ca9160ec Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Thu, 12 Sep 2024 13:58:28 +0800 Subject: [PATCH 25/30] fix compile error --- src/subcommand/server/ord/inscription.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subcommand/server/ord/inscription.rs b/src/subcommand/server/ord/inscription.rs index 7c46ebbd32..97bf8826a3 100644 --- a/src/subcommand/server/ord/inscription.rs +++ b/src/subcommand/server/ord/inscription.rs @@ -261,7 +261,7 @@ pub(crate) async fn ord_debug_domain_district( let rtx = index.begin_read()?; let inscription_id = rtx .domain_district_to_inscription_id(&btc_name, &index.domain_list)? - .ok_or_api_not_found(format!("district {base64_domain} not found."))?; + .ok_or_api_not_found(format!("district {btc_name} not found."))?; log::debug!( "rpc: get ord_debug_bitmap_district: {:?} {:?}", From f3f8fe5009a9077731484cadd3788b10433a40c5 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Thu, 12 Sep 2024 13:59:16 +0800 Subject: [PATCH 26/30] cargo clippy --- src/index/rtx.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index/rtx.rs b/src/index/rtx.rs index 38791431ea..60480c4c54 100644 --- a/src/index/rtx.rs +++ b/src/index/rtx.rs @@ -1,6 +1,5 @@ use super::*; use crate::okx::datastore::ord::btc_name::BtcName; -use base64::Engine; pub(crate) struct Rtx<'a>(pub(crate) redb::ReadTransaction<'a>); From a5d55ae72f21d99a2a0d09532838bfcaa5541618 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Thu, 12 Sep 2024 14:58:08 +0800 Subject: [PATCH 27/30] update --- src/index/rtx.rs | 2 +- src/okx/protocol/protocol_manager.rs | 7 ++----- src/subcommand/server.rs | 4 ++-- src/subcommand/server/ord/inscription.rs | 11 ++++------- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/index/rtx.rs b/src/index/rtx.rs index 60480c4c54..3931914c51 100644 --- a/src/index/rtx.rs +++ b/src/index/rtx.rs @@ -175,7 +175,7 @@ impl Rtx<'_> { get_collection_inscription_id(&table, &district.to_collection_key()) } - pub(crate) fn domain_district_to_inscription_id( + pub(crate) fn btc_name_to_inscription_id( &self, btc_name: &str, domain_list: &[String], diff --git a/src/okx/protocol/protocol_manager.rs b/src/okx/protocol/protocol_manager.rs index 39b06456f7..dc81a8dcf3 100644 --- a/src/okx/protocol/protocol_manager.rs +++ b/src/okx/protocol/protocol_manager.rs @@ -83,11 +83,8 @@ impl ProtocolManager { bitmap_count = ord_proto::bitmap::index_bitmap(context, &operations)?; } if self.config.enable_index_domain { - btc_domain_count = ord_proto::btc_name::index_btc_name( - context, - &operations, - &self.config.btc_domain_list, - )?; + btc_domain_count = + ord_proto::btc_name::index_btc_name(context, &operations, &self.config.btc_domain_list)?; } let cost4 = bitmap_start.elapsed().as_millis(); diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 9b0a36dfba..955981a160 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -310,8 +310,8 @@ impl Server { get(ord::ord_debug_bitmap_district), ) .route( - "/ord/debug/domain/:btc_name", - get(ord::ord_debug_domain_district), + "/ord/debug/btc/name/:btc_name", + get(ord::ord_debug_btc_name), ) .route("/brc20/tick/:tick", get(brc20::brc20_tick_info)) .route("/brc20/tick", get(brc20::brc20_all_tick_info)) diff --git a/src/subcommand/server/ord/inscription.rs b/src/subcommand/server/ord/inscription.rs index 97bf8826a3..1ee02a25bb 100644 --- a/src/subcommand/server/ord/inscription.rs +++ b/src/subcommand/server/ord/inscription.rs @@ -248,19 +248,16 @@ pub(crate) async fn ord_debug_bitmap_district( Ok(Json(ApiResponse::ok(inscription_id))) } -// ord/debug/domain/:base64_domain -pub(crate) async fn ord_debug_domain_district( +// ord/debug/btc_nam/:btc_name +pub(crate) async fn ord_debug_btc_name( Extension(index): Extension>, Path(btc_name): Path, ) -> ApiResult { - log::debug!( - "rpc: get ord_debug_domain_district: base64_domain:{}", - btc_name - ); + log::debug!("rpc: get ord_debug_btc_name:{btc_name}"); let rtx = index.begin_read()?; let inscription_id = rtx - .domain_district_to_inscription_id(&btc_name, &index.domain_list)? + .btc_name_to_inscription_id(&btc_name, &index.domain_list)? .ok_or_api_not_found(format!("district {btc_name} not found."))?; log::debug!( From badd4927de57998feaefca89a079bd5d8a7dbe87 Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Thu, 12 Sep 2024 14:59:23 +0800 Subject: [PATCH 28/30] update rust version to 1.70 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9aa41a36d9..d82c789e2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ autotests = false homepage = "https://github.com/ordinals/ord" repository = "https://github.com/ordinals/ord" autobins = false -rust-version = "1.67" +rust-version = "1.70" build = "build.rs" [package.metadata.deb] From e0086e52d4a32d53a87dce284c5a88800b4ce5cc Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Thu, 12 Sep 2024 15:53:20 +0800 Subject: [PATCH 29/30] fix cargo clippy --- src/epoch.rs | 2 +- src/height.rs | 2 +- src/index.rs | 4 +- src/runes.rs | 472 +++++++++++++++++++-------------------- src/runes/pile.rs | 4 +- src/runes/rune.rs | 8 +- src/runes/runestone.rs | 54 ++--- src/runes/varint.rs | 2 +- src/subcommand/server.rs | 32 +-- src/templates/rune.rs | 4 +- 10 files changed, 292 insertions(+), 292 deletions(-) diff --git a/src/epoch.rs b/src/epoch.rs index d8157897d8..9a96fc97dd 100644 --- a/src/epoch.rs +++ b/src/epoch.rs @@ -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] diff --git a/src/height.rs b/src/height.rs index e96a66f8f4..b3a58529b1 100644 --- a/src/height.rs +++ b/src/height.rs @@ -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() ); } diff --git a/src/index.rs b/src/index.rs index 62c95e333a..d40d11ac6f 100644 --- a/src/index.rs +++ b/src/index.rs @@ -1215,7 +1215,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) } @@ -4538,7 +4538,7 @@ mod tests { i, if i == 1 { 0 } else { 1 }, 0, - inscription("text/plain;charset=utf-8", &format!("hello {}", i)).to_witness(), + inscription("text/plain;charset=utf-8", format!("hello {}", i)).to_witness(), )], // for the first inscription use coinbase, otherwise use the previous tx ..Default::default() }); diff --git a/src/runes.rs b/src/runes.rs index ccc88be8bb..e8d1d8bbb8 100644 --- a/src/runes.rs +++ b/src/runes.rs @@ -44,7 +44,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -134,7 +134,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -161,12 +161,12 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, )], - [(OutPoint { txid, vout: 0 }, vec![(id, u128::max_value())])], + [(OutPoint { txid, vout: 0 }, vec![(id, u128::MAX)])], ); } @@ -188,7 +188,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -218,7 +218,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -245,12 +245,12 @@ mod tests { RuneEntry { etching: txid, rune: Rune(block_two_minimum), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, )], - [(OutPoint { txid, vout: 0 }, vec![(id, u128::max_value())])], + [(OutPoint { txid, vout: 0 }, vec![(id, u128::MAX)])], ); } } @@ -268,7 +268,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -298,7 +298,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -325,12 +325,12 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RESERVED - 1), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, )], - [(OutPoint { txid, vout: 0 }, vec![(id, u128::max_value())])], + [(OutPoint { txid, vout: 0 }, vec![(id, u128::MAX)])], ); } } @@ -348,7 +348,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -375,7 +375,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RESERVED), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -385,7 +385,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id0, u128::max_value())], + vec![(id0, u128::MAX)], )], ); @@ -397,7 +397,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -425,7 +425,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RESERVED), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -435,7 +435,7 @@ mod tests { RuneEntry { etching: txid1, rune: Rune(RESERVED + 1), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 4, number: 1, ..Default::default() @@ -448,14 +448,14 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id0, u128::max_value())], + vec![(id0, u128::MAX)], ), ( OutPoint { txid: txid1, vout: 0, }, - vec![(id1, u128::max_value())], + vec![(id1, u128::MAX)], ), ], ); @@ -473,7 +473,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -502,12 +502,12 @@ mod tests { rune: Rune(RUNE), etching: txid, divisibility: 1, - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, )], - [(OutPoint { txid, vout: 0 }, vec![(id, u128::max_value())])], + [(OutPoint { txid, vout: 0 }, vec![(id, u128::MAX)])], ); } @@ -524,12 +524,12 @@ mod tests { edicts: vec![ Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }, Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }, ], @@ -557,12 +557,12 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, )], - [(OutPoint { txid, vout: 0 }, vec![(id, u128::max_value())])], + [(OutPoint { txid, vout: 0 }, vec![(id, u128::MAX)])], ); } @@ -579,12 +579,12 @@ mod tests { edicts: vec![ Edict { id: 0, - amount: u128::max_value() / 2, + amount: u128::MAX / 2, output: 0, }, Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }, ], @@ -612,13 +612,13 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, symbol: None, timestamp: 2, ..Default::default() }, )], - [(OutPoint { txid, vout: 0 }, vec![(id, u128::max_value())])], + [(OutPoint { txid, vout: 0 }, vec![(id, u128::MAX)])], ); } @@ -793,7 +793,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -820,7 +820,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -830,7 +830,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -840,7 +840,7 @@ mod tests { Runestone { edicts: vec![Edict { id: id.into(), - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], ..Default::default() @@ -858,7 +858,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -868,7 +868,7 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); } @@ -885,7 +885,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -933,7 +933,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -995,7 +995,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching::default()), @@ -1040,7 +1040,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -1067,7 +1067,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1077,7 +1077,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -1099,10 +1099,10 @@ mod tests { [( id, RuneEntry { - burned: u128::max_value(), + burned: u128::MAX, etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1123,7 +1123,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -1150,7 +1150,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1160,7 +1160,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -1178,7 +1178,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1188,7 +1188,7 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); } @@ -1205,7 +1205,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -1232,7 +1232,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1242,7 +1242,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -1261,9 +1261,9 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, - burned: u128::max_value(), + burned: u128::MAX, ..Default::default() }, )], @@ -1283,7 +1283,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -1310,7 +1310,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1320,7 +1320,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -1345,7 +1345,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1355,7 +1355,7 @@ mod tests { txid: txid1, vout: 1, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); } @@ -1372,7 +1372,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -1399,7 +1399,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1409,7 +1409,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -1434,7 +1434,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1444,7 +1444,7 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); } @@ -1461,7 +1461,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -1488,7 +1488,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1498,7 +1498,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -1523,8 +1523,8 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), - burned: u128::max_value(), + supply: u128::MAX, + burned: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1546,7 +1546,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -1573,7 +1573,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1583,7 +1583,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -1601,7 +1601,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1611,7 +1611,7 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); } @@ -1628,7 +1628,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -1655,12 +1655,12 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, )], - [(OutPoint { txid, vout: 0 }, vec![(id, u128::max_value())])], + [(OutPoint { txid, vout: 0 }, vec![(id, u128::MAX)])], ); context.rpc_server.broadcast_tx(TransactionTemplate { @@ -1669,7 +1669,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -1691,12 +1691,12 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, )], - [(OutPoint { txid, vout: 0 }, vec![(id, u128::max_value())])], + [(OutPoint { txid, vout: 0 }, vec![(id, u128::MAX)])], ); } @@ -1712,7 +1712,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -1739,7 +1739,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1749,7 +1749,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id0, u128::max_value())], + vec![(id0, u128::MAX)], )], ); @@ -1759,7 +1759,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -1787,7 +1787,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1797,7 +1797,7 @@ mod tests { RuneEntry { etching: txid1, rune: Rune(RUNE + 1), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 3, number: 1, ..Default::default() @@ -1810,14 +1810,14 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id0, u128::max_value())], + vec![(id0, u128::MAX)], ), ( OutPoint { txid: txid1, vout: 0, }, - vec![(id1, u128::max_value())], + vec![(id1, u128::MAX)], ), ], ); @@ -1836,7 +1836,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1846,7 +1846,7 @@ mod tests { RuneEntry { etching: txid1, rune: Rune(RUNE + 1), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 3, number: 1, ..Default::default() @@ -1858,7 +1858,7 @@ mod tests { txid: txid2, vout: 0, }, - vec![(id0, u128::max_value()), (id1, u128::max_value())], + vec![(id0, u128::MAX), (id1, u128::MAX)], )], ); } @@ -1875,7 +1875,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -1902,7 +1902,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1912,7 +1912,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id0, u128::max_value())], + vec![(id0, u128::MAX)], )], ); @@ -1922,7 +1922,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -1950,7 +1950,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -1960,7 +1960,7 @@ mod tests { RuneEntry { etching: txid1, rune: Rune(RUNE + 1), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 3, number: 1, ..Default::default() @@ -1973,14 +1973,14 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id0, u128::max_value())], + vec![(id0, u128::MAX)], ), ( OutPoint { txid: txid1, vout: 0, }, - vec![(id1, u128::max_value())], + vec![(id1, u128::MAX)], ), ], ); @@ -1999,7 +1999,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2009,7 +2009,7 @@ mod tests { RuneEntry { etching: txid1, rune: Rune(RUNE + 1), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 3, number: 1, ..Default::default() @@ -2021,7 +2021,7 @@ mod tests { txid: txid2, vout: 0, }, - vec![(id0, u128::max_value()), (id1, u128::max_value())], + vec![(id0, u128::MAX), (id1, u128::MAX)], )], ); @@ -2033,12 +2033,12 @@ mod tests { edicts: vec![ Edict { id: id0.into(), - amount: u128::max_value() / 2, + amount: u128::MAX / 2, output: 1, }, Edict { id: id1.into(), - amount: u128::max_value() / 2, + amount: u128::MAX / 2, output: 1, }, ], @@ -2058,7 +2058,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2068,7 +2068,7 @@ mod tests { RuneEntry { etching: txid1, rune: Rune(RUNE + 1), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 3, number: 1, ..Default::default() @@ -2082,8 +2082,8 @@ mod tests { vout: 0, }, vec![ - (id0, u128::max_value() / 2 + 1), - (id1, u128::max_value() / 2 + 1), + (id0, u128::MAX / 2 + 1), + (id1, u128::MAX / 2 + 1), ], ), ( @@ -2091,7 +2091,7 @@ mod tests { txid: txid3, vout: 1, }, - vec![(id0, u128::max_value() / 2), (id1, u128::max_value() / 2)], + vec![(id0, u128::MAX / 2), (id1, u128::MAX / 2)], ), ], ); @@ -2109,7 +2109,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2136,7 +2136,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2146,7 +2146,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id0, u128::max_value())], + vec![(id0, u128::MAX)], )], ); @@ -2156,7 +2156,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2184,7 +2184,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2194,7 +2194,7 @@ mod tests { RuneEntry { etching: txid1, rune: Rune(RUNE + 1), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 3, number: 1, ..Default::default() @@ -2207,14 +2207,14 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id0, u128::max_value())], + vec![(id0, u128::MAX)], ), ( OutPoint { txid: txid1, vout: 0, }, - vec![(id1, u128::max_value())], + vec![(id1, u128::MAX)], ), ], ); @@ -2226,12 +2226,12 @@ mod tests { edicts: vec![ Edict { id: id0.into(), - amount: u128::max_value(), + amount: u128::MAX, output: 0, }, Edict { id: id1.into(), - amount: u128::max_value(), + amount: u128::MAX, output: 0, }, ], @@ -2251,7 +2251,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2261,7 +2261,7 @@ mod tests { RuneEntry { etching: txid1, rune: Rune(RUNE + 1), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 3, number: 1, ..Default::default() @@ -2273,7 +2273,7 @@ mod tests { txid: txid2, vout: 0, }, - vec![(id0, u128::max_value()), (id1, u128::max_value())], + vec![(id0, u128::MAX), (id1, u128::MAX)], )], ); } @@ -2291,7 +2291,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2318,7 +2318,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2328,7 +2328,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -2351,12 +2351,12 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, )], - [(OutPoint { txid, vout: 1 }, vec![(id, u128::max_value())])], + [(OutPoint { txid, vout: 1 }, vec![(id, u128::MAX)])], ); } @@ -2372,7 +2372,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2397,7 +2397,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2425,7 +2425,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 3, ..Default::default() }, @@ -2435,7 +2435,7 @@ mod tests { RuneEntry { etching: txid1, rune: Rune(RUNE + 1), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 3, number: 1, ..Default::default() @@ -2448,14 +2448,14 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id0, u128::max_value())], + vec![(id0, u128::MAX)], ), ( OutPoint { txid: txid1, vout: 0, }, - vec![(id1, u128::max_value())], + vec![(id1, u128::MAX)], ), ], ); @@ -2473,7 +2473,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2500,7 +2500,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2510,7 +2510,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -2526,7 +2526,7 @@ mod tests { }, Edict { id: id.into(), - amount: u128::max_value(), + amount: u128::MAX, output: 0, }, ], @@ -2545,7 +2545,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2555,7 +2555,7 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); } @@ -2572,7 +2572,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2599,7 +2599,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2609,7 +2609,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id0, u128::max_value())], + vec![(id0, u128::MAX)], )], ); @@ -2619,7 +2619,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2647,7 +2647,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2657,7 +2657,7 @@ mod tests { RuneEntry { etching: txid1, rune: Rune(RUNE + 1), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 3, number: 1, ..Default::default() @@ -2670,14 +2670,14 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id0, u128::max_value())], + vec![(id0, u128::MAX)], ), ( OutPoint { txid: txid1, vout: 0, }, - vec![(id1, u128::max_value())], + vec![(id1, u128::MAX)], ), ], ); @@ -2689,12 +2689,12 @@ mod tests { edicts: vec![ Edict { id: id0.into(), - amount: u128::max_value(), + amount: u128::MAX, output: 0, }, Edict { id: id1.into(), - amount: u128::max_value(), + amount: u128::MAX, output: 0, }, ], @@ -2714,7 +2714,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2724,7 +2724,7 @@ mod tests { RuneEntry { etching: txid1, rune: Rune(RUNE + 1), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 3, number: 1, ..Default::default() @@ -2737,14 +2737,14 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id1, u128::max_value())], + vec![(id1, u128::MAX)], ), ( OutPoint { txid: txid2, vout: 0, }, - vec![(id0, u128::max_value())], + vec![(id0, u128::MAX)], ), ], ); @@ -2762,7 +2762,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value() / 2, + amount: u128::MAX / 2, output: 0, }], etching: Some(Etching { @@ -2789,7 +2789,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value() / 2, + supply: u128::MAX / 2, timestamp: 2, ..Default::default() }, @@ -2799,7 +2799,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value() / 2)], + vec![(id, u128::MAX / 2)], )], ); @@ -2809,7 +2809,7 @@ mod tests { Runestone { edicts: vec![Edict { id: id.into(), - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], ..Default::default() @@ -2827,7 +2827,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value() / 2, + supply: u128::MAX / 2, timestamp: 2, ..Default::default() }, @@ -2837,7 +2837,7 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, u128::max_value() / 2)], + vec![(id, u128::MAX / 2)], )], ); } @@ -2854,7 +2854,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 1, }], etching: Some(Etching { @@ -2879,10 +2879,10 @@ mod tests { [( id, RuneEntry { - burned: u128::max_value(), + burned: u128::MAX, etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2904,7 +2904,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2931,12 +2931,12 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, )], - [(OutPoint { txid, vout: 0 }, vec![(id, u128::max_value())])], + [(OutPoint { txid, vout: 0 }, vec![(id, u128::MAX)])], ); } @@ -2954,7 +2954,7 @@ mod tests { edicts: vec![ Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }, Edict { @@ -2987,12 +2987,12 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, )], - [(OutPoint { txid, vout: 0 }, vec![(id, u128::max_value())])], + [(OutPoint { txid, vout: 0 }, vec![(id, u128::MAX)])], ); } @@ -3036,7 +3036,7 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3044,19 +3044,19 @@ mod tests { [ ( OutPoint { txid, vout: 0 }, - vec![(id, u128::max_value() / 4 + 1)], + vec![(id, u128::MAX / 4 + 1)], ), ( OutPoint { txid, vout: 1 }, - vec![(id, u128::max_value() / 4 + 1)], + vec![(id, u128::MAX / 4 + 1)], ), ( OutPoint { txid, vout: 2 }, - vec![(id, u128::max_value() / 4 + 1)], + vec![(id, u128::MAX / 4 + 1)], ), ( OutPoint { txid, vout: 3 }, - vec![(id, u128::max_value() / 4)], + vec![(id, u128::MAX / 4)], ), ], ); @@ -3109,7 +3109,7 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3117,19 +3117,19 @@ mod tests { [ ( OutPoint { txid, vout: 0 }, - vec![(id, 1000 + (u128::max_value() - 1000) / 4 + 1)], + vec![(id, 1000 + (u128::MAX - 1000) / 4 + 1)], ), ( OutPoint { txid, vout: 1 }, - vec![(id, (u128::max_value() - 1000) / 4 + 1)], + vec![(id, (u128::MAX - 1000) / 4 + 1)], ), ( OutPoint { txid, vout: 2 }, - vec![(id, (u128::max_value() - 1000) / 4 + 1)], + vec![(id, (u128::MAX - 1000) / 4 + 1)], ), ( OutPoint { txid, vout: 3 }, - vec![(id, (u128::max_value() - 1000) / 4)], + vec![(id, (u128::MAX - 1000) / 4)], ), ], ); @@ -3182,7 +3182,7 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3190,19 +3190,19 @@ mod tests { [ ( OutPoint { txid, vout: 0 }, - vec![(id, u128::max_value() / 4 + 1)], + vec![(id, u128::MAX / 4 + 1)], ), ( OutPoint { txid, vout: 1 }, - vec![(id, u128::max_value() / 4 + 1)], + vec![(id, u128::MAX / 4 + 1)], ), ( OutPoint { txid, vout: 2 }, - vec![(id, u128::max_value() / 4 + 1)], + vec![(id, u128::MAX / 4 + 1)], ), ( OutPoint { txid, vout: 3 }, - vec![(id, u128::max_value() / 4)], + vec![(id, u128::MAX / 4)], ), ], ); @@ -3276,7 +3276,7 @@ mod tests { edicts: vec![ Edict { id: 0, - amount: u128::max_value() - 3000, + amount: u128::MAX - 3000, output: 0, }, Edict { @@ -3309,7 +3309,7 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3317,7 +3317,7 @@ mod tests { [ ( OutPoint { txid, vout: 0 }, - vec![(id, u128::max_value() - 2000)], + vec![(id, u128::MAX - 2000)], ), (OutPoint { txid, vout: 1 }, vec![(id, 1000)]), (OutPoint { txid, vout: 2 }, vec![(id, 1000)]), @@ -3344,7 +3344,7 @@ mod tests { }, Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }, ], @@ -3372,7 +3372,7 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3380,7 +3380,7 @@ mod tests { [ ( OutPoint { txid, vout: 0 }, - vec![(id, u128::max_value() - 4000 + 1000)], + vec![(id, u128::MAX - 4000 + 1000)], ), (OutPoint { txid, vout: 1 }, vec![(id, 1000)]), (OutPoint { txid, vout: 2 }, vec![(id, 1000)]), @@ -3401,7 +3401,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -3428,7 +3428,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3438,7 +3438,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -3467,7 +3467,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3478,14 +3478,14 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, u128::max_value() / 2 + 1)], + vec![(id, u128::MAX / 2 + 1)], ), ( OutPoint { txid: txid1, vout: 1, }, - vec![(id, u128::max_value() / 2)], + vec![(id, u128::MAX / 2)], ), ], ); @@ -3503,7 +3503,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -3530,7 +3530,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3540,7 +3540,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -3576,7 +3576,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3587,14 +3587,14 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, 1000 + (u128::max_value() - 1000) / 2 + 1)], + vec![(id, 1000 + (u128::MAX - 1000) / 2 + 1)], ), ( OutPoint { txid: txid1, vout: 1, }, - vec![(id, (u128::max_value() - 1000) / 2)], + vec![(id, (u128::MAX - 1000) / 2)], ), ], ); @@ -3612,7 +3612,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -3639,7 +3639,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3649,7 +3649,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -3685,7 +3685,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3696,14 +3696,14 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, u128::max_value() / 2 + 1)], + vec![(id, u128::MAX / 2 + 1)], ), ( OutPoint { txid: txid1, vout: 1, }, - vec![(id, u128::max_value() / 2)], + vec![(id, u128::MAX / 2)], ), ], ); @@ -3721,7 +3721,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -3748,7 +3748,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3758,7 +3758,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -3787,7 +3787,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3798,7 +3798,7 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, u128::max_value() - 1000)], + vec![(id, u128::MAX - 1000)], ), ( OutPoint { @@ -3823,7 +3823,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -3850,7 +3850,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3860,7 +3860,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -3872,7 +3872,7 @@ mod tests { edicts: vec![ Edict { id: id.into(), - amount: u128::max_value() - 2000, + amount: u128::MAX - 2000, output: 0, }, Edict { @@ -3896,7 +3896,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3907,7 +3907,7 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, u128::max_value() - 2000 + 1000)], + vec![(id, u128::MAX - 2000 + 1000)], ), ( OutPoint { @@ -3932,7 +3932,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -3959,7 +3959,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3969,7 +3969,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -3986,7 +3986,7 @@ mod tests { }, Edict { id: id.into(), - amount: u128::max_value(), + amount: u128::MAX, output: 0, }, ], @@ -4005,7 +4005,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -4016,7 +4016,7 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, u128::max_value() - 4000 + 1000)], + vec![(id, u128::MAX - 4000 + 1000)], ), ( OutPoint { @@ -4055,7 +4055,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -4083,13 +4083,13 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, symbol: Some('$'), timestamp: 2, ..Default::default() }, )], - [(OutPoint { txid, vout: 0 }, vec![(id, u128::max_value())])], + [(OutPoint { txid, vout: 0 }, vec![(id, u128::MAX)])], ); } @@ -4132,12 +4132,12 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, )], - [(OutPoint { txid, vout: 0 }, vec![(id, u128::max_value())])], + [(OutPoint { txid, vout: 0 }, vec![(id, u128::MAX)])], ); } @@ -4153,7 +4153,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -4180,7 +4180,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -4190,7 +4190,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -4219,7 +4219,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -4229,7 +4229,7 @@ mod tests { txid: txid1, vout: 1, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); } @@ -4237,7 +4237,7 @@ mod tests { #[test] fn max_limit() { MAX_LIMIT - .checked_mul(u128::from(u16::max_value()) * 144 * 365 * 1_000_000_000) + .checked_mul(u128::from(u16::MAX) * 144 * 365 * 1_000_000_000) .unwrap(); } diff --git a/src/runes/pile.rs b/src/runes/pile.rs index 4ba6822514..13eec8cdda 100644 --- a/src/runes/pile.rs +++ b/src/runes/pile.rs @@ -122,7 +122,7 @@ mod tests { ); assert_eq!( Pile { - amount: u128::max_value(), + amount: u128::MAX, divisibility: 18, symbol: None, } @@ -131,7 +131,7 @@ mod tests { ); assert_eq!( Pile { - amount: u128::max_value(), + amount: u128::MAX, divisibility: MAX_DIVISIBILITY, symbol: None, } diff --git a/src/runes/rune.rs b/src/runes/rune.rs index 5be13c15fe..aeaa2ebb6f 100644 --- a/src/runes/rune.rs +++ b/src/runes/rune.rs @@ -183,9 +183,9 @@ mod tests { case(27, "AB"); case(51, "AZ"); case(52, "BA"); - case(u128::max_value() - 2, "BCGDENLQRQWDSLRUGSNLBTMFIJAT"); - case(u128::max_value() - 1, "BCGDENLQRQWDSLRUGSNLBTMFIJAU"); - case(u128::max_value(), "BCGDENLQRQWDSLRUGSNLBTMFIJAV"); + case(u128::MAX - 2, "BCGDENLQRQWDSLRUGSNLBTMFIJAT"); + case(u128::MAX - 1, "BCGDENLQRQWDSLRUGSNLBTMFIJAU"); + case(u128::MAX, "BCGDENLQRQWDSLRUGSNLBTMFIJAV"); } #[test] @@ -217,7 +217,7 @@ mod tests { case(END - 1, "A"); case(END, "A"); case(END + 1, "A"); - case(u32::max_value(), "A"); + case(u32::MAX, "A"); case(START + INTERVAL * 00 - 1, "AAAAAAAAAAAAA"); case(START + INTERVAL * 00 + 0, "ZZYZXBRKWXVA"); diff --git a/src/runes/runestone.rs b/src/runes/runestone.rs index e1cf9aa63e..085b44f16e 100644 --- a/src/runes/runestone.rs +++ b/src/runes/runestone.rs @@ -962,7 +962,7 @@ mod tests { #[test] fn id_deltas_saturate_to_max() { assert_eq!( - decipher(&[TAG_BODY, 1, 2, 3, u128::max_value(), 5, 6]), + decipher(&[TAG_BODY, 1, 2, 3, u128::MAX, 5, 6]), Runestone { edicts: vec![ Edict { @@ -971,7 +971,7 @@ mod tests { output: 3, }, Edict { - id: u128::max_value(), + id: u128::MAX, amount: 5, output: 6, }, @@ -1157,7 +1157,7 @@ mod tests { case( Vec::new(), Some(Etching { - rune: Some(Rune(u128::max_value())), + rune: Some(Rune(u128::MAX)), ..Default::default() }), 24, @@ -1175,7 +1175,7 @@ mod tests { }], Some(Etching { divisibility: MAX_DIVISIBILITY, - rune: Some(Rune(u128::max_value())), + rune: Some(Rune(u128::MAX)), ..Default::default() }), 30, @@ -1183,7 +1183,7 @@ mod tests { case( vec![Edict { - amount: u128::max_value(), + amount: u128::MAX, id: RuneId { height: 0, index: 0, @@ -1193,7 +1193,7 @@ mod tests { }], Some(Etching { divisibility: MAX_DIVISIBILITY, - rune: Some(Rune(u128::max_value())), + rune: Some(Rune(u128::MAX)), ..Default::default() }), 48, @@ -1204,7 +1204,7 @@ mod tests { amount: 0, id: RuneId { height: 1_000_000, - index: u16::max_value(), + index: u16::MAX, } .into(), output: 0, @@ -1225,10 +1225,10 @@ mod tests { case( vec![Edict { - amount: u128::max_value(), + amount: u128::MAX, id: RuneId { height: 1_000_000, - index: u16::max_value(), + index: u16::MAX, } .into(), output: 0, @@ -1240,19 +1240,19 @@ mod tests { case( vec![ Edict { - amount: u128::max_value(), + amount: u128::MAX, id: RuneId { height: 1_000_000, - index: u16::max_value(), + index: u16::MAX, } .into(), output: 0, }, Edict { - amount: u128::max_value(), + amount: u128::MAX, id: RuneId { height: 1_000_000, - index: u16::max_value(), + index: u16::MAX, } .into(), output: 0, @@ -1265,28 +1265,28 @@ mod tests { case( vec![ Edict { - amount: u128::max_value(), + amount: u128::MAX, id: RuneId { height: 1_000_000, - index: u16::max_value(), + index: u16::MAX, } .into(), output: 0, }, Edict { - amount: u128::max_value(), + amount: u128::MAX, id: RuneId { height: 1_000_000, - index: u16::max_value(), + index: u16::MAX, } .into(), output: 0, }, Edict { - amount: u128::max_value(), + amount: u128::MAX, id: RuneId { height: 1_000_000, - index: u16::max_value(), + index: u16::MAX, } .into(), output: 0, @@ -1299,10 +1299,10 @@ mod tests { case( vec![ Edict { - amount: u64::max_value().into(), + amount: u64::MAX.into(), id: RuneId { height: 1_000_000, - index: u16::max_value(), + index: u16::MAX, } .into(), output: 0, @@ -1316,10 +1316,10 @@ mod tests { case( vec![ Edict { - amount: u64::max_value().into(), + amount: u64::MAX.into(), id: RuneId { height: 1_000_000, - index: u16::max_value(), + index: u16::MAX, } .into(), output: 0, @@ -1333,10 +1333,10 @@ mod tests { case( vec![ Edict { - amount: u64::max_value().into(), + amount: u64::MAX.into(), id: RuneId { height: 0, - index: u16::max_value(), + index: u16::MAX, } .into(), output: 0, @@ -1353,7 +1353,7 @@ mod tests { amount: 1_000_000_000_000_000_000, id: RuneId { height: 1_000_000, - index: u16::max_value(), + index: u16::MAX, } .into(), output: 0, @@ -1372,7 +1372,7 @@ mod tests { TAG_FLAGS, FLAG_ETCH, TAG_TERM, - u128::from(u64::max_value()) + 1, + u128::from(u64::MAX) + 1, ]), Runestone { etching: Some(Etching::default()), diff --git a/src/runes/varint.rs b/src/runes/varint.rs index 0a9ff7a90e..438673a836 100644 --- a/src/runes/varint.rs +++ b/src/runes/varint.rs @@ -48,7 +48,7 @@ mod tests { #[test] fn u128_max_round_trips_successfully() { - let n = u128::max_value(); + let n = u128::MAX; let encoded = encode(n); let (decoded, length) = decode(&encoded); assert_eq!(decoded, n); diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 955981a160..0e77c06e65 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -2236,7 +2236,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2282,7 +2282,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2310,7 +2310,7 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() } @@ -2319,7 +2319,7 @@ mod tests { assert_eq!( server.index.get_rune_balances().unwrap(), - [(OutPoint { txid, vout: 0 }, vec![(id, u128::max_value())])] + [(OutPoint { txid, vout: 0 }, vec![(id, u128::MAX)])] ); server.assert_response_regex( @@ -2349,7 +2349,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2378,7 +2378,7 @@ mod tests { RuneEntry { etching: txid, rune, - supply: u128::max_value(), + supply: u128::MAX, symbol: Some('%'), timestamp: 2, ..Default::default() @@ -2388,7 +2388,7 @@ mod tests { assert_eq!( server.index.get_rune_balances().unwrap(), - [(OutPoint { txid, vout: 0 }, vec![(id, u128::max_value())])] + [(OutPoint { txid, vout: 0 }, vec![(id, u128::MAX)])] ); server.assert_response_regex( @@ -2457,7 +2457,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2487,7 +2487,7 @@ mod tests { RuneEntry { etching: txid, rune, - supply: u128::max_value(), + supply: u128::MAX, symbol: Some('%'), timestamp: 2, spacers: 1, @@ -2498,7 +2498,7 @@ mod tests { assert_eq!( server.index.get_rune_balances().unwrap(), - [(OutPoint { txid, vout: 0 }, vec![(id, u128::max_value())])] + [(OutPoint { txid, vout: 0 }, vec![(id, u128::MAX)])] ); server.assert_response_regex( @@ -2556,7 +2556,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2584,7 +2584,7 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() } @@ -2593,7 +2593,7 @@ mod tests { assert_eq!( server.index.get_rune_balances().unwrap(), - [(OutPoint { txid, vout: 0 }, vec![(id, u128::max_value())])] + [(OutPoint { txid, vout: 0 }, vec![(id, u128::MAX)])] ); server.assert_response_regex( @@ -2622,7 +2622,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2652,7 +2652,7 @@ mod tests { divisibility: 1, etching: txid, rune, - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() } @@ -2663,7 +2663,7 @@ mod tests { assert_eq!( server.index.get_rune_balances().unwrap(), - [(output, vec![(id, u128::max_value())])] + [(output, vec![(id, u128::MAX)])] ); server.assert_response_regex( diff --git a/src/templates/rune.rs b/src/templates/rune.rs index 78a688a66a..35b89912f0 100644 --- a/src/templates/rune.rs +++ b/src/templates/rune.rs @@ -32,7 +32,7 @@ mod tests { limit: Some(1000000001), mints: 100, number: 25, - rune: Rune(u128::max_value()), + rune: Rune(u128::MAX), spacers: 1, supply: 123456789123456789, symbol: Some('%'), @@ -98,7 +98,7 @@ mod tests { limit: None, mints: 0, number: 25, - rune: Rune(u128::max_value()), + rune: Rune(u128::MAX), spacers: 1, supply: 123456789123456789, symbol: Some('%'), From 0203bd6415efd5ed60b70c27e983d566f240e8cb Mon Sep 17 00:00:00 2001 From: "linfeng.yuan" Date: Thu, 12 Sep 2024 17:16:21 +0800 Subject: [PATCH 30/30] fix cargo fmt --- src/runes.rs | 50 +++++++++--------------------------------- src/runes/runestone.rs | 7 +----- 2 files changed, 11 insertions(+), 46 deletions(-) diff --git a/src/runes.rs b/src/runes.rs index e8d1d8bbb8..9e73a3d1f6 100644 --- a/src/runes.rs +++ b/src/runes.rs @@ -2081,10 +2081,7 @@ mod tests { txid: txid3, vout: 0, }, - vec![ - (id0, u128::MAX / 2 + 1), - (id1, u128::MAX / 2 + 1), - ], + vec![(id0, u128::MAX / 2 + 1), (id1, u128::MAX / 2 + 1)], ), ( OutPoint { @@ -3042,22 +3039,10 @@ mod tests { }, )], [ - ( - OutPoint { txid, vout: 0 }, - vec![(id, u128::MAX / 4 + 1)], - ), - ( - OutPoint { txid, vout: 1 }, - vec![(id, u128::MAX / 4 + 1)], - ), - ( - OutPoint { txid, vout: 2 }, - vec![(id, u128::MAX / 4 + 1)], - ), - ( - OutPoint { txid, vout: 3 }, - vec![(id, u128::MAX / 4)], - ), + (OutPoint { txid, vout: 0 }, vec![(id, u128::MAX / 4 + 1)]), + (OutPoint { txid, vout: 1 }, vec![(id, u128::MAX / 4 + 1)]), + (OutPoint { txid, vout: 2 }, vec![(id, u128::MAX / 4 + 1)]), + (OutPoint { txid, vout: 3 }, vec![(id, u128::MAX / 4)]), ], ); } @@ -3188,22 +3173,10 @@ mod tests { }, )], [ - ( - OutPoint { txid, vout: 0 }, - vec![(id, u128::MAX / 4 + 1)], - ), - ( - OutPoint { txid, vout: 1 }, - vec![(id, u128::MAX / 4 + 1)], - ), - ( - OutPoint { txid, vout: 2 }, - vec![(id, u128::MAX / 4 + 1)], - ), - ( - OutPoint { txid, vout: 3 }, - vec![(id, u128::MAX / 4)], - ), + (OutPoint { txid, vout: 0 }, vec![(id, u128::MAX / 4 + 1)]), + (OutPoint { txid, vout: 1 }, vec![(id, u128::MAX / 4 + 1)]), + (OutPoint { txid, vout: 2 }, vec![(id, u128::MAX / 4 + 1)]), + (OutPoint { txid, vout: 3 }, vec![(id, u128::MAX / 4)]), ], ); } @@ -3315,10 +3288,7 @@ mod tests { }, )], [ - ( - OutPoint { txid, vout: 0 }, - vec![(id, u128::MAX - 2000)], - ), + (OutPoint { txid, vout: 0 }, vec![(id, u128::MAX - 2000)]), (OutPoint { txid, vout: 1 }, vec![(id, 1000)]), (OutPoint { txid, vout: 2 }, vec![(id, 1000)]), ], diff --git a/src/runes/runestone.rs b/src/runes/runestone.rs index 085b44f16e..6e60b39bac 100644 --- a/src/runes/runestone.rs +++ b/src/runes/runestone.rs @@ -1368,12 +1368,7 @@ mod tests { #[test] fn etching_with_term_greater_than_maximum_is_ignored() { assert_eq!( - decipher(&[ - TAG_FLAGS, - FLAG_ETCH, - TAG_TERM, - u128::from(u64::MAX) + 1, - ]), + decipher(&[TAG_FLAGS, FLAG_ETCH, TAG_TERM, u128::from(u64::MAX) + 1,]), Runestone { etching: Some(Etching::default()), ..Default::default()