Skip to content

Commit

Permalink
Terms::limit → Terms::amount (ordinals#3383)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored and harutyunaraci committed Mar 30, 2024
1 parent 0d521d0 commit e7d3282
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 133 deletions.
53 changes: 29 additions & 24 deletions src/index/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,16 @@ impl RuneEntry {
return Err(MintError::Cap(cap));
}

Ok(terms.limit.unwrap_or_default())
Ok(terms.amount.unwrap_or_default())
}

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

pub fn pile(&self, amount: u128) -> Pile {
Expand Down Expand Up @@ -120,7 +125,7 @@ impl RuneEntry {
type TermsEntryValue = (
Option<u128>, // cap
(Option<u64>, Option<u64>), // height
Option<u128>, // limit
Option<u128>, // amount
(Option<u64>, Option<u64>), // offset
);

Expand Down Expand Up @@ -196,10 +201,10 @@ impl Entry for RuneEntry {
spacers,
},
symbol,
terms: terms.map(|(cap, height, limit, offset)| Terms {
terms: terms.map(|(cap, height, amount, offset)| Terms {
cap,
height,
limit,
amount,
offset,
}),
timestamp,
Expand Down Expand Up @@ -233,9 +238,9 @@ impl Entry for RuneEntry {
|Terms {
cap,
height,
limit,
amount,
offset,
}| (cap, height, limit, offset),
}| (cap, height, amount, offset),
),
self.timestamp,
)
Expand Down Expand Up @@ -543,7 +548,7 @@ mod tests {
terms: Some(Terms {
cap: Some(1),
height: (Some(2), Some(3)),
limit: Some(4),
amount: Some(4),
offset: (Some(5), Some(6)),
}),
mints: 11,
Expand Down Expand Up @@ -611,7 +616,7 @@ mod tests {
RuneEntry {
terms: Some(Terms {
cap: Some(1),
limit: Some(1000),
amount: Some(1000),
..default()
}),
mints: 0,
Expand All @@ -625,7 +630,7 @@ mod tests {
RuneEntry {
terms: Some(Terms {
cap: Some(1),
limit: Some(1000),
amount: Some(1000),
..default()
}),
mints: 1,
Expand All @@ -639,7 +644,7 @@ mod tests {
RuneEntry {
terms: Some(Terms {
cap: None,
limit: Some(1000),
amount: Some(1000),
..default()
}),
mints: 0,
Expand All @@ -657,7 +662,7 @@ mod tests {
block: 1,
terms: Some(Terms {
cap: Some(1),
limit: Some(1000),
amount: Some(1000),
offset: (Some(1), None),
..default()
}),
Expand All @@ -673,7 +678,7 @@ mod tests {
block: 1,
terms: Some(Terms {
cap: Some(1),
limit: Some(1000),
amount: Some(1000),
offset: (Some(1), None),
..default()
}),
Expand All @@ -692,7 +697,7 @@ mod tests {
block: 1,
terms: Some(Terms {
cap: Some(1),
limit: Some(1000),
amount: Some(1000),
offset: (None, Some(1)),
..default()
}),
Expand All @@ -708,7 +713,7 @@ mod tests {
block: 1,
terms: Some(Terms {
cap: Some(1),
limit: Some(1000),
amount: Some(1000),
offset: (None, Some(1)),
..default()
}),
Expand All @@ -726,7 +731,7 @@ mod tests {
RuneEntry {
terms: Some(Terms {
cap: Some(1),
limit: Some(1000),
amount: Some(1000),
height: (Some(1), None),
..default()
}),
Expand All @@ -741,7 +746,7 @@ mod tests {
RuneEntry {
terms: Some(Terms {
cap: Some(1),
limit: Some(1000),
amount: Some(1000),
height: (Some(1), None),
..default()
}),
Expand All @@ -759,7 +764,7 @@ mod tests {
RuneEntry {
terms: Some(Terms {
cap: Some(1),
limit: Some(1000),
amount: Some(1000),
height: (None, Some(1)),
..default()
}),
Expand All @@ -774,7 +779,7 @@ mod tests {
RuneEntry {
terms: Some(Terms {
cap: Some(1),
limit: Some(1000),
amount: Some(1000),
height: (None, Some(1)),
..default()
}),
Expand All @@ -791,7 +796,7 @@ mod tests {
let entry = RuneEntry {
terms: Some(Terms {
cap: Some(1),
limit: Some(1000),
amount: Some(1000),
height: (Some(10), Some(20)),
offset: (Some(0), Some(10)),
}),
Expand Down Expand Up @@ -838,7 +843,7 @@ mod tests {
assert_eq!(
RuneEntry {
terms: Some(Terms {
limit: Some(1000),
amount: Some(1000),
..default()
}),
mints: 0,
Expand All @@ -851,7 +856,7 @@ mod tests {
assert_eq!(
RuneEntry {
terms: Some(Terms {
limit: Some(1000),
amount: Some(1000),
..default()
}),
mints: 1,
Expand All @@ -864,7 +869,7 @@ mod tests {
assert_eq!(
RuneEntry {
terms: Some(Terms {
limit: Some(1000),
amount: Some(1000),
..default()
}),
mints: 0,
Expand All @@ -878,7 +883,7 @@ mod tests {
assert_eq!(
RuneEntry {
terms: Some(Terms {
limit: Some(1000),
amount: Some(1000),
..default()
}),
mints: 1,
Expand Down
8 changes: 4 additions & 4 deletions src/index/updater/rune_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {

struct Mint {
id: RuneId,
limit: u128,
amount: u128,
}

struct Etched {
Expand Down Expand Up @@ -54,7 +54,7 @@ impl<'a, 'tx, 'client> RuneUpdater<'a, 'tx, 'client> {
.and_then(|id| self.mint(id).transpose())
.transpose()?
{
*unallocated.entry(mint.id).or_default() += mint.limit;
*unallocated.entry(mint.id).or_default() += mint.amount;
}

let etched = self.etched(tx_index, tx, &runestone)?;
Expand Down Expand Up @@ -337,7 +337,7 @@ impl<'a, 'tx, 'client> RuneUpdater<'a, 'tx, 'client> {

let mut rune_entry = RuneEntry::load(entry.value());

let Ok(limit) = rune_entry.mintable(self.height.into()) else {
let Ok(amount) = rune_entry.mintable(self.height.into()) else {
return Ok(None);
};

Expand All @@ -347,7 +347,7 @@ impl<'a, 'tx, 'client> RuneUpdater<'a, 'tx, 'client> {

self.id_to_entry.insert(&id.store(), rune_entry.store())?;

Ok(Some(Mint { id, limit }))
Ok(Some(Mint { id, amount }))
}

fn tx_commits_to_rune(&self, tx: &Transaction, rune: Rune) -> Result<bool> {
Expand Down
Loading

0 comments on commit e7d3282

Please sign in to comment.