Skip to content

Commit 02217fa

Browse files
authored
Merge pull request #185 from cloudstruct/docs/ouroboros-package
docs: code docs for ouroboros package
2 parents 7b02ba1 + 06f8542 commit 02217fa

File tree

7 files changed

+172
-88
lines changed

7 files changed

+172
-88
lines changed

cmd/go-ouroboros-network/chainsync.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,16 @@ func testChainSync(f *globalFlags) {
129129
fmt.Printf("ERROR: %s\n", err)
130130
os.Exit(1)
131131
}
132-
o.ChainSync.Client.Start()
132+
o.ChainSync().Client.Start()
133133
if f.ntnProto {
134-
o.BlockFetch.Client.Start()
134+
o.BlockFetch().Client.Start()
135135
}
136136

137137
syncState.oConn = o
138138
syncState.nodeToNode = f.ntnProto
139139
var point common.Point
140140
if chainSyncFlags.tip {
141-
tip, err := o.ChainSync.Client.GetCurrentTip()
141+
tip, err := o.ChainSync().Client.GetCurrentTip()
142142
if err != nil {
143143
fmt.Printf("ERROR: failed to get current tip: %s\n", err)
144144
os.Exit(1)
@@ -153,7 +153,7 @@ func testChainSync(f *globalFlags) {
153153
} else {
154154
point = common.NewPointOrigin()
155155
}
156-
if err := o.ChainSync.Client.Sync([]common.Point{point}); err != nil {
156+
if err := o.ChainSync().Client.Sync([]common.Point{point}); err != nil {
157157
fmt.Printf("ERROR: failed to start chain-sync: %s\n", err)
158158
os.Exit(1)
159159
}
@@ -194,7 +194,7 @@ func chainSyncRollForwardHandler(blockType uint, blockData interface{}, tip chai
194194
blockSlot = h.Body.Slot
195195
blockHash, _ = hex.DecodeString(h.Id())
196196
}
197-
if err := syncState.oConn.BlockFetch.Client.RequestRange([]interface{}{blockSlot, blockHash}, []interface{}{blockSlot, blockHash}); err != nil {
197+
if err := syncState.oConn.BlockFetch().Client.RequestRange([]interface{}{blockSlot, blockHash}, []interface{}{blockSlot, blockHash}); err != nil {
198198
fmt.Printf("error calling RequestRange: %s\n", err)
199199
return err
200200
}

cmd/go-ouroboros-network/localtxsubmission.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func testLocalTxSubmission(f *globalFlags) {
6464
fmt.Printf("ERROR: %s\n", err)
6565
os.Exit(1)
6666
}
67-
o.LocalTxSubmission.Client.Start()
67+
o.LocalTxSubmission().Client.Start()
6868

6969
var txBytes []byte
7070
if localTxSubmissionFlags.txFile != "" {
@@ -94,7 +94,7 @@ func testLocalTxSubmission(f *globalFlags) {
9494
}
9595
}
9696

97-
if err = o.LocalTxSubmission.Client.SubmitTx(ledger.TX_TYPE_ALONZO, txBytes); err != nil {
97+
if err = o.LocalTxSubmission().Client.SubmitTx(ledger.TX_TYPE_ALONZO, txBytes); err != nil {
9898
fmt.Printf("Error submitting transaction: %s\n", err)
9999
os.Exit(1)
100100
}

cmd/go-ouroboros-network/mem_usage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ func testMemUsage(f *globalFlags) {
7171
fmt.Printf("ERROR: %s\n", err)
7272
os.Exit(1)
7373
}
74-
o.ChainSync.Client.Start()
74+
o.ChainSync().Client.Start()
7575

76-
tip, err := o.ChainSync.Client.GetCurrentTip()
76+
tip, err := o.ChainSync().Client.GetCurrentTip()
7777
if err != nil {
7878
fmt.Printf("ERROR: %s\n", err)
7979
os.Exit(1)

cmd/go-ouroboros-network/query.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,47 +56,47 @@ func testQuery(f *globalFlags) {
5656
fmt.Printf("ERROR: %s\n", err)
5757
os.Exit(1)
5858
}
59-
o.LocalStateQuery.Client.Start()
59+
o.LocalStateQuery().Client.Start()
6060

6161
switch queryFlags.flagset.Args()[0] {
6262
case "current-era":
63-
era, err := o.LocalStateQuery.Client.GetCurrentEra()
63+
era, err := o.LocalStateQuery().Client.GetCurrentEra()
6464
if err != nil {
6565
fmt.Printf("ERROR: failure querying current era: %s\n", err)
6666
os.Exit(1)
6767
}
6868
fmt.Printf("current-era: %d\n", era)
6969
case "tip":
70-
era, err := o.LocalStateQuery.Client.GetCurrentEra()
70+
era, err := o.LocalStateQuery().Client.GetCurrentEra()
7171
if err != nil {
7272
fmt.Printf("ERROR: failure querying current era: %s\n", err)
7373
os.Exit(1)
7474
}
75-
epochNo, err := o.LocalStateQuery.Client.GetEpochNo()
75+
epochNo, err := o.LocalStateQuery().Client.GetEpochNo()
7676
if err != nil {
7777
fmt.Printf("ERROR: failure querying current epoch: %s\n", err)
7878
os.Exit(1)
7979
}
80-
blockNo, err := o.LocalStateQuery.Client.GetChainBlockNo()
80+
blockNo, err := o.LocalStateQuery().Client.GetChainBlockNo()
8181
if err != nil {
8282
fmt.Printf("ERROR: failure querying current chain block number: %s\n", err)
8383
os.Exit(1)
8484
}
85-
point, err := o.LocalStateQuery.Client.GetChainPoint()
85+
point, err := o.LocalStateQuery().Client.GetChainPoint()
8686
if err != nil {
8787
fmt.Printf("ERROR: failure querying current chain point: %s\n", err)
8888
os.Exit(1)
8989
}
9090
fmt.Printf("tip: era = %d, epoch = %d, blockNo = %d, slot = %d, hash = %x\n", era, epochNo, blockNo, point.Slot, point.Hash)
9191
case "system-start":
92-
systemStart, err := o.LocalStateQuery.Client.GetSystemStart()
92+
systemStart, err := o.LocalStateQuery().Client.GetSystemStart()
9393
if err != nil {
9494
fmt.Printf("ERROR: failure querying system start: %s\n", err)
9595
os.Exit(1)
9696
}
9797
fmt.Printf("system-start: year = %d, day = %d, picoseconds = %d\n", systemStart.Year, systemStart.Day, systemStart.Picoseconds)
9898
case "era-history":
99-
eraHistory, err := o.LocalStateQuery.Client.GetEraHistory()
99+
eraHistory, err := o.LocalStateQuery().Client.GetEraHistory()
100100
if err != nil {
101101
fmt.Printf("ERROR: failure querying era history: %s\n", err)
102102
os.Exit(1)
@@ -106,21 +106,21 @@ func testQuery(f *globalFlags) {
106106
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)
107107
}
108108
case "protocol-params":
109-
protoParams, err := o.LocalStateQuery.Client.GetCurrentProtocolParams()
109+
protoParams, err := o.LocalStateQuery().Client.GetCurrentProtocolParams()
110110
if err != nil {
111111
fmt.Printf("ERROR: failure querying protocol params: %s\n", err)
112112
os.Exit(1)
113113
}
114114
fmt.Printf("protocol-params: %#v\n", *protoParams)
115115
case "stake-distribution":
116-
stakeDistribution, err := o.LocalStateQuery.Client.GetStakeDistribution()
116+
stakeDistribution, err := o.LocalStateQuery().Client.GetStakeDistribution()
117117
if err != nil {
118118
fmt.Printf("ERROR: failure querying stake distribution: %s\n", err)
119119
os.Exit(1)
120120
}
121121
fmt.Printf("stake-distribution: %#v\n", *stakeDistribution)
122122
case "genesis-config":
123-
genesisConfig, err := o.LocalStateQuery.Client.GetGenesisConfig()
123+
genesisConfig, err := o.LocalStateQuery().Client.GetGenesisConfig()
124124
if err != nil {
125125
fmt.Printf("ERROR: failure querying genesis config: %s\n", err)
126126
os.Exit(1)

options.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,86 +10,103 @@ import (
1010
"net"
1111
)
1212

13+
// OuroborosOptionFunc is a type that represents functions that modify the Ouroboros config
1314
type OuroborosOptionFunc func(*Ouroboros)
1415

16+
// WithConnection specifies an existing connection to use. If none is provided, the Dial() function can be
17+
// used to create one later
1518
func WithConnection(conn net.Conn) OuroborosOptionFunc {
1619
return func(o *Ouroboros) {
1720
o.conn = conn
1821
}
1922
}
2023

24+
// WithNetworkMagic specifies the network magic value
2125
func WithNetworkMagic(networkMagic uint32) OuroborosOptionFunc {
2226
return func(o *Ouroboros) {
2327
o.networkMagic = networkMagic
2428
}
2529
}
2630

31+
// WithErrorChan specifies the error channel to use. If none is provided, one will be created
2732
func WithErrorChan(errorChan chan error) OuroborosOptionFunc {
2833
return func(o *Ouroboros) {
29-
o.ErrorChan = errorChan
34+
o.errorChan = errorChan
3035
}
3136
}
3237

38+
// WithServer specifies whether to act as a server
3339
func WithServer(server bool) OuroborosOptionFunc {
3440
return func(o *Ouroboros) {
3541
o.server = server
3642
}
3743
}
3844

45+
// WithNodeToNode specifies whether to use the node-to-node protocol. The default is to use node-to-client
3946
func WithNodeToNode(nodeToNode bool) OuroborosOptionFunc {
4047
return func(o *Ouroboros) {
4148
o.useNodeToNodeProto = nodeToNode
4249
}
4350
}
4451

52+
// WithKeepAlives specifies whether to use keep-alives. This is disabled by default
4553
func WithKeepAlive(keepAlive bool) OuroborosOptionFunc {
4654
return func(o *Ouroboros) {
4755
o.sendKeepAlives = keepAlive
4856
}
4957
}
5058

59+
// WithDelayMuxerStart specifies whether to delay the muxer start. This is useful if you need to take some
60+
// custom actions before the muxer starts processing messages, generally when acting as a server
5161
func WithDelayMuxerStart(delayMuxerStart bool) OuroborosOptionFunc {
5262
return func(o *Ouroboros) {
5363
o.delayMuxerStart = delayMuxerStart
5464
}
5565
}
5666

67+
// WithFullDuplex specifies whether to enable full-duplex mode when acting as a client
5768
func WithFullDuplex(fullDuplex bool) OuroborosOptionFunc {
5869
return func(o *Ouroboros) {
5970
o.fullDuplex = fullDuplex
6071
}
6172
}
6273

74+
// WithBlockFetchConfig specifies BlockFetch protocol config
6375
func WithBlockFetchConfig(cfg blockfetch.Config) OuroborosOptionFunc {
6476
return func(o *Ouroboros) {
6577
o.blockFetchConfig = &cfg
6678
}
6779
}
6880

81+
// WithChainSyncConfig secifies ChainSync protocol config
6982
func WithChainSyncConfig(cfg chainsync.Config) OuroborosOptionFunc {
7083
return func(o *Ouroboros) {
7184
o.chainSyncConfig = &cfg
7285
}
7386
}
7487

88+
// WithKeepAliveConfig specifies KeepAlive protocol config
7589
func WithKeepAliveConfig(cfg keepalive.Config) OuroborosOptionFunc {
7690
return func(o *Ouroboros) {
7791
o.keepAliveConfig = &cfg
7892
}
7993
}
8094

95+
// WithLocalStateQueryConfig specifies LocalStateQuery protocol config
8196
func WithLocalStateQueryConfig(cfg localstatequery.Config) OuroborosOptionFunc {
8297
return func(o *Ouroboros) {
8398
o.localStateQueryConfig = &cfg
8499
}
85100
}
86101

102+
// WithLocalTxSubmissionConfig specifies LocalTxSubmission protocol config
87103
func WithLocalTxSubmissionConfig(cfg localtxsubmission.Config) OuroborosOptionFunc {
88104
return func(o *Ouroboros) {
89105
o.localTxSubmissionConfig = &cfg
90106
}
91107
}
92108

109+
// WithTxSubmissionConfig specifies TxSubmission protocol config
93110
func WithTxSubmissionConfig(cfg txsubmission.Config) OuroborosOptionFunc {
94111
return func(o *Ouroboros) {
95112
o.txSubmissionConfig = &cfg

0 commit comments

Comments
 (0)