BSV.OpCode (BSV v2.1.0) View Source

Module for accessing Bitcoin Script Op Codes.

Bitcoin Script provides a number of operations or commands, known as Op Codes. When the script is evaluated, the Op Codes manipulate the stack in some way.

Within a script, an Op Code is single byte integer. Op Codes can also be referenced by an atom representing the word or name of the Op Code.

Link to this section Summary

Types

t()

Op Code

Functions

Returns a map of all Op Codes.

Returns an atom/0 Op Code from the given value. Returns nil if the value is not a valid Op Code.

Returns an atom/0 Op Code from the given value.

Returns an integer/0 Op Code from the given value. Returns nil if the value is not a valid Op Code.

Returns an integer/0 Op Code from the given value.

Link to this section Types

Specs

t() :: atom() | integer()

Op Code

Represented as either an atom/0 or an integer/0.

Link to this section Functions

Specs

all() :: map()

Returns a map of all Op Codes.

Specs

to_atom(atom() | binary() | String.t() | integer()) :: t() | nil

Returns an atom/0 Op Code from the given value. Returns nil if the value is not a valid Op Code.

Examples

iex> BSV.OpCode.to_atom :OP_RETURN
:OP_RETURN

iex> BSV.OpCode.to_atom "op_return"
:OP_RETURN

iex> BSV.OpCode.to_atom <<106>>
:OP_RETURN

iex> BSV.OpCode.to_atom 106
:OP_RETURN

iex> BSV.OpCode.to_atom :UNKNOWN_CODE
nil

Specs

to_atom!(atom() | String.t() | binary() | integer()) :: t()

Returns an atom/0 Op Code from the given value.

As to_atom/1 but raises an error if the value is not a valid Op Code.

Specs

to_integer(atom() | binary() | String.t()) :: t() | nil

Returns an integer/0 Op Code from the given value. Returns nil if the value is not a valid Op Code.

Examples

iex> BSV.OpCode.to_integer :OP_RETURN
106

iex> BSV.OpCode.to_integer "op_return"
106

iex> BSV.OpCode.to_integer <<106>>
106

iex> BSV.OpCode.to_integer 106
106

iex> BSV.OpCode.to_integer :UNKNOWN_CODE
nil

Specs

to_integer!(atom() | binary() | String.t()) :: t()

Returns an integer/0 Op Code from the given value.

As to_integer/1 but raises an error if the value is not a valid Op Code.