Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token standard #390

Merged
7 commits merged into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/archethic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ defmodule Archethic do

defp get_balance([node | rest], address) do
case P2P.send_message(node, %GetBalance{address: address}) do
{:ok, %Balance{uco: uco, nft: nft}} ->
{:ok, %{uco: uco, nft: nft}}
{:ok, %Balance{uco: uco, token: token}} ->
{:ok, %{uco: uco, token: token}}

{:error, _} ->
get_balance(rest, address)
Expand Down
16 changes: 9 additions & 7 deletions lib/archethic/account.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Archethic.Account do
@moduledoc false

alias __MODULE__.MemTables.NFTLedger
alias __MODULE__.MemTables.TokenLedger
alias __MODULE__.MemTables.UCOLedger
alias __MODULE__.MemTablesLoader

Expand All @@ -13,7 +13,9 @@ defmodule Archethic.Account do

@type balance :: %{
uco: amount :: pos_integer(),
nft: %{(address :: binary()) => amount :: pos_integer()}
token: %{
{address :: binary(), token_id :: non_neg_integer()} => amount :: pos_integer()
}
}

@doc """
Expand All @@ -23,12 +25,12 @@ defmodule Archethic.Account do
def get_balance(address) when is_binary(address) do
address
|> get_unspent_outputs()
|> Enum.reduce(%{uco: 0, nft: %{}}, fn
|> Enum.reduce(%{uco: 0, token: %{}}, fn
%UnspentOutput{type: :UCO, amount: amount}, acc ->
Map.update!(acc, :uco, &(&1 + amount))

%UnspentOutput{type: {:NFT, nft_address}, amount: amount}, acc ->
update_in(acc, [:nft, Access.key(nft_address, 0)], &(&1 + amount))
%UnspentOutput{type: {:token, token_address, token_id}, amount: amount}, acc ->
update_in(acc, [:token, Access.key({token_address, token_id}, 0)], &(&1 + amount))
end)
end

Expand All @@ -37,15 +39,15 @@ defmodule Archethic.Account do
"""
@spec get_unspent_outputs(binary()) :: list(UnspentOutput.t())
def get_unspent_outputs(address) do
UCOLedger.get_unspent_outputs(address) ++ NFTLedger.get_unspent_outputs(address)
UCOLedger.get_unspent_outputs(address) ++ TokenLedger.get_unspent_outputs(address)
end

@doc """
List all the inputs for a given transaction (including the spend/unspent inputs)
"""
@spec get_inputs(binary()) :: list(TransactionInput.t())
def get_inputs(address) do
UCOLedger.get_inputs(address) ++ NFTLedger.get_inputs(address)
UCOLedger.get_inputs(address) ++ TokenLedger.get_inputs(address)
end

@doc """
Expand Down
201 changes: 0 additions & 201 deletions lib/archethic/account/mem_tables/nft_ledger.ex

This file was deleted.

Loading