-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.exs
44 lines (35 loc) · 1.03 KB
/
run.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
# Install Xander from local path
Mix.install([
{:xander, path: Path.expand(".")}
])
socket_path = System.get_env("CARDANO_NODE_SOCKET_PATH", "/tmp/cardano-node.socket")
if !File.exists?(socket_path) do
IO.puts("Error: socket file path #{socket_path} does not exist")
System.halt(1)
end
alias Xander.Config
alias Xander.Query
# Default config connects via a local UNIX socket
config = Config.default_config!(socket_path)
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 Cardano node 🎉\n")
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 Cardano node: #{inspect(reason)}")
System.halt(1)
end