Skip to content

Commit e9f8d50

Browse files
committed
chore: use lcommon and pcommon aliases consistently
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent f9101a6 commit e9f8d50

File tree

19 files changed

+116
-101
lines changed

19 files changed

+116
-101
lines changed

cmd/gouroboros/chainsync.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ import (
2323

2424
ouroboros "github.com/blinklabs-io/gouroboros"
2525
"github.com/blinklabs-io/gouroboros/ledger"
26+
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
2627
"github.com/blinklabs-io/gouroboros/protocol/blockfetch"
2728
"github.com/blinklabs-io/gouroboros/protocol/chainsync"
28-
"github.com/blinklabs-io/gouroboros/protocol/common"
29+
pcommon "github.com/blinklabs-io/gouroboros/protocol/common"
2930
)
3031

3132
var oConn *ouroboros.Connection
@@ -191,7 +192,7 @@ func testChainSync(f *globalFlags) {
191192
}
192193
oConn = o
193194

194-
var point common.Point
195+
var point pcommon.Point
195196
if chainSyncFlags.tip {
196197
tip, err := oConn.ChainSync().Client.GetCurrentTip()
197198
if err != nil {
@@ -204,13 +205,13 @@ func testChainSync(f *globalFlags) {
204205
slot := uint64(intersectPoint[0].(int)) // #nosec G115
205206
// Block hash
206207
hash, _ := hex.DecodeString(intersectPoint[1].(string))
207-
point = common.NewPoint(slot, hash)
208+
point = pcommon.NewPoint(slot, hash)
208209
} else {
209-
point = common.NewPointOrigin()
210+
point = pcommon.NewPointOrigin()
210211
}
211212
if chainSyncFlags.blockRange {
212213
start, end, err := oConn.ChainSync().Client.GetAvailableBlockRange(
213-
[]common.Point{point},
214+
[]pcommon.Point{point},
214215
)
215216
if err != nil {
216217
fmt.Printf("ERROR: failed to get available block range: %s\n", err)
@@ -220,12 +221,12 @@ func testChainSync(f *globalFlags) {
220221
fmt.Printf("End (tip): slot %d, hash %x\n", end.Slot, end.Hash)
221222
return
222223
} else if !f.ntnProto || !chainSyncFlags.bulk {
223-
if err := oConn.ChainSync().Client.Sync([]common.Point{point}); err != nil {
224+
if err := oConn.ChainSync().Client.Sync([]pcommon.Point{point}); err != nil {
224225
fmt.Printf("ERROR: failed to start chain-sync: %s\n", err)
225226
os.Exit(1)
226227
}
227228
} else {
228-
start, end, err := oConn.ChainSync().Client.GetAvailableBlockRange([]common.Point{point})
229+
start, end, err := oConn.ChainSync().Client.GetAvailableBlockRange([]pcommon.Point{point})
229230
if err != nil {
230231
fmt.Printf("ERROR: failed to get available block range: %s\n", err)
231232
os.Exit(1)
@@ -246,7 +247,7 @@ func testChainSync(f *globalFlags) {
246247

247248
func chainSyncRollBackwardHandler(
248249
ctx chainsync.CallbackContext,
249-
point common.Point,
250+
point pcommon.Point,
250251
tip chainsync.Tip,
251252
) error {
252253
fmt.Printf("roll backward: point = %#v, tip = %#v\n", point, tip)
@@ -259,18 +260,18 @@ func chainSyncRollForwardHandler(
259260
blockData any,
260261
tip chainsync.Tip,
261262
) error {
262-
var block ledger.Block
263+
var block lcommon.Block
263264
switch v := blockData.(type) {
264-
case ledger.Block:
265+
case lcommon.Block:
265266
block = v
266-
case ledger.BlockHeader:
267+
case lcommon.BlockHeader:
267268
blockSlot := v.SlotNumber()
268269
blockHash := v.Hash().Bytes()
269270
var err error
270271
if oConn == nil {
271272
return errors.New("empty ouroboros connection, aborting")
272273
}
273-
block, err = oConn.BlockFetch().Client.GetBlock(common.NewPoint(blockSlot, blockHash))
274+
block, err = oConn.BlockFetch().Client.GetBlock(pcommon.NewPoint(blockSlot, blockHash))
274275
if err != nil {
275276
return err
276277
}
@@ -313,14 +314,14 @@ func chainSyncRollForwardHandler(
313314
func blockFetchBlockHandler(
314315
ctx blockfetch.CallbackContext,
315316
blockType uint,
316-
blockData ledger.Block,
317+
blockData lcommon.Block,
317318
) error {
318319
switch block := blockData.(type) {
319320
case *ledger.ByronEpochBoundaryBlock:
320321
fmt.Printf("era = Byron (EBB), epoch = %d, slot = %d, block_no = %d, id = %s\n", block.BlockHeader.ConsensusData.Epoch, block.SlotNumber(), block.BlockNumber(), block.Hash())
321322
case *ledger.ByronMainBlock:
322323
fmt.Printf("era = Byron, epoch = %d, slot = %d, block_no = %d, id = %s\n", block.BlockHeader.ConsensusData.SlotId.Epoch, block.SlotNumber(), block.BlockNumber(), block.Hash())
323-
case ledger.Block:
324+
case lcommon.Block:
324325
fmt.Printf("era = %s, slot = %d, block_no = %d, id = %s\n", block.Era().Name, block.SlotNumber(), block.BlockNumber(), block.Hash())
325326
}
326327
return nil

cmd/gouroboros/query.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
ouroboros "github.com/blinklabs-io/gouroboros"
2727
"github.com/blinklabs-io/gouroboros/ledger"
28+
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
2829
"github.com/blinklabs-io/gouroboros/protocol/localstatequery"
2930
)
3031

@@ -180,13 +181,13 @@ func testQuery(f *globalFlags) {
180181
}
181182
fmt.Printf("genesis-config: %#v\n", *genesisConfig)
182183
case "pool-params":
183-
var tmpPools []ledger.PoolId
184+
var tmpPools []lcommon.PoolId
184185
if len(queryFlags.flagset.Args()) <= 1 {
185186
fmt.Println("No pools specified")
186187
os.Exit(1)
187188
}
188189
for _, pool := range queryFlags.flagset.Args()[1:] {
189-
tmpPoolId, err := ledger.NewPoolIdFromBech32(pool)
190+
tmpPoolId, err := lcommon.NewPoolIdFromBech32(pool)
190191
if err != nil {
191192
fmt.Printf("Invalid bech32 pool ID %q: %s", pool, err)
192193
os.Exit(1)
@@ -202,13 +203,13 @@ func testQuery(f *globalFlags) {
202203
}
203204
fmt.Printf("pool-params: %#v\n", *poolParams)
204205
case "utxos-by-address":
205-
var tmpAddrs []ledger.Address
206+
var tmpAddrs []lcommon.Address
206207
if len(queryFlags.flagset.Args()) <= 1 {
207208
fmt.Println("No addresses specified")
208209
os.Exit(1)
209210
}
210211
for _, addr := range queryFlags.flagset.Args()[1:] {
211-
tmpAddr, err := ledger.NewAddress(addr)
212+
tmpAddr, err := lcommon.NewAddress(addr)
212213
if err != nil {
213214
fmt.Printf("Invalid address %q: %s", addr, err)
214215
os.Exit(1)
@@ -234,7 +235,7 @@ func testQuery(f *globalFlags) {
234235
}
235236
}
236237
case "utxos-by-txin":
237-
var tmpTxIns []ledger.TransactionInput
238+
var tmpTxIns []lcommon.TransactionInput
238239
if len(queryFlags.flagset.Args()) <= 1 {
239240
fmt.Println("No UTxO IDs specified")
240241
os.Exit(1)

ledger/common/gov.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,21 @@ func encodeCip129Voter(
5555
copy(data[1:], hash)
5656
convData, err := bech32.ConvertBits(data, 8, 5, true)
5757
if err != nil {
58-
panic(fmt.Sprintf("unexpected error converting voter data to base32: %s", err))
58+
panic(
59+
fmt.Sprintf(
60+
"unexpected error converting voter data to base32: %s",
61+
err,
62+
),
63+
)
5964
}
6065
encoded, err := bech32.Encode(prefix, convData)
6166
if err != nil {
62-
panic(fmt.Sprintf("unexpected error encoding voter data as bech32: %s", err))
67+
panic(
68+
fmt.Sprintf(
69+
"unexpected error encoding voter data as bech32: %s",
70+
err,
71+
),
72+
)
6373
}
6474
return encoded
6575
}

protocol/blockfetch/blockfetch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/blinklabs-io/gouroboros/connection"
2525
"github.com/blinklabs-io/gouroboros/ledger"
2626
"github.com/blinklabs-io/gouroboros/protocol"
27-
"github.com/blinklabs-io/gouroboros/protocol/common"
27+
pcommon "github.com/blinklabs-io/gouroboros/protocol/common"
2828
)
2929

3030
// ProtocolName is the name of the Block Fetch protocol.
@@ -151,7 +151,7 @@ type BlockRawFunc func(CallbackContext, uint, []byte) error
151151
type BatchDoneFunc func(CallbackContext) error
152152

153153
// RequestRangeFunc is a callback for handling block range requests.
154-
type RequestRangeFunc func(CallbackContext, common.Point, common.Point) error
154+
type RequestRangeFunc func(CallbackContext, pcommon.Point, pcommon.Point) error
155155

156156
// New creates a new BlockFetch instance with the given protocol options and configuration.
157157
func New(protoOptions protocol.ProtocolOptions, cfg *Config) *BlockFetch {

protocol/blockfetch/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/blinklabs-io/gouroboros/ledger"
2424
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
2525
"github.com/blinklabs-io/gouroboros/protocol"
26-
"github.com/blinklabs-io/gouroboros/protocol/common"
26+
pcommon "github.com/blinklabs-io/gouroboros/protocol/common"
2727
)
2828

2929
// Client implements the Block Fetch protocol client, which requests blocks from a server.
@@ -122,7 +122,7 @@ func (c *Client) Stop() error {
122122

123123
// GetBlockRange starts an async process to fetch all blocks in the specified range (inclusive).
124124
// The provided callbacks are used for each block and when the batch is done.
125-
func (c *Client) GetBlockRange(start common.Point, end common.Point) error {
125+
func (c *Client) GetBlockRange(start pcommon.Point, end pcommon.Point) error {
126126
c.Protocol.Logger().
127127
Debug(
128128
fmt.Sprintf("calling GetBlockRange(start: {Slot: %d, Hash: %x}, end: {Slot: %d, Hash: %x})",
@@ -158,7 +158,7 @@ func (c *Client) GetBlockRange(start common.Point, end common.Point) error {
158158

159159
// GetBlock requests and returns a single block specified by the provided point.
160160
// This is a synchronous call that returns the block or an error.
161-
func (c *Client) GetBlock(point common.Point) (ledger.Block, error) {
161+
func (c *Client) GetBlock(point pcommon.Point) (ledger.Block, error) {
162162
c.Protocol.Logger().
163163
Debug(
164164
fmt.Sprintf("calling GetBlock(point: {Slot: %d, Hash: %x})", point.Slot, point.Hash),

protocol/blockfetch/client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/blinklabs-io/gouroboros/ledger"
2626
"github.com/blinklabs-io/gouroboros/protocol"
2727
"github.com/blinklabs-io/gouroboros/protocol/blockfetch"
28-
ocommon "github.com/blinklabs-io/gouroboros/protocol/common"
28+
pcommon "github.com/blinklabs-io/gouroboros/protocol/common"
2929
ouroboros_mock "github.com/blinklabs-io/ouroboros-mock"
3030
"go.uber.org/goleak"
3131
)
@@ -151,7 +151,7 @@ func TestGetBlock(t *testing.T) {
151151
conversation,
152152
func(t *testing.T, oConn *ouroboros.Connection) {
153153
blk, err := oConn.BlockFetch().Client.GetBlock(
154-
ocommon.NewPoint(
154+
pcommon.NewPoint(
155155
testBlockSlot,
156156
testBlockHash,
157157
),
@@ -197,7 +197,7 @@ func TestGetBlockNoBlocks(t *testing.T) {
197197
conversation,
198198
func(t *testing.T, oConn *ouroboros.Connection) {
199199
_, err := oConn.BlockFetch().Client.GetBlock(
200-
ocommon.NewPoint(
200+
pcommon.NewPoint(
201201
12345,
202202
test.DecodeHexString("abcdef0123456789"),
203203
),

protocol/blockfetch/messages.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
"github.com/blinklabs-io/gouroboros/cbor"
2121
"github.com/blinklabs-io/gouroboros/protocol"
22-
"github.com/blinklabs-io/gouroboros/protocol/common"
22+
pcommon "github.com/blinklabs-io/gouroboros/protocol/common"
2323
)
2424

2525
// MessageTypeRequestRange is the message type for requesting a range of blocks.
@@ -70,12 +70,15 @@ func NewMsgFromCbor(msgType uint, data []byte) (protocol.Message, error) {
7070
// MsgRequestRange represents a request for a range of blocks.
7171
type MsgRequestRange struct {
7272
protocol.MessageBase
73-
Start common.Point // Start point of the range
74-
End common.Point // End point of the range
73+
Start pcommon.Point // Start point of the range
74+
End pcommon.Point // End point of the range
7575
}
7676

7777
// NewMsgRequestRange creates a new MsgRequestRange with the given start and end points.
78-
func NewMsgRequestRange(start common.Point, end common.Point) *MsgRequestRange {
78+
func NewMsgRequestRange(
79+
start pcommon.Point,
80+
end pcommon.Point,
81+
) *MsgRequestRange {
7982
m := &MsgRequestRange{
8083
MessageBase: protocol.MessageBase{
8184
MessageType: MessageTypeRequestRange,

protocol/chainsync/chainsync.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
"github.com/blinklabs-io/gouroboros/connection"
2424
"github.com/blinklabs-io/gouroboros/protocol"
25-
"github.com/blinklabs-io/gouroboros/protocol/common"
25+
pcommon "github.com/blinklabs-io/gouroboros/protocol/common"
2626
)
2727

2828
// Protocol identifiers
@@ -246,13 +246,13 @@ type CallbackContext struct {
246246

247247
// Callback function types
248248
type (
249-
RollBackwardFunc func(CallbackContext, common.Point, Tip) error
249+
RollBackwardFunc func(CallbackContext, pcommon.Point, Tip) error
250250
RollForwardFunc func(CallbackContext, uint, any, Tip) error
251251
RollForwardRawFunc func(CallbackContext, uint, []byte, Tip) error
252252
)
253253

254254
type (
255-
FindIntersectFunc func(CallbackContext, []common.Point) (common.Point, Tip, error)
255+
FindIntersectFunc func(CallbackContext, []pcommon.Point) (pcommon.Point, Tip, error)
256256
RequestNextFunc func(CallbackContext) error
257257
)
258258

0 commit comments

Comments
 (0)