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", ] 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] 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 29d00ed454..d40d11ac6f 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(), }) } @@ -1213,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) } @@ -4536,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/index/rtx.rs b/src/index/rtx.rs index 1f76f25a79..3931914c51 100644 --- a/src/index/rtx.rs +++ b/src/index/rtx.rs @@ -1,4 +1,5 @@ use super::*; +use crate::okx::datastore::ord::btc_name::BtcName; pub(crate) struct Rtx<'a>(pub(crate) redb::ReadTransaction<'a>); @@ -174,6 +175,17 @@ impl Rtx<'_> { get_collection_inscription_id(&table, &district.to_collection_key()) } + pub(crate) fn btc_name_to_inscription_id( + &self, + btc_name: &str, + domain_list: &[String], + ) -> Result> { + 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()) + } + pub(crate) fn ord_transaction_id_to_inscription_operations( &self, txid: Txid, 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..749c1c394e 100644 --- a/src/okx/datastore/brc20/mod.rs +++ b/src/okx/datastore/brc20/mod.rs @@ -12,13 +12,13 @@ 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 { 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/btc_name.rs b/src/okx/datastore/ord/btc_name.rs new file mode 100644 index 0000000000..7d1f49d8e8 --- /dev/null +++ b/src/okx/datastore/ord/btc_name.rs @@ -0,0 +1,109 @@ +use {super::*, anyhow::anyhow, regex::Regex}; + +const BTC_DOMAIN_KEY: &str = r"BTC_NAME"; + +pub struct BtcName { + pub name: String, + pub domain: String, +} + +const DEFAULT_DOMAIN_LIST: [&str; 4] = ["btc", "unisat", "sats", "x"]; +impl BtcName { + pub fn parse(bytes: &[u8], domain_list: &[String]) -> Result { + let domains = if domain_list.is_empty() { + DEFAULT_DOMAIN_LIST.join("|") + } else { + domain_list.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.to_lowercase()) { + let name = &capture["name"]; + let domain = &capture["domain"]; + if Self::is_name_valid(name) { + return Ok(Self { + name: name.to_string(), + domain: domain.to_string(), + }); + } + } + 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"[\.\n ]"; + let re = Regex::new(pattern).unwrap(); + if re.captures(name).is_some() { + return false; + } + // check if it's json format + if name.contains("{") { + let value: Result = serde_json::from_str(name); + return value.is_err(); + } + true + } + + pub fn to_collection_key(&self) -> String { + format!("{}_{}_{}", BTC_DOMAIN_KEY, self.name, self.domain) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn validate_regex() { + let domain_list = vec![]; + 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 btc_name = BtcName::parse(domain.as_bytes(), &domain_list); + assert!(btc_name.is_err()); + } + + let valid_domains = [ + "01.btc", + "123456.btc", + "Jack.btc", + "JACK.BTC", + "jack.BtC", + "比特币.btc", + "😀.btc", + "\\jack.btc", + "\tjack.btc", + ]; + for domain in valid_domains { + let btc_name = BtcName::parse(domain.as_bytes(), &domain_list); + assert!(btc_name.is_ok()); + } + + for d in DEFAULT_DOMAIN_LIST { + let s = format!("abc.{d}"); + 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 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 196eceb929..b9cc96c527 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, + BtcName, } 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::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 3fe3b28afb..7359a9edbd 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_name; pub mod collections; pub mod operation; pub mod redb; @@ -25,15 +26,15 @@ pub trait OrdReader { chain: Chain, ) -> Result; - fn get_transaction_operations( - &self, - txid: &Txid, - ) -> 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_collections_of_inscription( + // &self, + // inscription_id: &InscriptionId, + // ) -> Result>, Self::Error>; fn get_collection_inscription_id( &self, 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]) 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..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, }, @@ -102,19 +98,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 +153,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 +169,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 +211,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/okx/protocol/mod.rs b/src/okx/protocol/mod.rs index 947ef633a9..a7a0c4a829 100644 --- a/src/okx/protocol/mod.rs +++ b/src/okx/protocol/mod.rs @@ -19,12 +19,14 @@ 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, + enable_index_domain: bool, + btc_domain_list: Vec, } impl ProtocolConfig { @@ -38,6 +40,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_name.rs b/src/okx/protocol/ord/btc_name.rs new file mode 100644 index 0000000000..fcabdd9566 --- /dev/null +++ b/src/okx/protocol/ord/btc_name.rs @@ -0,0 +1,83 @@ +use crate::okx::datastore::ord::{OrdReader, OrdReaderWriter}; +use crate::okx::protocol::context::Context; +use { + crate::{ + okx::datastore::ord::{ + btc_name::BtcName, + collections::CollectionKind, + operation::{Action, InscriptionOp}, + }, + Inscription, InscriptionId, Result, + }, + anyhow::anyhow, + bitcoin::Txid, + std::collections::HashMap, +}; + +pub fn index_btc_name( + 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, btc_name)) = + do_index_btc_name(context, inscription, op.inscription_id, domain_list)? + { + let key = btc_name.to_collection_key(); + context.set_inscription_by_collection_key(&key, &inscription_id)?; + context.add_inscription_attributes(&inscription_id, CollectionKind::BtcName)?; + count += 1; + } + } + _ => unreachable!(), + } + } + Ok(count) +} + +fn do_index_btc_name( + context: &mut Context, + inscription: Inscription, + inscription_id: InscriptionId, + domain_list: &[String], +) -> Result> { + if let Some(content) = inscription.body() { + 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) + .map_err(|e| { + anyhow!("failed to get collection inscription! key: {collection_key} error: {e}") + })? + .is_none() + { + log::info!( + "found valid btc domain btc_name! {}.{} inscription_id {}", + btc_name.name, + btc_name.domain, + inscription_id, + ); + return Ok(Some((inscription_id, btc_name))); + } + } + } + Ok(None) +} diff --git a/src/okx/protocol/ord/mod.rs b/src/okx/protocol/ord/mod.rs index 163f8968d3..5bccfb9974 100644 --- a/src/okx/protocol/ord/mod.rs +++ b/src/okx/protocol/ord/mod.rs @@ -1 +1,2 @@ pub mod bitmap; +pub mod btc_name; diff --git a/src/okx/protocol/protocol_manager.rs b/src/okx/protocol/protocol_manager.rs index e3a4d0ab66..dc81a8dcf3 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,17 +78,23 @@ 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_name::index_btc_name(context, &operations, &self.config.btc_domain_list)?; + } 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 a7854ccfca..b7feb4d4ed 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, default are btc,unisat,sats,x")] + pub(crate) btc_domain_list: Vec, #[arg( long, help = "Don't look for BRC20 messages below ." @@ -900,4 +905,14 @@ 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", "index", "update"]).unwrap(); + assert_eq!( + arguments.options.btc_domain_list, + vec!["aaa".to_string(), "bbb".to_string()] + ); + } } diff --git a/src/runes.rs b/src/runes.rs index ccc88be8bb..9e73a3d1f6 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() @@ -2081,17 +2081,14 @@ mod tests { txid: txid3, vout: 0, }, - vec![ - (id0, u128::max_value() / 2 + 1), - (id1, u128::max_value() / 2 + 1), - ], + vec![(id0, u128::MAX / 2 + 1), (id1, u128::MAX / 2 + 1)], ), ( OutPoint { 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 +2106,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2136,7 +2133,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2146,7 +2143,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id0, u128::max_value())], + vec![(id0, u128::MAX)], )], ); @@ -2156,7 +2153,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2184,7 +2181,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2194,7 +2191,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 +2204,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 +2223,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 +2248,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2261,7 +2258,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 +2270,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 +2288,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2318,7 +2315,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2328,7 +2325,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -2351,12 +2348,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 +2369,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2397,7 +2394,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2425,7 +2422,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 3, ..Default::default() }, @@ -2435,7 +2432,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 +2445,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 +2470,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2500,7 +2497,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2510,7 +2507,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -2526,7 +2523,7 @@ mod tests { }, Edict { id: id.into(), - amount: u128::max_value(), + amount: u128::MAX, output: 0, }, ], @@ -2545,7 +2542,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2555,7 +2552,7 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); } @@ -2572,7 +2569,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2599,7 +2596,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2609,7 +2606,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id0, u128::max_value())], + vec![(id0, u128::MAX)], )], ); @@ -2619,7 +2616,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2647,7 +2644,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2657,7 +2654,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 +2667,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 +2686,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 +2711,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -2724,7 +2721,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 +2734,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 +2759,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 +2786,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value() / 2, + supply: u128::MAX / 2, timestamp: 2, ..Default::default() }, @@ -2799,7 +2796,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value() / 2)], + vec![(id, u128::MAX / 2)], )], ); @@ -2809,7 +2806,7 @@ mod tests { Runestone { edicts: vec![Edict { id: id.into(), - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], ..Default::default() @@ -2827,7 +2824,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value() / 2, + supply: u128::MAX / 2, timestamp: 2, ..Default::default() }, @@ -2837,7 +2834,7 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, u128::max_value() / 2)], + vec![(id, u128::MAX / 2)], )], ); } @@ -2854,7 +2851,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 1, }], etching: Some(Etching { @@ -2879,10 +2876,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 +2901,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2931,12 +2928,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 +2951,7 @@ mod tests { edicts: vec![ Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }, Edict { @@ -2987,12 +2984,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,28 +3033,16 @@ 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() / 4 + 1)], - ), - ( - OutPoint { txid, vout: 1 }, - vec![(id, u128::max_value() / 4 + 1)], - ), - ( - OutPoint { txid, vout: 2 }, - vec![(id, u128::max_value() / 4 + 1)], - ), - ( - OutPoint { txid, vout: 3 }, - vec![(id, u128::max_value() / 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)]), ], ); } @@ -3109,7 +3094,7 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3117,19 +3102,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,28 +3167,16 @@ 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() / 4 + 1)], - ), - ( - OutPoint { txid, vout: 1 }, - vec![(id, u128::max_value() / 4 + 1)], - ), - ( - OutPoint { txid, vout: 2 }, - vec![(id, u128::max_value() / 4 + 1)], - ), - ( - OutPoint { txid, vout: 3 }, - vec![(id, u128::max_value() / 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)]), ], ); } @@ -3276,7 +3249,7 @@ mod tests { edicts: vec![ Edict { id: 0, - amount: u128::max_value() - 3000, + amount: u128::MAX - 3000, output: 0, }, Edict { @@ -3309,16 +3282,13 @@ 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() - 2000)], - ), + (OutPoint { txid, vout: 0 }, vec![(id, u128::MAX - 2000)]), (OutPoint { txid, vout: 1 }, vec![(id, 1000)]), (OutPoint { txid, vout: 2 }, vec![(id, 1000)]), ], @@ -3344,7 +3314,7 @@ mod tests { }, Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }, ], @@ -3372,7 +3342,7 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3380,7 +3350,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 +3371,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -3428,7 +3398,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3438,7 +3408,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -3467,7 +3437,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3478,14 +3448,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 +3473,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -3530,7 +3500,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3540,7 +3510,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -3576,7 +3546,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3587,14 +3557,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 +3582,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -3639,7 +3609,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3649,7 +3619,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -3685,7 +3655,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3696,14 +3666,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 +3691,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -3748,7 +3718,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3758,7 +3728,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -3787,7 +3757,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3798,7 +3768,7 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, u128::max_value() - 1000)], + vec![(id, u128::MAX - 1000)], ), ( OutPoint { @@ -3823,7 +3793,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -3850,7 +3820,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3860,7 +3830,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -3872,7 +3842,7 @@ mod tests { edicts: vec![ Edict { id: id.into(), - amount: u128::max_value() - 2000, + amount: u128::MAX - 2000, output: 0, }, Edict { @@ -3896,7 +3866,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3907,7 +3877,7 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, u128::max_value() - 2000 + 1000)], + vec![(id, u128::MAX - 2000 + 1000)], ), ( OutPoint { @@ -3932,7 +3902,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -3959,7 +3929,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -3969,7 +3939,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -3986,7 +3956,7 @@ mod tests { }, Edict { id: id.into(), - amount: u128::max_value(), + amount: u128::MAX, output: 0, }, ], @@ -4005,7 +3975,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -4016,7 +3986,7 @@ mod tests { txid: txid1, vout: 0, }, - vec![(id, u128::max_value() - 4000 + 1000)], + vec![(id, u128::MAX - 4000 + 1000)], ), ( OutPoint { @@ -4055,7 +4025,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -4083,13 +4053,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 +4102,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 +4123,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -4180,7 +4150,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -4190,7 +4160,7 @@ mod tests { txid: txid0, vout: 0, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); @@ -4219,7 +4189,7 @@ mod tests { RuneEntry { etching: txid0, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() }, @@ -4229,7 +4199,7 @@ mod tests { txid: txid1, vout: 1, }, - vec![(id, u128::max_value())], + vec![(id, u128::MAX)], )], ); } @@ -4237,7 +4207,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 8321c81680..aeaa2ebb6f 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"); } @@ -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..6e60b39bac 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, @@ -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_value()) + 1, - ]), + decipher(&[TAG_FLAGS, FLAG_ETCH, TAG_TERM, u128::from(u64::MAX) + 1,]), Runestone { etching: Some(Etching::default()), ..Default::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 8705e410c5..0e77c06e65 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 { @@ -309,6 +309,10 @@ impl Server { "/ord/debug/bitmap/district/:number", get(ord::ord_debug_bitmap_district), ) + .route( + "/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)) .route( @@ -2232,7 +2236,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2278,7 +2282,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2306,7 +2310,7 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() } @@ -2315,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( @@ -2345,7 +2349,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2374,7 +2378,7 @@ mod tests { RuneEntry { etching: txid, rune, - supply: u128::max_value(), + supply: u128::MAX, symbol: Some('%'), timestamp: 2, ..Default::default() @@ -2384,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( @@ -2453,7 +2457,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2483,7 +2487,7 @@ mod tests { RuneEntry { etching: txid, rune, - supply: u128::max_value(), + supply: u128::MAX, symbol: Some('%'), timestamp: 2, spacers: 1, @@ -2494,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( @@ -2552,7 +2556,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2580,7 +2584,7 @@ mod tests { RuneEntry { etching: txid, rune: Rune(RUNE), - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() } @@ -2589,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( @@ -2618,7 +2622,7 @@ mod tests { Runestone { edicts: vec![Edict { id: 0, - amount: u128::max_value(), + amount: u128::MAX, output: 0, }], etching: Some(Etching { @@ -2648,7 +2652,7 @@ mod tests { divisibility: 1, etching: txid, rune, - supply: u128::max_value(), + supply: u128::MAX, timestamp: 2, ..Default::default() } @@ -2659,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/subcommand/server/api.rs b/src/subcommand/server/api.rs index a5079a6026..49e8a7de21 100644 --- a/src/subcommand/server/api.rs +++ b/src/subcommand/server/api.rs @@ -1,12 +1,12 @@ -use {super::*, utoipa::IntoParams}; +use super::*; -#[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/server/ord/inscription.rs b/src/subcommand/server/ord/inscription.rs index 0ac551596a..1ee02a25bb 100644 --- a/src/subcommand/server/ord/inscription.rs +++ b/src/subcommand/server/ord/inscription.rs @@ -248,6 +248,27 @@ pub(crate) async fn ord_debug_bitmap_district( Ok(Json(ApiResponse::ok(inscription_id))) } +// 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_btc_name:{btc_name}"); + + let rtx = index.begin_read()?; + let inscription_id = rtx + .btc_name_to_inscription_id(&btc_name, &index.domain_list)? + .ok_or_api_not_found(format!("district {btc_name} not found."))?; + + log::debug!( + "rpc: get ord_debug_bitmap_district: {:?} {:?}", + btc_name, + inscription_id + ); + + Ok(Json(ApiResponse::ok(inscription_id))) +} + #[cfg(test)] mod tests { use super::*; 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)] 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('%'),