BSV-ex v0.3.0 BSV.Block View Source
Module for the construction, parsing and serialization of Bitcoin block headers.
Link to this section Summary
Functions
Gets the block hash.
Gets the block id (hash in the hex form).
Parse the given binary into a block. Returns a tuple containing the parsed block and the remaining binary data.
Gets the previous block id.
Serialises the given block into a binary.
Link to this section Types
t()
View Sourcet() :: %BSV.Block{ bits: binary(), hash: binary() | nil, merkle_root: binary(), nonce: binary(), previous_block: binary(), timestamp: DateTime.t(), transactions: [BSV.Transaction.t()] | nil, version: non_neg_integer() }
A Bitcoin block.
Link to this section Functions
Gets the block hash.
Examples
iex> raw = "010000006FE28C0AB6F1B372C1A6A246AE63F74F931E8365E15A089C68D6190000000000982051FD1E4BA744BBBE680E1FEE14677BA1A3C3540BF7B1CDB606E857233E0E61BC6649FFFF001D01E36299" iex> {block, ""} = BSV.Block.parse(raw, false, encoding: :hex) iex> BSV.Block.hash(block) <<0, 0, 0, 0, 131, 154, 142, 104, 134, 171, 89, 81, 215, 111, 65, 20, 117, 66, 138, 252, 144, 148, 126, 227, 32, 22, 27, 191, 24, 235, 96, 72>>
Gets the block id (hash in the hex form).
Examples
iex> raw = "010000006FE28C0AB6F1B372C1A6A246AE63F74F931E8365E15A089C68D6190000000000982051FD1E4BA744BBBE680E1FEE14677BA1A3C3540BF7B1CDB606E857233E0E61BC6649FFFF001D01E36299" iex> {block, ""} = BSV.Block.parse(raw, false, encoding: :hex) iex> BSV.Block.id(block) "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048"
Parse the given binary into a block. Returns a tuple containing the parsed block and the remaining binary data.
Arguments
include_transactions
- will attempt to parse transactions that follow the block header in the binary. Disabled by default.
Options
The accepted options are:
:encoding
- Optionally decode the binary with either the:base64
or:hex
encoding scheme.
Examples
iex> raw = "010000006FE28C0AB6F1B372C1A6A246AE63F74F931E8365E15A089C68D6190000000000982051FD1E4BA744BBBE680E1FEE14677BA1A3C3540BF7B1CDB606E857233E0E61BC6649FFFF001D01E36299" iex> {block, ""} = raw |> Base.decode16!() |> BSV.Block.parse() iex> Base.encode16(block.hash) "00000000839A8E6886AB5951D76F411475428AFC90947EE320161BBF18EB6048" iex> {block, ""} = raw |> BSV.Block.parse(false, encoding: :hex) iex> Base.encode16(block.hash) "00000000839A8E6886AB5951D76F411475428AFC90947EE320161BBF18EB6048"
Gets the previous block id.
Examples
iex> raw = "010000006FE28C0AB6F1B372C1A6A246AE63F74F931E8365E15A089C68D6190000000000982051FD1E4BA744BBBE680E1FEE14677BA1A3C3540BF7B1CDB606E857233E0E61BC6649FFFF001D01E36299" iex> {block, ""} = BSV.Block.parse(raw, false, encoding: :hex) iex> BSV.Block.previous_id(block) "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
Serialises the given block into a binary.
Arguments
include_transactions
- will add transactions into the serialized binary. Disabled by default.
Options
The accepted options are:
:encode
- Optionally encode the returned binary with either the:base64
or:hex
encoding scheme.
Examples
BSV.Block.serialize(input)
<<binary>>