Skip to content

Commit

Permalink
Better function name, and extra comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmart7t2 committed Feb 24, 2024
1 parent d397527 commit 2b26d2b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/inscriptions/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ impl Tag {
}
}

pub(crate) fn push_bytes(self, tmp: script::Builder) -> script::Builder {
// if it's a single byte between 1 and 16, use a PUSHNUM opcode
pub(crate) fn push_tag(self, tmp: script::Builder) -> script::Builder {
let bytes = self.bytes();

if bytes.len() == 1 && (1..17).contains(&bytes[0]) {
// if it's a single byte between 1 and 16, use a PUSHNUM opcode
tmp.push_opcode(
match bytes[0] {
1 => opcodes::all::OP_PUSHNUM_1, 2 => opcodes::all::OP_PUSHNUM_2, 3 => opcodes::all::OP_PUSHNUM_3, 4 => opcodes::all::OP_PUSHNUM_4,
Expand All @@ -49,6 +50,7 @@ impl Tag {
_ => panic!("unreachable"),
})
} else {
// otherwise use a PUSHBYTES opcode
tmp.push_slice::<&script::PushBytes>(bytes.try_into().unwrap())
}
}
Expand All @@ -60,11 +62,11 @@ impl Tag {

if self.is_chunked() {
for chunk in value.chunks(MAX_SCRIPT_ELEMENT_SIZE) {
tmp = self.push_bytes(tmp)
tmp = self.push_tag(tmp)
.push_slice::<&script::PushBytes>(chunk.try_into().unwrap());
}
} else {
tmp = self.push_bytes(tmp)
tmp = self.push_tag(tmp)
.push_slice::<&script::PushBytes>(value.as_slice().try_into().unwrap());
}

Expand Down

0 comments on commit 2b26d2b

Please sign in to comment.