BSV.Contract.VarIntHelpers (BSV v2.1.0) View Source

Helper module for working with BSV.VarInt.t/0 in BSV.Contract modules.

VarInts are commonly used in Bitcoin scripts to encode variable length bits of data. This module provides a number of functions for extracting the data from VarInts.

Link to this section Summary

Functions

Assuming the top stack item is a VarInt encoded binary, the VarInt is extracted and placed on top of the stack as a ScriptNum.

Assuming the top stack item is a VarInt encoded binary, the VarInt encoded data is extracted and placed on top of the stack as a ScriptNum.

Assuming the top stack item is a VarInt encoded binary, the VarInt prefix is trimmed from the leading bytes and the encoded data is placed on top of the stack.

Link to this section Functions

Specs

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

Assuming the top stack item is a VarInt encoded binary, the VarInt is extracted and placed on top of the stack as a ScriptNum.

The original element is not removed.

Use this function if you would like to to extract the VarInt number, yet leave the original data on the stack.

Specs

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

Assuming the top stack item is a VarInt encoded binary, the VarInt encoded data is extracted and placed on top of the stack as a ScriptNum.

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

Use this function if the VarInt is part of a larger string of bytes and you would like to extract the data whilst retaining the remaining bytes.

Specs

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

Assuming the top stack item is a VarInt encoded binary, the VarInt prefix is trimmed from the leading bytes and the encoded data is placed on top of the stack.

The original element is removed.

Use this function if the VarInt is not part of a larger string of bytes and you would like to cleanly trim the VarInt number from the leading bytes.