Script
ScriptVerificationFlags
Bases: IntEnum
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
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
ScriptPubkey
Bases: KernelOpaquePtr
A Bitcoin script defining spending conditions for an output.
Source code in pbk/script.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 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 | |
__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, spent_outputs: list[TransactionOutput] | None, input_index: int, flags: int) -> 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:
|
spent_outputs
|
All outputs being spent by the transaction. 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 script verification succeeds. |
| RAISES | DESCRIPTION |
|---|---|
ScriptVerifyException
|
If script verification fails. The exception contains a status code indicating the specific failure reason. |