Skip to content

Commit

Permalink
Merge branch 'master' into env-quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph committed Mar 22, 2024
2 parents ec55fee + 5c5042d commit 456bf07
Show file tree
Hide file tree
Showing 38 changed files with 1,417 additions and 852 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ miniscript = "10.0.0"
mp4 = "0.14.0"
ord-bitcoincore-rpc = "0.17.2"
ordinals = { version = "0.0.4", path = "crates/ordinals" }
redb = "1.5.0"
redb = "2.0.0"
regex = "1.6.0"
reqwest = { version = "0.11.23", features = ["blocking", "json"] }
rss = "2.0.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/test-bitcoincore-rpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ impl Api for Server {
txid: output.txid,
};
assert!(state.utxos.contains_key(&output));
state.locked.insert(output);
assert!(state.locked.insert(output));
}

Ok(true)
Expand Down
32 changes: 13 additions & 19 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use {
log::log_enabled,
redb::{
Database, DatabaseError, MultimapTable, MultimapTableDefinition, MultimapTableHandle,
ReadOnlyTable, ReadableMultimapTable, ReadableTable, RepairSession, StorageError, Table,
TableDefinition, TableHandle, TableStats, WriteTransaction,
ReadOnlyTable, ReadableMultimapTable, ReadableTable, ReadableTableMetadata, RepairSession,
StorageError, Table, TableDefinition, TableHandle, TableStats, WriteTransaction,
},
std::{
collections::HashMap,
Expand All @@ -48,7 +48,7 @@ mod updater;
#[cfg(test)]
pub(crate) mod testing;

const SCHEMA_VERSION: u64 = 21;
const SCHEMA_VERSION: u64 = 22;

macro_rules! define_table {
($name:ident, $key:ty, $value:ty) => {
Expand Down Expand Up @@ -834,7 +834,7 @@ impl Index {
.begin_read()?
.open_table(RUNE_ID_TO_RUNE_ENTRY)?
.get(&id.store())?
.map(|entry| RuneEntry::load(entry.value()).rune),
.map(|entry| RuneEntry::load(entry.value()).spaced_rune.rune),
)
}

Expand Down Expand Up @@ -909,17 +909,13 @@ impl Index {
let mut balances = Vec::new();
let mut i = 0;
while i < balances_buffer.len() {
let (id, length) = runes::varint::decode(&balances_buffer[i..]);
let ((id, amount), length) = RuneId::decode_balance(&balances_buffer[i..]).unwrap();
i += length;
let (amount, length) = runes::varint::decode(&balances_buffer[i..]);
i += length;

let id = RuneId::try_from(id).unwrap();

let entry = RuneEntry::load(id_to_rune_entries.get(id.store())?.unwrap().value());

balances.push((
entry.spaced_rune(),
entry.spaced_rune,
Pile {
amount,
divisibility: entry.divisibility,
Expand Down Expand Up @@ -954,8 +950,8 @@ impl Index {

for (rune_id, balances) in rune_balances_by_id {
let RuneEntry {
rune,
divisibility,
spaced_rune,
symbol,
..
} = RuneEntry::load(
Expand All @@ -966,7 +962,7 @@ impl Index {
);

rune_balances.insert(
rune,
spaced_rune.rune,
balances
.into_iter()
.map(|(outpoint, amount)| {
Expand Down Expand Up @@ -1002,11 +998,9 @@ impl Index {
let mut balances = Vec::new();
let mut i = 0;
while i < balances_buffer.len() {
let (id, length) = runes::varint::decode(&balances_buffer[i..]);
i += length;
let (balance, length) = runes::varint::decode(&balances_buffer[i..]);
let ((id, balance), length) = RuneId::decode_balance(&balances_buffer[i..]).unwrap();
i += length;
balances.push((RuneId::try_from(id)?, balance));
balances.push((id, balance));
}

result.push((outpoint, balances));
Expand Down Expand Up @@ -1220,7 +1214,7 @@ impl Index {
let rune_id_to_rune_entry = rtx.open_table(RUNE_ID_TO_RUNE_ENTRY)?;
let entry = rune_id_to_rune_entry.get(&id.value())?.unwrap();

Ok(Some(RuneEntry::load(entry.value()).spaced_rune()))
Ok(Some(RuneEntry::load(entry.value()).spaced_rune))
}

pub(crate) fn get_inscription_ids_by_sat(&self, sat: Sat) -> Result<Vec<InscriptionId>> {
Expand Down Expand Up @@ -1588,7 +1582,7 @@ impl Index {
return Ok(false);
}

if usize::try_from(outpoint.vout).unwrap() >= info.vout.len() {
if outpoint.vout.into_usize() >= info.vout.len() {
return Ok(false);
}

Expand Down Expand Up @@ -1869,7 +1863,7 @@ impl Index {
{
let rune_id_to_rune_entry = rtx.open_table(RUNE_ID_TO_RUNE_ENTRY)?;
let entry = rune_id_to_rune_entry.get(&rune_id.value())?.unwrap();
Some(RuneEntry::load(entry.value()).spaced_rune())
Some(RuneEntry::load(entry.value()).spaced_rune)
} else {
None
};
Expand Down
47 changes: 18 additions & 29 deletions src/index/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ pub struct RuneEntry {
pub mints: u64,
pub number: u64,
pub premine: u128,
pub rune: Rune,
pub spacers: u32,
pub spaced_rune: SpacedRune,
pub supply: u128,
pub symbol: Option<char>,
pub timestamp: u32,
Expand All @@ -67,18 +66,18 @@ pub struct RuneEntry {
impl RuneEntry {
pub fn mintable(&self, block_height: Height, block_time: u32) -> Result<u128, MintError> {
let Some(mint) = self.mint else {
return Err(MintError::Unmintable(self.rune));
return Err(MintError::Unmintable(self.spaced_rune.rune));
};

if let Some(end) = mint.end {
if block_height.0 >= end {
return Err(MintError::End((self.rune, end)));
return Err(MintError::End((self.spaced_rune.rune, end)));
}
}

if let Some(deadline) = mint.deadline {
if block_time >= deadline {
return Err(MintError::Deadline((self.rune, deadline)));
return Err(MintError::Deadline((self.spaced_rune.rune, deadline)));
}
}

Expand All @@ -94,8 +93,7 @@ pub(super) type RuneEntryValue = (
u64, // mints
u64, // number
u128, // premine
u128, // rune
u32, // spacers
(u128, u32), // spaced rune
u128, // supply
Option<char>, // symbol
u32, // timestamp
Expand All @@ -114,15 +112,6 @@ type MintEntryValue = (
Option<u128>, // limit
);

impl RuneEntry {
pub(crate) fn spaced_rune(&self) -> SpacedRune {
SpacedRune {
rune: self.rune,
spacers: self.spacers,
}
}
}

impl Default for RuneEntry {
fn default() -> Self {
Self {
Expand All @@ -133,8 +122,7 @@ impl Default for RuneEntry {
mints: 0,
number: 0,
premine: 0,
rune: Rune(0),
spacers: 0,
spaced_rune: SpacedRune::default(),
supply: 0,
symbol: None,
timestamp: 0,
Expand All @@ -154,8 +142,7 @@ impl Entry for RuneEntry {
mints,
number,
premine,
rune,
spacers,
(rune, spacers),
supply,
symbol,
timestamp,
Expand All @@ -182,8 +169,10 @@ impl Entry for RuneEntry {
mints,
number,
premine,
rune: Rune(rune),
spacers,
spaced_rune: SpacedRune {
rune: Rune(rune),
spacers,
},
supply,
symbol,
timestamp,
Expand Down Expand Up @@ -217,16 +206,15 @@ impl Entry for RuneEntry {
self.mints,
self.number,
self.premine,
self.rune.0,
self.spacers,
(self.spaced_rune.rune.0, self.spaced_rune.spacers),
self.supply,
self.symbol,
self.timestamp,
)
}
}

pub(super) type RuneIdValue = (u32, u16);
pub(super) type RuneIdValue = (u32, u32);

impl Entry for RuneId {
type Value = RuneIdValue;
Expand Down Expand Up @@ -531,8 +519,10 @@ mod tests {
mints: 11,
number: 6,
premine: 12,
rune: Rune(7),
spacers: 8,
spaced_rune: SpacedRune {
rune: Rune(7),
spacers: 8,
},
supply: 9,
symbol: Some('a'),
timestamp: 10,
Expand All @@ -549,8 +539,7 @@ mod tests {
11,
6,
12,
7,
8,
(7, 8),
9,
Some('a'),
10,
Expand Down
4 changes: 2 additions & 2 deletions src/index/rtx.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::*;

pub(crate) struct Rtx<'a>(pub(crate) redb::ReadTransaction<'a>);
pub(crate) struct Rtx(pub(crate) redb::ReadTransaction);

impl Rtx<'_> {
impl Rtx {
pub(crate) fn block_height(&self) -> Result<Option<Height>> {
Ok(
self
Expand Down
4 changes: 2 additions & 2 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(crate) struct Updater<'index> {
}

impl<'index> Updater<'index> {
pub(crate) fn update_index<'a>(&'a mut self, mut wtx: WriteTransaction<'a>) -> Result {
pub(crate) fn update_index(&mut self, mut wtx: WriteTransaction) -> Result {
let start = Instant::now();
let starting_height = u32::try_from(self.index.client.get_block_count()?).unwrap() + 1;
let starting_index_height = self.height;
Expand Down Expand Up @@ -608,7 +608,7 @@ impl<'index> Updater<'index> {
};

for (i, (tx, txid)) in block.txdata.iter().enumerate() {
rune_updater.index_runes(i, tx, *txid)?;
rune_updater.index_runes(u32::try_from(i).unwrap(), tx, *txid)?;
}

for (rune_id, update) in rune_updater.updates {
Expand Down
28 changes: 13 additions & 15 deletions src/index/updater/inscription_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,37 @@ enum Origin {
},
}

pub(super) struct InscriptionUpdater<'a, 'db, 'tx> {
pub(super) struct InscriptionUpdater<'a, 'tx> {
pub(super) blessed_inscription_count: u64,
pub(super) chain: Chain,
pub(super) content_type_to_count: &'a mut Table<'db, 'tx, Option<&'static [u8]>, u64>,
pub(super) content_type_to_count: &'a mut Table<'tx, Option<&'static [u8]>, u64>,
pub(super) cursed_inscription_count: u64,
pub(super) event_sender: Option<&'a Sender<Event>>,
pub(super) flotsam: Vec<Flotsam>,
pub(super) height: u32,
pub(super) home_inscription_count: u64,
pub(super) home_inscriptions: &'a mut Table<'db, 'tx, u32, InscriptionIdValue>,
pub(super) id_to_sequence_number: &'a mut Table<'db, 'tx, InscriptionIdValue, u32>,
pub(super) home_inscriptions: &'a mut Table<'tx, u32, InscriptionIdValue>,
pub(super) id_to_sequence_number: &'a mut Table<'tx, InscriptionIdValue, u32>,
pub(super) index_transactions: bool,
pub(super) inscription_number_to_sequence_number: &'a mut Table<'db, 'tx, i32, u32>,
pub(super) inscription_number_to_sequence_number: &'a mut Table<'tx, i32, u32>,
pub(super) lost_sats: u64,
pub(super) next_sequence_number: u32,
pub(super) outpoint_to_value: &'a mut Table<'db, 'tx, &'static OutPointValue, u64>,
pub(super) outpoint_to_value: &'a mut Table<'tx, &'static OutPointValue, u64>,
pub(super) reward: u64,
pub(super) transaction_buffer: Vec<u8>,
pub(super) transaction_id_to_transaction:
&'a mut Table<'db, 'tx, &'static TxidValue, &'static [u8]>,
pub(super) sat_to_sequence_number: &'a mut MultimapTable<'db, 'tx, u64, u32>,
pub(super) satpoint_to_sequence_number:
&'a mut MultimapTable<'db, 'tx, &'static SatPointValue, u32>,
pub(super) sequence_number_to_children: &'a mut MultimapTable<'db, 'tx, u32, u32>,
pub(super) sequence_number_to_entry: &'a mut Table<'db, 'tx, u32, InscriptionEntryValue>,
pub(super) sequence_number_to_satpoint: &'a mut Table<'db, 'tx, u32, &'static SatPointValue>,
pub(super) transaction_id_to_transaction: &'a mut Table<'tx, &'static TxidValue, &'static [u8]>,
pub(super) sat_to_sequence_number: &'a mut MultimapTable<'tx, u64, u32>,
pub(super) satpoint_to_sequence_number: &'a mut MultimapTable<'tx, &'static SatPointValue, u32>,
pub(super) sequence_number_to_children: &'a mut MultimapTable<'tx, u32, u32>,
pub(super) sequence_number_to_entry: &'a mut Table<'tx, u32, InscriptionEntryValue>,
pub(super) sequence_number_to_satpoint: &'a mut Table<'tx, u32, &'static SatPointValue>,
pub(super) timestamp: u32,
pub(super) unbound_inscriptions: u64,
pub(super) value_cache: &'a mut HashMap<OutPoint, u64>,
pub(super) value_receiver: &'a mut Receiver<u64>,
}

impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
impl<'a, 'tx> InscriptionUpdater<'a, 'tx> {
pub(super) fn index_inscriptions(
&mut self,
tx: &Transaction,
Expand Down
Loading

0 comments on commit 456bf07

Please sign in to comment.