-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #376 from kommitters/v0.22
V0.22
- Loading branch information
Showing
19 changed files
with
320 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule Stellar.Horizon.ErrorMapper do | ||
@moduledoc """ | ||
Assigns errors returned by the HTTP client to a custom structure. | ||
""" | ||
alias Stellar.Horizon.AsyncTransactionError | ||
alias Stellar.Horizon.AsyncTransaction | ||
alias Stellar.Horizon.Error | ||
|
||
@type error_source :: :horizon | :network | ||
@type error_body :: map() | atom() | String.t() | ||
@type error :: {error_source(), error_body()} | ||
|
||
@type t :: {:error, struct()} | ||
|
||
@spec build(error :: error()) :: t() | ||
def build( | ||
{:horizon, | ||
%{hash: _hash, errorResultXdr: _error_result_xdr, tx_status: _tx_status} = decoded_body} | ||
) do | ||
error = AsyncTransactionError.new(decoded_body) | ||
{:error, error} | ||
end | ||
|
||
def build({:horizon, %{hash: _hash, tx_status: _tx_status} = decoded_body}) do | ||
error = AsyncTransaction.new(decoded_body) | ||
{:error, error} | ||
end | ||
|
||
def build(error), do: {:error, Error.new(error)} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule Stellar.Horizon.AsyncTransaction do | ||
@moduledoc """ | ||
Represents a `Asynchronous transaction` resource from Horizon API. | ||
""" | ||
|
||
@behaviour Stellar.Horizon.Resource | ||
|
||
alias Stellar.Horizon.Mapping | ||
|
||
@type t :: %__MODULE__{ | ||
hash: String.t() | nil, | ||
tx_status: String.t() | nil | ||
} | ||
|
||
defstruct [ | ||
:hash, | ||
:tx_status | ||
] | ||
|
||
@impl true | ||
def new(attrs, opts \\ []) | ||
|
||
def new(attrs, _opts), do: Mapping.build(%__MODULE__{}, attrs) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule Stellar.Horizon.AsyncTransactionError do | ||
@moduledoc """ | ||
Represents a `Asynchronous transaction error` resource from Horizon API. | ||
""" | ||
|
||
@behaviour Stellar.Horizon.Resource | ||
|
||
alias Stellar.Horizon.Mapping | ||
|
||
@type t :: %__MODULE__{ | ||
hash: String.t() | nil, | ||
tx_status: String.t() | nil, | ||
errorResultXdr: String.t() | nil | ||
} | ||
|
||
defstruct [ | ||
:hash, | ||
:tx_status, | ||
:errorResultXdr | ||
] | ||
|
||
@impl true | ||
def new(attrs, opts \\ []) | ||
|
||
def new(attrs, _opts), do: Mapping.build(%__MODULE__{}, attrs) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule Stellar.Horizon.AsyncTransactionTest do | ||
use ExUnit.Case | ||
|
||
alias Stellar.Test.Fixtures.Horizon | ||
|
||
alias Stellar.Horizon.AsyncTransaction | ||
|
||
setup do | ||
json_body = Horizon.fixture("async_transaction") | ||
attrs = Jason.decode!(json_body, keys: :atoms) | ||
|
||
%{attrs: attrs} | ||
end | ||
|
||
test "new/2", %{attrs: attrs} do | ||
%AsyncTransaction{ | ||
hash: "12958c37b341802a19ddada4c2a56b453a9cba728b2eefdfbc0b622e37379222", | ||
tx_status: "PENDING" | ||
} = AsyncTransaction.new(attrs) | ||
end | ||
|
||
test "new/2 empty_attrs" do | ||
%AsyncTransaction{ | ||
hash: nil, | ||
tx_status: nil | ||
} = AsyncTransaction.new(%{}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.