Script
ScriptVerificationFlags
Bases: IntFlag
Script verification flags that may be composed with each other.
These flags control which validation rules are enforced during script verification. Multiple flags can be combined using bitwise OR operations.
Source code in pbk/script.py
ALL
class-attribute
instance-attribute
All verification flags combined
CHECKLOCKTIMEVERIFY
class-attribute
instance-attribute
Enable CHECKLOCKTIMEVERIFY (BIP65)
CHECKSEQUENCEVERIFY
class-attribute
instance-attribute
Enable CHECKSEQUENCEVERIFY (BIP112)
ScriptVerifyStatus
Bases: IntEnum
Status codes returned by script verification.
These codes indicate the result of script verification, including success, various error conditions, and validation failures.
Source code in pbk/script.py
ERROR_INVALID_FLAGS_COMBINATION
class-attribute
instance-attribute
The flags were combined in an invalid way.
ERROR_SPENT_OUTPUTS_REQUIRED
class-attribute
instance-attribute
The taproot flag was set, so valid spent_outputs have to be provided.
PrecomputedTransactionData
Bases: KernelOpaquePtr
Reusable structure holding precomputed transaction data for verifying multiple inputs of the same transaction.
This avoids recomputing transaction hashes for each input during script verification. Required when verifying taproot inputs.
Source code in pbk/script.py
__init__
Create precomputed transaction data for script verification.
| PARAMETER | DESCRIPTION |
|---|---|
tx_to
|
The transaction to precompute data for.
TYPE:
|
spent_outputs
|
The outputs spent by the transaction. Required for taproot verification, can be None for non-taproot verification.
TYPE:
|
Source code in pbk/script.py
ScriptPubkey
Bases: KernelOpaquePtr
A Bitcoin script defining spending conditions for an output.
Source code in pbk/script.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
__bytes__
Serialize the script pubkey to bytes.
| RETURNS | DESCRIPTION |
|---|---|
bytes
|
The raw script data. |
__init__
Create a script pubkey from raw script data.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The script pubkey data containing opcodes and operands.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If the C constructor fails (propagated from base class). |
Source code in pbk/script.py
__repr__
Return a string representation of the script pubkey.
__str__
Get the hexadecimal representation of the script.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The script data as a hex string. |
verify
verify(amount: int, tx_to: Transaction, precomputed_txdata: PrecomputedTransactionData | None, input_index: int, flags: ScriptVerificationFlags) -> bool
Verify that a transaction input correctly spends this script pubkey.
This function validates whether the input at the specified index in the spending transaction satisfies the conditions defined by the script pubkey. The verification process depends on the flags provided, which control which consensus rules are enforced.
| PARAMETER | DESCRIPTION |
|---|---|
amount
|
The value of the output being spent, in satoshis. Required when VERIFY_WITNESS flag is set.
TYPE:
|
tx_to
|
The transaction that is attempting to spend the output.
TYPE:
|
precomputed_txdata
|
Precomputed data for tx_to with the spent outputs. Required when VERIFY_TAPROOT flag is set, otherwise can be None.
TYPE:
|
input_index
|
The zero-based index of the input in
TYPE:
|
flags
|
Bitfield of ScriptFlags controlling which validation rules to enforce. Use ScriptFlags values combined with bitwise OR.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the input spends the script pubkey validly, False otherwise. |
| RAISES | DESCRIPTION |
|---|---|
ScriptVerifyException
|
If the verification could not run, e.g. because the flags were combined in an invalid way. The exception contains the status code. |