BSV-ex v0.1.0 BSV.Transaction.Script View Source
Module for the construction, parsing and serialization of transactions to and from binary data.
Examples
iex> %BSV.Transaction.Script{}
...> |> BSV.Transaction.Script.push(:OP_FALSE)
...> |> BSV.Transaction.Script.push(:OP_RETURN)
...> |> BSV.Transaction.Script.push("hello world")
...> |> BSV.Transaction.Script.serialize(encoding: :hex)
"006a0b68656c6c6f20776f726c64"
iex> "006a0b68656c6c6f20776f726c64"
...> |> BSV.Transaction.Script.parse(encoding: :hex)
%BSV.Transaction.Script{
chunks: [:OP_FALSE, :OP_RETURN, "hello world"]
}
Link to this section Summary
Functions
Returns a tuple caintaining the OP code and OP code byte number, depending on the given OP code name or integer.
Returns a map of all OP codes.
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
Returns a tuple caintaining the OP code and OP code byte number, depending on the given OP code name or integer.
Examples
iex> BSV.Transaction.Script.get_op_code :OP_RETURN
{:OP_RETURN, 106}
iex> BSV.Transaction.Script.get_op_code "op_return"
{:OP_RETURN, 106}
iex> BSV.Transaction.Script.get_op_code 106
{:OP_RETURN, 106}
iex> BSV.Transaction.Script.get_op_code :UNKNOWN_CODE
nil
Returns a map of all OP codes.
Parses the given binary into a transaction script.
Options
The accepted options are:
:encoding- Optionally decode the binary with either the:base64or:hexencoding scheme.
Examples
iex> "76a9146afc0d6bb578282ac0f6ad5c5af2294c1971210888ac"
...> |> BSV.Transaction.Script.parse(encoding: :hex)
%BSV.Transaction.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.Transaction.Script{}
...> |> BSV.Transaction.Script.push(:OP_DUP)
...> |> BSV.Transaction.Script.push(:OP_HASH160)
...> |> BSV.Transaction.Script.push(<<106, 252, 13, 107, 181, 120, 40, 42, 192, 246, 173, 92, 90, 242, 41, 76, 25, 113, 33, 8>>)
...> |> BSV.Transaction.Script.push(:OP_EQUALVERIFY)
...> |> BSV.Transaction.Script.push(:OP_CHECKSIG)
%BSV.Transaction.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
]
}
Serialises the given script into a binary.
Options
The accepted options are:
:encode- Optionally encode the returned binary with either the:base64or:hexencoding scheme.
Examples
iex> %BSV.Transaction.Script{}
...> |> BSV.Transaction.Script.push(:OP_DUP)
...> |> BSV.Transaction.Script.push(:OP_HASH160)
...> |> BSV.Transaction.Script.push(<<106, 252, 13, 107, 181, 120, 40, 42, 192, 246, 173, 92, 90, 242, 41, 76, 25, 113, 33, 8>>)
...> |> BSV.Transaction.Script.push(:OP_EQUALVERIFY)
...> |> BSV.Transaction.Script.push(:OP_CHECKSIG)
...> |> BSV.Transaction.Script.serialize(encoding: :hex)
"76a9146afc0d6bb578282ac0f6ad5c5af2294c1971210888ac"