Skip to content

Commit

Permalink
Revert "Allow supply-capped mints (ordinals#3365)"
Browse files Browse the repository at this point in the history
This reverts commit 293a8ea.
  • Loading branch information
harutyunaraci committed Apr 2, 2024
1 parent 7608e8a commit 118bce5
Show file tree
Hide file tree
Showing 26 changed files with 339 additions and 951 deletions.
2 changes: 1 addition & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mod updater;
#[cfg(test)]
pub(crate) mod testing;

const SCHEMA_VERSION: u64 = 23;
const SCHEMA_VERSION: u64 = 22;

macro_rules! define_table {
($name:ident, $key:ty, $value:ty) => {
Expand Down
212 changes: 17 additions & 195 deletions src/index/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,51 +34,34 @@ pub struct RuneEntry {
pub divisibility: u8,
pub etching: Txid,
pub mint: Option<MintEntry>,
pub mints: u128,
pub mints: u64,
pub number: u64,
pub premine: u128,
pub spaced_rune: SpacedRune,
pub supply: u128,
pub symbol: Option<char>,
pub timestamp: u32,
}

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);
return Err(MintError::Unmintable(self.spaced_rune.rune));
};

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

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

let cap = mint.cap.unwrap_or_default();

if self.mints >= cap {
return Err(MintError::Cap(cap));
}

Ok(mint.limit.unwrap_or_default())
}

pub fn supply(&self) -> u128 {
self.premine + self.mints * self.mint.and_then(|mint| mint.limit).unwrap_or_default()
}

pub fn pile(&self, amount: u128) -> Pile {
Pile {
amount,
divisibility: self.divisibility,
symbol: self.symbol,
}
Ok(mint.limit.unwrap_or(runes::MAX_LIMIT))
}
}

Expand All @@ -87,24 +70,23 @@ pub(super) type RuneEntryValue = (
u8, // divisibility
(u128, u128), // etching
Option<MintEntryValue>, // mint parameters
u128, // mints
u64, // mints
u64, // number
u128, // premine
(u128, u32), // spaced rune
u128, // supply
Option<char>, // symbol
u32, // timestamp
);

#[derive(Debug, PartialEq, Copy, Clone, Serialize, Deserialize, Default)]
pub struct MintEntry {
pub cap: Option<u128>, // mint cap
pub deadline: Option<u32>, // unix timestamp
pub end: Option<u32>, // block height
pub limit: Option<u128>, // claim amount
}

type MintEntryValue = (
Option<u128>, // cap
Option<u32>, // deadline
Option<u32>, // end
Option<u128>, // limit
Expand All @@ -121,6 +103,7 @@ impl Default for RuneEntry {
number: 0,
premine: 0,
spaced_rune: SpacedRune::default(),
supply: 0,
symbol: None,
timestamp: 0,
}
Expand All @@ -140,6 +123,7 @@ impl Entry for RuneEntry {
number,
premine,
(rune, spacers),
supply,
symbol,
timestamp,
): RuneEntryValue,
Expand All @@ -157,8 +141,7 @@ impl Entry for RuneEntry {
high[14], high[15],
])
},
mint: mint.map(|(cap, deadline, end, limit)| MintEntry {
cap,
mint: mint.map(|(deadline, end, limit)| MintEntry {
deadline,
end,
limit,
Expand All @@ -170,6 +153,7 @@ impl Entry for RuneEntry {
rune: Rune(rune),
spacers,
},
supply,
symbol,
timestamp,
}
Expand All @@ -194,16 +178,16 @@ impl Entry for RuneEntry {
},
self.mint.map(
|MintEntry {
cap,
deadline,
end,
limit,
}| (cap, deadline, end, limit),
}| (deadline, end, limit),
),
self.mints,
self.number,
self.premine,
(self.spaced_rune.rune.0, self.spaced_rune.spacers),
self.supply,
self.symbol,
self.timestamp,
)
Expand Down Expand Up @@ -508,7 +492,6 @@ mod tests {
0x1E, 0x1F,
]),
mint: Some(MintEntry {
cap: Some(1),
deadline: Some(2),
end: Some(4),
limit: Some(5),
Expand All @@ -520,6 +503,7 @@ mod tests {
rune: Rune(7),
spacers: 8,
},
supply: 9,
symbol: Some('a'),
timestamp: 10,
};
Expand All @@ -531,11 +515,12 @@ mod tests {
0x0F0E0D0C0B0A09080706050403020100,
0x1F1E1D1C1B1A19181716151413121110,
),
Some((Some(1), Some(2), Some(4), Some(5))),
Some((Some(2), Some(4), Some(5))),
11,
6,
12,
(7, 8),
9,
Some('a'),
10,
);
Expand Down Expand Up @@ -565,167 +550,4 @@ mod tests {

assert_eq!(actual, expected);
}

#[test]
fn mintable() {
assert_eq!(
RuneEntry::default().mintable(Height(0), 0),
Err(MintError::Unmintable)
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
end: Some(1),
limit: Some(1000),
cap: Some(1),
..default()
}),
..default()
}
.mintable(Height(0), 0),
Ok(1000),
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
end: Some(1),
limit: Some(1000),
cap: Some(1),
..default()
}),
..default()
}
.mintable(Height(1), 0),
Err(MintError::End(1)),
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
deadline: Some(1),
limit: Some(1000),
cap: Some(1),
..default()
}),
..default()
}
.mintable(Height(0), 0),
Ok(1000),
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
deadline: Some(1),
limit: Some(1000),
cap: Some(1),
..default()
}),
..default()
}
.mintable(Height(0), 1),
Err(MintError::Deadline(1)),
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
cap: Some(1),
limit: Some(1000),
..default()
}),
mints: 0,
..default()
}
.mintable(Height(0), 0),
Ok(1000),
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
cap: Some(1),
limit: Some(1000),
..default()
}),
mints: 1,
..default()
}
.mintable(Height(0), 0),
Err(MintError::Cap(1)),
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
cap: None,
limit: Some(1000),
..default()
}),
mints: 0,
..default()
}
.mintable(Height(0), 0),
Err(MintError::Cap(0)),
);
}

#[test]
fn supply() {
assert_eq!(
RuneEntry {
mint: Some(MintEntry {
limit: Some(1000),
..default()
}),
mints: 0,
..default()
}
.supply(),
0
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
limit: Some(1000),
..default()
}),
mints: 1,
..default()
}
.supply(),
1000
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
limit: Some(1000),
..default()
}),
mints: 0,
premine: 1,
..default()
}
.supply(),
1
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
limit: Some(1000),
..default()
}),
mints: 1,
premine: 1,
..default()
}
.supply(),
1001
);
}
}
2 changes: 1 addition & 1 deletion src/index/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl Context {
for (id, entry) in runes {
pretty_assert_eq!(
outstanding.get(id).copied().unwrap_or_default(),
entry.supply() - entry.burned
entry.supply - entry.burned
);
}
}
Expand Down
19 changes: 16 additions & 3 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,6 @@ impl<'index> Updater<'index> {
.unwrap_or(0);

let mut rune_updater = RuneUpdater {
block_time: block.header.time,
burned: HashMap::new(),
client: &self.index.client,
height: self.height,
id_to_entry: &mut rune_id_to_rune_entry,
Expand All @@ -603,14 +601,29 @@ impl<'index> Updater<'index> {
runes,
sequence_number_to_rune_id: &mut sequence_number_to_rune_id,
statistic_to_count: &mut statistic_to_count,
block_time: block.header.time,
transaction_id_to_rune: &mut transaction_id_to_rune,
updates: HashMap::new(),
};

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

rune_updater.update()?;
for (rune_id, update) in rune_updater.updates {
let mut entry = RuneEntry::load(
rune_id_to_rune_entry
.get(&rune_id.store())?
.unwrap()
.value(),
);

entry.burned += update.burned;
entry.mints += update.mints;
entry.supply += update.supply;

rune_id_to_rune_entry.insert(&rune_id.store(), entry.store())?;
}
}

height_to_block_header.insert(&self.height, &block.header.store())?;
Expand Down
Loading

0 comments on commit 118bce5

Please sign in to comment.