View Source Tezex.Forge (tezex v3.0.1)
Convert Tezos Micheline data from/to binary form for injection into the Tezos blockchain (aka forging/unforging Micheline).
Mostly ported from pytezos@9352c4579e436b92f8070343964af20747255197
pytezos / MIT License / (c) 2020 Baking Bad / (c) 2018 Arthur Breitman
Summary
Types
Represents a base58 encoding configuration.
Represents the encoding type for input/output operations.
Can be either :bytes
for raw binary data or :hex
for hexadecimal string representation.
Functions
Encode address or key hash into bytes.
Encodes a signed unbounded integer into byte form.
Encode a Micheline expression into byte form.
Encode a non-negative integer using LEB128 encoding.
Decode a contract (address + optional entrypoint) from bytes, returning a string with the base58 encoded address and, if present, the entrypoint separated by %
.
Decode a signed unbounded integer from bytes.
Parse Micheline map from bytes.
Types
@type base58_encoding() :: %{ e_prefix: String.t(), e_len: non_neg_integer(), d_prefix: binary(), d_len: non_neg_integer() }
Represents a base58 encoding configuration.
@type io_encoding() :: :bytes | :hex
Represents the encoding type for input/output operations.
Can be either :bytes
for raw binary data or :hex
for hexadecimal string representation.
Functions
@spec forge_address(binary(), io_encoding(), boolean()) :: nonempty_binary()
Encode address or key hash into bytes.
value
is a base58 encoded address or key_hashtz_only
indicates that it's a key_hash (will be encoded in a more compact form)
@spec forge_array(binary(), io_encoding(), non_neg_integer()) :: binary()
@spec forge_base58(binary(), io_encoding()) :: binary()
@spec forge_bool(boolean(), io_encoding()) :: nonempty_binary()
@spec forge_contract(binary(), io_encoding()) :: binary()
@spec forge_int16(integer(), io_encoding()) :: nonempty_binary()
@spec forge_int32(integer(), io_encoding()) :: nonempty_binary()
@spec forge_int(integer(), io_encoding()) :: nonempty_binary()
Encodes a signed unbounded integer into byte form.
Parameters
value
- The integer to be encoded.output_encoding
- The encoding type for the output. Defaults to:bytes
.
Returns
A binary string representing the encoded integer.
Examples
iex> forge_int(123)
<<123>>
iex> forge_int(123, :hex)
"7B"
@spec forge_micheline(list() | map(), io_encoding()) :: binary()
Encode a Micheline expression into byte form.
@spec forge_nat(non_neg_integer(), io_encoding()) :: nonempty_binary()
Encode a non-negative integer using LEB128 encoding.
@spec forge_public_key(binary(), io_encoding()) :: nonempty_binary()
@spec forge_script(map(), io_encoding()) :: binary()
@spec forge_script_expr(binary(), io_encoding()) :: nonempty_binary()
@spec unforge_address(binary(), io_encoding()) :: nonempty_binary()
@spec unforge_array(binary(), io_encoding(), non_neg_integer()) :: {binary(), non_neg_integer()}
@spec unforge_chain_id(binary(), io_encoding()) :: nonempty_binary()
@spec unforge_contract(binary(), io_encoding()) :: nonempty_binary()
Decode a contract (address + optional entrypoint) from bytes, returning a string with the base58 encoded address and, if present, the entrypoint separated by %
.
@spec unforge_int(binary(), io_encoding()) :: {integer(), non_neg_integer()}
Decode a signed unbounded integer from bytes.
@spec unforge_micheline(binary(), io_encoding()) :: list() | map()
Parse Micheline map from bytes.
@spec unforge_public_key(binary(), io_encoding()) :: nonempty_binary()
@spec unforge_signature(binary(), io_encoding()) :: nonempty_binary()