@@ -239,14 +239,12 @@ impl TransactionCache {
239
239
) -> Option < DbLedgerEntry > {
240
240
// TODO: What's the default mint amount if none was provided?
241
241
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 ;
250
248
}
251
249
info ! (
252
250
ctx. expect_logger( ) ,
@@ -280,14 +278,12 @@ impl TransactionCache {
280
278
) -> Option < DbLedgerEntry > {
281
279
// TODO: What's the default mint amount if none was provided?
282
280
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 ;
291
287
}
292
288
info ! (
293
289
ctx. expect_logger( ) ,
@@ -452,6 +448,37 @@ impl TransactionCache {
452
448
}
453
449
}
454
450
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.
455
482
fn new_ledger_entry (
456
483
location : & TransactionLocation ,
457
484
amount : u128 ,
0 commit comments