Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cenotaph column to runes #33

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
const total_burns = rune.total_burns == null ? '0' : rune.total_burns;
if (
rune.terms_amount == null ||
rune.cenotaph ||

Check warning on line 17 in api/src/api/util/helpers.ts

View check run for this annotation

Codecov / codecov/patch

api/src/api/util/helpers.ts#L17

Added line #L17 was not covered by tests
(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 @@
divisibility: number;
premine: string;
symbol: string;
cenotaph: boolean;

Check warning on line 20 in api/src/pg/types.ts

View check run for this annotation

Codecov / codecov/patch

api/src/pg/types.ts#L20

Added line #L20 was not covered by tests
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 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 @@
terms_offset_start,
terms_offset_end,
turbo: etching.turbo,
cenotaph: false,
timestamp: PgBigIntU32(location.timestamp),
}
}
Expand All @@ -111,6 +113,7 @@
terms_offset_start: None,
terms_offset_end: None,
turbo: false,
cenotaph: true,
timestamp: PgBigIntU32(location.timestamp),
}
}
Expand All @@ -135,6 +138,7 @@
terms_offset_start: row.get("terms_offset_start"),
terms_offset_end: row.get("terms_offset_end"),
turbo: row.get("turbo"),
cenotaph: row.get("cenotaph"),

Check warning on line 141 in src/db/models/db_rune.rs

View check run for this annotation

Codecov / codecov/patch

src/db/models/db_rune.rs#L141

Added line #L141 was not covered by tests
timestamp: row.get("timestamp"),
}
}
Expand Down Expand Up @@ -170,6 +174,7 @@
terms_offset_start: None,
terms_offset_end: None,
turbo: true,
cenotaph: false,
timestamp: PgBigIntU32(1713571767),
}
}
Expand Down
Loading