diff --git a/cmd/gouroboros/query.go b/cmd/gouroboros/query.go index 230a2e6c..86a73bae 100644 --- a/cmd/gouroboros/query.go +++ b/cmd/gouroboros/query.go @@ -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) diff --git a/protocol/localstatequery/client.go b/protocol/localstatequery/client.go index 1c938362..21e2f440 100644 --- a/protocol/localstatequery/client.go +++ b/protocol/localstatequery/client.go @@ -836,10 +836,18 @@ func (c *Client) GetPoolDistr(poolIds []any) (*PoolDistrResult, error) { if err != nil { return nil, err } + // GetPoolDistr always requires a pool set parameter according to the Haskell implementation + // The query expects (len=2, tag=21) format: [21, Set(poolIds)] + // If no pool IDs specified, use an empty set to query all pools + var params []any + if poolIds == nil { + poolIds = []any{} + } + params = append(params, cbor.Set(poolIds)) query := buildShelleyQuery( currentEra, QueryTypeShelleyPoolDistr, - // TODO: add args (#870) + params..., ) var result PoolDistrResult if err := c.runQuery(query, &result); err != nil { diff --git a/protocol/localstatequery/queries.go b/protocol/localstatequery/queries.go index a81b2526..02cc057e 100644 --- a/protocol/localstatequery/queries.go +++ b/protocol/localstatequery/queries.go @@ -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 + } +}