Skip to content

Commit

Permalink
feat: add hyperchain/config endpoint to read aeternity.yaml settings (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yaboiishere authored Feb 25, 2025
1 parent fdffad1 commit 205fb1a
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
55 changes: 55 additions & 0 deletions docs/swagger_v3/hyperchain.spec.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,59 @@
schemas:
Config:
description: The hyperchains config file (aeternity.yaml)
type: object
properties:
consensus:
type: array
items:
type: object
description: This is the consensus part of the configuration
fork_management:
type: object
properties:
network_id:
type: string
hard_forks:
type: object
properties:
protocol_number:
type: object
properties:
height:
type: integer
accounts_file:
type: string
nullable: true
contracts_file:
type: string
nullable: true
example:
consensus:
child_block_time: 3000
child_epoch_length: 600
consensus_key: "0"
contract_owner: "ak_11111111111111111111111111111115rHyByZ"
default_pinning_behavior: true
election_contract: "ct_LRbi65kmLtE7YMkG6mvG5TxAXTsPJDZjAtsPuaXtRyPA7gnfJ"
fixed_coinbase: 100
parent_chain:
consensus:
network_id: "devnet"
type: "AE2AE"
parent_epoch_length: 10,
polling:
fetch_interval: 500
nodes:
- "http://localhost:13013"
start_height: 10
pinning_reward_value: 1000
rewards_contract: "ct_KJgjAXMtRF68AbT5A2aC9fTk8PA4WFv26cFSY27fXs6FtYQHK"
staking_contract: "ct_KJgjAXMtRF68AbT5A2aC9fTk8PA4WFv26cFSY27fXs6FtYQHK"
fork_management:
network_id: "hc_devnet"
hard_forks:
"6": 0

Schedule:
description: Schedule information
type: object
Expand Down
24 changes: 24 additions & 0 deletions lib/ae_mdw/hyperchain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ defmodule AeMdw.Hyperchain do
epoch: Blocks.height()
}

@spec get_config() :: {:ok, map()} | :error
def get_config() do
with {:ok, consensus} <- :aeu_env.user_config(["chain", "consensus"]),
{:ok, hard_forks} <- :aeu_env.user_config(["chain", "hard_forks"]),
{:ok, fork_management} <- :aeu_env.user_config(["fork_management"]) do
cleaned_consensus =
consensus
|> Enum.map(fn {k, %{"config" => v}} ->
v |> Map.drop(["pinners", "stakers"]) |> Map.put("consensus_key", k)
end)

config = %{
consensus: cleaned_consensus,
hard_forks: hard_forks,
fork_management: fork_management
}

{:ok, config}
else
_otherwise ->
:error
end
end

@spec fetch_epochs(
State.t(),
Collection.pagination(),
Expand Down
11 changes: 11 additions & 0 deletions lib/ae_mdw_web/controllers/hyperchain_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ defmodule AeMdwWeb.HyperchainController do
plug(PaginatedPlug, order_by: ~w(expiration activation deactivation name)a)
action_fallback(FallbackController)

@spec config(Conn.t(), map()) :: Conn.t()
def config(conn, _params) do
case Hyperchain.get_config() do
{:ok, config} ->
json(conn, config)

:error ->
format_json(conn, %{error: "Unable to parse aeternity.yaml config file"}, 422)
end
end

@spec epochs(Conn.t(), map()) :: Conn.t()
def epochs(%Conn{assigns: assigns} = conn, _params) do
%{state: state, pagination: pagination, cursor: cursor, scope: scope} =
Expand Down
1 change: 1 addition & 0 deletions lib/ae_mdw_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ defmodule AeMdwWeb.Router do
get "/debug/dex/:contract_id/swaps", DexController, :debug_contract_swaps
get "/wealth", WealthController, :wealth

get "/hyperchain/config", HyperchainController, :config
get "/hyperchain/schedule", HyperchainController, :schedule
get "/hyperchain/schedule/height/:height", HyperchainController, :schedule_at_height
get "/hyperchain/epochs", HyperchainController, :epochs
Expand Down

0 comments on commit 205fb1a

Please sign in to comment.