Skip to content

jmcore.transaction_policy

jmcore.transaction_policy

Shared Bitcoin transaction fingerprint policy.

Attributes

MAX_LOCKTIME = 4294967295 module-attribute

NON_RBF_LOCKTIME_SEQUENCE = 4294967294 module-attribute

RBF_SEQUENCE = 4294967293 module-attribute

Classes

RandomSource

Bases: Protocol

Randomness interface needed by anti-fee-sniping locktime selection.

Source code in jmcore/src/jmcore/transaction_policy.py
14
15
16
17
class RandomSource(Protocol):
    """Randomness interface needed by anti-fee-sniping locktime selection."""

    def randint(self, start: int, end: int) -> int: ...
Methods:
randint(start: int, end: int) -> int
Source code in jmcore/src/jmcore/transaction_policy.py
17
def randint(self, start: int, end: int) -> int: ...

Functions:

compute_tx_locktime(current_height: int, rng: RandomSource = secure_random) -> int

Return a reference-compatible anti-fee-sniping locktime.

Source code in jmcore/src/jmcore/transaction_policy.py
20
21
22
23
24
25
26
27
28
29
30
31
32
def compute_tx_locktime(current_height: int, rng: RandomSource = secure_random) -> int:
    """Return a reference-compatible anti-fee-sniping locktime."""
    if (
        not isinstance(current_height, int)
        or isinstance(current_height, bool)
        or not 0 <= current_height <= MAX_LOCKTIME
    ):
        raise ValueError(f"Invalid current block height: {current_height!r}")
    if current_height == 0:
        return 0
    if rng.randint(0, 9) == 0:
        return max(1, current_height - rng.randint(0, 99))
    return current_height