BSV-ex v0.3.0 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
Functions
Gets a coinbase script.
Gets whether this is a coinbase script.
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
Bitcoin Script
Link to this section Functions
Gets a coinbase script.
Examples
iex> Script.get_coinbase("keep calm and BSV on") %Script{coinbase: "keep calm and BSV on", chunks: []}
Gets whether this is a coinbase script.
Examples
iex> Script.get_coinbase("keep calm and BSV on") |> Script.is_coinbase() true
iex> %Script{chunks: [:OP_1]} |> Script.is_coinbase() false
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"
]
}
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"