From 3d8d21a44ff118cf0669513c779feb7aefc7480f Mon Sep 17 00:00:00 2001 From: Brady Ouren Date: Wed, 17 Jul 2024 18:01:36 -0700 Subject: [PATCH] Add cenotaph column to runes (#33) * add cenotaph column to runes table * add cenotaph to existing mig * add cenotaph to api --------- Co-authored-by: brady.ouren --- api/src/api/util/helpers.ts | 1 + api/src/pg/types.ts | 1 + migrations/V1__runes.sql | 1 + src/db/cache/transaction_cache.rs | 28 +++++++++++++++------------- src/db/cache/utils.rs | 3 +++ src/db/models/db_rune.rs | 5 +++++ 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/api/src/api/util/helpers.ts b/api/src/api/util/helpers.ts index a73351e..547e453 100644 --- a/api/src/api/util/helpers.ts +++ b/api/src/api/util/helpers.ts @@ -14,6 +14,7 @@ export function parseEtchingResponse(rune: DbRuneWithChainTip): EtchingResponse const total_burns = rune.total_burns == null ? '0' : rune.total_burns; if ( rune.terms_amount == null || + rune.cenotaph || (rune.terms_cap && BigNumber(total_mints).gte(rune.terms_cap)) || (rune.terms_height_start && BigNumber(rune.chain_tip).lt(rune.terms_height_start)) || (rune.terms_height_end && BigNumber(rune.chain_tip).gt(rune.terms_height_end)) || diff --git a/api/src/pg/types.ts b/api/src/pg/types.ts index bf7a678..ce058c4 100644 --- a/api/src/pg/types.ts +++ b/api/src/pg/types.ts @@ -17,6 +17,7 @@ type DbRune = { divisibility: number; premine: string; symbol: string; + cenotaph: boolean; terms_amount: string | null; terms_cap: string | null; terms_height_start: string | null; diff --git a/migrations/V1__runes.sql b/migrations/V1__runes.sql index e965e6a..92e70c4 100644 --- a/migrations/V1__runes.sql +++ b/migrations/V1__runes.sql @@ -17,6 +17,7 @@ CREATE TABLE IF NOT EXISTS runes ( terms_offset_start NUMERIC, terms_offset_end NUMERIC, turbo BOOLEAN NOT NULL DEFAULT FALSE, + cenotaph BOOLEAN NOT NULL DEFAULT FALSE, timestamp BIGINT NOT NULL ); diff --git a/src/db/cache/transaction_cache.rs b/src/db/cache/transaction_cache.rs index 8ab1074..74c34d9 100644 --- a/src/db/cache/transaction_cache.rs +++ b/src/db/cache/transaction_cache.rs @@ -412,7 +412,10 @@ mod test { use ordinals::{Edict, Etching, Rune, Terms}; use crate::db::{ - cache::{input_rune_balance::InputRuneBalance, transaction_location::TransactionLocation}, + cache::{ + input_rune_balance::InputRuneBalance, transaction_location::TransactionLocation, + utils::is_rune_mintable, + }, models::{db_ledger_operation::DbLedgerOperation, db_rune::DbRune}, }; @@ -450,22 +453,21 @@ mod test { #[test] // TODO add cenotaph field to DbRune before filling this in fn etches_cenotaph_rune() { - // let location = TransactionLocation::dummy(); - // let mut cache = TransactionCache::empty(location.clone()); + let location = TransactionLocation::dummy(); + let mut cache = TransactionCache::empty(location.clone()); - // // Create a cenotaph rune - // let rune = Rune::reserved(location.block_height, location.tx_index); - // let number = 2; + // Create a cenotaph rune + let rune = Rune::reserved(location.block_height, location.tx_index); + let number = 2; - // let (_rune_id, db_rune, db_ledger_entry) = cache.apply_cenotaph_etching(&rune, number); + let (_rune_id, db_rune, db_ledger_entry) = cache.apply_cenotaph_etching(&rune, number); // // the etched rune has supply zero and is unmintable. - // // is_rune_mintable should have a cenotaph indicator column check - // assert_eq!(is_rune_mintable(&db_rune, 0, &location), false); - // assert_eq!(db_ledger_entry.amount, None); - // assert_eq!(db_rune.id, "840000:0"); - // assert_eq!(db_ledger_entry.operation, DbLedgerOperation::Etching); - // assert_eq!(db_ledger_entry.rune_id, "840000:0"); + assert_eq!(is_rune_mintable(&db_rune, 0, &location), false); + assert_eq!(db_ledger_entry.amount, None); + assert_eq!(db_rune.id, "840000:0"); + assert_eq!(db_ledger_entry.operation, DbLedgerOperation::Etching); + assert_eq!(db_ledger_entry.rune_id, "840000:0"); } #[test] diff --git a/src/db/cache/utils.rs b/src/db/cache/utils.rs index e4cdaec..fe13d0d 100644 --- a/src/db/cache/utils.rs +++ b/src/db/cache/utils.rs @@ -276,6 +276,9 @@ pub fn is_rune_mintable( total_mints: u128, location: &TransactionLocation, ) -> bool { + if db_rune.cenotaph { + return false; + } if db_rune.terms_amount.is_none() { return false; } diff --git a/src/db/models/db_rune.rs b/src/db/models/db_rune.rs index 84bd3be..561ed05 100644 --- a/src/db/models/db_rune.rs +++ b/src/db/models/db_rune.rs @@ -30,6 +30,7 @@ pub struct DbRune { pub terms_offset_start: Option, pub terms_offset_end: Option, pub turbo: bool, + pub cenotaph: bool, pub timestamp: PgBigIntU32, } @@ -87,6 +88,7 @@ impl DbRune { terms_offset_start, terms_offset_end, turbo: etching.turbo, + cenotaph: false, timestamp: PgBigIntU32(location.timestamp), } } @@ -111,6 +113,7 @@ impl DbRune { terms_offset_start: None, terms_offset_end: None, turbo: false, + cenotaph: true, timestamp: PgBigIntU32(location.timestamp), } } @@ -135,6 +138,7 @@ impl DbRune { terms_offset_start: row.get("terms_offset_start"), terms_offset_end: row.get("terms_offset_end"), turbo: row.get("turbo"), + cenotaph: row.get("cenotaph"), timestamp: row.get("timestamp"), } } @@ -170,6 +174,7 @@ impl DbRune { terms_offset_start: None, terms_offset_end: None, turbo: true, + cenotaph: false, timestamp: PgBigIntU32(1713571767), } }