Skip to content

Commit

Permalink
Add cenotaph column to runes (#33)
Browse files Browse the repository at this point in the history
* add cenotaph column to runes table

* add cenotaph to existing mig

* add cenotaph to api

---------

Co-authored-by: brady.ouren <[email protected]>
  • Loading branch information
tippenein and brady.ouren authored Jul 18, 2024
1 parent 14c69f8 commit 3d8d21a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions api/src/api/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) ||
Expand Down
1 change: 1 addition & 0 deletions api/src/pg/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions migrations/V1__runes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
28 changes: 15 additions & 13 deletions src/db/cache/transaction_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand Down Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions src/db/cache/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions src/db/models/db_rune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct DbRune {
pub terms_offset_start: Option<PgNumericU64>,
pub terms_offset_end: Option<PgNumericU64>,
pub turbo: bool,
pub cenotaph: bool,
pub timestamp: PgBigIntU32,
}

Expand Down Expand Up @@ -87,6 +88,7 @@ impl DbRune {
terms_offset_start,
terms_offset_end,
turbo: etching.turbo,
cenotaph: false,
timestamp: PgBigIntU32(location.timestamp),
}
}
Expand All @@ -111,6 +113,7 @@ impl DbRune {
terms_offset_start: None,
terms_offset_end: None,
turbo: false,
cenotaph: true,
timestamp: PgBigIntU32(location.timestamp),
}
}
Expand All @@ -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"),
}
}
Expand Down Expand Up @@ -170,6 +174,7 @@ impl DbRune {
terms_offset_start: None,
terms_offset_end: None,
turbo: true,
cenotaph: false,
timestamp: PgBigIntU32(1713571767),
}
}
Expand Down

0 comments on commit 3d8d21a

Please sign in to comment.