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

Always create rune, even if none were allocated #2543

Merged
merged 2 commits into from
Oct 15, 2023
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
34 changes: 14 additions & 20 deletions src/index/updater/rune_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,20 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {
symbol,
}) = allocation
{
// Calculate the allocated supply
let supply = u128::max_value() - balance;

// If no runes were allocated, ignore this issuance
if supply > 0 {
let id = RuneId::try_from(id).unwrap();
self.rune_to_id.insert(rune.0, id.store())?;
self.id_to_entry.insert(
id.store(),
RuneEntry {
burned: 0,
divisibility,
etching: txid,
rune,
supply,
symbol,
}
.store(),
)?;
}
let id = RuneId::try_from(id).unwrap();
self.rune_to_id.insert(rune.0, id.store())?;
self.id_to_entry.insert(
id.store(),
RuneEntry {
burned: 0,
divisibility,
etching: txid,
rune,
supply: u128::max_value() - balance,
symbol,
}
.store(),
)?;
}
}

Expand Down
25 changes: 22 additions & 3 deletions src/runes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ mod tests {
}

#[test]
fn etching_with_no_edicts_does_not_create_rune() {
fn etching_with_no_edicts_creates_rune() {
let context = Context::builder()
.arg("--index-runes-pre-alpha-i-agree-to-get-rekt")
.build();

context.mine_blocks(1);

context.rpc_server.broadcast_tx(TransactionTemplate {
let txid = context.rpc_server.broadcast_tx(TransactionTemplate {
inputs: &[(1, 0, 0, Witness::new())],
op_return: Some(
Runestone {
Expand All @@ -102,7 +102,26 @@ mod tests {

context.mine_blocks(1);

assert_eq!(context.index.runes().unwrap().unwrap(), []);
let id = RuneId {
height: 2,
index: 1,
};

assert_eq!(
context.index.runes().unwrap().unwrap(),
[(
id,
RuneEntry {
burned: 0,
divisibility: 0,
etching: txid,
rune: Rune(RUNE),
supply: 0,
symbol: None,
}
)]
);

assert_eq!(context.index.get_rune_balances(), []);
}

Expand Down