Skip to content

Commit

Permalink
fix: consider mint terms block height
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Jun 29, 2024
1 parent 909b59e commit 97263a1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/db/cache/index_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ impl IndexCache {
db_tx: &mut Transaction<'_>,
ctx: &Context,
) {
debug!(ctx.expect_logger(), "Cenotaph {}", self.tx_cache.location);
debug!(
ctx.expect_logger(),
"{:?} {}", cenotaph, self.tx_cache.location
);
self.scan_tx_input_rune_balance(tx_inputs, db_tx, ctx).await;
let entries = self.tx_cache.apply_cenotaph_input_burn(cenotaph);
self.add_ledger_entries_to_db_cache(&entries);
Expand Down
59 changes: 43 additions & 16 deletions src/db/cache/transaction_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,12 @@ impl TransactionCache {
) -> Option<DbLedgerEntry> {
// TODO: What's the default mint amount if none was provided?
let terms_amount = db_rune.terms_amount.unwrap_or(PgNumericU128(0));
if let Some(terms_cap) = db_rune.terms_cap {
if total_mints >= terms_cap.0 {
debug!(
ctx.expect_logger(),
"Mint {} exceeds mint cap, ignoring {}", rune_id, self.location
);
return None;
}
if !is_valid_mint(db_rune, total_mints, &self.location) {
debug!(
ctx.expect_logger(),
"Invalid mint {} {}", rune_id, self.location
);
return None;
}
info!(
ctx.expect_logger(),
Expand Down Expand Up @@ -280,14 +278,12 @@ impl TransactionCache {
) -> Option<DbLedgerEntry> {
// TODO: What's the default mint amount if none was provided?
let terms_amount = db_rune.terms_amount.unwrap_or(PgNumericU128(0));
if let Some(terms_cap) = db_rune.terms_cap {
if total_mints >= terms_cap.0 {
debug!(
ctx.expect_logger(),
"Cenotaph mint {} exceeds mint cap, ignoring {}", rune_id, self.location
);
return None;
}
if !is_valid_mint(db_rune, total_mints, &self.location) {
debug!(
ctx.expect_logger(),
"Invalid mint {} {}", rune_id, self.location
);
return None;
}
info!(
ctx.expect_logger(),
Expand Down Expand Up @@ -452,6 +448,37 @@ impl TransactionCache {
}
}

/// Determines if a mint is valid depending on the rune's mint terms.
fn is_valid_mint(db_rune: &DbRune, total_mints: u128, location: &TransactionLocation) -> bool {
if let Some(terms_cap) = db_rune.terms_cap {
if total_mints >= terms_cap.0 {
return false;
}
}
if let Some(terms_height_start) = db_rune.terms_height_start {
if location.block_height < terms_height_start.0 {
return false;
}
}
if let Some(terms_height_end) = db_rune.terms_height_end {
if location.block_height > terms_height_end.0 {
return false;
}
}
if let Some(terms_offset_start) = db_rune.terms_offset_start {
if location.block_height < db_rune.block_height.0 + terms_offset_start.0 {
return false;
}
}
if let Some(terms_offset_end) = db_rune.terms_offset_end {
if location.block_height > db_rune.block_height.0 + terms_offset_end.0 {
return false;
}
}
true
}

/// Creates a new ledger entry.
fn new_ledger_entry(
location: &TransactionLocation,
amount: u128,
Expand Down

0 comments on commit 97263a1

Please sign in to comment.