Skip to content

Commit

Permalink
fix extend() error on ScriptBuilder replacing it with script_mut() ac…
Browse files Browse the repository at this point in the history
…cessor
  • Loading branch information
aspect committed Dec 28, 2024
1 parent d654803 commit 5394020
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crypto/txscript/src/opcodes/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ macro_rules! opcode_list {
}
}
else if let Some(Ok(value)) = token.strip_prefix("0x").and_then(|trimmed| Some(hex::decode(trimmed))) {
builder.extend(&value);
builder.script_mut().extend(&value);
}
else if token.len() >= 2 && token.chars().nth(0) == Some('\'') && token.chars().last() == Some('\'') {
builder.add_data(token[1..token.len()-1].as_bytes())?;
Expand Down
10 changes: 7 additions & 3 deletions crypto/txscript/src/script_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ impl ScriptBuilder {
&self.script
}

#[cfg(any(test, target_arch = "wasm32"))]
pub fn extend(&mut self, data: &[u8]) {
self.script.extend(data);
pub fn script_mut(&mut self) -> &mut Vec<u8> {
&mut self.script
}

// #[cfg(any(test, target_arch = "wasm32"))]
// pub fn extend(&mut self, data: &[u8]) {
// self.script.extend(data);
// }

pub fn drain(&mut self) -> Vec<u8> {
// Note that the internal script, when taken, is replaced by
// vector with no predefined capacity because the script
Expand Down
2 changes: 1 addition & 1 deletion crypto/txscript/src/wasm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl ScriptBuilder {
pub fn from_script(script: BinaryT) -> Result<ScriptBuilder> {
let builder = ScriptBuilder::default();
let script = script.try_as_vec_u8()?;
builder.inner_mut().extend(&script);
builder.inner_mut().script_mut().extend(&script);

Ok(builder)
}
Expand Down

0 comments on commit 5394020

Please sign in to comment.