Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Commit

Permalink
implement /genesis endpoint and cmd
Browse files Browse the repository at this point in the history
Signed-off-by: Marko Kungla <marko.kungla@gmail.com>
  • Loading branch information
mkungla committed Feb 4, 2022
1 parent a95fbca commit 67f91c9
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cmd/koios-rest/cmd-network.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ func addNetworkCommands(app *cli.App, api *koios.Client) {
Name: "genesis",
Category: "NETWORK",
Usage: "Get the Genesis parameters used to start specific era on chain.",
Action: func(ctx *cli.Context) error {
res, err := api.GetGenesis(context.Background())
output(ctx, res, err)
return nil
},
},
{
Name: "totals",
Expand Down
2 changes: 1 addition & 1 deletion koios.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type (
}
Option func(*Client) error

// Response wraps API responses
// Response wraps API responses.
Response struct {
StatusCode int `json:"status_code"`
Status string `json:"status"`
Expand Down
19 changes: 19 additions & 0 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,22 @@ func (c *Client) GetTip(ctx context.Context) (*TipResponse, error) {

return res, nil
}

// Get the Genesis parameters used to start specific era on chain.
func (c *Client) GetGenesis(ctx context.Context) (*GenesisResponse, error) {
rsp, err := c.GET(ctx, "/genesis")
if err != nil {
return nil, err
}
res := &GenesisResponse{}
res.setStatus(rsp)
body, err := readResponseBody(rsp)
if err != nil {
return nil, err
}
if err := json.Unmarshal(body, &res.Genesis); err != nil {
return nil, err
}

return res, nil
}
59 changes: 58 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,66 @@ type (
Hash string `json:"hash"`
}

// TipResponse wraps response of /tip
// TipResponse response of /tip.
TipResponse struct {
Response
Tip Tip `json:"response"`
}
)

type (
// Genesis defines model for genesis.
Genesis []struct {
// Active Slot Co-Efficient (f) - determines the _probability_ of number of
// slots in epoch that are expected to have blocks
// (so mainnet, this would be: 432000 * 0.05 = 21600 estimated blocks).
Activeslotcoeff string `json:"activeslotcoeff"`

// A JSON dump of Alonzo Genesis.
Alonzogenesis string `json:"alonzogenesis"`

// Number of slots in an epoch.
Epochlength string `json:"epochlength"`

// Number of KES key evolutions that will automatically occur before a KES
// (hot) key is expired. This parameter is for security of a pool,
// in case an operator had access to his hot(online) machine compromised.
Maxkesrevolutions string `json:"maxkesrevolutions"`

// Maximum smallest units (lovelaces) supply for the blockchain.
Maxlovelacesupply string `json:"maxlovelacesupply"`

// Network ID used at various CLI identification to distinguish between
// Mainnet and other networks.
Networkid string `json:"networkid"`

// Unique network identifier for chain.
Networkmagic string `json:"networkmagic"`

// A unit (k) used to divide epochs to determine stability window
// (used in security checks like ensuring atleast 1 block was
// created in 3*k/f period, or to finalize next epoch's nonce
// at 4*k/f slots before end of epoch).
Securityparam string `json:"securityparam"`

// Duration of a single slot (in seconds).
Slotlength string `json:"slotlength"`

// Number of slots that represent a single KES period
// (a unit used for validation of KES key evolutions).
Slotsperkesperiod string `json:"slotsperkesperiod"`

// Timestamp for first block (genesis) on chain.
Systemstart string `json:"systemstart"`

// Number of BFT members that need to approve
// (via vote) a Protocol Update Proposal.
Updatequorum string `json:"updatequorum"`
}

// GenesisResponse response of /genesis.
GenesisResponse struct {
Response
Genesis Genesis `json:"response"`
}
)

0 comments on commit 67f91c9

Please sign in to comment.