Block
Block
Bases: KernelOpaquePtr
A deserialized Bitcoin block.
Source code in pbk/block.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
block_hash
property
The hash of this block.
Computes the double-SHA256 hash of the block header.
| RETURNS | DESCRIPTION |
|---|---|
BlockHash
|
The block hash. Owned handle. |
block_header
property
The header of this block.
| RETURNS | DESCRIPTION |
|---|---|
BlockHeader
|
The block header. Owned handle. |
transactions
property
All transactions in this block.
| RETURNS | DESCRIPTION |
|---|---|
TransactionSequence
|
A lazy sequence of transactions, including the coinbase. |
__bytes__
Serialize the block to bytes.
| RETURNS | DESCRIPTION |
|---|---|
bytes
|
The serialized block data in consensus format, suitable for |
bytes
|
P2P network transmission. |
__init__
Create a block from serialized data.
| PARAMETER | DESCRIPTION |
|---|---|
raw_block
|
The serialized block data in consensus format.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If parsing the block data fails (propagated from base class). |
Source code in pbk/block.py
__repr__
check
check(consensus_params: ConsensusParams, flags: BlockCheckFlags = BlockCheckFlags.ALL) -> BlockValidationState
Perform context-free validation checks on this block.
Checks size limits, coinbase structure, per-transaction validity and
sigop limits using the supplied consensus params. Proof-of-work and
merkle-root checks are optional and toggled via flags. Does not
include script, timestamp, ordering or other context-dependent checks.
| PARAMETER | DESCRIPTION |
|---|---|
consensus_params
|
The consensus parameters to validate against.
TYPE:
|
flags
|
Bitmask controlling the optional POW and merkle-root checks.
Defaults to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BlockValidationState
|
The resulting validation state. Inspect |
BlockValidationState
|
determine whether the block passed. Owned handle. |
Source code in pbk/block.py
BlockCheckFlags
Bases: IntFlag
Bitflags controlling optional context-free block checks.
These flags toggle the optional checks performed by Block.check. Multiple flags can be combined using bitwise OR operations.
Source code in pbk/block.py
BlockHash
Bases: KernelOpaquePtr
Identifier for a block.
Source code in pbk/block.py
__bytes__
Serialize the block hash to bytes.
| RETURNS | DESCRIPTION |
|---|---|
bytes
|
The 32-byte block hash in little-endian byte order. |
Source code in pbk/block.py
__eq__
Check equality with another block hash.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
Object to compare with.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if both are BlockHash instances with equal values. |
Source code in pbk/block.py
__hash__
Get hash value for use in sets and dictionaries.
| RETURNS | DESCRIPTION |
|---|---|
int
|
Hash of the block hash bytes. |
__init__
Create a block hash from raw bytes.
| PARAMETER | DESCRIPTION |
|---|---|
block_hash
|
The 32-byte block hash in little-endian byte order.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the block hash is not exactly 32 bytes. |
RuntimeError
|
If the C constructor fails (propagated from base class). |
Source code in pbk/block.py
__repr__
__str__
Get the hexadecimal representation of the block hash.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The block hash as a 64-character hex string in big-endian |
str
|
byte order (standard Bitcoin display format). |
Source code in pbk/block.py
BlockHeader
Bases: KernelOpaquePtr
A deserialized Bitcoin block header.
Source code in pbk/block.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
block_hash
property
The block hash.
| RETURNS | DESCRIPTION |
|---|---|
BlockHash
|
The block hash. Owned handle. |
prev_hash
property
The previous block hash.
| RETURNS | DESCRIPTION |
|---|---|
BlockHash
|
The previous block hash. View into this header. |
__bytes__
Serialize the block header to bytes.
| RETURNS | DESCRIPTION |
|---|---|
bytes
|
The 80-byte serialized block header in consensus format. |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If serialization fails. |
Source code in pbk/block.py
__init__
Create a block header from serialized data.
| PARAMETER | DESCRIPTION |
|---|---|
raw_header
|
The serialized block header data in consensus format. Must be 80 bytes.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If parsing the block header data fails (propagated from base class) |
Source code in pbk/block.py
BlockTreeEntry
Bases: KernelOpaquePtr
Entry in the block tree.
A block tree entry represents a single block in the block tree maintained by the chainstate manager. Each entry (except genesis) points to a single parent, and multiple entries may share a parent, forming a tree structure. Each entry corresponds to a single block and may be used to retrieve its data and validation status.
Source code in pbk/block.py
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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
block_hash
property
block_header
property
The header of the block this entry represents.
| RETURNS | DESCRIPTION |
|---|---|
BlockHeader
|
The block header. Owned handle. |
height
property
The height of this block in the chain.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The block height. Genesis block is at height 0. |
previous
property
The parent block tree entry.
| RETURNS | DESCRIPTION |
|---|---|
BlockTreeEntry
|
The previous block tree entry in the tree. View into the |
BlockTreeEntry
|
chainstate manager (transitively, via this entry's parent). |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If the C constructor fails (propagated from base class). |
__eq__
Check equality with another block tree entry.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
Object to compare with.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if both are BlockTreeEntry instances with equal height and hash. |
Source code in pbk/block.py
__hash__
Get hash value for use in sets and dictionaries.
| RETURNS | DESCRIPTION |
|---|---|
int
|
Hash combining height and block hash. |
__repr__
get_ancestor
Get the ancestor of this block tree entry at the given height.
| PARAMETER | DESCRIPTION |
|---|---|
height
|
The height of the requested ancestor. Must be between 0 and this entry's height (inclusive).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BlockTreeEntry
|
The block tree entry at the given height on the chain leading |
BlockTreeEntry
|
to this entry. View into the chainstate manager (transitively, |
BlockTreeEntry
|
via this entry's parent). |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in pbk/block.py
TransactionSequence
Bases: LazySequence[Transaction]
Lazily-evaluated sequence of transactions in a block.
This sequence provides indexed access to transactions within a block. The sequence is a view into the block and caches its length on first access.
Source code in pbk/block.py
__init__
Create a sequence view of transactions.
| PARAMETER | DESCRIPTION |
|---|---|
block
|
The block to create a sequence view for.
TYPE:
|
__len__
Number of transactions in the block.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The transaction count (cached after first call). |
Source code in pbk/block.py
TransactionSpentOutputsSequence
Bases: LazySequence[TransactionSpentOutputs]
Lazily-evaluated sequence of spent outputs for transactions in a block.
This sequence provides indexed access to the spent outputs (undo data) for each transaction in a block. The sequence excludes the coinbase transaction, which has no spent outputs.
Source code in pbk/block.py
__init__
Create a sequence view of transaction spent outputs.
| PARAMETER | DESCRIPTION |
|---|---|
block_spent_outputs
|
The block spent outputs to create a sequence view for.
TYPE:
|
Source code in pbk/block.py
__len__
Number of transaction spent outputs in the block. Equals the number of transactions in the block, minus 1 because the coinbase transaction is excluded as it has no spent outputs.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The count of transaction spent outputs (cached after first call). |
Source code in pbk/block.py
BlockSpentOutputs
Bases: KernelOpaquePtr
Spent outputs (undo data) for all transactions in a block.
Block spent outputs contain all the previous outputs consumed by all transactions in a specific block. This data is also known as "undo data" because it's necessary for reverting blocks during chain reorganizations. The data is stored as a nested structure: a sequence of transaction spent outputs, each containing the coins consumed by that transaction's inputs.
Source code in pbk/block.py
transactions
property
Spent outputs for each transaction in the block.
| RETURNS | DESCRIPTION |
|---|---|
TransactionSpentOutputsSequence
|
A sequence of transaction spent outputs, excluding the coinbase. |