pub struct Script { /* private fields */ }Expand description
A Bitcoin script represented as a sequence of parsed chunks.
Implementations§
Source§impl Script
impl Script
Sourcepub fn from_binary(bytes: &[u8]) -> Self
pub fn from_binary(bytes: &[u8]) -> Self
Parse a script from raw binary bytes.
Sourcepub fn from_hex(hex: &str) -> Result<Self, ScriptError>
pub fn from_hex(hex: &str) -> Result<Self, ScriptError>
Parse a script from a hex string.
Sourcepub fn from_asm(asm: &str) -> Self
pub fn from_asm(asm: &str) -> Self
Parse a script from a space-separated ASM string.
Handles opcodes like “OP_DUP”, data pushes as hex strings,
“0” as OP_0, and “-1” as OP_1NEGATE.
OP_PUSHDATA1/2/4 in ASM format: "OP_PUSHDATA1 <len> <hex>"
Sourcepub fn from_chunks(chunks: Vec<ScriptChunk>) -> Self
pub fn from_chunks(chunks: Vec<ScriptChunk>) -> Self
Create a script from pre-built chunks.
Sourcepub fn chunks(&self) -> &[ScriptChunk]
pub fn chunks(&self) -> &[ScriptChunk]
Access the parsed chunks.
Sourcepub fn find_and_delete(&self, target: &Script) -> Script
pub fn find_and_delete(&self, target: &Script) -> Script
Remove all occurrences of target from this script (borrowing).
Matching is done by comparing the serialized bytes of each chunk
against the full serialized target, following the TS SDK’s
findAndDelete algorithm.
Sourcepub fn find_and_delete_owned(self, target: &Script) -> Script
pub fn find_and_delete_owned(self, target: &Script) -> Script
Remove all occurrences of target from this script (consuming self to avoid clone).
Same semantics as find_and_delete but takes ownership, avoiding the
internal Vec<ScriptChunk> clone when the caller no longer needs the original.
Sourcepub fn is_push_only(&self) -> bool
pub fn is_push_only(&self) -> bool
Check if the script contains only push-data operations.
Push-only means all opcodes are <= OP_16 (0x60).