ScriptBuilder (Class)¶
Builder for constructing transaction scripts.
Provides a fluent interface for building custom scripts with opcodes and data. Used for creating complex spending conditions like multi-signature or time-locked transactions.
__new__
¶
__new__() -> ScriptBuilder
Create a new empty script builder.
| RETURNS | DESCRIPTION |
|---|---|
ScriptBuilder
|
A new empty ScriptBuilder instance.
TYPE:
|
add_data
¶
add_data(data: Binary) -> ScriptBuilder
Add data to the script with appropriate push opcodes.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Data bytes as hex, bytes, or list.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ScriptBuilder
|
Self for method chaining.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
Exception
|
If the data cannot be added. |
add_i64
¶
add_i64(value: int) -> ScriptBuilder
Add an integer value to the script.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The integer to add.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ScriptBuilder
|
Self for method chaining.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
Exception
|
If the value cannot be added. |
add_lock_time
¶
add_lock_time(lock_time: int) -> ScriptBuilder
Add a lock time value for CLTV (CheckLockTimeVerify).
| PARAMETER | DESCRIPTION |
|---|---|
lock_time
|
DAA score or timestamp for time lock.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ScriptBuilder
|
Self for method chaining.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
Exception
|
If the lock time cannot be added. |
add_op
¶
add_op(op: Any) -> ScriptBuilder
Add a single opcode to the script.
| PARAMETER | DESCRIPTION |
|---|---|
op
|
An Opcodes enum value or integer.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ScriptBuilder
|
Self for method chaining.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
Exception
|
If the opcode is invalid. |
add_ops
¶
add_ops(opcodes: Any) -> ScriptBuilder
Add multiple opcodes to the script.
| PARAMETER | DESCRIPTION |
|---|---|
opcodes
|
List of Opcodes enum values or integers.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ScriptBuilder
|
Self for method chaining.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
Exception
|
If any opcode is invalid. |
add_sequence
¶
add_sequence(sequence: int) -> ScriptBuilder
Add a sequence value for CSV (CheckSequenceVerify).
| PARAMETER | DESCRIPTION |
|---|---|
sequence
|
Relative time lock value.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ScriptBuilder
|
Self for method chaining.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
Exception
|
If the sequence cannot be added. |
canonical_data_size
staticmethod
¶
canonical_data_size(data: Binary) -> int
Calculate the canonical size for data in a script.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Data bytes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The size in bytes including push opcodes.
TYPE:
|
create_pay_to_script_hash_script
¶
create_pay_to_script_hash_script() -> ScriptPublicKey
Create a P2SH (pay-to-script-hash) locking script.
| RETURNS | DESCRIPTION |
|---|---|
ScriptPublicKey
|
The locking script for a P2SH address.
TYPE:
|
drain
¶
Drain and return the script, clearing the builder.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The script as a string.
TYPE:
|
encode_pay_to_script_hash_signature_script
¶
encode_pay_to_script_hash_signature_script(signature: Binary) -> str
Encode a P2SH signature script for spending.
| PARAMETER | DESCRIPTION |
|---|---|
signature
|
The signature bytes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The encoded signature script as hex.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
Exception
|
If encoding fails. |
from_script
staticmethod
¶
from_script(script: Binary) -> ScriptBuilder
Create a script builder from an existing script.
| PARAMETER | DESCRIPTION |
|---|---|
script
|
Existing script bytes as hex, bytes, or list.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ScriptBuilder
|
A new ScriptBuilder initialized with the script.
TYPE:
|
to_string
¶
Get the script as a hex string.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The script bytes as a hex string.
TYPE:
|