BSV-ex v0.2.3 BSV.Script View Source

Module for the construction, parsing and serialization of transactions to and from binary data.

Examples

iex> %BSV.Script{}
...> |> BSV.Script.push(:OP_FALSE)
...> |> BSV.Script.push(:OP_RETURN)
...> |> BSV.Script.push("hello world")
...> |> BSV.Script.serialize(encoding: :hex)
"006a0b68656c6c6f20776f726c64"

iex> "006a0b68656c6c6f20776f726c64"
...> |> BSV.Script.parse(encoding: :hex)
%BSV.Script{
  chunks: [:OP_FALSE, :OP_RETURN, "hello world"]
}

Link to this section Summary

Types

t()

Bitcoin Script

Functions

Parses the given binary into a transaction script.

Pushes a chunk into the given transaction script. The chunk can be any binary value or OP code.

Serialises the given script into a binary.

Link to this section Types

Link to this type

t()

View Source
t() :: %BSV.Script{chunks: list()}

Bitcoin Script

Link to this section Functions

Link to this function

parse(data, options \\ [])

View Source
parse(binary(), keyword()) :: BSV.Script.t()

Parses the given binary into a transaction script.

Options

The accepted options are:

  • :encoding - Optionally decode the binary with either the :base64 or :hex encoding scheme.

Examples

iex> "76a9146afc0d6bb578282ac0f6ad5c5af2294c1971210888ac"
...> |> BSV.Script.parse(encoding: :hex)
%BSV.Script{
  chunks: [
    :OP_DUP,
    :OP_HASH160,
    <<106, 252, 13, 107, 181, 120, 40, 42, 192, 246, 173, 92, 90, 242, 41, 76, 25, 113, 33, 8>>,
    :OP_EQUALVERIFY,
    :OP_CHECKSIG
  ]
}

Pushes a chunk into the given transaction script. The chunk can be any binary value or OP code.

Examples

iex> %BSV.Script{}
...> |> BSV.Script.push(:OP_FALSE)
...> |> BSV.Script.push(:OP_RETURN)
...> |> BSV.Script.push("Hello world")
%BSV.Script{
  chunks: [
    :OP_FALSE,
    :OP_RETURN,
    "Hello world"
  ]
}
Link to this function

serialize(script, options \\ [])

View Source
serialize(BSV.Script.t(), keyword()) :: binary()

Serialises the given script into a binary.

Options

The accepted options are:

  • :encode - Optionally encode the returned binary with either the :base64 or :hex encoding scheme.

Examples

iex> %BSV.Script{}
...> |> BSV.Script.push(:OP_DUP)
...> |> BSV.Script.push(:OP_HASH160)
...> |> BSV.Script.push(<<106, 252, 13, 107, 181, 120, 40, 42, 192, 246, 173, 92, 90, 242, 41, 76, 25, 113, 33, 8>>)
...> |> BSV.Script.push(:OP_EQUALVERIFY)
...> |> BSV.Script.push(:OP_CHECKSIG)
...> |> BSV.Script.serialize(encoding: :hex)
"76a9146afc0d6bb578282ac0f6ad5c5af2294c1971210888ac"