Skip to content

Commit

Permalink
Seed index with genesis rune (#3426)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Mar 31, 2024
1 parent 5e3420c commit e26b226
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: id.block,
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
Expand Down
43 changes: 43 additions & 0 deletions src/runes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5386,4 +5386,47 @@ mod tests {

context.assert_runes([], []);
}

#[test]
fn genesis_rune() {
assert_eq!(
Chain::Mainnet.first_rune_height(),
SUBSIDY_HALVING_INTERVAL * 4,
);

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,
},
)],
[],
);
}
}

0 comments on commit e26b226

Please sign in to comment.