ExPlasma.Encoding (ExPlasma v0.2.0)
Provides the common encoding functionality we use across all the transactions and clients.
Link to this section Summary
Functions
Converts a hex string into a binary.
Throwing version of to_binary/1
Converts binary and integer values into its hex string equivalent.
Converts a hex string into the integer value.
Link to this section Functions
Link to this function
to_binary(arg)
Specs
Converts a hex string into a binary.
Examples
iex> ExPlasma.Encoding.to_binary("0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e")
{:ok, <<29, 246, 47, 41, 27, 46, 150, 159, 176, 132, 157, 153, 217, 206, 65, 226, 241,
55, 0, 110>>}
Link to this function
to_binary!(prefixed_hex)
Specs
Throwing version of to_binary/1
Examples
iex> ExPlasma.Encoding.to_binary!("0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e")
<<29, 246, 47, 41, 27, 46, 150, 159, 176, 132, 157, 153, 217, 206, 65, 226, 241,
55, 0, 110>>
Link to this function
to_hex(non_hex)
Specs
to_hex(binary() | non_neg_integer()) :: String.t()
Converts binary and integer values into its hex string equivalent.
Examples
# Convert a raw binary to hex
iex> raw = <<29, 246, 47, 41, 27, 46, 150, 159, 176, 132, 157, 153, 217, 206, 65, 226, 241, 55, 0, 110>>
iex> ExPlasma.Encoding.to_hex(raw)
"0x1df62f291b2e969fb0849d99d9ce41e2f137006e"
# Convert an integer to hex
iex> ExPlasma.Encoding.to_hex(1)
"0x1"
Link to this function
to_int(encoded)
Specs
to_int(String.t()) :: non_neg_integer()
Converts a hex string into the integer value.
Examples
# Convert a hex string into an integer
iex> ExPlasma.Encoding.to_int("0xb")
11
# Convert a binary into an integer
iex> ExPlasma.Encoding.to_int(<<11>>)
11