Skip to content

Commit

Permalink
Always create rune, even if none were allocated (#2543)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Oct 15, 2023
1 parent 722d11e commit fd7cc20
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
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

0 comments on commit fd7cc20

Please sign in to comment.