pyrxd.script — Script types and evaluation

Script types, templates, and evaluation for Radiant transactions.

The public re-exports below are resolved lazily via PEP 562 __getattr__ so importing pyrxd.script.script (used by the inspect tool’s Transaction parser) doesn’t transitively pull pyrxd.script.type and through it pyrxd.keyscoincurve.

See pyrxd for the broader rationale on lazy public re-exports.

class pyrxd.script.BareMultisig[source]

Bases: ScriptTemplate

lock(participants, threshold)[source]
Returns:

locking script

Parameters:
Return type:

Script

unlock(private_keys)[source]
Returns:

sign (function), estimated_unlocking_byte_length (function)

Parameters:

private_keys (list[PrivateKey])

class pyrxd.script.CsvKind[source]

Bases: Enum

Relative time-lock kind, per BIP-112.

BLOCKS = 'blocks'
TIME_512_SECONDS = 'time'
class pyrxd.script.OpReturn[source]

Bases: ScriptTemplate

lock(pushdatas)[source]
Returns:

locking script

Parameters:

pushdatas (list[str | bytes])

Return type:

Script

unlock(**kwargs)[source]
Returns:

sign (function), estimated_unlocking_byte_length (function)

class pyrxd.script.P2PK[source]

Bases: ScriptTemplate

lock(public_key)[source]

from public key in format str or bytes

Parameters:

public_key (str | bytes)

Return type:

Script

unlock(private_key)[source]
Returns:

sign (function), estimated_unlocking_byte_length (function)

Parameters:

private_key (PrivateKey)

class pyrxd.script.P2PKH[source]

Bases: ScriptTemplate

lock(addr)[source]

from address (str) or public key hash160 (bytes)

Parameters:

addr (str | bytes)

Return type:

Script

unlock(private_key)[source]
Returns:

sign (function), estimated_unlocking_byte_length (function)

Parameters:

private_key (PrivateKey)

class pyrxd.script.Script[source]

Bases: object

__init__(script=None)[source]

Create script from hex string or bytes

Parameters:

script (str | bytes | None)

byte_length()[source]
Return type:

int

byte_length_varint()[source]
Return type:

bytes

classmethod find_and_delete(source, pattern)[source]
Parameters:
Return type:

Script

classmethod from_asm(asm)[source]
Parameters:

asm (str)

Return type:

Script

classmethod from_chunks(chunks)[source]
Parameters:

chunks (list[ScriptChunk])

Return type:

Script

hex()[source]
Return type:

str

is_push_only()[source]

Checks if the script contains only push data operations. :return: True if the script is push-only, otherwise false.

Return type:

bool

serialize()[source]
Return type:

bytes

size()
Return type:

int

size_varint()
Return type:

bytes

to_asm()[source]
Return type:

str

classmethod write_bin(octets)[source]
Parameters:

octets (bytes)

Return type:

Script

class pyrxd.script.ScriptChunk[source]

Bases: object

A representation of a chunk of a script, which includes an opcode. For push operations, the associated data to push onto the stack is also included.

__init__(op, data=None)[source]
Parameters:
class pyrxd.script.ScriptTemplate[source]

Bases: object

abstractmethod lock(*args, **kwargs)[source]
Returns:

locking script

Return type:

Script

abstractmethod unlock(*args, **kwargs)[source]
Returns:

sign (function), estimated_unlocking_byte_length (function)

Return type:

UnlockingScriptTemplate

class pyrxd.script.Unknown[source]

Bases: ScriptTemplate

lock(**kwargs)[source]
Returns:

locking script

Return type:

Script

unlock(**kwargs)[source]
Returns:

sign (function), estimated_unlocking_byte_length (function)

pyrxd.script.build_csv_sequence(units, kind)[source]

Encode an (units, kind) pair into the integer form CSV expects on the stack and in the spending input’s nSequence field.

units is the BIP-112 unit count: blocks for CsvKind.BLOCKS, or 512-second intervals for CsvKind.TIME_512_SECONDS. Must be in the range [0, 65535] (16 bits).

Parameters:
Return type:

int

pyrxd.script.build_p2pkh_with_cltv_script(owner_pkh, locktime)[source]

Build a P2PKH locking script gated by an absolute time-lock (CLTV).

The output is spendable only when the spending transaction’s nLockTime is at or after locktime.

locktime < 500_000_000 selects a block-height lock; values at or above LOCKTIME_THRESHOLD select a Unix-time lock (seconds). The caller is responsible for choosing the right interpretation — both are accepted at the script level.

Returns the raw locking-script bytes.

Parameters:
Return type:

bytes

pyrxd.script.build_p2pkh_with_csv_script(owner_pkh, sequence)[source]

Build a P2PKH locking script gated by a relative time-lock (CSV).

The output is spendable only after the BIP-112-encoded sequence has elapsed (measured from the funding-output’s confirmation). Use build_csv_sequence(units, kind) to construct sequence from a block count or a 512-second interval count.

Callers must NOT pass a sequence with the disable bit (1 << 31) set — that value means “no relative lock” and would silently make the script trivially spendable.

Returns the raw locking-script bytes.

Parameters:
Return type:

bytes