Skip to content

Commit

Permalink
Improve parameters order for smart contract STD
Browse files Browse the repository at this point in the history
The transaction statements functions using key value parameters
can use a non ordered list of parameters.

The parameters are converted into map to support this.
  • Loading branch information
Samuel committed Sep 3, 2021
1 parent a4b409b commit 3de1c5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 10 additions & 12 deletions lib/archethic/contracts/interpreter/transaction_statements.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ defmodule ArchEthic.Contracts.Interpreter.TransactionStatements do
}
"""
@spec add_uco_transfer(Transaction.t(), list()) :: Transaction.t()
def add_uco_transfer(tx = %Transaction{}, [{"to", to}, {"amount", amount}])
when is_binary(to) and is_float(amount) do
def add_uco_transfer(tx = %Transaction{}, args) when is_list(args) do
%{"to" => to, "amount" => amount} = Enum.into(args, %{})
update_in(
tx,
[Access.key(:data), Access.key(:ledger), Access.key(:uco), Access.key(:transfers)],
Expand Down Expand Up @@ -78,8 +78,9 @@ defmodule ArchEthic.Contracts.Interpreter.TransactionStatements do
}
"""
@spec add_nft_transfer(Transaction.t(), list()) :: Transaction.t()
def add_nft_transfer(tx = %Transaction{}, [{"to", to}, {"amount", amount}, {"nft", nft}])
when is_binary(to) and is_binary(nft) and is_float(amount) do
def add_nft_transfer(tx = %Transaction{}, args) when is_list(args) do
%{"to" => to, "amount" => amount, "nft" => nft} = Enum.into(args, %{})

update_in(
tx,
[Access.key(:data), Access.key(:ledger), Access.key(:nft), Access.key(:transfers)],
Expand Down Expand Up @@ -144,14 +145,11 @@ defmodule ArchEthic.Contracts.Interpreter.TransactionStatements do
}
}
"""
@spec add_authorized_key(Transaction.t(), list()) :: map()
def add_authorized_key(tx = %Transaction{}, [
{"secret_index", secret_index},
{"public_key", public_key},
{"encrypted_secret_key", encrypted_secret_key}
])
when is_integer(secret_index) and secret_index >= 0 and is_binary(public_key) and
is_binary(encrypted_secret_key) do
@spec add_authorized_key(Transaction.t(), list()) :: Transaction.t()
def add_authorized_key(tx = %Transaction{}, args) when is_list(args) do

%{ "secret_index" => secret_index, "public_key" => public_key, "encrypted_secret_key" => encrypted_secret_key } = Enum.into(args, %{})

update_in(
tx,
[Access.key(:data), Access.key(:keys), Access.key(:authorized_keys)],
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule ArchEthic.MixProject do
def project do
[
app: :archethic,
version: "0.11.0",
version: "0.11.1",
build_path: "_build",
config_path: "config/config.exs",
deps_path: "deps",
Expand Down

0 comments on commit 3de1c5c

Please sign in to comment.