-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_with_demeter.exs
48 lines (38 loc) · 1.18 KB
/
run_with_demeter.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Install Xander from local path
Mix.install([
{:xander, path: Path.expand(".")}
])
# Example script showing Xander usage with Demeter configuration
# Usage: DEMETER_URL=your-demeter-url elixir run_with_demeter.exs
demeter_url = System.get_env("DEMETER_URL")
if demeter_url == nil do
IO.puts("Error: DEMETER_URL environment variable is not set")
System.halt(1)
end
alias Xander.Config
alias Xander.Query
network = System.get_env("CARDANO_NETWORK", "mainnet") |> String.to_atom()
# Configure Xander client for Demeter
config = Config.demeter_config!(demeter_url, network: network)
queries = [
:get_epoch_number,
:get_current_era,
:get_current_block_height,
:get_current_tip
]
case Query.start_link(config) do
{:ok, pid} ->
IO.puts("Successfully connected to Demeter node")
for query <- queries do
case Query.run(pid, query) do
{:ok, result} ->
IO.puts("Query #{query} result: #{inspect(result)}")
{:error, reason} ->
IO.puts("Error querying #{inspect(query)}: #{inspect(reason)}")
System.halt(1)
end
end
{:error, reason} ->
IO.puts("Failed to connect to Demeter node: #{inspect(reason)}")
System.halt(1)
end