forked from kommitters/kadena.ex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Local endpoint implementation (kommitters#177)
* Add local endpoint implementation Co-authored-by: Miguel Nieto A <[email protected]>
- Loading branch information
1 parent
e490f49
commit 0175b67
Showing
9 changed files
with
312 additions
and
75 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,38 @@ | ||
defmodule Kadena.Chainweb.Pact.Local do | ||
@moduledoc """ | ||
Local endpoint implementation | ||
""" | ||
|
||
alias Kadena.Chainweb.Request | ||
alias Kadena.Chainweb.Pact.{LocalRequestBody, LocalResponse, Spec} | ||
alias Kadena.Types.Command | ||
|
||
@behaviour Spec | ||
|
||
@endpoint "local" | ||
|
||
@type cmd :: Command.t() | ||
@type json :: String.t() | ||
|
||
@impl true | ||
def process(%Command{} = cmd, network_id: network_id, chain_id: chain_id) do | ||
headers = [{"Content-Type", "application/json"}] | ||
body = json_request_body(cmd) | ||
|
||
:post | ||
|> Request.new(pact: [endpoint: @endpoint]) | ||
|> Request.set_chain_id(chain_id) | ||
|> Request.set_network(network_id) | ||
|> Request.add_body(body) | ||
|> Request.add_headers(headers) | ||
|> Request.perform() | ||
|> Request.results(as: LocalResponse) | ||
end | ||
|
||
@spec json_request_body(cmd :: cmd()) :: json() | ||
defp json_request_body(cmd) do | ||
cmd | ||
|> LocalRequestBody.new() | ||
|> 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 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
Oops, something went wrong.