Skip to content

Commit

Permalink
Allow premining with open etchings (#3311)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph authored Mar 18, 2024
1 parent 17ed330 commit 88580ce
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 53 deletions.
20 changes: 2 additions & 18 deletions src/index/updater/rune_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,7 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {
mint: mint.and_then(|mint| (!burn).then_some(mint)),
rune,
spacers,
supply: if let Some(mint) = mint {
if mint.end == Some(self.height) {
0
} else {
mint.limit.unwrap_or(runes::MAX_LIMIT)
}
} else {
u128::MAX
} - balance,
supply: u128::MAX - balance,
symbol,
timestamp: self.block_time,
}
Expand Down Expand Up @@ -369,15 +361,7 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {
};

Ok(Some(Etched {
balance: if let Some(mint) = etching.mint {
if mint.term == Some(0) {
0
} else {
mint.limit.unwrap_or(runes::MAX_LIMIT)
}
} else {
u128::MAX
},
balance: u128::MAX,
divisibility: etching.divisibility,
id: u128::from(self.height) << 16 | u128::from(index),
rune,
Expand Down
79 changes: 44 additions & 35 deletions src/runes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3947,14 +3947,14 @@ mod tests {
}

#[test]
fn open_etchings_with_term_zero_cannot_be_minted() {
fn open_etchings_with_term_zero_can_be_premined() {
let context = Context::builder().arg("--index-runes").build();

let (txid, id) = context.etch(
Runestone {
edicts: vec![Edict {
id: 0,
amount: 1000,
amount: 1111,
output: 0,
}],
etching: Some(Etching {
Expand Down Expand Up @@ -3983,22 +3983,18 @@ mod tests {
..Default::default()
}),
timestamp: id.block,
supply: 1111,
..Default::default()
},
)],
[],
[(OutPoint { txid, vout: 0 }, vec![(id, 1111)])],
);

context.rpc_server.broadcast_tx(TransactionTemplate {
inputs: &[(2, 0, 0, Witness::new())],
outputs: 2,
op_return: Some(
Runestone {
edicts: vec![Edict {
id: u128::from(id),
amount: 1,
output: 3,
}],
claim: Some(id),
..Default::default()
}
Expand All @@ -4021,10 +4017,11 @@ mod tests {
end: Some(id.block),
..Default::default()
}),
supply: 1111,
..Default::default()
},
)],
[],
[(OutPoint { txid, vout: 0 }, vec![(id, 1111)])],
);
}

Expand Down Expand Up @@ -4491,7 +4488,7 @@ mod tests {
}

#[test]
fn runes_can_be_etched_and_claimed_in_the_same_transaction() {
fn runes_can_be_etched_and_premined_in_the_same_transaction() {
let context = Context::builder().arg("--index-runes").build();

let (txid, id) = context.etch(
Expand Down Expand Up @@ -4525,11 +4522,11 @@ mod tests {
..Default::default()
}),
timestamp: id.block,
supply: 1000,
supply: 2000,
..Default::default()
},
)],
[(OutPoint { txid, vout: 0 }, vec![(id, 1000)])],
[(OutPoint { txid, vout: 0 }, vec![(id, 2000)])],
);
}

Expand Down Expand Up @@ -4655,10 +4652,10 @@ mod tests {
}

#[test]
fn transactions_cannot_claim_more_than_limit() {
fn premines_can_claim_over_the_max_limit() {
let context = Context::builder().arg("--index-runes").build();

let (txid0, id) = context.etch(
let (txid0, rune_id) = context.etch(
Runestone {
etching: Some(Etching {
rune: Some(Rune(RUNE)),
Expand All @@ -4680,16 +4677,17 @@ mod tests {

context.assert_runes(
[(
id,
rune_id,
RuneEntry {
etching: txid0,
rune: Rune(RUNE),
mint: Some(MintEntry {
limit: Some(1000),
..Default::default()
}),
timestamp: id.block,
supply: 1000,
timestamp: rune_id.block,
supply: 2000,
mints: 0,
..Default::default()
},
)],
Expand All @@ -4698,9 +4696,29 @@ mod tests {
txid: txid0,
vout: 0,
},
vec![(id, 1000)],
vec![(rune_id, 2000)],
)],
);
}

#[test]
fn transactions_cannot_claim_more_than_limit() {
let context = Context::builder().arg("--index-runes").build();

let (txid0, id) = context.etch(
Runestone {
etching: Some(Etching {
rune: Some(Rune(RUNE)),
mint: Some(Mint {
limit: Some(1000),
..Default::default()
}),
..Default::default()
}),
..Default::default()
},
1,
);

let txid1 = context.rpc_server.broadcast_tx(TransactionTemplate {
inputs: &[(2, 0, 0, Witness::new())],
Expand Down Expand Up @@ -4732,27 +4750,18 @@ mod tests {
..Default::default()
}),
timestamp: id.block,
supply: 2000,
supply: 1000,
mints: 1,
..Default::default()
},
)],
[
(
OutPoint {
txid: txid0,
vout: 0,
},
vec![(id, 1000)],
),
(
OutPoint {
txid: txid1,
vout: 0,
},
vec![(id, 1000)],
),
],
[(
OutPoint {
txid: txid1,
vout: 0,
},
vec![(id, 1000)],
)],
);
}

Expand Down

0 comments on commit 88580ce

Please sign in to comment.