Skip to content

Commit

Permalink
Merge pull request #26 from wowica/publish-v0.3.0
Browse files Browse the repository at this point in the history
Publish v0.3.0
  • Loading branch information
caike authored Mar 29, 2024
2 parents 1739b4b + 4cc9f1d commit 0a186e9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@ Add the dependency to `mix.exs`:
```elixir
defp deps do
[
{:xogmios, "~> 0.2.0"}
{:xogmios, "~> 0.3.0"}
]
end
```

Add your client module(s) to your application's supervision tree as such:
Add your client modules to your application's supervision tree as such:

```elixir
# file: application.ex
def start(_type, _args) do
ogmios_url = System.fetch_env!("OGMIOS_URL")

children = [
{ChainSyncClient, url: "ws://..."},
{StateQueryClient, url: "ws://..."},
{ChainSyncClient, url: ogmios_url},
{StateQueryClient, url: ogmios_url},
{TxSubmissionClient, url: ogmios_url}
]
#...
end
Expand All @@ -51,7 +54,7 @@ See section below for examples of client modules.

### Chain Sync

The following is an example of a module that implement the **Chain Sync** behaviour. This module syncs with the tip of the chain, reads the next 3 blocks and then closes the connection with the server.
The following is an example of a module that implement the **Chain Sync** behaviour. In this example, the client syncs with the tip of the chain, reads the next 3 blocks and then closes the connection with the server.

```elixir
defmodule ChainSyncClient do
Expand Down Expand Up @@ -91,12 +94,26 @@ defmodule StateQueryClient do
end

def get_current_epoch(pid \\ __MODULE__) do
# Defaults to Ledger-state queries.
# The following call is the same as calling
# `StateQuery.send_query(pid, "queryLedgerState/epoch")`
StateQuery.send_query(pid, "epoch")
end

def send_query(pid \\ __MODULE__, query_name) do
def get_network_height(pid \\ __MODULE__) do
# For network queries, scope must be explicitly used.
StateQuery.send_query(pid, "queryNetwork/blockHeight")`
end

def send_query_no_params(pid \\ __MODULE__, query_name) do
StateQuery.send_query(pid, query_name)
end

def send_query(pid \\ __MODULE__, query_name, query_params) do
# Optional query params are sent as the third argument
# to StateQuery.send_query/3
StateQuery.send_query(pid, query_name, query_params)
end
end
```

Expand Down
25 changes: 22 additions & 3 deletions lib/xogmios/state_query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,32 @@ defmodule Xogmios.StateQuery do
Support for all [Ledger-state](https://ogmios.dev/mini-protocols/local-state-query/#ledger-state)
and [Network](https://ogmios.dev/mini-protocols/local-state-query/#network) queries.
For Ledger-state queries, only the name of the query is needed. For example:
For Ledger-state queries, only the name of the query is needed. For example, the following
function call
`StateQuery.send_query(pid, "epoch")` will send the query for ""queryLedgerState/epoch".
```
StateQuery.send_query(pid, "epoch")
```
is the same as calling
```
StateQuery.send_query(pid, "queryLedgerState/epoch")
```
For Network queries, the prefix "queryNetwork/" is needed. For example:
`StateQueryClient.send_query("queryNetwork/blockHeight")` will send the query for "queryNetwork/blockHeight"
```
StateQuery.send_query(pid, "queryNetwork/blockHeight")
```
Optional parameters are passed as the third argument:
```
query_name = "utxo"
query_params = %{addresses: [address_1, address_2]}
StateQuery.send_query(pid, query_name, query_params)
```
"""
@spec send_query(pid() | atom(), String.t(), map()) :: {:ok, any()} | {:error, any()}

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Xogmios.MixProject do

@description "An Elixir client for Ogmios"
@source_url "https://github.com/wowica/xogmios"
@version "0.2.0"
@version "0.3.0"

def project do
[
Expand Down

0 comments on commit 0a186e9

Please sign in to comment.