Skip to content

Commit

Permalink
Revert "Move runes types into ordinals crate (ordinals#3391)"
Browse files Browse the repository at this point in the history
This reverts commit e36ca44.
  • Loading branch information
harutyunaraci authored Apr 2, 2024
1 parent 0cc66ca commit a745d1e
Show file tree
Hide file tree
Showing 35 changed files with 407 additions and 624 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ reqwest = { version = "0.11.10", features = ["blocking", "brotli", "json"] }
test-bitcoincore-rpc = { path = "crates/test-bitcoincore-rpc" }
unindent = "0.2.1"

[[bench]]
name = "server"
harness = false

[[bin]]
name = "ord"
path = "src/bin/main.rs"
Expand Down
16 changes: 16 additions & 0 deletions benches/server.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use {criterion::Criterion, ord::Index};

fn main() {
let mut criterion = Criterion::default().configure_from_args();
let index = Index::open(&Default::default()).unwrap();
let mut i = 0;

criterion.bench_function("inscription", |b| {
b.iter(|| {
Index::inscription_info_benchmark(&index, i);
i += 1;
});
});

Criterion::default().configure_from_args().final_summary();
}
1 change: 0 additions & 1 deletion crates/ordinals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ thiserror = "1.0.56"

[dev-dependencies]
serde_json = { version = "1.0.81", features = ["preserve_order"] }
pretty_assertions = "1.2.1"
63 changes: 0 additions & 63 deletions crates/ordinals/src/cenotaph.rs

This file was deleted.

5 changes: 3 additions & 2 deletions crates/ordinals/src/charm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub enum Charm {
}

impl Charm {
pub const ALL: [Self; 12] = [
pub const ALL: [Charm; 12] = [
Self::Coin,
Self::Uncommon,
Self::Rare,
Expand Down Expand Up @@ -67,8 +67,9 @@ impl Charm {

pub fn charms(charms: u16) -> Vec<Charm> {
Self::ALL
.into_iter()
.iter()
.filter(|charm| charm.is_set(charms))
.copied()
.collect()
}
}
Expand Down
39 changes: 0 additions & 39 deletions crates/ordinals/src/etching.rs

This file was deleted.

35 changes: 7 additions & 28 deletions crates/ordinals/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
//! Types for interoperating with ordinals, inscriptions, and runes.
//! Types for interoperating with ordinals and inscriptions.
use {
bitcoin::constants::{COIN_VALUE, DIFFCHANGE_INTERVAL, SUBSIDY_HALVING_INTERVAL},
bitcoin::{
consensus::{Decodable, Encodable},
constants::{
COIN_VALUE, DIFFCHANGE_INTERVAL, MAX_SCRIPT_ELEMENT_SIZE, SUBSIDY_HALVING_INTERVAL,
},
opcodes,
script::{self, Instruction},
Network, OutPoint, ScriptBuf, Transaction,
OutPoint,
},
derive_more::{Display, FromStr},
serde::{Deserialize, Serialize},
serde_with::{DeserializeFromStr, SerializeDisplay},
std::{
cmp,
collections::{HashMap, VecDeque},
fmt::{self, Display, Formatter},
io,
num::ParseIntError,
Expand All @@ -25,34 +20,18 @@ use {
thiserror::Error,
};

pub use {
cenotaph::Cenotaph, charm::Charm, decimal_sat::DecimalSat, degree::Degree, edict::Edict,
epoch::Epoch, etching::Etching, height::Height, pile::Pile, rarity::Rarity, rune::Rune,
rune_id::RuneId, runestone::Runestone, sat::Sat, sat_point::SatPoint, spaced_rune::SpacedRune,
terms::Terms,
};

pub const CYCLE_EPOCHS: u32 = 6;

fn default<T: Default>() -> T {
Default::default()
}
pub use {
charm::Charm, decimal_sat::DecimalSat, degree::Degree, epoch::Epoch, height::Height,
rarity::Rarity, sat::Sat, sat_point::SatPoint,
};

mod cenotaph;
mod charm;
mod decimal_sat;
mod degree;
mod edict;
mod epoch;
mod etching;
mod height;
mod pile;
mod rarity;
mod rune;
mod rune_id;
mod runestone;
mod sat;
mod sat_point;
mod spaced_rune;
mod terms;
pub mod varint;
56 changes: 0 additions & 56 deletions crates/ordinals/src/runestone/message.rs

This file was deleted.

26 changes: 13 additions & 13 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ pub enum Chain {

impl Chain {
pub(crate) fn network(self) -> Network {
self.into()
match self {
Self::Mainnet => Network::Bitcoin,
Self::Testnet => Network::Testnet,
Self::Signet => Network::Signet,
Self::Regtest => Network::Regtest,
}
}

pub(crate) fn default_rpc_port(self) -> u16 {
Expand Down Expand Up @@ -43,7 +48,13 @@ impl Chain {
}

pub(crate) fn first_rune_height(self) -> u32 {
Rune::first_rune_height(self.into())
SUBSIDY_HALVING_INTERVAL
* match self {
Self::Mainnet => 4,
Self::Regtest => 0,
Self::Signet => 0,
Self::Testnet => 12,
}
}

pub(crate) fn jubilee_height(self) -> u32 {
Expand Down Expand Up @@ -83,17 +94,6 @@ impl Chain {
}
}

impl From<Chain> for Network {
fn from(chain: Chain) -> Network {
match chain {
Chain::Mainnet => Network::Bitcoin,
Chain::Testnet => Network::Testnet,
Chain::Signet => Network::Signet,
Chain::Regtest => Network::Regtest,
}
}
}

impl Display for Chain {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(
Expand Down
27 changes: 3 additions & 24 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ impl Index {
inscriptions: blessed_inscriptions + cursed_inscriptions,
lost_sats: statistic(Statistic::LostSats)?,
minimum_rune_for_next_block: Rune::minimum_at_height(
self.settings.chain().network(),
self.settings.chain(),
Height(next_height),
),
rune_index: statistic(Statistic::IndexRunes)? != 0,
Expand Down Expand Up @@ -887,27 +887,6 @@ impl Index {
Ok(entries)
}

pub(crate) fn encode_rune_balance(id: RuneId, balance: u128, buffer: &mut Vec<u8>) {
varint::encode_to_vec(id.block.into(), buffer);
varint::encode_to_vec(id.tx.into(), buffer);
varint::encode_to_vec(balance, buffer);
}

pub(crate) fn decode_rune_balance(buffer: &[u8]) -> Option<((RuneId, u128), usize)> {
let mut len = 0;
let (block, block_len) = varint::decode(&buffer[len..])?;
len += block_len;
let (tx, tx_len) = varint::decode(&buffer[len..])?;
len += tx_len;
let id = RuneId {
block: block.try_into().ok()?,
tx: tx.try_into().ok()?,
};
let (balance, balance_len) = varint::decode(&buffer[len..])?;
len += balance_len;
Some(((id, balance), len))
}

pub(crate) fn get_rune_balances_for_outpoint(
&self,
outpoint: OutPoint,
Expand All @@ -927,7 +906,7 @@ impl Index {
let mut balances = Vec::new();
let mut i = 0;
while i < balances_buffer.len() {
let ((id, amount), length) = Index::decode_rune_balance(&balances_buffer[i..]).unwrap();
let ((id, amount), length) = RuneId::decode_balance(&balances_buffer[i..]).unwrap();
i += length;

let entry = RuneEntry::load(id_to_rune_entries.get(id.store())?.unwrap().value());
Expand Down Expand Up @@ -1018,7 +997,7 @@ impl Index {
let mut balances = Vec::new();
let mut i = 0;
while i < balances_buffer.len() {
let ((id, balance), length) = Index::decode_rune_balance(&balances_buffer[i..]).unwrap();
let ((id, balance), length) = RuneId::decode_balance(&balances_buffer[i..]).unwrap();
i += length;
balances.push((id, balance));
}
Expand Down
5 changes: 1 addition & 4 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,7 @@ impl<'index> Updater<'index> {
height: self.height,
id_to_entry: &mut rune_id_to_rune_entry,
inscription_id_to_sequence_number: &mut inscription_id_to_sequence_number,
minimum: Rune::minimum_at_height(
self.index.settings.chain().network(),
Height(self.height),
),
minimum: Rune::minimum_at_height(self.index.settings.chain(), Height(self.height)),
outpoint_to_balances: &mut outpoint_to_rune_balances,
rune_to_id: &mut rune_to_rune_id,
runes,
Expand Down
Loading

0 comments on commit a745d1e

Please sign in to comment.