diff --git a/.gitignore b/.gitignore index a4a9a7d..b20138a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,10 +7,6 @@ # The directory Mix downloads your dependencies sources to. /deps/ -# Directories, where we keep autogenerated code. -/lib/aeternity_node/ -/lib/middleware/ - # Where third-party dependencies like ExDoc output generated docs. /doc/ diff --git a/examples/usage.md b/examples/usage.md index 18e3091..97a69f5 100644 --- a/examples/usage.md +++ b/examples/usage.md @@ -5,7 +5,7 @@ First, add **Aepp SDK Elixir** to your `mix.exs` dependencies: ``` elixir defp deps do [ - {:aepp_sdk_elixir, git: "https://github.com/aeternity/aepp-sdk-elixir.git", tag: "v0.5.1"} + {:aepp_sdk_elixir, git: "https://github.com/aeternity/aepp-sdk-elixir.git", tag: "v0.5.2"} ] end ``` diff --git a/lib/aeternity_node/.openapi-generator-ignore b/lib/aeternity_node/.openapi-generator-ignore new file mode 100644 index 0000000..7484ee5 --- /dev/null +++ b/lib/aeternity_node/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/lib/aeternity_node/.openapi-generator/VERSION b/lib/aeternity_node/.openapi-generator/VERSION new file mode 100644 index 0000000..83a328a --- /dev/null +++ b/lib/aeternity_node/.openapi-generator/VERSION @@ -0,0 +1 @@ +4.1.0-SNAPSHOT \ No newline at end of file diff --git a/lib/aeternity_node/api/account.ex b/lib/aeternity_node/api/account.ex new file mode 100644 index 0000000..d68b7e4 --- /dev/null +++ b/lib/aeternity_node/api/account.ex @@ -0,0 +1,122 @@ +defmodule AeternityNode.Api.Account do + @moduledoc """ + API calls for all endpoints tagged `Account`. + """ + + alias AeternityNode.Connection + import AeternityNode.RequestBuilder + + @doc """ + Get an account by public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The public key of the account + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Account{}} on success + {:error, info} on failure + """ + @spec get_account_by_pubkey(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.Account.t()} | {:error, Tesla.Env.t()} + def get_account_by_pubkey(connection, pubkey, _opts \\ []) do + %{} + |> method(:get) + |> url("/accounts/#{pubkey}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Account{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get an account by public key after the block indicated by hash + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The public key of the account + - hash (String.t): The hash of the block + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Account{}} on success + {:error, info} on failure + """ + @spec get_account_by_pubkey_and_hash(Tesla.Env.client(), String.t(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.Account.t()} | {:error, Tesla.Env.t()} + def get_account_by_pubkey_and_hash(connection, pubkey, hash, _opts \\ []) do + %{} + |> method(:get) + |> url("/accounts/#{pubkey}/hash/#{hash}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Account{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get an account by public key after the opening key block of the generation at height + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The public key of the account + - height (integer()): The height + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Account{}} on success + {:error, info} on failure + """ + @spec get_account_by_pubkey_and_height(Tesla.Env.client(), String.t(), integer(), keyword()) :: + {:ok, AeternityNode.Model.Account.t()} | {:error, Tesla.Env.t()} + def get_account_by_pubkey_and_height(connection, pubkey, height, _opts \\ []) do + %{} + |> method(:get) + |> url("/accounts/#{pubkey}/height/#{height}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Account{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get pending account transactions by public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The public key of the account + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.GenericTxs{}} on success + {:error, info} on failure + """ + @spec get_pending_account_transactions_by_pubkey(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.GenericTxs.t()} | {:error, Tesla.Env.t()} + def get_pending_account_transactions_by_pubkey(connection, pubkey, _opts \\ []) do + %{} + |> method(:get) + |> url("/accounts/#{pubkey}/transactions/pending") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.GenericTxs{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end +end diff --git a/lib/aeternity_node/api/chain.ex b/lib/aeternity_node/api/chain.ex new file mode 100644 index 0000000..d0a36d3 --- /dev/null +++ b/lib/aeternity_node/api/chain.ex @@ -0,0 +1,420 @@ +defmodule AeternityNode.Api.Chain do + @moduledoc """ + API calls for all endpoints tagged `Chain`. + """ + + alias AeternityNode.Connection + import AeternityNode.RequestBuilder + + @doc """ + Get the current generation + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Generation{}} on success + {:error, info} on failure + """ + @spec get_current_generation(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.Generation.t()} | {:error, Tesla.Env.t()} + def get_current_generation(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/generations/current") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Generation{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get the current key block + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.KeyBlock{}} on success + {:error, info} on failure + """ + @spec get_current_key_block(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.KeyBlock.t()} | {:error, Tesla.Env.t()} + def get_current_key_block(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/key-blocks/current") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.KeyBlock{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get the hash of the current key block + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.InlineResponse200{}} on success + {:error, info} on failure + """ + @spec get_current_key_block_hash(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.InlineResponse200.t()} | {:error, Tesla.Env.t()} + def get_current_key_block_hash(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/key-blocks/current/hash") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.InlineResponse200{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get the height of the current key block + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.InlineResponse2001{}} on success + {:error, info} on failure + """ + @spec get_current_key_block_height(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.InlineResponse2001.t()} | {:error, Tesla.Env.t()} + def get_current_key_block_height(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/key-blocks/current/height") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.InlineResponse2001{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a generation by hash + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - hash (String.t): The hash of the generation + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Generation{}} on success + {:error, info} on failure + """ + @spec get_generation_by_hash(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.Generation.t()} | {:error, Tesla.Env.t()} + def get_generation_by_hash(connection, hash, _opts \\ []) do + %{} + |> method(:get) + |> url("/generations/hash/#{hash}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Generation{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a generation by height + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - height (integer()): The height + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Generation{}} on success + {:error, info} on failure + """ + @spec get_generation_by_height(Tesla.Env.client(), integer(), keyword()) :: + {:ok, AeternityNode.Model.Generation.t()} | {:error, Tesla.Env.t()} + def get_generation_by_height(connection, height, _opts \\ []) do + %{} + |> method(:get) + |> url("/generations/height/#{height}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Generation{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a key block by hash + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - hash (String.t): The hash of the block + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.KeyBlock{}} on success + {:error, info} on failure + """ + @spec get_key_block_by_hash(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.KeyBlock.t()} | {:error, Tesla.Env.t()} + def get_key_block_by_hash(connection, hash, _opts \\ []) do + %{} + |> method(:get) + |> url("/key-blocks/hash/#{hash}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.KeyBlock{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a key block by height + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - height (integer()): The height + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.KeyBlock{}} on success + {:error, info} on failure + """ + @spec get_key_block_by_height(Tesla.Env.client(), integer(), keyword()) :: + {:ok, AeternityNode.Model.KeyBlock.t()} | {:error, Tesla.Env.t()} + def get_key_block_by_height(connection, height, _opts \\ []) do + %{} + |> method(:get) + |> url("/key-blocks/height/#{height}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.KeyBlock{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a micro block header by hash + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - hash (String.t): The hash of the block + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.MicroBlockHeader{}} on success + {:error, info} on failure + """ + @spec get_micro_block_header_by_hash(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.MicroBlockHeader.t()} | {:error, Tesla.Env.t()} + def get_micro_block_header_by_hash(connection, hash, _opts \\ []) do + %{} + |> method(:get) + |> url("/micro-blocks/hash/#{hash}/header") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.MicroBlockHeader{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a micro block transaction by hash and index + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - hash (String.t): The hash of the block + - index (integer()): The index of the transaction in a block + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.GenericSignedTx{}} on success + {:error, info} on failure + """ + @spec get_micro_block_transaction_by_hash_and_index( + Tesla.Env.client(), + String.t(), + integer(), + keyword() + ) :: {:ok, AeternityNode.Model.GenericSignedTx.t()} | {:error, Tesla.Env.t()} + def get_micro_block_transaction_by_hash_and_index(connection, hash, index, _opts \\ []) do + %{} + |> method(:get) + |> url("/micro-blocks/hash/#{hash}/transactions/index/#{index}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.GenericSignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get micro block transactions by hash + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - hash (String.t): The hash of the block + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.GenericTxs{}} on success + {:error, info} on failure + """ + @spec get_micro_block_transactions_by_hash(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.GenericTxs.t()} | {:error, Tesla.Env.t()} + def get_micro_block_transactions_by_hash(connection, hash, _opts \\ []) do + %{} + |> method(:get) + |> url("/micro-blocks/hash/#{hash}/transactions") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.GenericTxs{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get micro block transaction count by hash + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - hash (String.t): The hash of the block + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.InlineResponse2002{}} on success + {:error, info} on failure + """ + @spec get_micro_block_transactions_count_by_hash(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.InlineResponse2002.t()} | {:error, Tesla.Env.t()} + def get_micro_block_transactions_count_by_hash(connection, hash, _opts \\ []) do + %{} + |> method(:get) + |> url("/micro-blocks/hash/#{hash}/transactions/count") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.InlineResponse2002{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get the pending key block + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.KeyBlock{}} on success + {:error, info} on failure + """ + @spec get_pending_key_block(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.KeyBlock.t()} | {:error, Tesla.Env.t()} + def get_pending_key_block(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/key-blocks/pending") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.KeyBlock{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get the top block (either key or micro block) + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.KeyBlockOrMicroBlockHeader{}} on success + {:error, info} on failure + """ + @spec get_top_block(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.KeyBlockOrMicroBlockHeader.t()} | {:error, Tesla.Env.t()} + def get_top_block(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/blocks/top") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.KeyBlockOrMicroBlockHeader{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Post a mined key block + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (KeyBlock): Mined key block + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec post_key_block(Tesla.Env.client(), AeternityNode.Model.KeyBlock.t(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def post_key_block(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/key-blocks") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false}, + {400, %AeternityNode.Model.Error{}} + ]) + end +end diff --git a/lib/aeternity_node/api/channel.ex b/lib/aeternity_node/api/channel.ex new file mode 100644 index 0000000..16ad217 --- /dev/null +++ b/lib/aeternity_node/api/channel.ex @@ -0,0 +1,282 @@ +defmodule AeternityNode.Api.Channel do + @moduledoc """ + API calls for all endpoints tagged `Channel`. + """ + + alias AeternityNode.Connection + import AeternityNode.RequestBuilder + + @doc """ + Get channel by public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The pubkey of the channel + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Channel{}} on success + {:error, info} on failure + """ + @spec get_channel_by_pubkey(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.Channel.t()} | {:error, Tesla.Env.t()} + def get_channel_by_pubkey(connection, pubkey, _opts \\ []) do + %{} + |> method(:get) + |> url("/channels/#{pubkey}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Channel{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_close_mutual transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelCloseMutualTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_close_mutual( + Tesla.Env.client(), + AeternityNode.Model.ChannelCloseMutualTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_close_mutual(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/close/mutual") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_close_solo transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelCloseSoloTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_close_solo( + Tesla.Env.client(), + AeternityNode.Model.ChannelCloseSoloTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_close_solo(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/close/solo") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_create transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelCreateTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_create( + Tesla.Env.client(), + AeternityNode.Model.ChannelCreateTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_create(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/create") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_deposit transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelDepositTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_deposit( + Tesla.Env.client(), + AeternityNode.Model.ChannelDepositTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_deposit(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/deposit") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_settle transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelSettleTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_settle( + Tesla.Env.client(), + AeternityNode.Model.ChannelSettleTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_settle(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/settle") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_slash transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelSlashTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_slash(Tesla.Env.client(), AeternityNode.Model.ChannelSlashTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_slash(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/slash") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_snapshot_solo transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelSnapshotSoloTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_snapshot_solo( + Tesla.Env.client(), + AeternityNode.Model.ChannelSnapshotSoloTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_snapshot_solo(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/snapshot/solo") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_withdrawal transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelWithdrawTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_withdraw( + Tesla.Env.client(), + AeternityNode.Model.ChannelWithdrawTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_withdraw(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/withdraw") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end +end diff --git a/lib/aeternity_node/api/contract.ex b/lib/aeternity_node/api/contract.ex new file mode 100644 index 0000000..369c4b7 --- /dev/null +++ b/lib/aeternity_node/api/contract.ex @@ -0,0 +1,181 @@ +defmodule AeternityNode.Api.Contract do + @moduledoc """ + API calls for all endpoints tagged `Contract`. + """ + + alias AeternityNode.Connection + import AeternityNode.RequestBuilder + + @doc """ + Get a contract by pubkey + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The pubkey of the contract + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.ContractObject{}} on success + {:error, info} on failure + """ + @spec get_contract(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.ContractObject.t()} | {:error, Tesla.Env.t()} + def get_contract(connection, pubkey, _opts \\ []) do + %{} + |> method(:get) + |> url("/contracts/#{pubkey}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.ContractObject{}}, + {400, %AeternityNode.Model.Error{}}, + {404, false} + ]) + end + + @doc """ + Get contract code by pubkey + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The pubkey of the contract + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.ByteCode{}} on success + {:error, info} on failure + """ + @spec get_contract_code(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.ByteCode.t()} | {:error, Tesla.Env.t()} + def get_contract_code(connection, pubkey, _opts \\ []) do + %{} + |> method(:get) + |> url("/contracts/#{pubkey}/code") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.ByteCode{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a proof of inclusion for a contract + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): Contract pubkey to get proof for + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.PoI{}} on success + {:error, info} on failure + """ + @spec get_contract_po_i(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.PoI.t()} | {:error, Tesla.Env.t()} + def get_contract_po_i(connection, pubkey, _opts \\ []) do + %{} + |> method(:get) + |> url("/contracts/#{pubkey}/poi") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.PoI{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get contract store by pubkey + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The pubkey of the contract + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.ContractStore{}} on success + {:error, info} on failure + """ + @spec get_contract_store(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.ContractStore.t()} | {:error, Tesla.Env.t()} + def get_contract_store(connection, pubkey, _opts \\ []) do + %{} + |> method(:get) + |> url("/contracts/#{pubkey}/store") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.ContractStore{}}, + {400, %AeternityNode.Model.Error{}}, + {404, false} + ]) + end + + @doc """ + Get a contract_call transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ContractCallTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_contract_call(Tesla.Env.client(), AeternityNode.Model.ContractCallTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_contract_call(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/contracts/call") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a contract_create transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ContractCreateTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.CreateContractUnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_contract_create( + Tesla.Env.client(), + AeternityNode.Model.ContractCreateTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.CreateContractUnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_contract_create(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/contracts/create") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.CreateContractUnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end +end diff --git a/lib/aeternity_node/api/debug.ex b/lib/aeternity_node/api/debug.ex new file mode 100644 index 0000000..cf3c1ef --- /dev/null +++ b/lib/aeternity_node/api/debug.ex @@ -0,0 +1,799 @@ +defmodule AeternityNode.Api.Debug do + @moduledoc """ + API calls for all endpoints tagged `Debug`. + """ + + alias AeternityNode.Connection + import AeternityNode.RequestBuilder + + @doc """ + Dry-run transactions on top of a given block. Supports SpendTx, ContractCreateTx and ContractCallTx + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (DryRunInput): transactions + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.DryRunResults{}} on success + {:error, info} on failure + """ + @spec dry_run_txs(Tesla.Env.client(), AeternityNode.Model.DryRunInput.t(), keyword()) :: + {:ok, AeternityNode.Model.DryRunResults.t()} | {:error, Tesla.Env.t()} + def dry_run_txs(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/transactions/dry-run") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.DryRunResults{}}, + {403, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Compute commitment ID for a given salt and name + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - name (String.t): Name + - salt (integer()): Salt + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.CommitmentId{}} on success + {:error, info} on failure + """ + @spec get_commitment_id(Tesla.Env.client(), String.t(), integer(), keyword()) :: + {:ok, AeternityNode.Model.CommitmentId.t()} | {:error, Tesla.Env.t()} + def get_commitment_id(connection, name, salt, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/names/commitment-id") + |> add_param(:query, :name, name) + |> add_param(:query, :salt, salt) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.CommitmentId{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get node's beneficiary public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.PubKey{}} on success + {:error, info} on failure + """ + @spec get_node_beneficiary(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.PubKey.t()} | {:error, Tesla.Env.t()} + def get_node_beneficiary(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/accounts/beneficiary") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.PubKey{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get node's public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.PubKey{}} on success + {:error, info} on failure + """ + @spec get_node_pubkey(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.PubKey.t()} | {:error, Tesla.Env.t()} + def get_node_pubkey(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/accounts/node") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.PubKey{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get node Peers + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Peers{}} on success + {:error, info} on failure + """ + @spec get_peers(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.Peers.t()} | {:error, Tesla.Env.t()} + def get_peers(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/peers") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Peers{}}, + {403, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get pending transactions + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.GenericTxs{}} on success + {:error, info} on failure + """ + @spec get_pending_transactions(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.GenericTxs.t()} | {:error, Tesla.Env.t()} + def get_pending_transactions(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/transactions/pending") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.GenericTxs{}} + ]) + end + + @doc """ + Get total token supply at height + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - height (integer()): The height + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.TokenSupply{}} on success + {:error, info} on failure + """ + @spec get_token_supply_by_height(Tesla.Env.client(), integer(), keyword()) :: + {:ok, AeternityNode.Model.TokenSupply.t()} | {:error, Tesla.Env.t()} + def get_token_supply_by_height(connection, height, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/token-supply/height/#{height}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.TokenSupply{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_close_mutual transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelCloseMutualTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_close_mutual( + Tesla.Env.client(), + AeternityNode.Model.ChannelCloseMutualTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_close_mutual(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/close/mutual") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_close_solo transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelCloseSoloTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_close_solo( + Tesla.Env.client(), + AeternityNode.Model.ChannelCloseSoloTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_close_solo(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/close/solo") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_create transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelCreateTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_create( + Tesla.Env.client(), + AeternityNode.Model.ChannelCreateTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_create(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/create") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_deposit transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelDepositTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_deposit( + Tesla.Env.client(), + AeternityNode.Model.ChannelDepositTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_deposit(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/deposit") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_settle transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelSettleTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_settle( + Tesla.Env.client(), + AeternityNode.Model.ChannelSettleTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_settle(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/settle") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_slash transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelSlashTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_slash(Tesla.Env.client(), AeternityNode.Model.ChannelSlashTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_slash(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/slash") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_snapshot_solo transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelSnapshotSoloTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_snapshot_solo( + Tesla.Env.client(), + AeternityNode.Model.ChannelSnapshotSoloTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_snapshot_solo(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/snapshot/solo") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_withdrawal transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelWithdrawTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_withdraw( + Tesla.Env.client(), + AeternityNode.Model.ChannelWithdrawTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_withdraw(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/withdraw") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a contract_call transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ContractCallTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_contract_call(Tesla.Env.client(), AeternityNode.Model.ContractCallTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_contract_call(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/contracts/call") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a contract_create transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ContractCreateTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.CreateContractUnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_contract_create( + Tesla.Env.client(), + AeternityNode.Model.ContractCreateTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.CreateContractUnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_contract_create(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/contracts/create") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.CreateContractUnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a name_claim transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (NameClaimTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_name_claim(Tesla.Env.client(), AeternityNode.Model.NameClaimTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_name_claim(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/names/claim") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a name_preclaim transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (NamePreclaimTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_name_preclaim(Tesla.Env.client(), AeternityNode.Model.NamePreclaimTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_name_preclaim(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/names/preclaim") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a name_revoke transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (NameRevokeTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_name_revoke(Tesla.Env.client(), AeternityNode.Model.NameRevokeTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_name_revoke(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/names/revoke") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a name_transfer transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (NameTransferTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_name_transfer(Tesla.Env.client(), AeternityNode.Model.NameTransferTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_name_transfer(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/names/transfer") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a name_update transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (NameUpdateTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_name_update(Tesla.Env.client(), AeternityNode.Model.NameUpdateTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_name_update(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/names/update") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get an oracle_extend transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (OracleExtendTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_oracle_extend(Tesla.Env.client(), AeternityNode.Model.OracleExtendTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_oracle_extend(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/oracles/extend") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get an oracle_query transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (OracleQueryTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_oracle_query(Tesla.Env.client(), AeternityNode.Model.OracleQueryTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_oracle_query(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/oracles/query") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a oracle_register transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (OracleRegisterTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_oracle_register( + Tesla.Env.client(), + AeternityNode.Model.OracleRegisterTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_oracle_register(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/oracles/register") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get an oracle_response transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (OracleRespondTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_oracle_respond( + Tesla.Env.client(), + AeternityNode.Model.OracleRespondTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_oracle_respond(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/oracles/respond") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a spend transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (SpendTx): A spend transaction + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_spend(Tesla.Env.client(), AeternityNode.Model.SpendTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_spend(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/transactions/spend") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end +end diff --git a/lib/aeternity_node/api/external.ex b/lib/aeternity_node/api/external.ex new file mode 100644 index 0000000..a4f05ef --- /dev/null +++ b/lib/aeternity_node/api/external.ex @@ -0,0 +1,906 @@ +defmodule AeternityNode.Api.External do + @moduledoc """ + API calls for all endpoints tagged `External`. + """ + + alias AeternityNode.Connection + import AeternityNode.RequestBuilder + + @doc """ + Get an account by public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The public key of the account + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Account{}} on success + {:error, info} on failure + """ + @spec get_account_by_pubkey(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.Account.t()} | {:error, Tesla.Env.t()} + def get_account_by_pubkey(connection, pubkey, _opts \\ []) do + %{} + |> method(:get) + |> url("/accounts/#{pubkey}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Account{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get an account by public key after the block indicated by hash + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The public key of the account + - hash (String.t): The hash of the block + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Account{}} on success + {:error, info} on failure + """ + @spec get_account_by_pubkey_and_hash(Tesla.Env.client(), String.t(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.Account.t()} | {:error, Tesla.Env.t()} + def get_account_by_pubkey_and_hash(connection, pubkey, hash, _opts \\ []) do + %{} + |> method(:get) + |> url("/accounts/#{pubkey}/hash/#{hash}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Account{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get an account by public key after the opening key block of the generation at height + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The public key of the account + - height (integer()): The height + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Account{}} on success + {:error, info} on failure + """ + @spec get_account_by_pubkey_and_height(Tesla.Env.client(), String.t(), integer(), keyword()) :: + {:ok, AeternityNode.Model.Account.t()} | {:error, Tesla.Env.t()} + def get_account_by_pubkey_and_height(connection, pubkey, height, _opts \\ []) do + %{} + |> method(:get) + |> url("/accounts/#{pubkey}/height/#{height}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Account{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get channel by public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The pubkey of the channel + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Channel{}} on success + {:error, info} on failure + """ + @spec get_channel_by_pubkey(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.Channel.t()} | {:error, Tesla.Env.t()} + def get_channel_by_pubkey(connection, pubkey, _opts \\ []) do + %{} + |> method(:get) + |> url("/channels/#{pubkey}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Channel{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a contract by pubkey + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The pubkey of the contract + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.ContractObject{}} on success + {:error, info} on failure + """ + @spec get_contract(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.ContractObject.t()} | {:error, Tesla.Env.t()} + def get_contract(connection, pubkey, _opts \\ []) do + %{} + |> method(:get) + |> url("/contracts/#{pubkey}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.ContractObject{}}, + {400, %AeternityNode.Model.Error{}}, + {404, false} + ]) + end + + @doc """ + Get contract code by pubkey + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The pubkey of the contract + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.ByteCode{}} on success + {:error, info} on failure + """ + @spec get_contract_code(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.ByteCode.t()} | {:error, Tesla.Env.t()} + def get_contract_code(connection, pubkey, _opts \\ []) do + %{} + |> method(:get) + |> url("/contracts/#{pubkey}/code") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.ByteCode{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a proof of inclusion for a contract + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): Contract pubkey to get proof for + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.PoI{}} on success + {:error, info} on failure + """ + @spec get_contract_po_i(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.PoI.t()} | {:error, Tesla.Env.t()} + def get_contract_po_i(connection, pubkey, _opts \\ []) do + %{} + |> method(:get) + |> url("/contracts/#{pubkey}/poi") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.PoI{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get contract store by pubkey + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The pubkey of the contract + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.ContractStore{}} on success + {:error, info} on failure + """ + @spec get_contract_store(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.ContractStore.t()} | {:error, Tesla.Env.t()} + def get_contract_store(connection, pubkey, _opts \\ []) do + %{} + |> method(:get) + |> url("/contracts/#{pubkey}/store") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.ContractStore{}}, + {400, %AeternityNode.Model.Error{}}, + {404, false} + ]) + end + + @doc """ + Get the current generation + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Generation{}} on success + {:error, info} on failure + """ + @spec get_current_generation(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.Generation.t()} | {:error, Tesla.Env.t()} + def get_current_generation(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/generations/current") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Generation{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get the current key block + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.KeyBlock{}} on success + {:error, info} on failure + """ + @spec get_current_key_block(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.KeyBlock.t()} | {:error, Tesla.Env.t()} + def get_current_key_block(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/key-blocks/current") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.KeyBlock{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get the hash of the current key block + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.InlineResponse200{}} on success + {:error, info} on failure + """ + @spec get_current_key_block_hash(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.InlineResponse200.t()} | {:error, Tesla.Env.t()} + def get_current_key_block_hash(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/key-blocks/current/hash") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.InlineResponse200{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get the height of the current key block + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.InlineResponse2001{}} on success + {:error, info} on failure + """ + @spec get_current_key_block_height(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.InlineResponse2001.t()} | {:error, Tesla.Env.t()} + def get_current_key_block_height(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/key-blocks/current/height") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.InlineResponse2001{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a generation by hash + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - hash (String.t): The hash of the generation + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Generation{}} on success + {:error, info} on failure + """ + @spec get_generation_by_hash(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.Generation.t()} | {:error, Tesla.Env.t()} + def get_generation_by_hash(connection, hash, _opts \\ []) do + %{} + |> method(:get) + |> url("/generations/hash/#{hash}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Generation{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a generation by height + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - height (integer()): The height + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Generation{}} on success + {:error, info} on failure + """ + @spec get_generation_by_height(Tesla.Env.client(), integer(), keyword()) :: + {:ok, AeternityNode.Model.Generation.t()} | {:error, Tesla.Env.t()} + def get_generation_by_height(connection, height, _opts \\ []) do + %{} + |> method(:get) + |> url("/generations/height/#{height}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Generation{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a key block by hash + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - hash (String.t): The hash of the block + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.KeyBlock{}} on success + {:error, info} on failure + """ + @spec get_key_block_by_hash(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.KeyBlock.t()} | {:error, Tesla.Env.t()} + def get_key_block_by_hash(connection, hash, _opts \\ []) do + %{} + |> method(:get) + |> url("/key-blocks/hash/#{hash}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.KeyBlock{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a key block by height + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - height (integer()): The height + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.KeyBlock{}} on success + {:error, info} on failure + """ + @spec get_key_block_by_height(Tesla.Env.client(), integer(), keyword()) :: + {:ok, AeternityNode.Model.KeyBlock.t()} | {:error, Tesla.Env.t()} + def get_key_block_by_height(connection, height, _opts \\ []) do + %{} + |> method(:get) + |> url("/key-blocks/height/#{height}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.KeyBlock{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a micro block header by hash + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - hash (String.t): The hash of the block + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.MicroBlockHeader{}} on success + {:error, info} on failure + """ + @spec get_micro_block_header_by_hash(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.MicroBlockHeader.t()} | {:error, Tesla.Env.t()} + def get_micro_block_header_by_hash(connection, hash, _opts \\ []) do + %{} + |> method(:get) + |> url("/micro-blocks/hash/#{hash}/header") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.MicroBlockHeader{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a micro block transaction by hash and index + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - hash (String.t): The hash of the block + - index (integer()): The index of the transaction in a block + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.GenericSignedTx{}} on success + {:error, info} on failure + """ + @spec get_micro_block_transaction_by_hash_and_index( + Tesla.Env.client(), + String.t(), + integer(), + keyword() + ) :: {:ok, AeternityNode.Model.GenericSignedTx.t()} | {:error, Tesla.Env.t()} + def get_micro_block_transaction_by_hash_and_index(connection, hash, index, _opts \\ []) do + %{} + |> method(:get) + |> url("/micro-blocks/hash/#{hash}/transactions/index/#{index}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.GenericSignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get micro block transactions by hash + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - hash (String.t): The hash of the block + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.GenericTxs{}} on success + {:error, info} on failure + """ + @spec get_micro_block_transactions_by_hash(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.GenericTxs.t()} | {:error, Tesla.Env.t()} + def get_micro_block_transactions_by_hash(connection, hash, _opts \\ []) do + %{} + |> method(:get) + |> url("/micro-blocks/hash/#{hash}/transactions") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.GenericTxs{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get micro block transaction count by hash + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - hash (String.t): The hash of the block + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.InlineResponse2002{}} on success + {:error, info} on failure + """ + @spec get_micro_block_transactions_count_by_hash(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.InlineResponse2002.t()} | {:error, Tesla.Env.t()} + def get_micro_block_transactions_count_by_hash(connection, hash, _opts \\ []) do + %{} + |> method(:get) + |> url("/micro-blocks/hash/#{hash}/transactions/count") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.InlineResponse2002{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get name entry from naming system + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - name (String.t): The name key of the name entry + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.NameEntry{}} on success + {:error, info} on failure + """ + @spec get_name_entry_by_name(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.NameEntry.t()} | {:error, Tesla.Env.t()} + def get_name_entry_by_name(connection, name, _opts \\ []) do + %{} + |> method(:get) + |> url("/names/#{name}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.NameEntry{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get an oracle by public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The public key of the oracle + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.RegisteredOracle{}} on success + {:error, info} on failure + """ + @spec get_oracle_by_pubkey(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.RegisteredOracle.t()} | {:error, Tesla.Env.t()} + def get_oracle_by_pubkey(connection, pubkey, _opts \\ []) do + %{} + |> method(:get) + |> url("/oracles/#{pubkey}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.RegisteredOracle{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get oracle queries by public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The public key of the oracle + - opts (KeywordList): [optional] Optional parameters + - :from (String.t): Last query id in previous page + - :limit (integer()): Max number of oracle queries + - :type (String.t): The type of a query: open, closed or all + ## Returns + + {:ok, %AeternityNode.Model.OracleQueries{}} on success + {:error, info} on failure + """ + @spec get_oracle_queries_by_pubkey(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.OracleQueries.t()} | {:error, Tesla.Env.t()} + def get_oracle_queries_by_pubkey(connection, pubkey, opts \\ []) do + optional_params = %{ + :from => :query, + :limit => :query, + :type => :query + } + + %{} + |> method(:get) + |> url("/oracles/#{pubkey}/queries") + |> add_optional_params(optional_params, opts) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.OracleQueries{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get an oracle query by public key and query ID + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The public key of the oracle + - query_id (String.t): The ID of the query + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.OracleQuery{}} on success + {:error, info} on failure + """ + @spec get_oracle_query_by_pubkey_and_query_id( + Tesla.Env.client(), + String.t(), + String.t(), + keyword() + ) :: {:ok, AeternityNode.Model.OracleQuery.t()} | {:error, Tesla.Env.t()} + def get_oracle_query_by_pubkey_and_query_id(connection, pubkey, query_id, _opts \\ []) do + %{} + |> method(:get) + |> url("/oracles/#{pubkey}/queries/#{query_id}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.OracleQuery{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get peer public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.PeerPubKey{}} on success + {:error, info} on failure + """ + @spec get_peer_pubkey(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.PeerPubKey.t()} | {:error, Tesla.Env.t()} + def get_peer_pubkey(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/peers/pubkey") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.PeerPubKey{}} + ]) + end + + @doc """ + Get pending account transactions by public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The public key of the account + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.GenericTxs{}} on success + {:error, info} on failure + """ + @spec get_pending_account_transactions_by_pubkey(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.GenericTxs.t()} | {:error, Tesla.Env.t()} + def get_pending_account_transactions_by_pubkey(connection, pubkey, _opts \\ []) do + %{} + |> method(:get) + |> url("/accounts/#{pubkey}/transactions/pending") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.GenericTxs{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get the pending key block + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.KeyBlock{}} on success + {:error, info} on failure + """ + @spec get_pending_key_block(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.KeyBlock.t()} | {:error, Tesla.Env.t()} + def get_pending_key_block(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/key-blocks/pending") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.KeyBlock{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get the status of a node + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Status{}} on success + {:error, info} on failure + """ + @spec get_status(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.Status.t()} | {:error, Tesla.Env.t()} + def get_status(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/status") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Status{}} + ]) + end + + @doc """ + Get the top block (either key or micro block) + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.KeyBlockOrMicroBlockHeader{}} on success + {:error, info} on failure + """ + @spec get_top_block(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.KeyBlockOrMicroBlockHeader.t()} | {:error, Tesla.Env.t()} + def get_top_block(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/blocks/top") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.KeyBlockOrMicroBlockHeader{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a transaction by hash + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - hash (String.t): The hash of the transaction + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.GenericSignedTx{}} on success + {:error, info} on failure + """ + @spec get_transaction_by_hash(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.GenericSignedTx.t()} | {:error, Tesla.Env.t()} + def get_transaction_by_hash(connection, hash, _opts \\ []) do + %{} + |> method(:get) + |> url("/transactions/#{hash}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.GenericSignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - hash (String.t): The hash of the transaction + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.TxInfoObject{}} on success + {:error, info} on failure + """ + @spec get_transaction_info_by_hash(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.TxInfoObject.t()} | {:error, Tesla.Env.t()} + def get_transaction_info_by_hash(connection, hash, _opts \\ []) do + %{} + |> method(:get) + |> url("/transactions/#{hash}/info") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.TxInfoObject{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Post a new transaction + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (Tx): The new transaction + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.PostTxResponse{}} on success + {:error, info} on failure + """ + @spec post_transaction(Tesla.Env.client(), AeternityNode.Model.Tx.t(), keyword()) :: + {:ok, AeternityNode.Model.PostTxResponse.t()} | {:error, Tesla.Env.t()} + def post_transaction(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/transactions") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.PostTxResponse{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end +end diff --git a/lib/aeternity_node/api/internal.ex b/lib/aeternity_node/api/internal.ex new file mode 100644 index 0000000..d573a44 --- /dev/null +++ b/lib/aeternity_node/api/internal.ex @@ -0,0 +1,827 @@ +defmodule AeternityNode.Api.Internal do + @moduledoc """ + API calls for all endpoints tagged `Internal`. + """ + + alias AeternityNode.Connection + import AeternityNode.RequestBuilder + + @doc """ + Dry-run transactions on top of a given block. Supports SpendTx, ContractCreateTx and ContractCallTx + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (DryRunInput): transactions + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.DryRunResults{}} on success + {:error, info} on failure + """ + @spec dry_run_txs(Tesla.Env.client(), AeternityNode.Model.DryRunInput.t(), keyword()) :: + {:ok, AeternityNode.Model.DryRunResults.t()} | {:error, Tesla.Env.t()} + def dry_run_txs(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/transactions/dry-run") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.DryRunResults{}}, + {403, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Compute commitment ID for a given salt and name + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - name (String.t): Name + - salt (integer()): Salt + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.CommitmentId{}} on success + {:error, info} on failure + """ + @spec get_commitment_id(Tesla.Env.client(), String.t(), integer(), keyword()) :: + {:ok, AeternityNode.Model.CommitmentId.t()} | {:error, Tesla.Env.t()} + def get_commitment_id(connection, name, salt, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/names/commitment-id") + |> add_param(:query, :name, name) + |> add_param(:query, :salt, salt) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.CommitmentId{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get node's beneficiary public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.PubKey{}} on success + {:error, info} on failure + """ + @spec get_node_beneficiary(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.PubKey.t()} | {:error, Tesla.Env.t()} + def get_node_beneficiary(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/accounts/beneficiary") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.PubKey{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get node's public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.PubKey{}} on success + {:error, info} on failure + """ + @spec get_node_pubkey(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.PubKey.t()} | {:error, Tesla.Env.t()} + def get_node_pubkey(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/accounts/node") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.PubKey{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get node Peers + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Peers{}} on success + {:error, info} on failure + """ + @spec get_peers(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.Peers.t()} | {:error, Tesla.Env.t()} + def get_peers(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/peers") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Peers{}}, + {403, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get pending transactions + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.GenericTxs{}} on success + {:error, info} on failure + """ + @spec get_pending_transactions(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.GenericTxs.t()} | {:error, Tesla.Env.t()} + def get_pending_transactions(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/transactions/pending") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.GenericTxs{}} + ]) + end + + @doc """ + Get total token supply at height + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - height (integer()): The height + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.TokenSupply{}} on success + {:error, info} on failure + """ + @spec get_token_supply_by_height(Tesla.Env.client(), integer(), keyword()) :: + {:ok, AeternityNode.Model.TokenSupply.t()} | {:error, Tesla.Env.t()} + def get_token_supply_by_height(connection, height, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/token-supply/height/#{height}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.TokenSupply{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_close_mutual transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelCloseMutualTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_close_mutual( + Tesla.Env.client(), + AeternityNode.Model.ChannelCloseMutualTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_close_mutual(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/close/mutual") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_close_solo transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelCloseSoloTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_close_solo( + Tesla.Env.client(), + AeternityNode.Model.ChannelCloseSoloTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_close_solo(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/close/solo") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_create transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelCreateTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_create( + Tesla.Env.client(), + AeternityNode.Model.ChannelCreateTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_create(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/create") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_deposit transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelDepositTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_deposit( + Tesla.Env.client(), + AeternityNode.Model.ChannelDepositTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_deposit(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/deposit") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_settle transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelSettleTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_settle( + Tesla.Env.client(), + AeternityNode.Model.ChannelSettleTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_settle(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/settle") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_slash transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelSlashTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_slash(Tesla.Env.client(), AeternityNode.Model.ChannelSlashTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_slash(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/slash") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_snapshot_solo transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelSnapshotSoloTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_snapshot_solo( + Tesla.Env.client(), + AeternityNode.Model.ChannelSnapshotSoloTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_snapshot_solo(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/snapshot/solo") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a channel_withdrawal transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ChannelWithdrawTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_channel_withdraw( + Tesla.Env.client(), + AeternityNode.Model.ChannelWithdrawTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_channel_withdraw(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/channels/withdraw") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a contract_call transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ContractCallTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_contract_call(Tesla.Env.client(), AeternityNode.Model.ContractCallTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_contract_call(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/contracts/call") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a contract_create transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (ContractCreateTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.CreateContractUnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_contract_create( + Tesla.Env.client(), + AeternityNode.Model.ContractCreateTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.CreateContractUnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_contract_create(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/contracts/create") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.CreateContractUnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Post a mined key block + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (KeyBlock): Mined key block + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec post_key_block(Tesla.Env.client(), AeternityNode.Model.KeyBlock.t(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def post_key_block(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/key-blocks") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a name_claim transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (NameClaimTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_name_claim(Tesla.Env.client(), AeternityNode.Model.NameClaimTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_name_claim(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/names/claim") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a name_preclaim transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (NamePreclaimTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_name_preclaim(Tesla.Env.client(), AeternityNode.Model.NamePreclaimTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_name_preclaim(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/names/preclaim") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a name_revoke transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (NameRevokeTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_name_revoke(Tesla.Env.client(), AeternityNode.Model.NameRevokeTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_name_revoke(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/names/revoke") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a name_transfer transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (NameTransferTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_name_transfer(Tesla.Env.client(), AeternityNode.Model.NameTransferTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_name_transfer(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/names/transfer") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a name_update transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (NameUpdateTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_name_update(Tesla.Env.client(), AeternityNode.Model.NameUpdateTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_name_update(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/names/update") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get an oracle_extend transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (OracleExtendTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_oracle_extend(Tesla.Env.client(), AeternityNode.Model.OracleExtendTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_oracle_extend(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/oracles/extend") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get an oracle_query transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (OracleQueryTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_oracle_query(Tesla.Env.client(), AeternityNode.Model.OracleQueryTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_oracle_query(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/oracles/query") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a oracle_register transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (OracleRegisterTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_oracle_register( + Tesla.Env.client(), + AeternityNode.Model.OracleRegisterTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_oracle_register(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/oracles/register") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get an oracle_response transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (OracleRespondTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_oracle_respond( + Tesla.Env.client(), + AeternityNode.Model.OracleRespondTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_oracle_respond(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/oracles/respond") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a spend transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (SpendTx): A spend transaction + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_spend(Tesla.Env.client(), AeternityNode.Model.SpendTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_spend(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/transactions/spend") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end +end diff --git a/lib/aeternity_node/api/name_service.ex b/lib/aeternity_node/api/name_service.ex new file mode 100644 index 0000000..6817450 --- /dev/null +++ b/lib/aeternity_node/api/name_service.ex @@ -0,0 +1,211 @@ +defmodule AeternityNode.Api.NameService do + @moduledoc """ + API calls for all endpoints tagged `NameService`. + """ + + alias AeternityNode.Connection + import AeternityNode.RequestBuilder + + @doc """ + Compute commitment ID for a given salt and name + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - name (String.t): Name + - salt (integer()): Salt + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.CommitmentId{}} on success + {:error, info} on failure + """ + @spec get_commitment_id(Tesla.Env.client(), String.t(), integer(), keyword()) :: + {:ok, AeternityNode.Model.CommitmentId.t()} | {:error, Tesla.Env.t()} + def get_commitment_id(connection, name, salt, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/names/commitment-id") + |> add_param(:query, :name, name) + |> add_param(:query, :salt, salt) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.CommitmentId{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get name entry from naming system + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - name (String.t): The name key of the name entry + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.NameEntry{}} on success + {:error, info} on failure + """ + @spec get_name_entry_by_name(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.NameEntry.t()} | {:error, Tesla.Env.t()} + def get_name_entry_by_name(connection, name, _opts \\ []) do + %{} + |> method(:get) + |> url("/names/#{name}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.NameEntry{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a name_claim transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (NameClaimTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_name_claim(Tesla.Env.client(), AeternityNode.Model.NameClaimTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_name_claim(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/names/claim") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a name_preclaim transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (NamePreclaimTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_name_preclaim(Tesla.Env.client(), AeternityNode.Model.NamePreclaimTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_name_preclaim(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/names/preclaim") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a name_revoke transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (NameRevokeTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_name_revoke(Tesla.Env.client(), AeternityNode.Model.NameRevokeTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_name_revoke(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/names/revoke") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a name_transfer transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (NameTransferTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_name_transfer(Tesla.Env.client(), AeternityNode.Model.NameTransferTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_name_transfer(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/names/transfer") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a name_update transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (NameUpdateTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_name_update(Tesla.Env.client(), AeternityNode.Model.NameUpdateTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_name_update(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/names/update") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end +end diff --git a/lib/aeternity_node/api/node_info.ex b/lib/aeternity_node/api/node_info.ex new file mode 100644 index 0000000..e4f6187 --- /dev/null +++ b/lib/aeternity_node/api/node_info.ex @@ -0,0 +1,136 @@ +defmodule AeternityNode.Api.NodeInfo do + @moduledoc """ + API calls for all endpoints tagged `NodeInfo`. + """ + + alias AeternityNode.Connection + import AeternityNode.RequestBuilder + + @doc """ + Get node's beneficiary public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.PubKey{}} on success + {:error, info} on failure + """ + @spec get_node_beneficiary(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.PubKey.t()} | {:error, Tesla.Env.t()} + def get_node_beneficiary(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/accounts/beneficiary") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.PubKey{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get node's public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.PubKey{}} on success + {:error, info} on failure + """ + @spec get_node_pubkey(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.PubKey.t()} | {:error, Tesla.Env.t()} + def get_node_pubkey(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/accounts/node") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.PubKey{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get peer public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.PeerPubKey{}} on success + {:error, info} on failure + """ + @spec get_peer_pubkey(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.PeerPubKey.t()} | {:error, Tesla.Env.t()} + def get_peer_pubkey(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/peers/pubkey") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.PeerPubKey{}} + ]) + end + + @doc """ + Get node Peers + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Peers{}} on success + {:error, info} on failure + """ + @spec get_peers(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.Peers.t()} | {:error, Tesla.Env.t()} + def get_peers(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/peers") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Peers{}}, + {403, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get the status of a node + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.Status{}} on success + {:error, info} on failure + """ + @spec get_status(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.Status.t()} | {:error, Tesla.Env.t()} + def get_status(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/status") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.Status{}} + ]) + end +end diff --git a/lib/aeternity_node/api/oracle.ex b/lib/aeternity_node/api/oracle.ex new file mode 100644 index 0000000..f531fa5 --- /dev/null +++ b/lib/aeternity_node/api/oracle.ex @@ -0,0 +1,229 @@ +defmodule AeternityNode.Api.Oracle do + @moduledoc """ + API calls for all endpoints tagged `Oracle`. + """ + + alias AeternityNode.Connection + import AeternityNode.RequestBuilder + + @doc """ + Get an oracle by public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The public key of the oracle + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.RegisteredOracle{}} on success + {:error, info} on failure + """ + @spec get_oracle_by_pubkey(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.RegisteredOracle.t()} | {:error, Tesla.Env.t()} + def get_oracle_by_pubkey(connection, pubkey, _opts \\ []) do + %{} + |> method(:get) + |> url("/oracles/#{pubkey}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.RegisteredOracle{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get oracle queries by public key + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The public key of the oracle + - opts (KeywordList): [optional] Optional parameters + - :from (String.t): Last query id in previous page + - :limit (integer()): Max number of oracle queries + - :type (String.t): The type of a query: open, closed or all + ## Returns + + {:ok, %AeternityNode.Model.OracleQueries{}} on success + {:error, info} on failure + """ + @spec get_oracle_queries_by_pubkey(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.OracleQueries.t()} | {:error, Tesla.Env.t()} + def get_oracle_queries_by_pubkey(connection, pubkey, opts \\ []) do + optional_params = %{ + :from => :query, + :limit => :query, + :type => :query + } + + %{} + |> method(:get) + |> url("/oracles/#{pubkey}/queries") + |> add_optional_params(optional_params, opts) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.OracleQueries{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get an oracle query by public key and query ID + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - pubkey (String.t): The public key of the oracle + - query_id (String.t): The ID of the query + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.OracleQuery{}} on success + {:error, info} on failure + """ + @spec get_oracle_query_by_pubkey_and_query_id( + Tesla.Env.client(), + String.t(), + String.t(), + keyword() + ) :: {:ok, AeternityNode.Model.OracleQuery.t()} | {:error, Tesla.Env.t()} + def get_oracle_query_by_pubkey_and_query_id(connection, pubkey, query_id, _opts \\ []) do + %{} + |> method(:get) + |> url("/oracles/#{pubkey}/queries/#{query_id}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.OracleQuery{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get an oracle_extend transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (OracleExtendTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_oracle_extend(Tesla.Env.client(), AeternityNode.Model.OracleExtendTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_oracle_extend(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/oracles/extend") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get an oracle_query transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (OracleQueryTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_oracle_query(Tesla.Env.client(), AeternityNode.Model.OracleQueryTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_oracle_query(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/oracles/query") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a oracle_register transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (OracleRegisterTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_oracle_register( + Tesla.Env.client(), + AeternityNode.Model.OracleRegisterTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_oracle_register(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/oracles/register") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get an oracle_response transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (OracleRespondTx): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_oracle_respond( + Tesla.Env.client(), + AeternityNode.Model.OracleRespondTx.t(), + keyword() + ) :: {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_oracle_respond(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/oracles/respond") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end +end diff --git a/lib/aeternity_node/api/transaction.ex b/lib/aeternity_node/api/transaction.ex new file mode 100644 index 0000000..054cb38 --- /dev/null +++ b/lib/aeternity_node/api/transaction.ex @@ -0,0 +1,145 @@ +defmodule AeternityNode.Api.Transaction do + @moduledoc """ + API calls for all endpoints tagged `Transaction`. + """ + + alias AeternityNode.Connection + import AeternityNode.RequestBuilder + + @doc """ + Get pending transactions + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.GenericTxs{}} on success + {:error, info} on failure + """ + @spec get_pending_transactions(Tesla.Env.client(), keyword()) :: + {:ok, AeternityNode.Model.GenericTxs.t()} | {:error, Tesla.Env.t()} + def get_pending_transactions(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/debug/transactions/pending") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.GenericTxs{}} + ]) + end + + @doc """ + Get a transaction by hash + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - hash (String.t): The hash of the transaction + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.GenericSignedTx{}} on success + {:error, info} on failure + """ + @spec get_transaction_by_hash(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.GenericSignedTx.t()} | {:error, Tesla.Env.t()} + def get_transaction_by_hash(connection, hash, _opts \\ []) do + %{} + |> method(:get) + |> url("/transactions/#{hash}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.GenericSignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - hash (String.t): The hash of the transaction + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.TxInfoObject{}} on success + {:error, info} on failure + """ + @spec get_transaction_info_by_hash(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, AeternityNode.Model.TxInfoObject.t()} | {:error, Tesla.Env.t()} + def get_transaction_info_by_hash(connection, hash, _opts \\ []) do + %{} + |> method(:get) + |> url("/transactions/#{hash}/info") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.TxInfoObject{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Get a spend transaction object + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (SpendTx): A spend transaction + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.UnsignedTx{}} on success + {:error, info} on failure + """ + @spec post_spend(Tesla.Env.client(), AeternityNode.Model.SpendTx.t(), keyword()) :: + {:ok, AeternityNode.Model.UnsignedTx.t()} | {:error, Tesla.Env.t()} + def post_spend(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/debug/transactions/spend") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.UnsignedTx{}}, + {400, %AeternityNode.Model.Error{}}, + {404, %AeternityNode.Model.Error{}} + ]) + end + + @doc """ + Post a new transaction + + ## Parameters + + - connection (AeternityNode.Connection): Connection to server + - body (Tx): The new transaction + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %AeternityNode.Model.PostTxResponse{}} on success + {:error, info} on failure + """ + @spec post_transaction(Tesla.Env.client(), AeternityNode.Model.Tx.t(), keyword()) :: + {:ok, AeternityNode.Model.PostTxResponse.t()} | {:error, Tesla.Env.t()} + def post_transaction(connection, body, _opts \\ []) do + %{} + |> method(:post) + |> url("/transactions") + |> add_param(:body, :body, body) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, %AeternityNode.Model.PostTxResponse{}}, + {400, %AeternityNode.Model.Error{}} + ]) + end +end diff --git a/lib/aeternity_node/connection.ex b/lib/aeternity_node/connection.ex new file mode 100644 index 0000000..36e61e8 --- /dev/null +++ b/lib/aeternity_node/connection.ex @@ -0,0 +1,29 @@ +defmodule AeternityNode.Connection do + @moduledoc """ + Handle Tesla connections for AeternityNode. + """ + + use Tesla + + plug(Tesla.Middleware.Headers, [{"user-agent", "Elixir"}]) + plug(Tesla.Middleware.EncodeJson, engine: Poison) + + @doc """ + Configure an authless client connection + + # Returns + + Tesla.Env.client + """ + @spec new() :: Tesla.Env.client() + def new do + adapter = {Tesla.Adapter.Hackney, [recv_timeout: 30_000]} + Tesla.client([{Tesla.Middleware.BaseUrl, "http://localhost:3013/v2"}], adapter) + end + + @spec new(String.t()) :: Tesla.Env.client() + def new(path) do + adapter = {Tesla.Adapter.Hackney, [recv_timeout: 30_000]} + Tesla.client([{Tesla.Middleware.BaseUrl, path}], adapter) + end +end diff --git a/lib/aeternity_node/deserializer.ex b/lib/aeternity_node/deserializer.ex new file mode 100644 index 0000000..6f7e926 --- /dev/null +++ b/lib/aeternity_node/deserializer.ex @@ -0,0 +1,47 @@ +defmodule AeternityNode.Deserializer do + @moduledoc """ + Helper functions for deserializing responses into models + """ + + @doc """ + Update the provided model with a deserialization of a nested value + """ + @spec deserialize(struct(), :atom, :atom, struct(), keyword()) :: struct() + def deserialize(model, field, :list, mod, options) do + model + |> Map.update!(field, &Poison.Decode.decode(&1, Keyword.merge(options, as: [struct(mod)]))) + end + + def deserialize(model, field, :struct, mod, options) do + model + |> Map.update!(field, &Poison.Decode.decode(&1, Keyword.merge(options, as: struct(mod)))) + end + + def deserialize(model, field, :map, mod, options) do + model + |> Map.update!( + field, + &Map.new(&1, fn {key, val} -> + {key, Poison.Decode.decode(val, Keyword.merge(options, as: struct(mod)))} + end) + ) + end + + def deserialize(model, field, :date, _, _options) do + value = Map.get(model, field) + + case is_binary(value) do + true -> + case DateTime.from_iso8601(value) do + {:ok, datetime, _offset} -> + Map.put(model, field, datetime) + + _ -> + model + end + + false -> + model + end + end +end diff --git a/lib/aeternity_node/model/account.ex b/lib/aeternity_node/model/account.ex new file mode 100644 index 0000000..ca13c0e --- /dev/null +++ b/lib/aeternity_node/model/account.ex @@ -0,0 +1,32 @@ +defmodule AeternityNode.Model.Account do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :id, + :balance, + :nonce, + :payable, + :kind, + :contract_id, + :auth_fun + ] + + @type t :: %__MODULE__{ + :id => String.t(), + :balance => integer(), + :nonce => integer(), + :payable => boolean() | nil, + :kind => String.t() | nil, + :contract_id => String.t() | nil, + :auth_fun => String.t() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.Account do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/byte_code.ex b/lib/aeternity_node/model/byte_code.ex new file mode 100644 index 0000000..006c8f9 --- /dev/null +++ b/lib/aeternity_node/model/byte_code.ex @@ -0,0 +1,20 @@ +defmodule AeternityNode.Model.ByteCode do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :bytecode + ] + + @type t :: %__MODULE__{ + :bytecode => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ByteCode do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel.ex b/lib/aeternity_node/model/channel.ex new file mode 100644 index 0000000..8e200f0 --- /dev/null +++ b/lib/aeternity_node/model/channel.ex @@ -0,0 +1,44 @@ +defmodule AeternityNode.Model.Channel do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :id, + :initiator_id, + :responder_id, + :channel_amount, + :initiator_amount, + :responder_amount, + :channel_reserve, + :delegate_ids, + :state_hash, + :round, + :solo_round, + :lock_period, + :locked_until + ] + + @type t :: %__MODULE__{ + :id => String.t(), + :initiator_id => String.t(), + :responder_id => String.t(), + :channel_amount => integer(), + :initiator_amount => integer(), + :responder_amount => integer(), + :channel_reserve => integer(), + :delegate_ids => [String], + :state_hash => String.t(), + :round => integer(), + :solo_round => integer(), + :lock_period => integer(), + :locked_until => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.Channel do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel_close_mutual_tx.ex b/lib/aeternity_node/model/channel_close_mutual_tx.ex new file mode 100644 index 0000000..c6aa773 --- /dev/null +++ b/lib/aeternity_node/model/channel_close_mutual_tx.ex @@ -0,0 +1,32 @@ +defmodule AeternityNode.Model.ChannelCloseMutualTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :channel_id, + :from_id, + :initiator_amount_final, + :responder_amount_final, + :ttl, + :fee, + :nonce + ] + + @type t :: %__MODULE__{ + :channel_id => String.t(), + :from_id => String.t(), + :initiator_amount_final => integer(), + :responder_amount_final => integer(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelCloseMutualTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel_close_mutual_tx_json.ex b/lib/aeternity_node/model/channel_close_mutual_tx_json.ex new file mode 100644 index 0000000..00d19a2 --- /dev/null +++ b/lib/aeternity_node/model/channel_close_mutual_tx_json.ex @@ -0,0 +1,36 @@ +defmodule AeternityNode.Model.ChannelCloseMutualTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :channel_id, + :from_id, + :initiator_amount_final, + :responder_amount_final, + :ttl, + :fee, + :nonce + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :channel_id => String.t(), + :from_id => String.t(), + :initiator_amount_final => integer(), + :responder_amount_final => integer(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelCloseMutualTxJson do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel_close_solo_tx.ex b/lib/aeternity_node/model/channel_close_solo_tx.ex new file mode 100644 index 0000000..846cfc3 --- /dev/null +++ b/lib/aeternity_node/model/channel_close_solo_tx.ex @@ -0,0 +1,32 @@ +defmodule AeternityNode.Model.ChannelCloseSoloTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :channel_id, + :from_id, + :payload, + :ttl, + :fee, + :nonce, + :poi + ] + + @type t :: %__MODULE__{ + :channel_id => String.t(), + :from_id => String.t(), + :payload => String.t(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer() | nil, + :poi => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelCloseSoloTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel_close_solo_tx_json.ex b/lib/aeternity_node/model/channel_close_solo_tx_json.ex new file mode 100644 index 0000000..12108a8 --- /dev/null +++ b/lib/aeternity_node/model/channel_close_solo_tx_json.ex @@ -0,0 +1,36 @@ +defmodule AeternityNode.Model.ChannelCloseSoloTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :channel_id, + :from_id, + :payload, + :ttl, + :fee, + :nonce, + :poi + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :channel_id => String.t(), + :from_id => String.t(), + :payload => String.t(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer() | nil, + :poi => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelCloseSoloTxJson do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel_create_tx.ex b/lib/aeternity_node/model/channel_create_tx.ex new file mode 100644 index 0000000..fcbb485 --- /dev/null +++ b/lib/aeternity_node/model/channel_create_tx.ex @@ -0,0 +1,42 @@ +defmodule AeternityNode.Model.ChannelCreateTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :initiator_id, + :initiator_amount, + :responder_id, + :responder_amount, + :push_amount, + :channel_reserve, + :lock_period, + :ttl, + :fee, + :nonce, + :state_hash, + :delegate_ids + ] + + @type t :: %__MODULE__{ + :initiator_id => String.t(), + :initiator_amount => integer(), + :responder_id => String.t(), + :responder_amount => integer(), + :push_amount => integer(), + :channel_reserve => integer(), + :lock_period => integer(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer() | nil, + :state_hash => String.t(), + :delegate_ids => [String] | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelCreateTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel_create_tx_json.ex b/lib/aeternity_node/model/channel_create_tx_json.ex new file mode 100644 index 0000000..8944ab4 --- /dev/null +++ b/lib/aeternity_node/model/channel_create_tx_json.ex @@ -0,0 +1,46 @@ +defmodule AeternityNode.Model.ChannelCreateTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :initiator_id, + :initiator_amount, + :responder_id, + :responder_amount, + :push_amount, + :channel_reserve, + :lock_period, + :ttl, + :fee, + :nonce, + :state_hash, + :delegate_ids + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :initiator_id => String.t(), + :initiator_amount => integer(), + :responder_id => String.t(), + :responder_amount => integer(), + :push_amount => integer(), + :channel_reserve => integer(), + :lock_period => integer(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer() | nil, + :state_hash => String.t(), + :delegate_ids => [String] | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelCreateTxJson do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel_deposit_tx.ex b/lib/aeternity_node/model/channel_deposit_tx.ex new file mode 100644 index 0000000..ca0497b --- /dev/null +++ b/lib/aeternity_node/model/channel_deposit_tx.ex @@ -0,0 +1,34 @@ +defmodule AeternityNode.Model.ChannelDepositTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :channel_id, + :from_id, + :amount, + :ttl, + :fee, + :nonce, + :state_hash, + :round + ] + + @type t :: %__MODULE__{ + :channel_id => String.t(), + :from_id => String.t(), + :amount => integer(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer(), + :state_hash => String.t(), + :round => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelDepositTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel_deposit_tx_json.ex b/lib/aeternity_node/model/channel_deposit_tx_json.ex new file mode 100644 index 0000000..37ebf5f --- /dev/null +++ b/lib/aeternity_node/model/channel_deposit_tx_json.ex @@ -0,0 +1,38 @@ +defmodule AeternityNode.Model.ChannelDepositTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :channel_id, + :from_id, + :amount, + :ttl, + :fee, + :nonce, + :state_hash, + :round + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :channel_id => String.t(), + :from_id => String.t(), + :amount => integer(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer(), + :state_hash => String.t(), + :round => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelDepositTxJson do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel_force_progress_tx.ex b/lib/aeternity_node/model/channel_force_progress_tx.ex new file mode 100644 index 0000000..c8e9dd3 --- /dev/null +++ b/lib/aeternity_node/model/channel_force_progress_tx.ex @@ -0,0 +1,41 @@ +defmodule AeternityNode.Model.ChannelForceProgressTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :channel_id, + :from_id, + :payload, + :round, + :update, + :state_hash, + :ttl, + :fee, + :nonce, + :offchain_trees + ] + + @type t :: %__MODULE__{ + :channel_id => String.t(), + :from_id => String.t(), + :payload => String.t(), + :round => integer(), + :update => OffChainUpdate, + :state_hash => String.t(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer() | nil, + :offchain_trees => String.t() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelForceProgressTx do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:update, :struct, AeternityNode.Model.OffChainUpdate, options) + end +end diff --git a/lib/aeternity_node/model/channel_force_progress_tx_json.ex b/lib/aeternity_node/model/channel_force_progress_tx_json.ex new file mode 100644 index 0000000..a9fe69b --- /dev/null +++ b/lib/aeternity_node/model/channel_force_progress_tx_json.ex @@ -0,0 +1,45 @@ +defmodule AeternityNode.Model.ChannelForceProgressTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :channel_id, + :from_id, + :payload, + :round, + :update, + :state_hash, + :ttl, + :fee, + :nonce, + :offchain_trees + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :channel_id => String.t(), + :from_id => String.t(), + :payload => String.t(), + :round => integer(), + :update => OffChainUpdate, + :state_hash => String.t(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer() | nil, + :offchain_trees => String.t() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelForceProgressTxJson do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:update, :struct, AeternityNode.Model.OffChainUpdate, options) + end +end diff --git a/lib/aeternity_node/model/channel_settle_tx.ex b/lib/aeternity_node/model/channel_settle_tx.ex new file mode 100644 index 0000000..5991576 --- /dev/null +++ b/lib/aeternity_node/model/channel_settle_tx.ex @@ -0,0 +1,32 @@ +defmodule AeternityNode.Model.ChannelSettleTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :channel_id, + :from_id, + :initiator_amount_final, + :responder_amount_final, + :ttl, + :fee, + :nonce + ] + + @type t :: %__MODULE__{ + :channel_id => String.t(), + :from_id => String.t(), + :initiator_amount_final => integer(), + :responder_amount_final => integer(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelSettleTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel_settle_tx_json.ex b/lib/aeternity_node/model/channel_settle_tx_json.ex new file mode 100644 index 0000000..cb78eed --- /dev/null +++ b/lib/aeternity_node/model/channel_settle_tx_json.ex @@ -0,0 +1,36 @@ +defmodule AeternityNode.Model.ChannelSettleTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :channel_id, + :from_id, + :initiator_amount_final, + :responder_amount_final, + :ttl, + :fee, + :nonce + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :channel_id => String.t(), + :from_id => String.t(), + :initiator_amount_final => integer(), + :responder_amount_final => integer(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelSettleTxJson do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel_slash_tx.ex b/lib/aeternity_node/model/channel_slash_tx.ex new file mode 100644 index 0000000..c844734 --- /dev/null +++ b/lib/aeternity_node/model/channel_slash_tx.ex @@ -0,0 +1,32 @@ +defmodule AeternityNode.Model.ChannelSlashTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :channel_id, + :from_id, + :payload, + :ttl, + :fee, + :nonce, + :poi + ] + + @type t :: %__MODULE__{ + :channel_id => String.t(), + :from_id => String.t(), + :payload => String.t(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer() | nil, + :poi => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelSlashTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel_slash_tx_json.ex b/lib/aeternity_node/model/channel_slash_tx_json.ex new file mode 100644 index 0000000..175589a --- /dev/null +++ b/lib/aeternity_node/model/channel_slash_tx_json.ex @@ -0,0 +1,36 @@ +defmodule AeternityNode.Model.ChannelSlashTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :channel_id, + :from_id, + :payload, + :ttl, + :fee, + :nonce, + :poi + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :channel_id => String.t(), + :from_id => String.t(), + :payload => String.t(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer() | nil, + :poi => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelSlashTxJson do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel_snapshot_solo_tx.ex b/lib/aeternity_node/model/channel_snapshot_solo_tx.ex new file mode 100644 index 0000000..9afb9c8 --- /dev/null +++ b/lib/aeternity_node/model/channel_snapshot_solo_tx.ex @@ -0,0 +1,30 @@ +defmodule AeternityNode.Model.ChannelSnapshotSoloTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :channel_id, + :from_id, + :payload, + :ttl, + :fee, + :nonce + ] + + @type t :: %__MODULE__{ + :channel_id => String.t(), + :from_id => String.t(), + :payload => String.t(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelSnapshotSoloTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel_snapshot_solo_tx_json.ex b/lib/aeternity_node/model/channel_snapshot_solo_tx_json.ex new file mode 100644 index 0000000..503f517 --- /dev/null +++ b/lib/aeternity_node/model/channel_snapshot_solo_tx_json.ex @@ -0,0 +1,34 @@ +defmodule AeternityNode.Model.ChannelSnapshotSoloTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :channel_id, + :from_id, + :payload, + :ttl, + :fee, + :nonce + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :channel_id => String.t(), + :from_id => String.t(), + :payload => String.t(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelSnapshotSoloTxJson do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel_withdraw_tx.ex b/lib/aeternity_node/model/channel_withdraw_tx.ex new file mode 100644 index 0000000..525edce --- /dev/null +++ b/lib/aeternity_node/model/channel_withdraw_tx.ex @@ -0,0 +1,34 @@ +defmodule AeternityNode.Model.ChannelWithdrawTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :channel_id, + :to_id, + :amount, + :ttl, + :fee, + :nonce, + :state_hash, + :round + ] + + @type t :: %__MODULE__{ + :channel_id => String.t(), + :to_id => String.t(), + :amount => integer(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer(), + :state_hash => String.t(), + :round => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelWithdrawTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/channel_withdrawal_tx_json.ex b/lib/aeternity_node/model/channel_withdrawal_tx_json.ex new file mode 100644 index 0000000..5f6fb8d --- /dev/null +++ b/lib/aeternity_node/model/channel_withdrawal_tx_json.ex @@ -0,0 +1,38 @@ +defmodule AeternityNode.Model.ChannelWithdrawalTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :channel_id, + :to_id, + :amount, + :ttl, + :fee, + :nonce, + :state_hash, + :round + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :channel_id => String.t(), + :to_id => String.t(), + :amount => integer(), + :ttl => integer() | nil, + :fee => integer(), + :nonce => integer(), + :state_hash => String.t(), + :round => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ChannelWithdrawalTxJson do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/commitment_id.ex b/lib/aeternity_node/model/commitment_id.ex new file mode 100644 index 0000000..d53caef --- /dev/null +++ b/lib/aeternity_node/model/commitment_id.ex @@ -0,0 +1,20 @@ +defmodule AeternityNode.Model.CommitmentId do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :commitment_id + ] + + @type t :: %__MODULE__{ + :commitment_id => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.CommitmentId do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/contract_call_object.ex b/lib/aeternity_node/model/contract_call_object.ex new file mode 100644 index 0000000..0c38c03 --- /dev/null +++ b/lib/aeternity_node/model/contract_call_object.ex @@ -0,0 +1,39 @@ +defmodule AeternityNode.Model.ContractCallObject do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :caller_id, + :caller_nonce, + :height, + :contract_id, + :gas_price, + :gas_used, + :log, + :return_value, + :return_type + ] + + @type t :: %__MODULE__{ + :caller_id => String.t(), + :caller_nonce => integer(), + :height => integer(), + :contract_id => String.t(), + :gas_price => integer(), + :gas_used => integer(), + :log => [Event], + :return_value => String.t(), + :return_type => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ContractCallObject do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:log, :list, AeternityNode.Model.Event, options) + end +end diff --git a/lib/aeternity_node/model/contract_call_tx.ex b/lib/aeternity_node/model/contract_call_tx.ex new file mode 100644 index 0000000..0436355 --- /dev/null +++ b/lib/aeternity_node/model/contract_call_tx.ex @@ -0,0 +1,38 @@ +defmodule AeternityNode.Model.ContractCallTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :caller_id, + :nonce, + :contract_id, + :abi_version, + :fee, + :ttl, + :amount, + :gas, + :gas_price, + :call_data + ] + + @type t :: %__MODULE__{ + :caller_id => String.t(), + :nonce => integer() | nil, + :contract_id => String.t(), + :abi_version => integer(), + :fee => integer(), + :ttl => integer() | nil, + :amount => integer(), + :gas => integer(), + :gas_price => integer(), + :call_data => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ContractCallTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/contract_call_tx_json.ex b/lib/aeternity_node/model/contract_call_tx_json.ex new file mode 100644 index 0000000..a1617ad --- /dev/null +++ b/lib/aeternity_node/model/contract_call_tx_json.ex @@ -0,0 +1,42 @@ +defmodule AeternityNode.Model.ContractCallTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :caller_id, + :nonce, + :contract_id, + :abi_version, + :fee, + :ttl, + :amount, + :gas, + :gas_price, + :call_data + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :caller_id => String.t(), + :nonce => integer() | nil, + :contract_id => String.t(), + :abi_version => integer(), + :fee => integer(), + :ttl => integer() | nil, + :amount => integer(), + :gas => integer(), + :gas_price => integer(), + :call_data => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ContractCallTxJson do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/contract_create_tx.ex b/lib/aeternity_node/model/contract_create_tx.ex new file mode 100644 index 0000000..70f93e1 --- /dev/null +++ b/lib/aeternity_node/model/contract_create_tx.ex @@ -0,0 +1,42 @@ +defmodule AeternityNode.Model.ContractCreateTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :owner_id, + :nonce, + :code, + :vm_version, + :abi_version, + :deposit, + :amount, + :gas, + :gas_price, + :fee, + :ttl, + :call_data + ] + + @type t :: %__MODULE__{ + :owner_id => String.t(), + :nonce => integer() | nil, + :code => String.t(), + :vm_version => integer(), + :abi_version => integer(), + :deposit => integer(), + :amount => integer(), + :gas => integer(), + :gas_price => integer(), + :fee => integer(), + :ttl => integer() | nil, + :call_data => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ContractCreateTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/contract_create_tx_json.ex b/lib/aeternity_node/model/contract_create_tx_json.ex new file mode 100644 index 0000000..b781961 --- /dev/null +++ b/lib/aeternity_node/model/contract_create_tx_json.ex @@ -0,0 +1,46 @@ +defmodule AeternityNode.Model.ContractCreateTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :owner_id, + :nonce, + :code, + :vm_version, + :abi_version, + :deposit, + :amount, + :gas, + :gas_price, + :fee, + :ttl, + :call_data + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :owner_id => String.t(), + :nonce => integer() | nil, + :code => String.t(), + :vm_version => integer(), + :abi_version => integer(), + :deposit => integer(), + :amount => integer(), + :gas => integer(), + :gas_price => integer(), + :fee => integer(), + :ttl => integer() | nil, + :call_data => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ContractCreateTxJson do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/contract_object.ex b/lib/aeternity_node/model/contract_object.ex new file mode 100644 index 0000000..827efbb --- /dev/null +++ b/lib/aeternity_node/model/contract_object.ex @@ -0,0 +1,32 @@ +defmodule AeternityNode.Model.ContractObject do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :id, + :owner_id, + :vm_version, + :abi_version, + :active, + :referrer_ids, + :deposit + ] + + @type t :: %__MODULE__{ + :id => String.t(), + :owner_id => String.t(), + :vm_version => integer(), + :abi_version => integer(), + :active => boolean(), + :referrer_ids => [String], + :deposit => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ContractObject do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/contract_store.ex b/lib/aeternity_node/model/contract_store.ex new file mode 100644 index 0000000..9ee4e2a --- /dev/null +++ b/lib/aeternity_node/model/contract_store.ex @@ -0,0 +1,23 @@ +defmodule AeternityNode.Model.ContractStore do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :store + ] + + @type t :: %__MODULE__{ + :store => [ContractStoreStore] + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ContractStore do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:store, :list, AeternityNode.Model.ContractStoreStore, options) + end +end diff --git a/lib/aeternity_node/model/contract_store_store.ex b/lib/aeternity_node/model/contract_store_store.ex new file mode 100644 index 0000000..1c8a4b3 --- /dev/null +++ b/lib/aeternity_node/model/contract_store_store.ex @@ -0,0 +1,22 @@ +defmodule AeternityNode.Model.ContractStoreStore do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :key, + :value + ] + + @type t :: %__MODULE__{ + :key => String.t() | nil, + :value => String.t() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.ContractStoreStore do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/create_contract_unsigned_tx.ex b/lib/aeternity_node/model/create_contract_unsigned_tx.ex new file mode 100644 index 0000000..e3e26a9 --- /dev/null +++ b/lib/aeternity_node/model/create_contract_unsigned_tx.ex @@ -0,0 +1,22 @@ +defmodule AeternityNode.Model.CreateContractUnsignedTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :tx, + :contract_id + ] + + @type t :: %__MODULE__{ + :tx => String.t(), + :contract_id => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.CreateContractUnsignedTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/create_contract_unsigned_tx_all_of.ex b/lib/aeternity_node/model/create_contract_unsigned_tx_all_of.ex new file mode 100644 index 0000000..0ff81ec --- /dev/null +++ b/lib/aeternity_node/model/create_contract_unsigned_tx_all_of.ex @@ -0,0 +1,20 @@ +defmodule AeternityNode.Model.CreateContractUnsignedTxAllOf do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :contract_id + ] + + @type t :: %__MODULE__{ + :contract_id => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.CreateContractUnsignedTxAllOf do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/dry_run_account.ex b/lib/aeternity_node/model/dry_run_account.ex new file mode 100644 index 0000000..320f761 --- /dev/null +++ b/lib/aeternity_node/model/dry_run_account.ex @@ -0,0 +1,22 @@ +defmodule AeternityNode.Model.DryRunAccount do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :pub_key, + :amount + ] + + @type t :: %__MODULE__{ + :pub_key => String.t(), + :amount => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.DryRunAccount do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/dry_run_call_context.ex b/lib/aeternity_node/model/dry_run_call_context.ex new file mode 100644 index 0000000..77069fb --- /dev/null +++ b/lib/aeternity_node/model/dry_run_call_context.ex @@ -0,0 +1,22 @@ +defmodule AeternityNode.Model.DryRunCallContext do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :tx_hash, + :stateful + ] + + @type t :: %__MODULE__{ + :tx_hash => String.t() | nil, + :stateful => boolean() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.DryRunCallContext do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/dry_run_call_req.ex b/lib/aeternity_node/model/dry_run_call_req.ex new file mode 100644 index 0000000..aa5e4e1 --- /dev/null +++ b/lib/aeternity_node/model/dry_run_call_req.ex @@ -0,0 +1,37 @@ +defmodule AeternityNode.Model.DryRunCallReq do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :calldata, + :contract, + :amount, + :gas, + :caller, + :nonce, + :abi_version, + :context + ] + + @type t :: %__MODULE__{ + :calldata => String.t(), + :contract => String.t(), + :amount => integer() | nil, + :gas => integer() | nil, + :caller => String.t() | nil, + :nonce => integer() | nil, + :abi_version => integer() | nil, + :context => DryRunCallContext | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.DryRunCallReq do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:context, :struct, AeternityNode.Model.DryRunCallContext, options) + end +end diff --git a/lib/aeternity_node/model/dry_run_input.ex b/lib/aeternity_node/model/dry_run_input.ex new file mode 100644 index 0000000..ba3d2b9 --- /dev/null +++ b/lib/aeternity_node/model/dry_run_input.ex @@ -0,0 +1,28 @@ +defmodule AeternityNode.Model.DryRunInput do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :top, + :accounts, + :txs + ] + + @type t :: %__MODULE__{ + :top => String.t() | nil, + :accounts => [DryRunAccount] | nil, + :txs => [DryRunInputItem] + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.DryRunInput do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:accounts, :list, AeternityNode.Model.DryRunAccount, options) + |> deserialize(:txs, :list, AeternityNode.Model.DryRunInputItem, options) + end +end diff --git a/lib/aeternity_node/model/dry_run_input_item.ex b/lib/aeternity_node/model/dry_run_input_item.ex new file mode 100644 index 0000000..1933bc0 --- /dev/null +++ b/lib/aeternity_node/model/dry_run_input_item.ex @@ -0,0 +1,25 @@ +defmodule AeternityNode.Model.DryRunInputItem do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :tx, + :call_req + ] + + @type t :: %__MODULE__{ + :tx => String.t() | nil, + :call_req => DryRunCallReq | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.DryRunInputItem do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:call_req, :struct, AeternityNode.Model.DryRunCallReq, options) + end +end diff --git a/lib/aeternity_node/model/dry_run_result.ex b/lib/aeternity_node/model/dry_run_result.ex new file mode 100644 index 0000000..ecad0ef --- /dev/null +++ b/lib/aeternity_node/model/dry_run_result.ex @@ -0,0 +1,29 @@ +defmodule AeternityNode.Model.DryRunResult do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :type, + :result, + :reason, + :call_obj + ] + + @type t :: %__MODULE__{ + :type => String.t(), + :result => String.t(), + :reason => String.t() | nil, + :call_obj => ContractCallObject | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.DryRunResult do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:call_obj, :struct, AeternityNode.Model.ContractCallObject, options) + end +end diff --git a/lib/aeternity_node/model/dry_run_results.ex b/lib/aeternity_node/model/dry_run_results.ex new file mode 100644 index 0000000..51bd5f1 --- /dev/null +++ b/lib/aeternity_node/model/dry_run_results.ex @@ -0,0 +1,23 @@ +defmodule AeternityNode.Model.DryRunResults do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :results + ] + + @type t :: %__MODULE__{ + :results => [DryRunResult] + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.DryRunResults do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:results, :list, AeternityNode.Model.DryRunResult, options) + end +end diff --git a/lib/aeternity_node/model/error.ex b/lib/aeternity_node/model/error.ex new file mode 100644 index 0000000..486f7c2 --- /dev/null +++ b/lib/aeternity_node/model/error.ex @@ -0,0 +1,20 @@ +defmodule AeternityNode.Model.Error do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :reason + ] + + @type t :: %__MODULE__{ + :reason => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.Error do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/event.ex b/lib/aeternity_node/model/event.ex new file mode 100644 index 0000000..3a1aa21 --- /dev/null +++ b/lib/aeternity_node/model/event.ex @@ -0,0 +1,24 @@ +defmodule AeternityNode.Model.Event do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :address, + :topics, + :data + ] + + @type t :: %__MODULE__{ + :address => String.t(), + :topics => [Integer], + :data => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.Event do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/ga_attach_tx.ex b/lib/aeternity_node/model/ga_attach_tx.ex new file mode 100644 index 0000000..9fdf40e --- /dev/null +++ b/lib/aeternity_node/model/ga_attach_tx.ex @@ -0,0 +1,40 @@ +defmodule AeternityNode.Model.GaAttachTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :owner_id, + :nonce, + :code, + :vm_version, + :abi_version, + :gas, + :gas_price, + :fee, + :ttl, + :call_data, + :auth_fun + ] + + @type t :: %__MODULE__{ + :owner_id => String.t(), + :nonce => integer() | nil, + :code => String.t(), + :vm_version => integer(), + :abi_version => integer(), + :gas => integer(), + :gas_price => integer(), + :fee => integer(), + :ttl => integer() | nil, + :call_data => String.t(), + :auth_fun => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.GaAttachTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/ga_attach_tx_json.ex b/lib/aeternity_node/model/ga_attach_tx_json.ex new file mode 100644 index 0000000..0caeed9 --- /dev/null +++ b/lib/aeternity_node/model/ga_attach_tx_json.ex @@ -0,0 +1,44 @@ +defmodule AeternityNode.Model.GaAttachTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :owner_id, + :nonce, + :code, + :vm_version, + :abi_version, + :gas, + :gas_price, + :fee, + :ttl, + :call_data, + :auth_fun + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :owner_id => String.t(), + :nonce => integer() | nil, + :code => String.t(), + :vm_version => integer(), + :abi_version => integer(), + :gas => integer(), + :gas_price => integer(), + :fee => integer(), + :ttl => integer() | nil, + :call_data => String.t(), + :auth_fun => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.GaAttachTxJson do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/ga_meta_tx.ex b/lib/aeternity_node/model/ga_meta_tx.ex new file mode 100644 index 0000000..4c93a40 --- /dev/null +++ b/lib/aeternity_node/model/ga_meta_tx.ex @@ -0,0 +1,37 @@ +defmodule AeternityNode.Model.GaMetaTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :ga_id, + :abi_version, + :gas, + :gas_price, + :fee, + :ttl, + :auth_data, + :tx + ] + + @type t :: %__MODULE__{ + :ga_id => String.t(), + :abi_version => integer(), + :gas => integer(), + :gas_price => integer(), + :fee => integer(), + :ttl => integer() | nil, + :auth_data => String.t(), + :tx => GenericSignedTx + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.GaMetaTx do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:tx, :struct, AeternityNode.Model.GenericSignedTx, options) + end +end diff --git a/lib/aeternity_node/model/ga_meta_tx_json.ex b/lib/aeternity_node/model/ga_meta_tx_json.ex new file mode 100644 index 0000000..3d3f1b0 --- /dev/null +++ b/lib/aeternity_node/model/ga_meta_tx_json.ex @@ -0,0 +1,41 @@ +defmodule AeternityNode.Model.GaMetaTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :ga_id, + :abi_version, + :gas, + :gas_price, + :fee, + :ttl, + :auth_data, + :tx + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :ga_id => String.t(), + :abi_version => integer(), + :gas => integer(), + :gas_price => integer(), + :fee => integer(), + :ttl => integer() | nil, + :auth_data => String.t(), + :tx => GenericSignedTx + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.GaMetaTxJson do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:tx, :struct, AeternityNode.Model.GenericSignedTx, options) + end +end diff --git a/lib/aeternity_node/model/ga_object.ex b/lib/aeternity_node/model/ga_object.ex new file mode 100644 index 0000000..1673ee5 --- /dev/null +++ b/lib/aeternity_node/model/ga_object.ex @@ -0,0 +1,35 @@ +defmodule AeternityNode.Model.GaObject do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :caller_id, + :height, + :gas_price, + :gas_used, + :return_value, + :return_type, + :inner_object + ] + + @type t :: %__MODULE__{ + :caller_id => String.t(), + :height => integer(), + :gas_price => integer(), + :gas_used => integer(), + :return_value => String.t(), + :return_type => String.t(), + :inner_object => TxInfoObject | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.GaObject do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:inner_object, :struct, AeternityNode.Model.TxInfoObject, options) + end +end diff --git a/lib/aeternity_node/model/generation.ex b/lib/aeternity_node/model/generation.ex new file mode 100644 index 0000000..2c400af --- /dev/null +++ b/lib/aeternity_node/model/generation.ex @@ -0,0 +1,25 @@ +defmodule AeternityNode.Model.Generation do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :key_block, + :micro_blocks + ] + + @type t :: %__MODULE__{ + :key_block => KeyBlock, + :micro_blocks => [String] + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.Generation do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:key_block, :struct, AeternityNode.Model.KeyBlock, options) + end +end diff --git a/lib/aeternity_node/model/generic_signed_tx.ex b/lib/aeternity_node/model/generic_signed_tx.ex new file mode 100644 index 0000000..f558297 --- /dev/null +++ b/lib/aeternity_node/model/generic_signed_tx.ex @@ -0,0 +1,31 @@ +defmodule AeternityNode.Model.GenericSignedTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :tx, + :block_height, + :block_hash, + :hash, + :signatures + ] + + @type t :: %__MODULE__{ + :tx => GenericTx, + :block_height => integer(), + :block_hash => String.t(), + :hash => String.t(), + :signatures => [String] | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.GenericSignedTx do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:tx, :struct, AeternityNode.Model.GenericTx, options) + end +end diff --git a/lib/aeternity_node/model/generic_tx.ex b/lib/aeternity_node/model/generic_tx.ex new file mode 100644 index 0000000..937c2ab --- /dev/null +++ b/lib/aeternity_node/model/generic_tx.ex @@ -0,0 +1,22 @@ +defmodule AeternityNode.Model.GenericTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.GenericTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/generic_txs.ex b/lib/aeternity_node/model/generic_txs.ex new file mode 100644 index 0000000..16f1ce4 --- /dev/null +++ b/lib/aeternity_node/model/generic_txs.ex @@ -0,0 +1,23 @@ +defmodule AeternityNode.Model.GenericTxs do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :transactions + ] + + @type t :: %__MODULE__{ + :transactions => [GenericSignedTx] + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.GenericTxs do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:transactions, :list, AeternityNode.Model.GenericSignedTx, options) + end +end diff --git a/lib/aeternity_node/model/inline_response_200.ex b/lib/aeternity_node/model/inline_response_200.ex new file mode 100644 index 0000000..c271e36 --- /dev/null +++ b/lib/aeternity_node/model/inline_response_200.ex @@ -0,0 +1,20 @@ +defmodule AeternityNode.Model.InlineResponse200 do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :hash + ] + + @type t :: %__MODULE__{ + :hash => String.t() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.InlineResponse200 do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/inline_response_200_1.ex b/lib/aeternity_node/model/inline_response_200_1.ex new file mode 100644 index 0000000..eb446f6 --- /dev/null +++ b/lib/aeternity_node/model/inline_response_200_1.ex @@ -0,0 +1,20 @@ +defmodule AeternityNode.Model.InlineResponse2001 do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :height + ] + + @type t :: %__MODULE__{ + :height => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.InlineResponse2001 do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/inline_response_200_2.ex b/lib/aeternity_node/model/inline_response_200_2.ex new file mode 100644 index 0000000..065508d --- /dev/null +++ b/lib/aeternity_node/model/inline_response_200_2.ex @@ -0,0 +1,20 @@ +defmodule AeternityNode.Model.InlineResponse2002 do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :count + ] + + @type t :: %__MODULE__{ + :count => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.InlineResponse2002 do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/key_block.ex b/lib/aeternity_node/model/key_block.ex new file mode 100644 index 0000000..1e43293 --- /dev/null +++ b/lib/aeternity_node/model/key_block.ex @@ -0,0 +1,44 @@ +defmodule AeternityNode.Model.KeyBlock do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :hash, + :height, + :prev_hash, + :prev_key_hash, + :state_hash, + :miner, + :beneficiary, + :target, + :pow, + :nonce, + :time, + :version, + :info + ] + + @type t :: %__MODULE__{ + :hash => String.t(), + :height => integer(), + :prev_hash => String.t(), + :prev_key_hash => String.t(), + :state_hash => String.t(), + :miner => String.t(), + :beneficiary => String.t(), + :target => integer(), + :pow => [Integer] | nil, + :nonce => integer() | nil, + :time => integer(), + :version => integer(), + :info => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.KeyBlock do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/key_block_or_micro_block_header.ex b/lib/aeternity_node/model/key_block_or_micro_block_header.ex new file mode 100644 index 0000000..650d77e --- /dev/null +++ b/lib/aeternity_node/model/key_block_or_micro_block_header.ex @@ -0,0 +1,26 @@ +defmodule AeternityNode.Model.KeyBlockOrMicroBlockHeader do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :key_block, + :micro_block + ] + + @type t :: %__MODULE__{ + :key_block => KeyBlock | nil, + :micro_block => MicroBlockHeader | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.KeyBlockOrMicroBlockHeader do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:key_block, :struct, AeternityNode.Model.KeyBlock, options) + |> deserialize(:micro_block, :struct, AeternityNode.Model.MicroBlockHeader, options) + end +end diff --git a/lib/aeternity_node/model/micro_block_header.ex b/lib/aeternity_node/model/micro_block_header.ex new file mode 100644 index 0000000..add1d03 --- /dev/null +++ b/lib/aeternity_node/model/micro_block_header.ex @@ -0,0 +1,38 @@ +defmodule AeternityNode.Model.MicroBlockHeader do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :hash, + :height, + :pof_hash, + :prev_hash, + :prev_key_hash, + :state_hash, + :txs_hash, + :signature, + :time, + :version + ] + + @type t :: %__MODULE__{ + :hash => String.t(), + :height => integer(), + :pof_hash => String.t(), + :prev_hash => String.t(), + :prev_key_hash => String.t(), + :state_hash => String.t(), + :txs_hash => String.t(), + :signature => String.t(), + :time => integer(), + :version => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.MicroBlockHeader do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/name_claim_tx.ex b/lib/aeternity_node/model/name_claim_tx.ex new file mode 100644 index 0000000..bf51105 --- /dev/null +++ b/lib/aeternity_node/model/name_claim_tx.ex @@ -0,0 +1,32 @@ +defmodule AeternityNode.Model.NameClaimTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :name, + :name_salt, + :name_fee, + :fee, + :ttl, + :account_id, + :nonce + ] + + @type t :: %__MODULE__{ + :name => String.t(), + :name_salt => integer(), + :name_fee => integer() | nil, + :fee => integer(), + :ttl => integer() | nil, + :account_id => String.t(), + :nonce => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.NameClaimTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/name_claim_tx_json.ex b/lib/aeternity_node/model/name_claim_tx_json.ex new file mode 100644 index 0000000..ac15a6c --- /dev/null +++ b/lib/aeternity_node/model/name_claim_tx_json.ex @@ -0,0 +1,36 @@ +defmodule AeternityNode.Model.NameClaimTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :name, + :name_salt, + :name_fee, + :fee, + :ttl, + :account_id, + :nonce + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :name => String.t(), + :name_salt => integer(), + :name_fee => integer() | nil, + :fee => integer(), + :ttl => integer() | nil, + :account_id => String.t(), + :nonce => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.NameClaimTxJson do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/name_entry.ex b/lib/aeternity_node/model/name_entry.ex new file mode 100644 index 0000000..b415d5a --- /dev/null +++ b/lib/aeternity_node/model/name_entry.ex @@ -0,0 +1,27 @@ +defmodule AeternityNode.Model.NameEntry do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :id, + :ttl, + :pointers + ] + + @type t :: %__MODULE__{ + :id => String.t(), + :ttl => integer(), + :pointers => [NamePointer] + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.NameEntry do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:pointers, :list, AeternityNode.Model.NamePointer, options) + end +end diff --git a/lib/aeternity_node/model/name_hash.ex b/lib/aeternity_node/model/name_hash.ex new file mode 100644 index 0000000..6feb6c3 --- /dev/null +++ b/lib/aeternity_node/model/name_hash.ex @@ -0,0 +1,20 @@ +defmodule AeternityNode.Model.NameHash do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :name_id + ] + + @type t :: %__MODULE__{ + :name_id => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.NameHash do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/name_pointer.ex b/lib/aeternity_node/model/name_pointer.ex new file mode 100644 index 0000000..3b4526a --- /dev/null +++ b/lib/aeternity_node/model/name_pointer.ex @@ -0,0 +1,22 @@ +defmodule AeternityNode.Model.NamePointer do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :key, + :id + ] + + @type t :: %__MODULE__{ + :key => String.t(), + :id => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.NamePointer do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/name_preclaim_tx.ex b/lib/aeternity_node/model/name_preclaim_tx.ex new file mode 100644 index 0000000..3b8931d --- /dev/null +++ b/lib/aeternity_node/model/name_preclaim_tx.ex @@ -0,0 +1,28 @@ +defmodule AeternityNode.Model.NamePreclaimTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :commitment_id, + :fee, + :ttl, + :account_id, + :nonce + ] + + @type t :: %__MODULE__{ + :commitment_id => String.t(), + :fee => integer(), + :ttl => integer() | nil, + :account_id => String.t(), + :nonce => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.NamePreclaimTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/name_preclaim_tx_json.ex b/lib/aeternity_node/model/name_preclaim_tx_json.ex new file mode 100644 index 0000000..5fdd5f9 --- /dev/null +++ b/lib/aeternity_node/model/name_preclaim_tx_json.ex @@ -0,0 +1,32 @@ +defmodule AeternityNode.Model.NamePreclaimTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :commitment_id, + :fee, + :ttl, + :account_id, + :nonce + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :commitment_id => String.t(), + :fee => integer(), + :ttl => integer() | nil, + :account_id => String.t(), + :nonce => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.NamePreclaimTxJson do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/name_revoke_tx.ex b/lib/aeternity_node/model/name_revoke_tx.ex new file mode 100644 index 0000000..cb45a12 --- /dev/null +++ b/lib/aeternity_node/model/name_revoke_tx.ex @@ -0,0 +1,28 @@ +defmodule AeternityNode.Model.NameRevokeTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :name_id, + :fee, + :ttl, + :account_id, + :nonce + ] + + @type t :: %__MODULE__{ + :name_id => String.t(), + :fee => integer(), + :ttl => integer() | nil, + :account_id => String.t(), + :nonce => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.NameRevokeTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/name_revoke_tx_json.ex b/lib/aeternity_node/model/name_revoke_tx_json.ex new file mode 100644 index 0000000..0c0aa9a --- /dev/null +++ b/lib/aeternity_node/model/name_revoke_tx_json.ex @@ -0,0 +1,32 @@ +defmodule AeternityNode.Model.NameRevokeTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :name_id, + :fee, + :ttl, + :account_id, + :nonce + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :name_id => String.t(), + :fee => integer(), + :ttl => integer() | nil, + :account_id => String.t(), + :nonce => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.NameRevokeTxJson do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/name_transfer_tx.ex b/lib/aeternity_node/model/name_transfer_tx.ex new file mode 100644 index 0000000..ea43c18 --- /dev/null +++ b/lib/aeternity_node/model/name_transfer_tx.ex @@ -0,0 +1,30 @@ +defmodule AeternityNode.Model.NameTransferTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :name_id, + :recipient_id, + :fee, + :ttl, + :account_id, + :nonce + ] + + @type t :: %__MODULE__{ + :name_id => String.t(), + :recipient_id => String.t(), + :fee => integer(), + :ttl => integer() | nil, + :account_id => String.t(), + :nonce => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.NameTransferTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/name_transfer_tx_json.ex b/lib/aeternity_node/model/name_transfer_tx_json.ex new file mode 100644 index 0000000..e56e266 --- /dev/null +++ b/lib/aeternity_node/model/name_transfer_tx_json.ex @@ -0,0 +1,34 @@ +defmodule AeternityNode.Model.NameTransferTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :name_id, + :recipient_id, + :fee, + :ttl, + :account_id, + :nonce + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :name_id => String.t(), + :recipient_id => String.t(), + :fee => integer(), + :ttl => integer() | nil, + :account_id => String.t(), + :nonce => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.NameTransferTxJson do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/name_update_tx.ex b/lib/aeternity_node/model/name_update_tx.ex new file mode 100644 index 0000000..93fa5c8 --- /dev/null +++ b/lib/aeternity_node/model/name_update_tx.ex @@ -0,0 +1,37 @@ +defmodule AeternityNode.Model.NameUpdateTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :name_id, + :name_ttl, + :pointers, + :client_ttl, + :fee, + :ttl, + :account_id, + :nonce + ] + + @type t :: %__MODULE__{ + :name_id => String.t(), + :name_ttl => integer(), + :pointers => [NamePointer], + :client_ttl => integer(), + :fee => integer(), + :ttl => integer() | nil, + :account_id => String.t(), + :nonce => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.NameUpdateTx do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:pointers, :list, AeternityNode.Model.NamePointer, options) + end +end diff --git a/lib/aeternity_node/model/name_update_tx_json.ex b/lib/aeternity_node/model/name_update_tx_json.ex new file mode 100644 index 0000000..dc693ad --- /dev/null +++ b/lib/aeternity_node/model/name_update_tx_json.ex @@ -0,0 +1,41 @@ +defmodule AeternityNode.Model.NameUpdateTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :name_id, + :name_ttl, + :pointers, + :client_ttl, + :fee, + :ttl, + :account_id, + :nonce + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :name_id => String.t(), + :name_ttl => integer(), + :pointers => [NamePointer], + :client_ttl => integer(), + :fee => integer(), + :ttl => integer() | nil, + :account_id => String.t(), + :nonce => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.NameUpdateTxJson do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:pointers, :list, AeternityNode.Model.NamePointer, options) + end +end diff --git a/lib/aeternity_node/model/off_chain_call_contract.ex b/lib/aeternity_node/model/off_chain_call_contract.ex new file mode 100644 index 0000000..bd53b2f --- /dev/null +++ b/lib/aeternity_node/model/off_chain_call_contract.ex @@ -0,0 +1,34 @@ +defmodule AeternityNode.Model.OffChainCallContract do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :op, + :caller, + :contract, + :abi_version, + :amount, + :gas, + :gas_price, + :call_data + ] + + @type t :: %__MODULE__{ + :op => String.t(), + :caller => String.t(), + :contract => String.t(), + :abi_version => integer(), + :amount => integer(), + :gas => integer(), + :gas_price => integer(), + :call_data => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OffChainCallContract do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/off_chain_call_contract_all_of.ex b/lib/aeternity_node/model/off_chain_call_contract_all_of.ex new file mode 100644 index 0000000..94b30b7 --- /dev/null +++ b/lib/aeternity_node/model/off_chain_call_contract_all_of.ex @@ -0,0 +1,32 @@ +defmodule AeternityNode.Model.OffChainCallContractAllOf do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :caller, + :contract, + :abi_version, + :amount, + :gas, + :gas_price, + :call_data + ] + + @type t :: %__MODULE__{ + :caller => String.t(), + :contract => String.t(), + :abi_version => integer(), + :amount => integer(), + :gas => integer(), + :gas_price => integer(), + :call_data => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OffChainCallContractAllOf do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/off_chain_deposit.ex b/lib/aeternity_node/model/off_chain_deposit.ex new file mode 100644 index 0000000..9755b61 --- /dev/null +++ b/lib/aeternity_node/model/off_chain_deposit.ex @@ -0,0 +1,24 @@ +defmodule AeternityNode.Model.OffChainDeposit do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :op, + :from, + :amount + ] + + @type t :: %__MODULE__{ + :op => String.t(), + :from => String.t(), + :amount => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OffChainDeposit do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/off_chain_deposit_all_of.ex b/lib/aeternity_node/model/off_chain_deposit_all_of.ex new file mode 100644 index 0000000..a8b60d3 --- /dev/null +++ b/lib/aeternity_node/model/off_chain_deposit_all_of.ex @@ -0,0 +1,22 @@ +defmodule AeternityNode.Model.OffChainDepositAllOf do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :from, + :amount + ] + + @type t :: %__MODULE__{ + :from => String.t(), + :amount => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OffChainDepositAllOf do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/off_chain_new_contract.ex b/lib/aeternity_node/model/off_chain_new_contract.ex new file mode 100644 index 0000000..b38c162 --- /dev/null +++ b/lib/aeternity_node/model/off_chain_new_contract.ex @@ -0,0 +1,35 @@ +defmodule AeternityNode.Model.OffChainNewContract do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :op, + :owner, + :vm_version, + :abi_version, + :code, + :deposit, + :call_data + ] + + @type t :: %__MODULE__{ + :op => String.t(), + :owner => String.t(), + :vm_version => integer(), + :abi_version => integer(), + :code => ByteCode, + :deposit => integer(), + :call_data => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OffChainNewContract do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:code, :struct, AeternityNode.Model.ByteCode, options) + end +end diff --git a/lib/aeternity_node/model/off_chain_new_contract_all_of.ex b/lib/aeternity_node/model/off_chain_new_contract_all_of.ex new file mode 100644 index 0000000..068cc3d --- /dev/null +++ b/lib/aeternity_node/model/off_chain_new_contract_all_of.ex @@ -0,0 +1,33 @@ +defmodule AeternityNode.Model.OffChainNewContractAllOf do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :owner, + :vm_version, + :abi_version, + :code, + :deposit, + :call_data + ] + + @type t :: %__MODULE__{ + :owner => String.t(), + :vm_version => integer(), + :abi_version => integer(), + :code => ByteCode, + :deposit => integer(), + :call_data => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OffChainNewContractAllOf do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:code, :struct, AeternityNode.Model.ByteCode, options) + end +end diff --git a/lib/aeternity_node/model/off_chain_transfer.ex b/lib/aeternity_node/model/off_chain_transfer.ex new file mode 100644 index 0000000..92c9259 --- /dev/null +++ b/lib/aeternity_node/model/off_chain_transfer.ex @@ -0,0 +1,26 @@ +defmodule AeternityNode.Model.OffChainTransfer do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :op, + :from, + :to, + :amount + ] + + @type t :: %__MODULE__{ + :op => String.t(), + :from => String.t(), + :to => String.t(), + :amount => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OffChainTransfer do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/off_chain_transfer_all_of.ex b/lib/aeternity_node/model/off_chain_transfer_all_of.ex new file mode 100644 index 0000000..287b95f --- /dev/null +++ b/lib/aeternity_node/model/off_chain_transfer_all_of.ex @@ -0,0 +1,24 @@ +defmodule AeternityNode.Model.OffChainTransferAllOf do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :from, + :to, + :amount + ] + + @type t :: %__MODULE__{ + :from => String.t(), + :to => String.t(), + :amount => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OffChainTransferAllOf do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/off_chain_update.ex b/lib/aeternity_node/model/off_chain_update.ex new file mode 100644 index 0000000..c504d4b --- /dev/null +++ b/lib/aeternity_node/model/off_chain_update.ex @@ -0,0 +1,20 @@ +defmodule AeternityNode.Model.OffChainUpdate do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :op + ] + + @type t :: %__MODULE__{ + :op => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OffChainUpdate do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/off_chain_withdrawal.ex b/lib/aeternity_node/model/off_chain_withdrawal.ex new file mode 100644 index 0000000..86d254c --- /dev/null +++ b/lib/aeternity_node/model/off_chain_withdrawal.ex @@ -0,0 +1,24 @@ +defmodule AeternityNode.Model.OffChainWithdrawal do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :op, + :to, + :amount + ] + + @type t :: %__MODULE__{ + :op => String.t(), + :to => String.t(), + :amount => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OffChainWithdrawal do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/off_chain_withdrawal_all_of.ex b/lib/aeternity_node/model/off_chain_withdrawal_all_of.ex new file mode 100644 index 0000000..36be37e --- /dev/null +++ b/lib/aeternity_node/model/off_chain_withdrawal_all_of.ex @@ -0,0 +1,22 @@ +defmodule AeternityNode.Model.OffChainWithdrawalAllOf do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :to, + :amount + ] + + @type t :: %__MODULE__{ + :to => String.t(), + :amount => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OffChainWithdrawalAllOf do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/oracle_extend_tx.ex b/lib/aeternity_node/model/oracle_extend_tx.ex new file mode 100644 index 0000000..cea206d --- /dev/null +++ b/lib/aeternity_node/model/oracle_extend_tx.ex @@ -0,0 +1,31 @@ +defmodule AeternityNode.Model.OracleExtendTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :fee, + :oracle_ttl, + :oracle_id, + :nonce, + :ttl + ] + + @type t :: %__MODULE__{ + :fee => integer(), + :oracle_ttl => RelativeTtl, + :oracle_id => String.t(), + :nonce => integer() | nil, + :ttl => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OracleExtendTx do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:oracle_ttl, :struct, AeternityNode.Model.RelativeTtl, options) + end +end diff --git a/lib/aeternity_node/model/oracle_extend_tx_json.ex b/lib/aeternity_node/model/oracle_extend_tx_json.ex new file mode 100644 index 0000000..ab1fd61 --- /dev/null +++ b/lib/aeternity_node/model/oracle_extend_tx_json.ex @@ -0,0 +1,35 @@ +defmodule AeternityNode.Model.OracleExtendTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :fee, + :oracle_ttl, + :oracle_id, + :nonce, + :ttl + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :fee => integer(), + :oracle_ttl => RelativeTtl, + :oracle_id => String.t(), + :nonce => integer() | nil, + :ttl => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OracleExtendTxJson do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:oracle_ttl, :struct, AeternityNode.Model.RelativeTtl, options) + end +end diff --git a/lib/aeternity_node/model/oracle_queries.ex b/lib/aeternity_node/model/oracle_queries.ex new file mode 100644 index 0000000..4310161 --- /dev/null +++ b/lib/aeternity_node/model/oracle_queries.ex @@ -0,0 +1,23 @@ +defmodule AeternityNode.Model.OracleQueries do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :oracle_queries + ] + + @type t :: %__MODULE__{ + :oracle_queries => [OracleQuery] + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OracleQueries do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:oracle_queries, :list, AeternityNode.Model.OracleQuery, options) + end +end diff --git a/lib/aeternity_node/model/oracle_query.ex b/lib/aeternity_node/model/oracle_query.ex new file mode 100644 index 0000000..cb9963a --- /dev/null +++ b/lib/aeternity_node/model/oracle_query.ex @@ -0,0 +1,39 @@ +defmodule AeternityNode.Model.OracleQuery do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :id, + :sender_id, + :sender_nonce, + :oracle_id, + :query, + :response, + :ttl, + :response_ttl, + :fee + ] + + @type t :: %__MODULE__{ + :id => String.t(), + :sender_id => String.t(), + :sender_nonce => integer(), + :oracle_id => String.t(), + :query => String.t(), + :response => String.t(), + :ttl => integer(), + :response_ttl => Ttl, + :fee => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OracleQuery do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:response_ttl, :struct, AeternityNode.Model.Ttl, options) + end +end diff --git a/lib/aeternity_node/model/oracle_query_tx.ex b/lib/aeternity_node/model/oracle_query_tx.ex new file mode 100644 index 0000000..d5428e0 --- /dev/null +++ b/lib/aeternity_node/model/oracle_query_tx.ex @@ -0,0 +1,40 @@ +defmodule AeternityNode.Model.OracleQueryTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :oracle_id, + :query, + :query_fee, + :query_ttl, + :response_ttl, + :fee, + :ttl, + :sender_id, + :nonce + ] + + @type t :: %__MODULE__{ + :oracle_id => String.t(), + :query => String.t(), + :query_fee => integer(), + :query_ttl => Ttl, + :response_ttl => RelativeTtl, + :fee => integer(), + :ttl => integer() | nil, + :sender_id => String.t(), + :nonce => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OracleQueryTx do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:query_ttl, :struct, AeternityNode.Model.Ttl, options) + |> deserialize(:response_ttl, :struct, AeternityNode.Model.RelativeTtl, options) + end +end diff --git a/lib/aeternity_node/model/oracle_query_tx_json.ex b/lib/aeternity_node/model/oracle_query_tx_json.ex new file mode 100644 index 0000000..70a7d87 --- /dev/null +++ b/lib/aeternity_node/model/oracle_query_tx_json.ex @@ -0,0 +1,44 @@ +defmodule AeternityNode.Model.OracleQueryTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :oracle_id, + :query, + :query_fee, + :query_ttl, + :response_ttl, + :fee, + :ttl, + :sender_id, + :nonce + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :oracle_id => String.t(), + :query => String.t(), + :query_fee => integer(), + :query_ttl => Ttl, + :response_ttl => RelativeTtl, + :fee => integer(), + :ttl => integer() | nil, + :sender_id => String.t(), + :nonce => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OracleQueryTxJson do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:query_ttl, :struct, AeternityNode.Model.Ttl, options) + |> deserialize(:response_ttl, :struct, AeternityNode.Model.RelativeTtl, options) + end +end diff --git a/lib/aeternity_node/model/oracle_register_tx.ex b/lib/aeternity_node/model/oracle_register_tx.ex new file mode 100644 index 0000000..609e8a9 --- /dev/null +++ b/lib/aeternity_node/model/oracle_register_tx.ex @@ -0,0 +1,39 @@ +defmodule AeternityNode.Model.OracleRegisterTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :query_format, + :response_format, + :query_fee, + :oracle_ttl, + :account_id, + :nonce, + :fee, + :ttl, + :abi_version + ] + + @type t :: %__MODULE__{ + :query_format => String.t(), + :response_format => String.t(), + :query_fee => integer(), + :oracle_ttl => Ttl, + :account_id => String.t(), + :nonce => integer() | nil, + :fee => integer(), + :ttl => integer() | nil, + :abi_version => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OracleRegisterTx do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:oracle_ttl, :struct, AeternityNode.Model.Ttl, options) + end +end diff --git a/lib/aeternity_node/model/oracle_register_tx_json.ex b/lib/aeternity_node/model/oracle_register_tx_json.ex new file mode 100644 index 0000000..ebefdce --- /dev/null +++ b/lib/aeternity_node/model/oracle_register_tx_json.ex @@ -0,0 +1,43 @@ +defmodule AeternityNode.Model.OracleRegisterTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :query_format, + :response_format, + :query_fee, + :oracle_ttl, + :account_id, + :nonce, + :fee, + :ttl, + :abi_version + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :query_format => String.t(), + :response_format => String.t(), + :query_fee => integer(), + :oracle_ttl => Ttl, + :account_id => String.t(), + :nonce => integer() | nil, + :fee => integer(), + :ttl => integer() | nil, + :abi_version => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OracleRegisterTxJson do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:oracle_ttl, :struct, AeternityNode.Model.Ttl, options) + end +end diff --git a/lib/aeternity_node/model/oracle_respond_tx.ex b/lib/aeternity_node/model/oracle_respond_tx.ex new file mode 100644 index 0000000..3039711 --- /dev/null +++ b/lib/aeternity_node/model/oracle_respond_tx.ex @@ -0,0 +1,35 @@ +defmodule AeternityNode.Model.OracleRespondTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :query_id, + :response, + :response_ttl, + :fee, + :ttl, + :oracle_id, + :nonce + ] + + @type t :: %__MODULE__{ + :query_id => String.t(), + :response => String.t(), + :response_ttl => RelativeTtl, + :fee => integer(), + :ttl => integer() | nil, + :oracle_id => String.t(), + :nonce => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OracleRespondTx do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:response_ttl, :struct, AeternityNode.Model.RelativeTtl, options) + end +end diff --git a/lib/aeternity_node/model/oracle_response_tx_json.ex b/lib/aeternity_node/model/oracle_response_tx_json.ex new file mode 100644 index 0000000..116af0b --- /dev/null +++ b/lib/aeternity_node/model/oracle_response_tx_json.ex @@ -0,0 +1,39 @@ +defmodule AeternityNode.Model.OracleResponseTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :query_id, + :response, + :response_ttl, + :fee, + :ttl, + :oracle_id, + :nonce + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :query_id => String.t(), + :response => String.t(), + :response_ttl => RelativeTtl, + :fee => integer(), + :ttl => integer() | nil, + :oracle_id => String.t(), + :nonce => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.OracleResponseTxJson do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:response_ttl, :struct, AeternityNode.Model.RelativeTtl, options) + end +end diff --git a/lib/aeternity_node/model/peer_pub_key.ex b/lib/aeternity_node/model/peer_pub_key.ex new file mode 100644 index 0000000..2b4d4eb --- /dev/null +++ b/lib/aeternity_node/model/peer_pub_key.ex @@ -0,0 +1,20 @@ +defmodule AeternityNode.Model.PeerPubKey do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :pubkey + ] + + @type t :: %__MODULE__{ + :pubkey => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.PeerPubKey do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/peers.ex b/lib/aeternity_node/model/peers.ex new file mode 100644 index 0000000..fe9eb1d --- /dev/null +++ b/lib/aeternity_node/model/peers.ex @@ -0,0 +1,22 @@ +defmodule AeternityNode.Model.Peers do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :peers, + :blocked + ] + + @type t :: %__MODULE__{ + :peers => [String], + :blocked => [String] + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.Peers do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/po_i.ex b/lib/aeternity_node/model/po_i.ex new file mode 100644 index 0000000..eb0d796 --- /dev/null +++ b/lib/aeternity_node/model/po_i.ex @@ -0,0 +1,20 @@ +defmodule AeternityNode.Model.PoI do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :poi + ] + + @type t :: %__MODULE__{ + :poi => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.PoI do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/post_tx_response.ex b/lib/aeternity_node/model/post_tx_response.ex new file mode 100644 index 0000000..8765154 --- /dev/null +++ b/lib/aeternity_node/model/post_tx_response.ex @@ -0,0 +1,20 @@ +defmodule AeternityNode.Model.PostTxResponse do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :tx_hash + ] + + @type t :: %__MODULE__{ + :tx_hash => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.PostTxResponse do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/protocol.ex b/lib/aeternity_node/model/protocol.ex new file mode 100644 index 0000000..21343c0 --- /dev/null +++ b/lib/aeternity_node/model/protocol.ex @@ -0,0 +1,22 @@ +defmodule AeternityNode.Model.Protocol do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :effective_at_height + ] + + @type t :: %__MODULE__{ + :version => integer(), + :effective_at_height => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.Protocol do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/pub_key.ex b/lib/aeternity_node/model/pub_key.ex new file mode 100644 index 0000000..a279dc3 --- /dev/null +++ b/lib/aeternity_node/model/pub_key.ex @@ -0,0 +1,20 @@ +defmodule AeternityNode.Model.PubKey do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :pub_key + ] + + @type t :: %__MODULE__{ + :pub_key => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.PubKey do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/registered_oracle.ex b/lib/aeternity_node/model/registered_oracle.ex new file mode 100644 index 0000000..239af10 --- /dev/null +++ b/lib/aeternity_node/model/registered_oracle.ex @@ -0,0 +1,30 @@ +defmodule AeternityNode.Model.RegisteredOracle do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :id, + :query_format, + :response_format, + :query_fee, + :ttl, + :abi_version + ] + + @type t :: %__MODULE__{ + :id => String.t(), + :query_format => String.t(), + :response_format => String.t(), + :query_fee => integer(), + :ttl => integer(), + :abi_version => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.RegisteredOracle do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/relative_ttl.ex b/lib/aeternity_node/model/relative_ttl.ex new file mode 100644 index 0000000..d81d174 --- /dev/null +++ b/lib/aeternity_node/model/relative_ttl.ex @@ -0,0 +1,22 @@ +defmodule AeternityNode.Model.RelativeTtl do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :type, + :value + ] + + @type t :: %__MODULE__{ + :type => String.t(), + :value => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.RelativeTtl do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/spend_tx.ex b/lib/aeternity_node/model/spend_tx.ex new file mode 100644 index 0000000..87ff17a --- /dev/null +++ b/lib/aeternity_node/model/spend_tx.ex @@ -0,0 +1,32 @@ +defmodule AeternityNode.Model.SpendTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :recipient_id, + :amount, + :fee, + :ttl, + :sender_id, + :nonce, + :payload + ] + + @type t :: %__MODULE__{ + :recipient_id => String.t(), + :amount => integer(), + :fee => integer(), + :ttl => integer() | nil, + :sender_id => String.t(), + :nonce => integer() | nil, + :payload => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.SpendTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/spend_tx_json.ex b/lib/aeternity_node/model/spend_tx_json.ex new file mode 100644 index 0000000..8bb4989 --- /dev/null +++ b/lib/aeternity_node/model/spend_tx_json.ex @@ -0,0 +1,36 @@ +defmodule AeternityNode.Model.SpendTxJson do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :version, + :type, + :recipient_id, + :amount, + :fee, + :ttl, + :sender_id, + :nonce, + :payload + ] + + @type t :: %__MODULE__{ + :version => integer(), + :type => String.t(), + :recipient_id => String.t(), + :amount => integer(), + :fee => integer(), + :ttl => integer() | nil, + :sender_id => String.t(), + :nonce => integer() | nil, + :payload => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.SpendTxJson do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/status.ex b/lib/aeternity_node/model/status.ex new file mode 100644 index 0000000..b8e4797 --- /dev/null +++ b/lib/aeternity_node/model/status.ex @@ -0,0 +1,51 @@ +defmodule AeternityNode.Model.Status do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :genesis_key_block_hash, + :solutions, + :difficulty, + :syncing, + :sync_progress, + :listening, + :protocols, + :node_version, + :node_revision, + :peer_count, + :pending_transactions_count, + :network_id, + :peer_pubkey, + :top_key_block_hash, + :top_block_height + ] + + @type t :: %__MODULE__{ + :genesis_key_block_hash => String.t(), + :solutions => integer(), + :difficulty => integer(), + :syncing => boolean(), + :sync_progress => float() | nil, + :listening => boolean(), + :protocols => [Protocol], + :node_version => String.t(), + :node_revision => String.t(), + :peer_count => integer(), + :pending_transactions_count => integer(), + :network_id => String.t(), + :peer_pubkey => String.t(), + :top_key_block_hash => String.t(), + :top_block_height => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.Status do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:protocols, :list, AeternityNode.Model.Protocol, options) + end +end diff --git a/lib/aeternity_node/model/token_supply.ex b/lib/aeternity_node/model/token_supply.ex new file mode 100644 index 0000000..b0b3178 --- /dev/null +++ b/lib/aeternity_node/model/token_supply.ex @@ -0,0 +1,34 @@ +defmodule AeternityNode.Model.TokenSupply do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :accounts, + :contracts, + :contract_oracles, + :locked, + :oracles, + :oracle_queries, + :pending_rewards, + :total + ] + + @type t :: %__MODULE__{ + :accounts => integer() | nil, + :contracts => integer() | nil, + :contract_oracles => integer() | nil, + :locked => integer() | nil, + :oracles => integer() | nil, + :oracle_queries => integer() | nil, + :pending_rewards => integer() | nil, + :total => integer() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.TokenSupply do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/ttl.ex b/lib/aeternity_node/model/ttl.ex new file mode 100644 index 0000000..26dd3a9 --- /dev/null +++ b/lib/aeternity_node/model/ttl.ex @@ -0,0 +1,22 @@ +defmodule AeternityNode.Model.Ttl do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :type, + :value + ] + + @type t :: %__MODULE__{ + :type => String.t(), + :value => integer() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.Ttl do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/tx.ex b/lib/aeternity_node/model/tx.ex new file mode 100644 index 0000000..ce834fb --- /dev/null +++ b/lib/aeternity_node/model/tx.ex @@ -0,0 +1,20 @@ +defmodule AeternityNode.Model.Tx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :tx + ] + + @type t :: %__MODULE__{ + :tx => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.Tx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/model/tx_info_object.ex b/lib/aeternity_node/model/tx_info_object.ex new file mode 100644 index 0000000..79f02f4 --- /dev/null +++ b/lib/aeternity_node/model/tx_info_object.ex @@ -0,0 +1,28 @@ +defmodule AeternityNode.Model.TxInfoObject do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :call_info, + :ga_info, + :tx_info + ] + + @type t :: %__MODULE__{ + :call_info => ContractCallObject | nil, + :ga_info => GaObject | nil, + :tx_info => String.t() | nil + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.TxInfoObject do + import AeternityNode.Deserializer + + def decode(value, options) do + value + |> deserialize(:call_info, :struct, AeternityNode.Model.ContractCallObject, options) + |> deserialize(:ga_info, :struct, AeternityNode.Model.GaObject, options) + end +end diff --git a/lib/aeternity_node/model/unsigned_tx.ex b/lib/aeternity_node/model/unsigned_tx.ex new file mode 100644 index 0000000..64e0a56 --- /dev/null +++ b/lib/aeternity_node/model/unsigned_tx.ex @@ -0,0 +1,20 @@ +defmodule AeternityNode.Model.UnsignedTx do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :tx + ] + + @type t :: %__MODULE__{ + :tx => String.t() + } +end + +defimpl Poison.Decoder, for: AeternityNode.Model.UnsignedTx do + def decode(value, _options) do + value + end +end diff --git a/lib/aeternity_node/request_builder.ex b/lib/aeternity_node/request_builder.ex new file mode 100644 index 0000000..b98d914 --- /dev/null +++ b/lib/aeternity_node/request_builder.ex @@ -0,0 +1,151 @@ +defmodule AeternityNode.RequestBuilder do + @moduledoc """ + Helper functions for building Tesla requests + """ + + @doc """ + Specify the request method when building a request + + ## Parameters + + - request (Map) - Collected request options + - m (atom) - Request method + + ## Returns + + Map + """ + @spec method(map(), atom) :: map() + def method(request, m) do + Map.put_new(request, :method, m) + end + + @doc """ + Specify the request method when building a request + + ## Parameters + + - request (Map) - Collected request options + - u (String) - Request URL + + ## Returns + + Map + """ + @spec url(map(), String.t()) :: map() + def url(request, u) do + Map.put_new(request, :url, u) + end + + @doc """ + Add optional parameters to the request + + ## Parameters + + - request (Map) - Collected request options + - definitions (Map) - Map of parameter name to parameter location. + - options (KeywordList) - The provided optional parameters + + ## Returns + + Map + """ + @spec add_optional_params(map(), %{optional(atom) => atom}, keyword()) :: map() + def add_optional_params(request, _, []), do: request + + def add_optional_params(request, definitions, [{key, value} | tail]) do + case definitions do + %{^key => location} -> + request + |> add_param(location, key, value) + |> add_optional_params(definitions, tail) + + _ -> + add_optional_params(request, definitions, tail) + end + end + + @doc """ + Add optional parameters to the request + + ## Parameters + + - request (Map) - Collected request options + - location (atom) - Where to put the parameter + - key (atom) - The name of the parameter + - value (any) - The value of the parameter + + ## Returns + + Map + """ + @spec add_param(map(), atom, atom, any()) :: map() + def add_param(request, :body, :body, value), do: Map.put(request, :body, value) + + def add_param(request, :body, key, value) do + request + |> Map.put_new_lazy(:body, &Tesla.Multipart.new/0) + |> Map.update!( + :body, + &Tesla.Multipart.add_field(&1, key, Poison.encode!(value), + headers: [{:"Content-Type", "application/json"}] + ) + ) + end + + def add_param(request, :headers, key, value) do + request + |> Tesla.put_header(key, value) + end + + def add_param(request, :file, name, path) do + request + |> Map.put_new_lazy(:body, &Tesla.Multipart.new/0) + |> Map.update!(:body, &Tesla.Multipart.add_file(&1, path, name: name)) + end + + def add_param(request, :form, name, value) do + request + |> Map.update(:body, %{name => value}, &Map.put(&1, name, value)) + end + + def add_param(request, location, key, value) do + Map.update(request, location, [{key, value}], &(&1 ++ [{key, value}])) + end + + @doc """ + Handle the response for a Tesla request + + ## Parameters + + - arg1 (Tesla.Env.t | term) - The response object + - arg2 (:false | struct | [struct]) - The shape of the struct to deserialize into + + ## Returns + + {:ok, struct | any} on success + {:error, term} on failure + """ + @spec decode(Tesla.Env.t() | term(), false | struct() | [struct()]) :: + {:ok, struct()} | {:ok, any()} | {:error, any} + def decode(%Tesla.Env{body: body}, false), do: Poison.decode(body, keys: :atoms) + def decode(%Tesla.Env{body: body}, struct), do: Poison.decode(body, as: struct) + + def evaluate_response({:ok, %Tesla.Env{} = env}, mapping) do + resolve_mapping(env, mapping) + end + + def evaluate_response({:error, _} = error, _), do: error + + def resolve_mapping(env, mapping, default \\ nil) + + def resolve_mapping(%Tesla.Env{status: status} = env, [{mapping_status, struct} | _], _) + when status == mapping_status do + decode(env, struct) + end + + def resolve_mapping(env, [{:default, struct} | tail], _), do: resolve_mapping(env, tail, struct) + def resolve_mapping(env, [_ | tail], struct), do: resolve_mapping(env, tail, struct) + def resolve_mapping(env, [], nil), do: {:error, env} + def resolve_mapping(env, [], struct), do: decode(env, struct) +end diff --git a/lib/middleware/.openapi-generator-ignore b/lib/middleware/.openapi-generator-ignore new file mode 100644 index 0000000..7484ee5 --- /dev/null +++ b/lib/middleware/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/lib/middleware/.openapi-generator/VERSION b/lib/middleware/.openapi-generator/VERSION new file mode 100644 index 0000000..83a328a --- /dev/null +++ b/lib/middleware/.openapi-generator/VERSION @@ -0,0 +1 @@ +4.1.0-SNAPSHOT \ No newline at end of file diff --git a/lib/middleware/api/default.ex b/lib/middleware/api/default.ex new file mode 100644 index 0000000..13321db --- /dev/null +++ b/lib/middleware/api/default.ex @@ -0,0 +1,869 @@ +defmodule Aeternal.Api.Default do + @moduledoc """ + API calls for all endpoints tagged `Default`. + """ + + alias Aeternal.Connection + import Aeternal.RequestBuilder + + @doc """ + Get Active Channel Names + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_active_channels(Tesla.Env.client(), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t()} + def get_active_channels(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/channels/active") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get a list of all the active name auctions + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + - :length (integer()): returns the names with provided length + - :reverse (String.t): no value needs to be provided. if present the response will be reversed + - :limit (integer()): + - :page (integer()): + - :sort (String.t): Can be 'name', 'max_bid' or 'expiration'(default) + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_active_name_auctions(Tesla.Env.client(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_active_name_auctions(connection, opts \\ []) do + optional_params = %{ + :length => :query, + :reverse => :query, + :limit => :query, + :page => :query, + :sort => :query + } + + %{} + |> method(:get) + |> url("/names/auctions/active") + |> add_optional_params(optional_params, opts) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get a count of all the active name auctions + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + - :length (integer()): returns the names with provided length + - :reverse (String.t): no value needs to be provided. if present the response will be reversed + - :limit (integer()): + - :page (integer()): + - :sort (String.t): Can be 'name', 'max_bid' or 'expiration'(default) + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_active_name_auctions_count(Tesla.Env.client(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_active_name_auctions_count(connection, opts \\ []) do + optional_params = %{ + :length => :query, + :reverse => :query, + :limit => :query, + :page => :query, + :sort => :query + } + + %{} + |> method(:get) + |> url("/names/auctions/active/count") + |> add_optional_params(optional_params, opts) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get a list of all the active names + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + - :limit (integer()): + - :page (integer()): + - :owner (String.t): Address of the owner account to filter the results + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_active_names(Tesla.Env.client(), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t()} + def get_active_names(connection, opts \\ []) do + optional_params = %{ + :limit => :query, + :page => :query, + :owner => :query + } + + %{} + |> method(:get) + |> url("/names/active") + |> add_optional_params(optional_params, opts) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get all the contracts + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_all_contracts(Tesla.Env.client(), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t()} + def get_all_contracts(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/contracts/all") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + get all names + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + - :limit (integer()): + - :page (integer()): + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_all_names(Tesla.Env.client(), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t()} + def get_all_names(connection, opts \\ []) do + optional_params = %{ + :limit => :query, + :page => :query + } + + %{} + |> method(:get) + |> url("/names") + |> add_optional_params(optional_params, opts) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get a list of oracles + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + - :limit (integer()): + - :page (integer()): + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_all_oracles(Tesla.Env.client(), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t()} + def get_all_oracles(connection, opts \\ []) do + optional_params = %{ + :limit => :query, + :page => :query + } + + %{} + |> method(:get) + |> url("/oracles/list") + |> add_optional_params(optional_params, opts) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get the current of size of blockchain + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_chain_size(Tesla.Env.client(), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t()} + def get_chain_size(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/size/current") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get all transactions for a state channel + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - address (String.t): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_channel_tx(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_channel_tx(connection, address, _opts \\ []) do + %{} + |> method(:get) + |> url("/channels/transactions/address/#{address}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get list of compilers available to the middleware + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_compilers(Tesla.Env.client(), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t()} + def get_compilers(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/compilers") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get contract calls for a provided contract + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - address (String.t): Contract Address/id + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_contract_address_calls(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_contract_address_calls(connection, address, _opts \\ []) do + %{} + |> method(:get) + |> url("/contracts/calls/address/#{address}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get all the transactions for a contract + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - address (String.t): Contract Address/id + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_contract_tx(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_contract_tx(connection, address, _opts \\ []) do + %{} + |> method(:get) + |> url("/contracts/transactions/address/#{address}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + get count of transactions at the current height + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_current_tx_count(Tesla.Env.client(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_current_tx_count(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/count/current") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get generations between a given range + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - from (integer()): Start Generation or Key Block Number + - to (integer()): End Generation or Key Block Number + - opts (KeywordList): [optional] Optional parameters + - :limit (integer()): + - :page (integer()): + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_generations_by_range(Tesla.Env.client(), integer(), integer(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_generations_by_range(connection, from, to, opts \\ []) do + optional_params = %{ + :limit => :query, + :page => :query + } + + %{} + |> method(:get) + |> url("/generations/#{from}/#{to}") + |> add_optional_params(optional_params, opts) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get block height at a given time(provided in milliseconds) + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - milliseconds (integer()): Time in milliseconds + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_height_by_time(Tesla.Env.client(), integer(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_height_by_time(connection, milliseconds, _opts \\ []) do + %{} + |> method(:get) + |> url("/height/at/#{milliseconds}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + get middleware status + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_mdw_status(Tesla.Env.client(), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t()} + def get_mdw_status(connection, _opts \\ []) do + %{} + |> method(:get) + |> url("/status") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get bids made by a given account + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - account (String.t): Account address + - opts (KeywordList): [optional] Optional parameters + - :limit (integer()): + - :page (integer()): + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_name_auctions_bidsby_address(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_name_auctions_bidsby_address(connection, account, opts \\ []) do + optional_params = %{ + :limit => :query, + :page => :query + } + + %{} + |> method(:get) + |> url("/names/auctions/bids/account/#{account}") + |> add_optional_params(optional_params, opts) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get a bids for a given name + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - name (String.t): Name to fetch the bids for + - opts (KeywordList): [optional] Optional parameters + - :limit (integer()): + - :page (integer()): + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_name_auctions_bidsby_name(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_name_auctions_bidsby_name(connection, name, opts \\ []) do + optional_params = %{ + :limit => :query, + :page => :query + } + + %{} + |> method(:get) + |> url("/names/auctions/bids/#{name}") + |> add_optional_params(optional_params, opts) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get a list of names mapped to the given address + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - account (String.t): Account address + - opts (KeywordList): [optional] Optional parameters + - :limit (integer()): + - :page (integer()): + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_name_by_address(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_name_by_address(connection, account, opts \\ []) do + optional_params = %{ + :limit => :query, + :page => :query + } + + %{} + |> method(:get) + |> url("/names/reverse/#{account}") + |> add_optional_params(optional_params, opts) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get a list of query and response for a given oracle + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - oracle_id (String.t): oracle address/id to get the query and responses + - opts (KeywordList): [optional] Optional parameters + - :limit (integer()): + - :page (integer()): + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_oracle_data(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_oracle_data(connection, oracle_id, opts \\ []) do + optional_params = %{ + :limit => :query, + :page => :query + } + + %{} + |> method(:get) + |> url("/oracles/#{oracle_id}") + |> add_optional_params(optional_params, opts) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get the block reward for a given block height + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - height (integer()): Blockchain height + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_reward_at_height(Tesla.Env.client(), integer(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_reward_at_height(connection, height, _opts \\ []) do + %{} + |> method(:get) + |> url("/reward/height/#{height}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get size of blockchain at a given height + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - height (integer()): Blockchain height + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_size_at_height(Tesla.Env.client(), integer(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_size_at_height(connection, height, _opts \\ []) do + %{} + |> method(:get) + |> url("/size/height/#{height}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get a list of transactions between two accounts + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - sender (String.t): Sender account address + - receiver (String.t): Receiver account address + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_tx_between_address(Tesla.Env.client(), String.t(), String.t(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_tx_between_address(connection, sender, receiver, _opts \\ []) do + %{} + |> method(:get) + |> url("/transactions/account/#{sender}/to/#{receiver}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get list of transactions for a given account + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - account (String.t): Account address + - opts (KeywordList): [optional] Optional parameters + - :limit (integer()): + - :page (integer()): + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_tx_by_account(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_tx_by_account(connection, account, opts \\ []) do + optional_params = %{ + :limit => :query, + :page => :query + } + + %{} + |> method(:get) + |> url("/transactions/account/#{account}") + |> add_optional_params(optional_params, opts) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get transactions between an interval of generations + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - from (integer()): Start Generation/Key-block height + - to (integer()): End Generation/Key-block height + - opts (KeywordList): [optional] Optional parameters + - :limit (integer()): + - :page (integer()): + - :txtype (String.t): Transaction Type + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_tx_by_generation_range(Tesla.Env.client(), integer(), integer(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_tx_by_generation_range(connection, from, to, opts \\ []) do + optional_params = %{ + :limit => :query, + :page => :query, + :txtype => :query + } + + %{} + |> method(:get) + |> url("/transactions/interval/#{from}/#{to}") + |> add_optional_params(optional_params, opts) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get the count of transactions for a given account address + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - address (String.t): Account address + - opts (KeywordList): [optional] Optional parameters + - :txtype (String.t): Transaction Type + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_tx_count_by_address(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_tx_count_by_address(connection, address, opts \\ []) do + optional_params = %{ + :txtype => :query + } + + %{} + |> method(:get) + |> url("/transactions/account/#{address}/count") + |> add_optional_params(optional_params, opts) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Get transaction amount and count for the date interval + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - from (String.t): Start Date(yyyymmdd) + - to (String.t): End Date(yyyymmdd) + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec get_tx_rate_by_date_range(Tesla.Env.client(), String.t(), String.t(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def get_tx_rate_by_date_range(connection, from, to, _opts \\ []) do + %{} + |> method(:get) + |> url("/transactions/rate/#{from}/#{to}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Search for a name + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - name (String.t): String to match and find the name against + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec search_name(Tesla.Env.client(), String.t(), keyword()) :: + {:ok, nil} | {:error, Tesla.Env.t()} + def search_name(connection, name, _opts \\ []) do + %{} + |> method(:get) + |> url("/names/#{name}") + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end + + @doc """ + Verify a contract by submitting the source, compiler version and contract identifier + + ## Parameters + + - connection (Aeternal.Connection): Connection to server + - opts (KeywordList): [optional] Optional parameters + - :contract (InlineObject): + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec verify_contract(Tesla.Env.client(), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t()} + def verify_contract(connection, opts \\ []) do + optional_params = %{ + :contract => :body + } + + %{} + |> method(:post) + |> url("/contracts/verify") + |> add_optional_params(optional_params, opts) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> evaluate_response([ + {200, false} + ]) + end +end diff --git a/lib/middleware/connection.ex b/lib/middleware/connection.ex new file mode 100644 index 0000000..1de2e00 --- /dev/null +++ b/lib/middleware/connection.ex @@ -0,0 +1,29 @@ +defmodule Aeternal.Connection do + @moduledoc """ + Handle Tesla connections for Aeternal. + """ + + use Tesla + + plug(Tesla.Middleware.Headers, [{"user-agent", "Elixir"}]) + plug(Tesla.Middleware.EncodeJson, engine: Poison) + + @doc """ + Configure an authless client connection + + # Returns + + Tesla.Env.client + """ + @spec new() :: Tesla.Env.client() + def new do + adapter = {Tesla.Adapter.Hackney, [recv_timeout: 30_000]} + Tesla.client([{Tesla.Middleware.BaseUrl, "http://localhost:3013/v2"}], adapter) + end + + @spec new(String.t()) :: Tesla.Env.client() + def new(path) do + adapter = {Tesla.Adapter.Hackney, [recv_timeout: 30_000]} + Tesla.client([{Tesla.Middleware.BaseUrl, path}], adapter) + end +end diff --git a/lib/middleware/deserializer.ex b/lib/middleware/deserializer.ex new file mode 100644 index 0000000..1789192 --- /dev/null +++ b/lib/middleware/deserializer.ex @@ -0,0 +1,47 @@ +defmodule Aeternal.Deserializer do + @moduledoc """ + Helper functions for deserializing responses into models + """ + + @doc """ + Update the provided model with a deserialization of a nested value + """ + @spec deserialize(struct(), :atom, :atom, struct(), keyword()) :: struct() + def deserialize(model, field, :list, mod, options) do + model + |> Map.update!(field, &Poison.Decode.decode(&1, Keyword.merge(options, as: [struct(mod)]))) + end + + def deserialize(model, field, :struct, mod, options) do + model + |> Map.update!(field, &Poison.Decode.decode(&1, Keyword.merge(options, as: struct(mod)))) + end + + def deserialize(model, field, :map, mod, options) do + model + |> Map.update!( + field, + &Map.new(&1, fn {key, val} -> + {key, Poison.Decode.decode(val, Keyword.merge(options, as: struct(mod)))} + end) + ) + end + + def deserialize(model, field, :date, _, _options) do + value = Map.get(model, field) + + case is_binary(value) do + true -> + case DateTime.from_iso8601(value) do + {:ok, datetime, _offset} -> + Map.put(model, field, datetime) + + _ -> + model + end + + false -> + model + end + end +end diff --git a/lib/middleware/model/inline_object.ex b/lib/middleware/model/inline_object.ex new file mode 100644 index 0000000..80b8e1d --- /dev/null +++ b/lib/middleware/model/inline_object.ex @@ -0,0 +1,24 @@ +defmodule Aeternal.Model.InlineObject do + @moduledoc """ + + """ + + @derive [Poison.Encoder] + defstruct [ + :contract_id, + :source, + :compiler + ] + + @type t :: %__MODULE__{ + :contract_id => String.t(), + :source => String.t(), + :compiler => String.t() + } +end + +defimpl Poison.Decoder, for: Aeternal.Model.InlineObject do + def decode(value, _options) do + value + end +end diff --git a/lib/middleware/request_builder.ex b/lib/middleware/request_builder.ex new file mode 100644 index 0000000..4c315d5 --- /dev/null +++ b/lib/middleware/request_builder.ex @@ -0,0 +1,151 @@ +defmodule Aeternal.RequestBuilder do + @moduledoc """ + Helper functions for building Tesla requests + """ + + @doc """ + Specify the request method when building a request + + ## Parameters + + - request (Map) - Collected request options + - m (atom) - Request method + + ## Returns + + Map + """ + @spec method(map(), atom) :: map() + def method(request, m) do + Map.put_new(request, :method, m) + end + + @doc """ + Specify the request method when building a request + + ## Parameters + + - request (Map) - Collected request options + - u (String) - Request URL + + ## Returns + + Map + """ + @spec url(map(), String.t()) :: map() + def url(request, u) do + Map.put_new(request, :url, u) + end + + @doc """ + Add optional parameters to the request + + ## Parameters + + - request (Map) - Collected request options + - definitions (Map) - Map of parameter name to parameter location. + - options (KeywordList) - The provided optional parameters + + ## Returns + + Map + """ + @spec add_optional_params(map(), %{optional(atom) => atom}, keyword()) :: map() + def add_optional_params(request, _, []), do: request + + def add_optional_params(request, definitions, [{key, value} | tail]) do + case definitions do + %{^key => location} -> + request + |> add_param(location, key, value) + |> add_optional_params(definitions, tail) + + _ -> + add_optional_params(request, definitions, tail) + end + end + + @doc """ + Add optional parameters to the request + + ## Parameters + + - request (Map) - Collected request options + - location (atom) - Where to put the parameter + - key (atom) - The name of the parameter + - value (any) - The value of the parameter + + ## Returns + + Map + """ + @spec add_param(map(), atom, atom, any()) :: map() + def add_param(request, :body, :body, value), do: Map.put(request, :body, value) + + def add_param(request, :body, key, value) do + request + |> Map.put_new_lazy(:body, &Tesla.Multipart.new/0) + |> Map.update!( + :body, + &Tesla.Multipart.add_field(&1, key, Poison.encode!(value), + headers: [{:"Content-Type", "application/json"}] + ) + ) + end + + def add_param(request, :headers, key, value) do + request + |> Tesla.put_header(key, value) + end + + def add_param(request, :file, name, path) do + request + |> Map.put_new_lazy(:body, &Tesla.Multipart.new/0) + |> Map.update!(:body, &Tesla.Multipart.add_file(&1, path, name: name)) + end + + def add_param(request, :form, name, value) do + request + |> Map.update(:body, %{name => value}, &Map.put(&1, name, value)) + end + + def add_param(request, location, key, value) do + Map.update(request, location, [{key, value}], &(&1 ++ [{key, value}])) + end + + @doc """ + Handle the response for a Tesla request + + ## Parameters + + - arg1 (Tesla.Env.t | term) - The response object + - arg2 (:false | struct | [struct]) - The shape of the struct to deserialize into + + ## Returns + + {:ok, struct | any} on success + {:error, term} on failure + """ + @spec decode(Tesla.Env.t() | term(), false | struct() | [struct()]) :: + {:ok, struct()} | {:ok, any()} | {:error, any} + def decode(%Tesla.Env{body: body}, false), do: Poison.decode(body, keys: :atoms) + def decode(%Tesla.Env{body: body}, struct), do: Poison.decode(body, as: struct) + + def evaluate_response({:ok, %Tesla.Env{} = env}, mapping) do + resolve_mapping(env, mapping) + end + + def evaluate_response({:error, _} = error, _), do: error + + def resolve_mapping(env, mapping, default \\ nil) + + def resolve_mapping(%Tesla.Env{status: status} = env, [{mapping_status, struct} | _], _) + when status == mapping_status do + decode(env, struct) + end + + def resolve_mapping(env, [{:default, struct} | tail], _), do: resolve_mapping(env, tail, struct) + def resolve_mapping(env, [_ | tail], struct), do: resolve_mapping(env, tail, struct) + def resolve_mapping(env, [], nil), do: {:error, env} + def resolve_mapping(env, [], struct), do: decode(env, struct) +end diff --git a/mix.exs b/mix.exs index 5ff3d92..b6f8327 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule AeppSdkElixir.MixProject do def project do [ app: :aepp_sdk_elixir, - version: "0.5.1", + version: "0.5.2", start_permanent: Mix.env() == :prod, description: description(), package: package(),