Skip to content

Commit 8be1cfb

Browse files
authored
Merge pull request #135 from cloudstruct/feat/finish-local-state-query
feat: flesh out query result types
2 parents 40b1d6a + e6e7ad5 commit 8be1cfb

File tree

3 files changed

+161
-29
lines changed

3 files changed

+161
-29
lines changed

cmd/go-ouroboros-network/query.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,31 @@ func testQuery(f *globalFlags) {
101101
fmt.Printf("ERROR: failure querying era history: %s\n", err)
102102
os.Exit(1)
103103
}
104-
fmt.Printf("era-history: %#v", *eraHistory)
104+
fmt.Printf("era-history:\n")
105+
for eraId, era := range eraHistory {
106+
fmt.Printf("id = %d, begin slot/epoch = %d/%d, end slot/epoch = %d/%d, epoch length = %d, slot length (ms) = %d, slots per KES period = %d\n", eraId, era.Begin.SlotNo, era.Begin.EpochNo, era.End.SlotNo, era.End.EpochNo, era.Params.EpochLength, era.Params.SlotLength, era.Params.SlotsPerKESPeriod.Value)
107+
}
108+
case "protocol-params":
109+
protoParams, err := o.LocalStateQuery.Client.GetCurrentProtocolParams()
110+
if err != nil {
111+
fmt.Printf("ERROR: failure querying protocol params: %s\n", err)
112+
os.Exit(1)
113+
}
114+
fmt.Printf("protocol-params: %#v\n", *protoParams)
115+
case "stake-distribution":
116+
stakeDistribution, err := o.LocalStateQuery.Client.GetStakeDistribution()
117+
if err != nil {
118+
fmt.Printf("ERROR: failure querying stake distribution: %s\n", err)
119+
os.Exit(1)
120+
}
121+
fmt.Printf("stake-distribution: %#v\n", *stakeDistribution)
122+
case "genesis-config":
123+
genesisConfig, err := o.LocalStateQuery.Client.GetGenesisConfig()
124+
if err != nil {
125+
fmt.Printf("ERROR: failure querying genesis config: %s\n", err)
126+
os.Exit(1)
127+
}
128+
fmt.Printf("genesis-config: %#v\n", *genesisConfig)
105129
default:
106130
fmt.Printf("ERROR: unknown query: %s\n", queryFlags.flagset.Args()[0])
107131
os.Exit(1)

protocol/localstatequery/client.go

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,15 @@ func (c *Client) GetChainPoint() (*common.Point, error) {
215215
return &result, nil
216216
}
217217

218-
func (c *Client) GetEraHistory() (*EraHistoryResult, error) {
218+
func (c *Client) GetEraHistory() ([]EraHistoryResult, error) {
219219
c.busyMutex.Lock()
220220
defer c.busyMutex.Unlock()
221221
query := buildHardForkQuery(QUERY_TYPE_HARD_FORK_ERA_HISTORY)
222-
var result EraHistoryResult
222+
var result []EraHistoryResult
223223
if err := c.runQuery(query, &result); err != nil {
224-
return nil, err
224+
return []EraHistoryResult{}, err
225225
}
226-
return &result, nil
226+
return result, nil
227227
}
228228

229229
func (c *Client) GetEpochNo() (int, error) {
@@ -244,6 +244,7 @@ func (c *Client) GetEpochNo() (int, error) {
244244
return result[0], nil
245245
}
246246

247+
// TODO
247248
func (c *Client) GetNonMyopicMemberRewards() (*NonMyopicMemberRewardsResult, error) {
248249
c.busyMutex.Lock()
249250
defer c.busyMutex.Unlock()
@@ -273,14 +274,15 @@ func (c *Client) GetCurrentProtocolParams() (*CurrentProtocolParamsResult, error
273274
currentEra,
274275
QUERY_TYPE_SHELLEY_CURRENT_PROTOCOL_PARAMS,
275276
)
276-
var result CurrentProtocolParamsResult
277+
var result []CurrentProtocolParamsResult
277278
if err := c.runQuery(query, &result); err != nil {
278279
return nil, err
279280
}
280-
return &result, nil
281+
return &result[0], nil
281282

282283
}
283284

285+
// TODO
284286
func (c *Client) GetProposedProtocolParamsUpdates() (*ProposedProtocolParamsUpdatesResult, error) {
285287
c.busyMutex.Lock()
286288
defer c.busyMutex.Unlock()
@@ -316,9 +318,9 @@ func (c *Client) GetStakeDistribution() (*StakeDistributionResult, error) {
316318
return nil, err
317319
}
318320
return &result, nil
319-
320321
}
321322

323+
// TODO
322324
func (c *Client) GetUTxOByAddress(addrs []interface{}) (*UTxOByAddressResult, error) {
323325
c.busyMutex.Lock()
324326
defer c.busyMutex.Unlock()
@@ -335,9 +337,9 @@ func (c *Client) GetUTxOByAddress(addrs []interface{}) (*UTxOByAddressResult, er
335337
return nil, err
336338
}
337339
return &result, nil
338-
339340
}
340341

342+
// TODO
341343
func (c *Client) GetUTxOWhole() (*UTxOWholeResult, error) {
342344
c.busyMutex.Lock()
343345
defer c.busyMutex.Unlock()
@@ -354,9 +356,9 @@ func (c *Client) GetUTxOWhole() (*UTxOWholeResult, error) {
354356
return nil, err
355357
}
356358
return &result, nil
357-
358359
}
359360

361+
// TODO
360362
func (c *Client) DebugEpochState() (*DebugEpochStateResult, error) {
361363
c.busyMutex.Lock()
362364
defer c.busyMutex.Unlock()
@@ -373,9 +375,9 @@ func (c *Client) DebugEpochState() (*DebugEpochStateResult, error) {
373375
return nil, err
374376
}
375377
return &result, nil
376-
377378
}
378379

380+
// TODO
379381
func (c *Client) GetFilteredDelegationsAndRewardAccounts(creds []interface{}) (*FilteredDelegationsAndRewardAccountsResult, error) {
380382
c.busyMutex.Lock()
381383
defer c.busyMutex.Unlock()
@@ -392,9 +394,9 @@ func (c *Client) GetFilteredDelegationsAndRewardAccounts(creds []interface{}) (*
392394
return nil, err
393395
}
394396
return &result, nil
395-
396397
}
397398

399+
// TODO
398400
func (c *Client) GetGenesisConfig() (*GenesisConfigResult, error) {
399401
c.busyMutex.Lock()
400402
defer c.busyMutex.Unlock()
@@ -406,14 +408,14 @@ func (c *Client) GetGenesisConfig() (*GenesisConfigResult, error) {
406408
currentEra,
407409
QUERY_TYPE_SHELLEY_GENESIS_CONFIG,
408410
)
409-
var result GenesisConfigResult
411+
var result []GenesisConfigResult
410412
if err := c.runQuery(query, &result); err != nil {
411413
return nil, err
412414
}
413-
return &result, nil
414-
415+
return &result[0], nil
415416
}
416417

418+
// TODO
417419
func (c *Client) DebugNewEpochState() (*DebugNewEpochStateResult, error) {
418420
c.busyMutex.Lock()
419421
defer c.busyMutex.Unlock()
@@ -430,9 +432,9 @@ func (c *Client) DebugNewEpochState() (*DebugNewEpochStateResult, error) {
430432
return nil, err
431433
}
432434
return &result, nil
433-
434435
}
435436

437+
// TODO
436438
func (c *Client) DebugChainDepState() (*DebugChainDepStateResult, error) {
437439
c.busyMutex.Lock()
438440
defer c.busyMutex.Unlock()
@@ -449,9 +451,9 @@ func (c *Client) DebugChainDepState() (*DebugChainDepStateResult, error) {
449451
return nil, err
450452
}
451453
return &result, nil
452-
453454
}
454455

456+
// TODO
455457
func (c *Client) GetRewardProvenance() (*RewardProvenanceResult, error) {
456458
c.busyMutex.Lock()
457459
defer c.busyMutex.Unlock()
@@ -468,9 +470,9 @@ func (c *Client) GetRewardProvenance() (*RewardProvenanceResult, error) {
468470
return nil, err
469471
}
470472
return &result, nil
471-
472473
}
473474

475+
// TODO
474476
func (c *Client) GetUTxOByTxIn(txins []interface{}) (*UTxOByTxInResult, error) {
475477
c.busyMutex.Lock()
476478
defer c.busyMutex.Unlock()
@@ -487,9 +489,9 @@ func (c *Client) GetUTxOByTxIn(txins []interface{}) (*UTxOByTxInResult, error) {
487489
return nil, err
488490
}
489491
return &result, nil
490-
491492
}
492493

494+
// TODO
493495
func (c *Client) GetStakePools() (*StakePoolsResult, error) {
494496
c.busyMutex.Lock()
495497
defer c.busyMutex.Unlock()
@@ -506,9 +508,9 @@ func (c *Client) GetStakePools() (*StakePoolsResult, error) {
506508
return nil, err
507509
}
508510
return &result, nil
509-
510511
}
511512

513+
// TODO
512514
func (c *Client) GetStakePoolParams(poolIds []interface{}) (*StakePoolParamsResult, error) {
513515
c.busyMutex.Lock()
514516
defer c.busyMutex.Unlock()
@@ -525,9 +527,9 @@ func (c *Client) GetStakePoolParams(poolIds []interface{}) (*StakePoolParamsResu
525527
return nil, err
526528
}
527529
return &result, nil
528-
529530
}
530531

532+
// TODO
531533
func (c *Client) GetRewardInfoPools() (*RewardInfoPoolsResult, error) {
532534
c.busyMutex.Lock()
533535
defer c.busyMutex.Unlock()
@@ -544,9 +546,9 @@ func (c *Client) GetRewardInfoPools() (*RewardInfoPoolsResult, error) {
544546
return nil, err
545547
}
546548
return &result, nil
547-
548549
}
549550

551+
// TODO
550552
func (c *Client) GetPoolState(poolIds []interface{}) (*PoolStateResult, error) {
551553
c.busyMutex.Lock()
552554
defer c.busyMutex.Unlock()
@@ -563,9 +565,9 @@ func (c *Client) GetPoolState(poolIds []interface{}) (*PoolStateResult, error) {
563565
return nil, err
564566
}
565567
return &result, nil
566-
567568
}
568569

570+
// TODO
569571
func (c *Client) GetStakeSnapshots(poolId interface{}) (*StakeSnapshotsResult, error) {
570572
c.busyMutex.Lock()
571573
defer c.busyMutex.Unlock()
@@ -582,9 +584,9 @@ func (c *Client) GetStakeSnapshots(poolId interface{}) (*StakeSnapshotsResult, e
582584
return nil, err
583585
}
584586
return &result, nil
585-
586587
}
587588

589+
// TODO
588590
func (c *Client) GetPoolDistr(poolIds []interface{}) (*PoolDistrResult, error) {
589591
c.busyMutex.Lock()
590592
defer c.busyMutex.Unlock()
@@ -601,5 +603,4 @@ func (c *Client) GetPoolDistr(poolIds []interface{}) (*PoolDistrResult, error) {
601603
return nil, err
602604
}
603605
return &result, nil
604-
605606
}

protocol/localstatequery/queries.go

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package localstatequery
22

3+
import (
4+
"github.com/fxamacker/cbor/v2"
5+
)
6+
37
const (
48
QUERY_TYPE_BLOCK = 0
59
QUERY_TYPE_SYSTEM_START = 1
@@ -86,17 +90,120 @@ type SystemStartResult struct {
8690
Picoseconds uint64
8791
}
8892

89-
// TODO: populate me
90-
type EraHistoryResult interface{}
93+
type EraHistoryResult struct {
94+
// Tells the CBOR decoder to convert to/from a struct and a CBOR array
95+
_ struct{} `cbor:",toarray"`
96+
Begin eraHistoryResultBeginEnd
97+
End eraHistoryResultBeginEnd
98+
Params eraHistoryResultParams
99+
}
100+
101+
type eraHistoryResultBeginEnd struct {
102+
// Tells the CBOR decoder to convert to/from a struct and a CBOR array
103+
_ struct{} `cbor:",toarray"`
104+
Timespan interface{}
105+
SlotNo int
106+
EpochNo int
107+
}
108+
109+
type eraHistoryResultParams struct {
110+
// Tells the CBOR decoder to convert to/from a struct and a CBOR array
111+
_ struct{} `cbor:",toarray"`
112+
EpochLength int
113+
SlotLength int
114+
SlotsPerKESPeriod struct {
115+
// Tells the CBOR decoder to convert to/from a struct and a CBOR array
116+
_ struct{} `cbor:",toarray"`
117+
Dummy1 interface{}
118+
Value int
119+
Dummy2 interface{}
120+
}
121+
}
122+
123+
// TODO
91124
type NonMyopicMemberRewardsResult interface{}
92-
type CurrentProtocolParamsResult interface{}
125+
126+
type CurrentProtocolParamsResult struct {
127+
// Tells the CBOR decoder to convert to/from a struct and a CBOR array
128+
_ struct{} `cbor:",toarray"`
129+
MinFeeA int
130+
MinFeeB int
131+
MaxBlockBodySize int
132+
MaxTxSize int
133+
MaxBlockHeaderSize int
134+
KeyDeposit int
135+
PoolDeposit int
136+
EMax int
137+
NOpt int
138+
A0 []int
139+
Rho []int
140+
Tau []int
141+
// This field no longer exists in Babbage, but we're keeping this here for reference
142+
// unless we need to support querying a node still on an older era
143+
//DecentralizationParam []int
144+
ProtocolVersionMajor int
145+
ProtocolVersionMinor int
146+
MinPoolCost int
147+
Unknown interface{}
148+
CostModels interface{}
149+
ExecutionUnitPrices interface{} // [priceMemory priceSteps] both elements are fractions
150+
MaxTxExecutionUnits []uint
151+
MaxBlockExecutionUnits []uint
152+
MaxValueSize int
153+
CollateralPercentage int
154+
}
155+
156+
// TODO
93157
type ProposedProtocolParamsUpdatesResult interface{}
94158
type StakeDistributionResult interface{}
95159
type UTxOByAddressResult interface{}
96160
type UTxOWholeResult interface{}
97161
type DebugEpochStateResult interface{}
98162
type FilteredDelegationsAndRewardAccountsResult interface{}
99-
type GenesisConfigResult interface{}
163+
164+
type GenesisConfigResult struct {
165+
// Tells the CBOR decoder to convert to/from a struct and a CBOR array
166+
_ struct{} `cbor:",toarray"`
167+
Start SystemStartResult
168+
NetworkMagic int
169+
NetworkId uint8
170+
ActiveSlotsCoeff []interface{}
171+
SecurityParam int
172+
EpochLength int
173+
SlotsPerKESPeriod int
174+
MaxKESEvolutions int
175+
SlotLength int
176+
UpdateQuorum int
177+
MaxLovelaceSupply int64
178+
ProtocolParams struct {
179+
// Tells the CBOR decoder to convert to/from a struct and a CBOR array
180+
_ struct{} `cbor:",toarray"`
181+
MinFeeA int
182+
MinFeeB int
183+
MaxBlockBodySize int
184+
MaxTxSize int
185+
MaxBlockHeaderSize int
186+
KeyDeposit int
187+
PoolDeposit int
188+
EMax int
189+
NOpt int
190+
A0 []int
191+
Rho []int
192+
Tau []int
193+
DecentralizationParam []int
194+
ExtraEntropy interface{}
195+
ProtocolVersionMajor int
196+
ProtocolVersionMinor int
197+
MinUTxOValue int
198+
MinPoolCost int
199+
}
200+
// This value contains maps with bytestring keys, which we can't parse yet
201+
GenDelegs cbor.RawMessage
202+
Unknown1 interface{}
203+
Unknown2 interface{}
204+
}
205+
206+
// TODO
100207
type DebugNewEpochStateResult interface{}
101208
type DebugChainDepStateResult interface{}
102209
type RewardProvenanceResult interface{}

0 commit comments

Comments
 (0)