Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ordinals/ord into display-mintabi…
Browse files Browse the repository at this point in the history
…lity
  • Loading branch information
raphjaph committed Mar 19, 2024
2 parents d946496 + 40095d0 commit fa7cc94
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 29 deletions.
4 changes: 4 additions & 0 deletions src/runes/edict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ impl Edict {
) -> Option<Self> {
let id = RuneId::try_from(id).ok()?;

if id.block == 0 && id.tx > 0 {
return None;
}

if output > u128::try_from(tx.output.len()).ok()? {
return None;
}
Expand Down
93 changes: 65 additions & 28 deletions src/runes/runestone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,14 @@ mod tests {
script_pubkey: script::Builder::new()
.push_opcode(opcodes::all::OP_RETURN)
.push_opcode(MAGIC_NUMBER)
.push_slice([0, 1])
.push_opcode(opcodes::all::OP_VERIFY)
.push_slice([0])
.push_slice::<&script::PushBytes>(
varint::encode(rune_id(1).into())
.as_slice()
.try_into()
.unwrap()
)
.push_slice([2, 0])
.into_script(),
value: 0,
Expand Down Expand Up @@ -525,10 +531,10 @@ mod tests {
#[test]
fn deciphering_non_empty_runestone_is_successful() {
assert_eq!(
decipher(&[Tag::Body.into(), 1, 2, 0]),
decipher(&[Tag::Body.into(), rune_id(1).into(), 2, 0]),
Runestone {
edicts: vec![Edict {
id: RuneId { block: 0, tx: 1 },
id: rune_id(1),
amount: 2,
output: 0,
}],
Expand All @@ -544,7 +550,7 @@ mod tests {
Tag::Flags.into(),
Flag::Etch.mask(),
Tag::Body.into(),
1,
rune_id(1).into(),
2,
0
]),
Expand All @@ -569,7 +575,7 @@ mod tests {
Tag::Rune.into(),
4,
Tag::Body.into(),
1,
rune_id(1).into(),
2,
0
]),
Expand Down Expand Up @@ -597,7 +603,7 @@ mod tests {
Tag::Term.into(),
4,
Tag::Body.into(),
1,
rune_id(1).into(),
2,
0
]),
Expand All @@ -621,7 +627,7 @@ mod tests {
Tag::Term.into(),
4,
Tag::Body.into(),
1,
rune_id(1).into(),
2,
0
]),
Expand Down Expand Up @@ -652,7 +658,7 @@ mod tests {
Tag::Limit.into(),
4,
Tag::Body.into(),
1,
rune_id(1).into(),
2,
0
]),
Expand Down Expand Up @@ -685,7 +691,7 @@ mod tests {
Tag::Rune.into(),
5,
Tag::Body.into(),
1,
rune_id(1).into(),
2,
0,
]),
Expand All @@ -707,7 +713,14 @@ mod tests {
#[test]
fn unrecognized_odd_tag_is_ignored() {
assert_eq!(
decipher(&[Tag::Nop.into(), 100, Tag::Body.into(), 1, 2, 0]),
decipher(&[
Tag::Nop.into(),
100,
Tag::Body.into(),
rune_id(1).into(),
2,
0
]),
Runestone {
edicts: vec![Edict {
id: rune_id(1),
Expand All @@ -722,7 +735,14 @@ mod tests {
#[test]
fn unrecognized_even_tag_is_burn() {
assert_eq!(
decipher(&[Tag::Burn.into(), 0, Tag::Body.into(), 1, 2, 0]),
decipher(&[
Tag::Burn.into(),
0,
Tag::Body.into(),
rune_id(1).into(),
2,
0
]),
Runestone {
edicts: vec![Edict {
id: rune_id(1),
Expand All @@ -742,7 +762,7 @@ mod tests {
Tag::Flags.into(),
Flag::Burn.mask(),
Tag::Body.into(),
1,
rune_id(1).into(),
2,
0
]),
Expand All @@ -758,6 +778,18 @@ mod tests {
);
}

#[test]
fn rune_id_with_zero_block_and_nonzero_tx_is_burn() {
pretty_assert_eq!(
decipher(&[Tag::Body.into(), RuneId { block: 0, tx: 1 }.into(), 2, 0]),
Runestone {
edicts: Vec::new(),
burn: true,
..Default::default()
},
);
}

#[test]
fn output_over_max_is_burn() {
pretty_assert_eq!(
Expand Down Expand Up @@ -790,7 +822,7 @@ mod tests {
Tag::Rune.into(),
4,
Tag::Body.into(),
1,
rune_id(1).into(),
2,
0,
4,
Expand Down Expand Up @@ -822,7 +854,7 @@ mod tests {
Tag::Divisibility.into(),
5,
Tag::Body.into(),
1,
rune_id(1).into(),
2,
0,
]),
Expand Down Expand Up @@ -853,7 +885,7 @@ mod tests {
Tag::Divisibility.into(),
(MAX_DIVISIBILITY + 1).into(),
Tag::Body.into(),
1,
rune_id(1).into(),
2,
0,
]),
Expand Down Expand Up @@ -881,7 +913,7 @@ mod tests {
Tag::Symbol.into(),
u128::from(u32::from(char::MAX) + 1),
Tag::Body.into(),
1,
rune_id(1).into(),
2,
0,
]),
Expand All @@ -908,7 +940,7 @@ mod tests {
Tag::Symbol.into(),
'a'.into(),
Tag::Body.into(),
1,
rune_id(1).into(),
2,
0,
]),
Expand Down Expand Up @@ -949,7 +981,7 @@ mod tests {
Tag::Limit.into(),
3,
Tag::Body.into(),
1,
rune_id(1).into(),
2,
0,
]),
Expand Down Expand Up @@ -990,7 +1022,7 @@ mod tests {
Tag::Limit.into(),
3,
Tag::Body.into(),
1,
rune_id(1).into(),
2,
0,
]),
Expand Down Expand Up @@ -1018,7 +1050,7 @@ mod tests {
Tag::Symbol.into(),
'a'.into(),
Tag::Body.into(),
1,
rune_id(1).into(),
2,
0,
]),
Expand Down Expand Up @@ -1048,7 +1080,7 @@ mod tests {
Tag::Divisibility.into(),
Tag::Body.into(),
Tag::Body.into(),
1,
rune_id(1).into(),
2,
0,
]),
Expand All @@ -1067,7 +1099,7 @@ mod tests {
#[test]
fn runestone_may_contain_multiple_edicts() {
pretty_assert_eq!(
decipher(&[Tag::Body.into(), 1, 2, 0, 3, 5, 0]),
decipher(&[Tag::Body.into(), rune_id(1).into(), 2, 0, 3, 5, 0]),
Runestone {
edicts: vec![
Edict {
Expand All @@ -1088,8 +1120,8 @@ mod tests {

#[test]
fn runestones_with_invalid_rune_ids_are_burn() {
assert_eq!(
decipher(&[Tag::Body.into(), 1, 2, 0, u128::MAX, 5, 6]),
pretty_assert_eq!(
decipher(&[Tag::Body.into(), rune_id(1).into(), 2, 0, u128::MAX, 5, 6]),
Runestone {
edicts: vec![Edict {
id: rune_id(1),
Expand Down Expand Up @@ -1136,7 +1168,12 @@ mod tests {
.try_into()
.unwrap()
)
.push_slice::<&PushBytes>(varint::encode(1).as_slice().try_into().unwrap())
.push_slice::<&script::PushBytes>(
varint::encode(rune_id(1).into())
.as_slice()
.try_into()
.unwrap()
)
.push_slice::<&PushBytes>(varint::encode(2).as_slice().try_into().unwrap())
.push_slice::<&PushBytes>(varint::encode(0).as_slice().try_into().unwrap())
.into_script(),
Expand All @@ -1162,7 +1199,7 @@ mod tests {

#[test]
fn runestone_may_be_in_second_output() {
let payload = payload(&[0, 1, 2, 0]);
let payload = payload(&[0, rune_id(1).into(), 2, 0]);

let payload: &PushBytes = payload.as_slice().try_into().unwrap();

Expand Down Expand Up @@ -1199,7 +1236,7 @@ mod tests {

#[test]
fn runestone_may_be_after_non_matching_op_return() {
let payload = payload(&[0, 1, 2, 0]);
let payload = payload(&[0, rune_id(1).into(), 2, 0]);

let payload: &PushBytes = payload.as_slice().try_into().unwrap();

Expand Down Expand Up @@ -1578,7 +1615,7 @@ mod tests {
Tag::Burn.into(),
0,
Tag::Body.into(),
6,
rune_id(6).into(),
5,
1,
3,
Expand Down
2 changes: 1 addition & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub(crate) fn inscription_id(n: u32) -> InscriptionId {
}

pub(crate) fn rune_id(tx: u16) -> RuneId {
RuneId { block: 0, tx }
RuneId { block: 1, tx }
}

pub(crate) fn envelope(payload: &[&[u8]]) -> Witness {
Expand Down

0 comments on commit fa7cc94

Please sign in to comment.