From 59915f6e4b283324e0f70c4923285a7f94da4ebc Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 31 Mar 2024 01:00:09 -0700 Subject: [PATCH 1/3] Seed index with genesis rune --- src/index.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ src/runes.rs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/src/index.rs b/src/index.rs index af13f9dbb9..f4b2662533 100644 --- a/src/index.rs +++ b/src/index.rs @@ -377,6 +377,49 @@ impl Index { Self::set_statistic(&mut statistics, Statistic::Schema, SCHEMA_VERSION)?; } + if settings.index_runes() && settings.chain() == Chain::Mainnet { + let rune = Rune(2055900680524219742); + + let id = RuneId { block: 1, tx: 0 }; + let etching = Txid::all_zeros(); + + tx.open_table(RUNE_TO_RUNE_ID)? + .insert(rune.store(), id.store())?; + + let mut statistics = tx.open_table(STATISTIC_TO_COUNT)?; + + Self::set_statistic(&mut statistics, Statistic::Runes, 1)?; + + tx.open_table(RUNE_ID_TO_RUNE_ENTRY)?.insert( + id.store(), + RuneEntry { + block: 1, + burned: 0, + divisibility: 0, + etching, + terms: Some(Terms { + amount: Some(1), + cap: Some(u128::MAX), + height: ( + Some((SUBSIDY_HALVING_INTERVAL * 4).into()), + Some((SUBSIDY_HALVING_INTERVAL * 5).into()), + ), + offset: (None, None), + }), + mints: 0, + number: 0, + premine: 0, + spaced_rune: SpacedRune { rune, spacers: 128 }, + symbol: Some('\u{29C9}'), + timestamp: 0, + } + .store(), + )?; + + tx.open_table(TRANSACTION_ID_TO_RUNE)? + .insert(&etching.store(), rune.store())?; + } + tx.commit()?; database diff --git a/src/runes.rs b/src/runes.rs index 5d4664c33f..1f1023e530 100644 --- a/src/runes.rs +++ b/src/runes.rs @@ -5386,4 +5386,42 @@ mod tests { context.assert_runes([], []); } + + #[test] + fn genesis_rune() { + Context::builder() + .chain(Chain::Mainnet) + .arg("--index-runes") + .build() + .assert_runes( + [( + RuneId { block: 1, tx: 0 }, + RuneEntry { + block: 1, + burned: 0, + divisibility: 0, + etching: Txid::all_zeros(), + mints: 0, + number: 0, + premine: 0, + spaced_rune: SpacedRune { + rune: Rune(2055900680524219742), + spacers: 128, + }, + symbol: Some('\u{29C9}'), + terms: Some(Terms { + amount: Some(1), + cap: Some(u128::MAX), + height: ( + Some((SUBSIDY_HALVING_INTERVAL * 4).into()), + Some((SUBSIDY_HALVING_INTERVAL * 5).into()), + ), + offset: (None, None), + }), + timestamp: 0, + }, + )], + [], + ); + } } From 395d7049bdbbbc3efb4f788dfe776440425561bc Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 31 Mar 2024 01:24:42 -0700 Subject: [PATCH 2/3] Assert start height is correct --- src/runes.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/runes.rs b/src/runes.rs index 1f1023e530..3919273fb3 100644 --- a/src/runes.rs +++ b/src/runes.rs @@ -5389,6 +5389,11 @@ mod tests { #[test] fn genesis_rune() { + assert_eq!( + Chain::Mainnet.first_rune_height(), + SUBSIDY_HALVING_INTERVAL * 4, + ); + Context::builder() .chain(Chain::Mainnet) .arg("--index-runes") From 6a55ec6e8d4fd70039fd5589837572762ccc44f3 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 31 Mar 2024 01:41:11 -0700 Subject: [PATCH 3/3] Modify --- src/index.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.rs b/src/index.rs index f4b2662533..4b5aaeec66 100644 --- a/src/index.rs +++ b/src/index.rs @@ -393,7 +393,7 @@ impl Index { tx.open_table(RUNE_ID_TO_RUNE_ENTRY)?.insert( id.store(), RuneEntry { - block: 1, + block: id.block, burned: 0, divisibility: 0, etching,