generated from kommitters/.template
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9902a38
commit 737a6eb
Showing
9 changed files
with
132 additions
and
265 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,12 @@ | ||
defmodule Kadena.Chainweb.Pact do | ||
@moduledoc """ | ||
<<<<<<< HEAD | ||
Exposes functions to interact with the Pact API endpoints. | ||
""" | ||
|
||
alias Kadena.Chainweb.Pact.Send | ||
alias Kadena.Chainweb.Pact.{Local, Send} | ||
|
||
@default_network_opts [network_id: :testnet04, chain_id: 0] | ||
|
||
defdelegate send(cmds, network_opts \\ @default_network_opts), to: Send, as: :process | ||
======= | ||
Specifies the API for processing HTTP requests. | ||
""" | ||
alias Kadena.Chainweb.Pact.Local | ||
defdelegate local(request, network \\ :testnet04, chain_id \\ "0"), to: Local, as: :process | ||
|
||
# defdelegate send(request, network \\ :test, chain_id \\ "0"), to: Send, as: :process | ||
# defdelegate poll(request, network \\ :test, chain_id \\ "0"), to: Poll, as: :process | ||
# defdelegate listen(request, network \\ :test, chain_id \\ "0"), to: Listen, as: :process | ||
# defdelegate spv(request, network \\ :test, chain_id \\ "0"), to: SPV, as: :process | ||
>>>>>>> 40795f4 (Add local endpoitn and PACT API) | ||
defdelegate local(cmds, network_opts \\ @default_network_opts), to: Local, as: :process | ||
end |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,39 +1,38 @@ | ||
defmodule Kadena.Chainweb.Pact.Local do | ||
@moduledoc """ | ||
Send endpoint implementation | ||
Local endpoint implementation | ||
""" | ||
|
||
alias Kadena.Chainweb.Request | ||
alias Kadena.Chainweb.Pact.{Endpoints, JSONPayload, LocalResponse} | ||
alias Kadena.Types.{Command, LocalRequestBody} | ||
alias Kadena.Chainweb.Pact.{LocalRequestBody, LocalResponse, Spec} | ||
alias Kadena.Types.Command | ||
|
||
@type cmd :: Command.t() | ||
@type json_request_body :: String.t() | ||
@behaviour Endpoints | ||
@behaviour Spec | ||
|
||
@endpoint "local" | ||
@headers [{"Content-Type", "application/json"}] | ||
|
||
@type cmd :: Command.t() | ||
@type json :: String.t() | ||
|
||
@impl true | ||
def process(%Command{} = cmd, network, chain_id) do | ||
request_body = get_json_request_body(cmd) | ||
def process(%Command{} = cmd, network_id: network_id, chain_id: chain_id) do | ||
request_body = json_request_body(cmd) | ||
headers = [{"Content-Type", "application/json"}] | ||
|
||
:post | ||
|> Request.new(pact: [endpoint: @endpoint]) | ||
|> Request.set_chain_id(chain_id) | ||
|> Request.set_network(network) | ||
|> Request.set_network(network_id) | ||
|> Request.add_body(request_body) | ||
|> Request.add_headers(@headers) | ||
|> Request.add_headers(headers) | ||
|> Request.perform() | ||
|> Request.results(as: LocalResponse) | ||
end | ||
|
||
def process(_cmds, _network, _chain_id), do: {:error, [command: :invalid_command]} | ||
|
||
@spec get_json_request_body(cmd :: cmd()) :: json_request_body() | ||
defp get_json_request_body(cmd) do | ||
@spec json_request_body(cmd :: cmd()) :: json() | ||
defp json_request_body(cmd) do | ||
cmd | ||
|> LocalRequestBody.new() | ||
|> JSONPayload.parse() | ||
|> LocalRequestBody.to_json!() | ||
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
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 was deleted.
Oops, something went wrong.
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.