@@ -12,15 +12,24 @@ defmodule Stellar.Horizon.Transactions do
12
12
Horizon API reference: https://developers.stellar.org/api/resources/transactions/
13
13
"""
14
14
15
- alias Stellar.Horizon . { Collection , Effect , Error , Operation , Transaction , Request , Server }
15
+ alias Stellar.Horizon . {
16
+ Collection ,
17
+ Effect ,
18
+ Operation ,
19
+ Transaction ,
20
+ AsyncTransaction ,
21
+ Request ,
22
+ Server
23
+ }
16
24
17
25
@ type server :: Server . t ( )
18
26
@ type hash :: String . t ( )
19
27
@ type options :: Keyword . t ( )
20
28
@ type resource :: Transaction . t ( ) | Collection . t ( )
21
- @ type response :: { :ok , resource ( ) } | { :error , Error . t ( ) }
29
+ @ type response :: { :ok , resource ( ) } | { :error , struct ( ) }
22
30
23
31
@ endpoint "transactions"
32
+ @ endpoint_async "transactions_async"
24
33
25
34
@ doc """
26
35
Creates a transaction to the Stellar network.
@@ -152,4 +161,26 @@ defmodule Stellar.Horizon.Transactions do
152
161
|> Request . perform ( )
153
162
|> Request . results ( collection: { Operation , & list_operations ( server , hash , & 1 ) } )
154
163
end
164
+
165
+ @ doc """
166
+ Creates a transaction to the Stellar network asynchronously.
167
+
168
+ ## Parameters:
169
+ * `server`: The Horizon server to query.
170
+ * `tx`: The base64-encoded XDR of the transaction.
171
+
172
+ ## Examples
173
+
174
+ iex> Transactions.create_async(Stellar.Horizon.Server.testnet(), "AAAAAgAAAACQcEK2yfQA9CHrX+2UMkRIb/1wzltKqHpbdIcJbp+b/QAAAGQAAiEYAAAAAQAAAAEAAAAAAAAAAAAAAABgXP3QAAAAAQAAABBUZXN0IFRyYW5zYWN0aW9uAAAAAQAAAAAAAAABAAAAAJBwQrbJ9AD0Ietf7ZQyREhv/XDOW0qoelt0hwlun5v9AAAAAAAAAAAF9eEAAAAAAAAAAAFun5v9AAAAQKdJnG8QRiv9xGp1Oq7ACv/xR2BnNqjfUHrGNua7m4tWbrun3+GmAj6ca3xz+4ZppWRTbvTUcCxvpbHERZ85QgY=")
175
+ {:ok, %AsyncTransaction{}}
176
+ """
177
+ @ spec create_async ( server :: server ( ) , base64_envelope :: String . t ( ) ) :: response ( )
178
+ def create_async ( server , base64_envelope ) do
179
+ server
180
+ |> Request . new ( :post , @ endpoint_async )
181
+ |> Request . add_headers ( [ { "Content-Type" , "application/x-www-form-urlencoded" } ] )
182
+ |> Request . add_body ( tx: base64_envelope )
183
+ |> Request . perform ( )
184
+ |> Request . results ( as: AsyncTransaction )
185
+ end
155
186
end
0 commit comments