Packages
elixium_core
0.6.2
0.6.3
0.6.2
0.6.1
0.6.0
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.12
0.4.11
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.19
0.3.18
0.3.17
0.3.16
0.3.15
0.3.14
0.3.13
0.3.12
0.3.11
0.3.10
0.3.9
0.3.8
0.3.7
0.3.6
0.3.5
0.3.4
0.3.3
0.3.1
0.2.13
0.2.12
0.2.11
0.2.10
0.2.9
0.2.8
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.4
0.1.3
The core package for the Elixium blockchain, containing all the modules needed to run the chain
Current section
Files
Jump to
Current section
Files
lib/error.ex
defmodule Elixium.Error do
alias Elixium.Error
@moduledoc """
Converts error tuples to human-readable strings.
"""
@doc """
Converts a tuple in the form {:error, any} to a string.
"""
@spec to_string({:error, any}) :: String.t()
def to_string({:error, err}), do: str(err)
def to_string(err), do: "Error #{inspect(err)} isn't a valid error tuple"
defp str({:invalid_index, prev, index}),
do: "Invalid index #{:binary.decode_unsigned(index)}, expected > #{:binary.decode_unsigned(prev)}"
defp str({:wrong_hash, reason}), do: "Invalid hash: #{hash_err(reason)}"
defp str(:no_coinbase), do: "No coinbase found in a block"
defp str(:invalid_inputs), do: "Invalid transaction inputs"
defp str(:block_too_large), do: "Block too large -- Exceeds byte limit"
defp str({:not_coinbase, txtype}),
do: "The first transaction is not a coinbase, but a #{txtype}"
defp str({:invalid_coinbase, fees, reward, amount}),
do:
"The coinbase is invalid, since the fees (#{fees}) + reward (#{reward}) ≠ coinbase amount (#{
amount
})"
defp str({:invalid_difficulty, difficulty, diff}),
do: "Invalid block difficulty #{difficulty}. expected #{diff}"
defp str({:invalid_tx_id, expected, received}),
do: "Invalid transaction id. Calculated #{expected} but got #{received}"
defp str(:failed_pool_check), do: "Input in transaction was not found in UTXO pool"
defp str(:sig_set_mismatch), do: "Transaction is missing signature(s)"
defp str(:invalid_tx_sig), do: "One or more signatures in transaction are invalid"
defp str(:utxo_amount_not_decimal),
do: "One or more inputs/outputs in the transaction have an amount that is not of type Decimal"
defp str({:outputs_exceed_inputs, output_total, input_total}),
do: "Outputs exceed inputs. Outputs: #{output_total}, Inputs: #{input_total}"
defp str({:invalid_transaction, errors}), do: Enum.each(errors, &Error.to_string/1)
defp str(err), do: "Unrecognized error: #{err}"
defp hash_err({:doesnt_match_last, prev, hash}),
do: "Doesn't match last hash. expected #{prev}, got #{hash}"
defp hash_err({:too_high, hash, difficulty}),
do: "Hash #{hash} is too high for a difficulty of #{difficulty}"
defp hash_err({:doesnt_match_provided, computed, hash}),
do: "Provided hash #{hash} doesn't equal #{computed}"
end