View Source DigitalToken (Digital Token v0.4.0)
Functions to validate, search and retrieve digital token data sourced from the DTIF registry.
Link to this section Summary
Types
A digital token may have zero of more short names associated with it. They are arbitrary strings, usually three or four characters in length. For example "BTC", "ETH" and "DOGE".
A mapping from a short name to token identifier.
A mapping of digital token identifiers to a currency symbol for that token.
The structure of data matching that hosted in the DTIF registry/
token_id is a random 9-character string defined by the dtif registry that uniquely identifies a digital token.
A mapping of digital token identifiers to the registry data for that token.
Functions
Returns the registry data for a given token identifier.
Returns the registry data for a given token identifier.
Returns the long name of a digital token.
Returns the short name of a digital token.
Returns a mapping of digital token short names to digital token identifiers.
Returns a currency symbol used in number formatting.
Returns a mapping of digital token identifiers names to a currency symbol.
Returns a map of the digital tokens in the dtif registry.
Validates a token identifier or short name and returns the token identifier or an error.
Link to this section Types
@type short_name() :: String.t()
A digital token may have zero of more short names associated with it. They are arbitrary strings, usually three or four characters in length. For example "BTC", "ETH" and "DOGE".
@type short_name_map() :: %{required(short_name()) => token_id()}
A mapping from a short name to token identifier.
A mapping of digital token identifiers to a currency symbol for that token.
The structure of data matching that hosted in the DTIF registry/
@type token_id() :: String.t()
token_id is a random 9-character string defined by the dtif registry that uniquely identifies a digital token.
A mapping of digital token identifiers to the registry data for that token.
Link to this section Functions
@spec get_token!(token_id() | short_name()) :: t() | no_return()
Returns the registry data for a given token identifier.
arugments
Arugments
id
is any token identifier or short name
returns
Returns
registry_data
orraises an exception
example
Example
DigitalToken.get_token("BTC")
#=> %DigitalToken{
header: %{
dlt_type: :blockchain,
dti: "4H95J0R2X",
dti_type: :native,
template_version: #Version<1.0.0>
},
informative: %{
long_name: "Bitcoin",
public_distributed_ledger_indication: false,
short_names: ["BTC", "XBT"],
unit_multiplier: 100000000,
url: "https://github.com/bitcoin/bitcoin"
},
metadata: %{
.....
@spec get_token(token_id() | short_name()) :: {:ok, t()} | {:error, {module(), any()}}
Returns the registry data for a given token identifier.
arugments
Arugments
id
is any token identifier or short name
returns
Returns
{:ok, registry_data}
or{:error, {exception, id}}
example
Example
DigitalToken.get_token("BTC")
#=> {:ok,
%DigitalToken{
header: %{
dlt_type: :blockchain,
dti: "4H95J0R2X",
dti_type: :native,
template_version: #Version<1.0.0>
},
informative: %{
long_name: "Bitcoin",
public_distributed_ledger_indication: false,
short_names: ["BTC", "XBT"],
unit_multiplier: 100000000,
url: "https://github.com/bitcoin/bitcoin"
},
metadata: %{
.....
Returns the long name of a digital token.
arguments
Arguments
token_id
is any validate digitial token identifier.
returns
Returns
{:ok, long_name}
wherelong_name
is the token's registered name.{:error, {exceoption, reason}}
examples
Examples
iex> DigitalToken.long_name "BTC"
{:ok, "Bitcoin"}
iex> DigitalToken.long_name "4H95J0R2X"
{:ok, "Bitcoin"}
iex> DigitalToken.long_name "W0HBX7RC4"
{:ok, "Terra"}
Returns the short name of a digital token.
arguments
Arguments
token_id
is any validate digitial token identifier.
returns
Returns
{:ok, short_name}
whereshort_name
is either the first short name intoken.informative.short_names
or the token long name if there are no short names.{:error, {exceoption, reason}}
examples
Examples
iex> DigitalToken.short_name "BTC"
{:ok, "BTC"}
iex> DigitalToken.short_name "4H95J0R2X"
{:ok, "BTC"}
iex> DigitalToken.short_name "W0HBX7RC4"
{:ok, "Terra"}
@spec short_names() :: short_name_map()
Returns a mapping of digital token short names to digital token identifiers.
Returns a currency symbol used in number formatting.
arguements
Arguements
token_id
is any validate digitial token identifier.style
is a number in the range1
to4
as follows:1
is the token's symbol, if it exists2
is the token's short name as a proxy for a currency code3
is the token's long name4
is the token's symbol as a proxy for a narrow currency symbol
returns
Returns
{:ok, symbol}
or{:error, {exception, reason}}
examples
Examples
iex> DigitalToken.symbol "BTC", 1
{:ok, "₿"}
iex> DigitalToken.symbol "BTC", 2
{:ok, "BTC"}
iex> DigitalToken.symbol "BTC", 3
{:ok, "Bitcoin"}
iex> DigitalToken.symbol "BTC", 4
{:ok, "₿"}
iex> DigitalToken.symbol "ETH", 4
{:ok, "Ξ"}
iex> DigitalToken.symbol "DOGE", 4
{:ok, "Ð"}
iex> DigitalToken.symbol "DODGY", 4
{:error, {DigitalToken.UnknownTokenError, "DODGY"}}
@spec symbols() :: symbol_map()
Returns a mapping of digital token identifiers names to a currency symbol.
@spec tokens() :: token_map()
Returns a map of the digital tokens in the dtif registry.
@spec validate_token(token_id() | short_name()) :: {:ok, token_id()} | {:error, {module(), any()}}
Validates a token identifier or short name and returns the token identifier or an error.
arguments
Arguments
id
is any token identifier or short name
returns
Returns
{:ok, token_id}
or{:error, {exception, id}}
example
Example
iex> DigitalToken.validate_token("BTC")
{:ok, "4H95J0R2X"}
iex> DigitalToken.validate_token("Bitcoin")
{:ok, "4H95J0R2X"}
iex> DigitalToken.validate_token "4H95J0R2X"
{:ok, "4H95J0R2X"}
iex> DigitalToken.validate_token("Nothing")
{:error, {DigitalToken.UnknownTokenError, "Nothing"}}