BSV.Contract.VarIntHelpers (bsv_sdk v1.5.1)

Copy Markdown View Source

Script-level VarInt helpers for BSV.Contract modules.

VarInts are commonly used in Bitcoin scripts to encode variable-length data. These helpers generate script opcodes that extract or trim VarInt prefixes at runtime on the script stack.

Usage

import BSV.Contract.VarIntHelpers

Or through use BSV.Contract (auto-imported).

Summary

Functions

Assuming the top stack item is a VarInt-prefixed binary, extract the VarInt number and place it on top of the stack.

Assuming the top stack item is a VarInt-prefixed binary, extract the VarInt data and place it on top of the stack.

Assuming the top stack item is a VarInt-prefixed binary, trim the VarInt prefix from the leading bytes.

Functions

get_varint(ctx)

@spec get_varint(BSV.Contract.t()) :: BSV.Contract.t()

Assuming the top stack item is a VarInt-prefixed binary, extract the VarInt number and place it on top of the stack.

The original element is not removed (it is duplicated first).

read_varint(ctx)

@spec read_varint(BSV.Contract.t()) :: BSV.Contract.t()

Assuming the top stack item is a VarInt-prefixed binary, extract the VarInt data and place it on top of the stack.

The original element is removed. Any remaining data is second on the stack.

trim_varint(ctx)

@spec trim_varint(BSV.Contract.t()) :: BSV.Contract.t()

Assuming the top stack item is a VarInt-prefixed binary, trim the VarInt prefix from the leading bytes.

The original element is replaced with the data after the VarInt prefix.