Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Commit 97263a1

Browse files
committed
fix: consider mint terms block height
1 parent 909b59e commit 97263a1

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

src/db/cache/index_cache.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ impl IndexCache {
107107
db_tx: &mut Transaction<'_>,
108108
ctx: &Context,
109109
) {
110-
debug!(ctx.expect_logger(), "Cenotaph {}", self.tx_cache.location);
110+
debug!(
111+
ctx.expect_logger(),
112+
"{:?} {}", cenotaph, self.tx_cache.location
113+
);
111114
self.scan_tx_input_rune_balance(tx_inputs, db_tx, ctx).await;
112115
let entries = self.tx_cache.apply_cenotaph_input_burn(cenotaph);
113116
self.add_ledger_entries_to_db_cache(&entries);

src/db/cache/transaction_cache.rs

+43-16
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,12 @@ impl TransactionCache {
239239
) -> Option<DbLedgerEntry> {
240240
// TODO: What's the default mint amount if none was provided?
241241
let terms_amount = db_rune.terms_amount.unwrap_or(PgNumericU128(0));
242-
if let Some(terms_cap) = db_rune.terms_cap {
243-
if total_mints >= terms_cap.0 {
244-
debug!(
245-
ctx.expect_logger(),
246-
"Mint {} exceeds mint cap, ignoring {}", rune_id, self.location
247-
);
248-
return None;
249-
}
242+
if !is_valid_mint(db_rune, total_mints, &self.location) {
243+
debug!(
244+
ctx.expect_logger(),
245+
"Invalid mint {} {}", rune_id, self.location
246+
);
247+
return None;
250248
}
251249
info!(
252250
ctx.expect_logger(),
@@ -280,14 +278,12 @@ impl TransactionCache {
280278
) -> Option<DbLedgerEntry> {
281279
// TODO: What's the default mint amount if none was provided?
282280
let terms_amount = db_rune.terms_amount.unwrap_or(PgNumericU128(0));
283-
if let Some(terms_cap) = db_rune.terms_cap {
284-
if total_mints >= terms_cap.0 {
285-
debug!(
286-
ctx.expect_logger(),
287-
"Cenotaph mint {} exceeds mint cap, ignoring {}", rune_id, self.location
288-
);
289-
return None;
290-
}
281+
if !is_valid_mint(db_rune, total_mints, &self.location) {
282+
debug!(
283+
ctx.expect_logger(),
284+
"Invalid mint {} {}", rune_id, self.location
285+
);
286+
return None;
291287
}
292288
info!(
293289
ctx.expect_logger(),
@@ -452,6 +448,37 @@ impl TransactionCache {
452448
}
453449
}
454450

451+
/// Determines if a mint is valid depending on the rune's mint terms.
452+
fn is_valid_mint(db_rune: &DbRune, total_mints: u128, location: &TransactionLocation) -> bool {
453+
if let Some(terms_cap) = db_rune.terms_cap {
454+
if total_mints >= terms_cap.0 {
455+
return false;
456+
}
457+
}
458+
if let Some(terms_height_start) = db_rune.terms_height_start {
459+
if location.block_height < terms_height_start.0 {
460+
return false;
461+
}
462+
}
463+
if let Some(terms_height_end) = db_rune.terms_height_end {
464+
if location.block_height > terms_height_end.0 {
465+
return false;
466+
}
467+
}
468+
if let Some(terms_offset_start) = db_rune.terms_offset_start {
469+
if location.block_height < db_rune.block_height.0 + terms_offset_start.0 {
470+
return false;
471+
}
472+
}
473+
if let Some(terms_offset_end) = db_rune.terms_offset_end {
474+
if location.block_height > db_rune.block_height.0 + terms_offset_end.0 {
475+
return false;
476+
}
477+
}
478+
true
479+
}
480+
481+
/// Creates a new ledger entry.
455482
fn new_ledger_entry(
456483
location: &TransactionLocation,
457484
amount: u128,

0 commit comments

Comments
 (0)