Skip to content

Commit

Permalink
Add update getHealth response (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
einerzg authored Jul 24, 2024
1 parent a352507 commit 62074f8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,13 @@ General node health check.
server = Soroban.RPC.Server.testnet()
Soroban.RPC.get_health(server)

{:ok, %Soroban.RPC.GetHealthResponse{status: "healthy"}}
{:ok,
%Soroban.RPC.GetHealthResponse{
status: "healthy",
latest_ledger: 706073,
oldest_ledger: 688794,
ledger_retention_window: 17280
}}

```

Expand Down
11 changes: 9 additions & 2 deletions lib/rpc/responses/get_health_response.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ defmodule Soroban.RPC.GetHealthResponse do
@behaviour Soroban.RPC.Response.Spec

@type status :: String.t()
@type latest_ledger :: non_neg_integer()
@type oldest_ledger :: non_neg_integer()
@type ledger_retention_window :: non_neg_integer()

@type t :: %__MODULE__{
status: status()
status: status(),
latest_ledger: latest_ledger(),
oldest_ledger: oldest_ledger(),
ledger_retention_window: ledger_retention_window()
}

defstruct [:status]
defstruct [:status, :latest_ledger, :oldest_ledger, :ledger_retention_window]

@impl true
def new(attrs), do: struct(%__MODULE__{}, attrs)
Expand Down
5 changes: 4 additions & 1 deletion test/rpc/responses/get_health_response_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ defmodule Soroban.RPC.GetHealthResponseTest do
setup do
%{
result: %{
status: "healthy"
status: "healthy",
latest_ledger: 706_073,
oldest_ledger: 688_794,
ledger_retention_window: 17_280
}
}
end
Expand Down
5 changes: 4 additions & 1 deletion test/rpc_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ defmodule Soroban.RPC.CannedRPCGetHealthClientImpl do

{:ok,
%{
status: "healthy"
status: "healthy",
latest_ledger: 706_073,
oldest_ledger: 688_794,
ledger_retention_window: 17_280
}}
end
end
Expand Down

0 comments on commit 62074f8

Please sign in to comment.