Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Misc review comments #3331

Merged
merged 23 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
38648f3
Make Edict::output a u32
casey Mar 20, 2024
1054c97
Add comment that `Witness::tapscript()` doesn't guarantee that input …
casey Mar 20, 2024
424c4f2
Non-push op returns in a runestone produce a cenotaph
casey Mar 20, 2024
9db05a2
Make invalid claims produce cenotaph
casey Mar 20, 2024
e674dcf
Make Tag::take leave invalid entries
casey Mar 20, 2024
33c15dc
Fix lints
casey Mar 20, 2024
7673561
Add IntoUsize for guaranteed conversions from u32 to usize
casey Mar 20, 2024
29c41f9
Default output greater than maximum output index is a cenotaph
casey Mar 20, 2024
2cf5f40
Require tx index be a u16 to call RuneUpdater::Etched
casey Mar 21, 2024
29e4bc8
Remove superfluous tests
casey Mar 21, 2024
b3468df
Use more sensible varint implementation
casey Mar 21, 2024
8aeb333
Allow duplicate runestone tags
casey Mar 21, 2024
b7ba0cb
Use generic currency symbol for runes without a symbol
casey Mar 21, 2024
95c6d70
Fix clippy lint
casey Mar 21, 2024
ae5bc8c
Encode Rune ID in claim as two values
casey Mar 21, 2024
8ddbe9f
Store SpacedRune in RuneEntry
casey Mar 22, 2024
74a0846
Store RuneIds in edicts as two values
casey Mar 22, 2024
bcf1204
Invalid varints and not pushdata opcodes produce cenotaph
casey Mar 22, 2024
6030407
Merge remote-tracking branch 'upstream/master' into misc
casey Mar 22, 2024
3bf1646
Merge remote-tracking branch 'upstream/master' into misc
casey Mar 22, 2024
0bddc83
Merge remote-tracking branch 'upstream/master' into misc
casey Mar 22, 2024
db3bf88
Add partial claim test
casey Mar 22, 2024
1ee0d8d
Fix bug
casey Mar 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/index/updater.rs
Original file line number Diff line number Diff line change
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
Loading
Loading