Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cmd/gouroboros/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,31 @@ func testQuery(f *globalFlags) {
os.Exit(1)
}
fmt.Printf("proposed-protocol-params-updates: %v\n", *proposedUpdates)
case "pool-distr":
// GetPoolDistr without specific pool IDs to get all pools distribution
poolDistr, err := o.LocalStateQuery().Client.GetPoolDistr(nil)
if err != nil {
fmt.Printf(
"ERROR: failure querying pool distribution: %s\n",
err,
)
os.Exit(1)
}
fmt.Printf("pool-distr (raw): %#v\n", poolDistr)

// Build a JSON-friendly view: map pool ID (hex) -> entry
jsonResults := make(map[string]any, len(poolDistr.Results))
for poolID, entry := range poolDistr.Results {
// PoolId is [28]byte; represent as hex for debugging
jsonKey := hex.EncodeToString(poolID[:])
jsonResults[jsonKey] = entry
}
jsonData, err := json.Marshal(jsonResults)
if err != nil {
fmt.Printf("pool-distr (JSON marshaling failed): %s\n", err)
} else {
fmt.Printf("pool-distr (JSON): %s\n", string(jsonData))
}
default:
fmt.Printf("ERROR: unknown query: %s\n", queryFlags.flagset.Args()[0])
os.Exit(1)
Expand Down
23 changes: 18 additions & 5 deletions protocol/localstatequery/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,11 +836,24 @@ func (c *Client) GetPoolDistr(poolIds []any) (*PoolDistrResult, error) {
if err != nil {
return nil, err
}
query := buildShelleyQuery(
currentEra,
QueryTypeShelleyPoolDistr,
// TODO: add args (#870)
)
// If no pool IDs specified, query without parameters (get all pools)
// Otherwise, query with specific pool IDs as a CBOR set
var query []any
if len(poolIds) == 0 {
query = buildShelleyQuery(
currentEra,
QueryTypeShelleyPoolDistr,
)
} else {
query = buildShelleyQuery(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of building the query twice, it's a bit cleaner to build the params dynamically. Something like this:

var params []any
if len(poolIds) > 0 {
  params = append(params, cbor.Set(poolIds))
}
query := buildShelleyQuery(
  currentEra,
  QueryTypeShelleyPoolDistr,
  params...,
)

currentEra,
QueryTypeShelleyPoolDistr,
cbor.Tag{
Number: cbor.CborTagSet,
Content: poolIds,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the cbor.Set type that handles this

)
}
var result PoolDistrResult
if err := c.runQuery(query, &result); err != nil {
return nil, err
Expand Down
12 changes: 10 additions & 2 deletions protocol/localstatequery/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,13 @@ type PoolStateResult any
// TODO (#869)
type StakeSnapshotsResult any

// TODO (#870)
type PoolDistrResult any
// PoolDistrResult represents the pool distribution result
// It contains a map of pool IDs to their stake distribution (fraction and VRF hash)
type PoolDistrResult struct {
cbor.StructAsArray
Results map[ledger.PoolId]struct {
cbor.StructAsArray
StakeFraction *cbor.Rat
VrfHash ledger.Blake2b256
}
}
Loading