Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions cmd/gouroboros/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,24 @@
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([]any{})
if err != nil {
fmt.Printf(
"ERROR: failure querying pool distribution: %s\n",
err,
)
os.Exit(1)
}
fmt.Printf("pool-distr (raw): %#v\n", poolDistr)
// Also try JSON marshaling to see structure
jsonData, err := json.Marshal(poolDistr)

Check failure on line 330 in cmd/gouroboros/query.go

View workflow job for this annotation

GitHub Actions / lint

`encoding/json.Marshal` for unsupported type `github.com/blinklabs-io/gouroboros/ledger.PoolId` as map key found (errchkjson)
if err != nil {
fmt.Printf("pool-distr (JSON marshaling failed): %s\n", err)
Copy link

@cubic-dev-ai cubic-dev-ai bot Dec 3, 2025

Choose a reason for hiding this comment

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

P2: JSON marshaling error handling is inconsistent with other cases in this file. Other cases (e.g., utxos-by-address, utxos-by-txin) call os.Exit(1) after JSON marshal failures and use ERROR: prefix format. This case silently continues execution.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At cmd/gouroboros/query.go, line 339:

<comment>JSON marshaling error handling is inconsistent with other cases in this file. Other cases (e.g., `utxos-by-address`, `utxos-by-txin`) call `os.Exit(1)` after JSON marshal failures and use `ERROR:` prefix format. This case silently continues execution.</comment>

<file context>
@@ -315,6 +315,31 @@ func testQuery(f *globalFlags) {
+		}
+		jsonData, err := json.Marshal(jsonResults)
+		if err != nil {
+			fmt.Printf(&quot;pool-distr (JSON marshaling failed): %s\n&quot;, err)
+		} else {
+			fmt.Printf(&quot;pool-distr (JSON): %s\n&quot;, string(jsonData))
</file context>
Suggested change
fmt.Printf("pool-distr (JSON marshaling failed): %s\n", err)
fmt.Printf("ERROR: failed to marshal pool-distr JSON: %s\n", err)
os.Exit(1)
Fix with Cubic

} 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