Skip to content

Commit

Permalink
chore: make format golines (#637)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
  • Loading branch information
wolf31o2 authored May 17, 2024
1 parent e7f2e2e commit c635297
Show file tree
Hide file tree
Showing 44 changed files with 661 additions and 183 deletions.
5 changes: 4 additions & 1 deletion cbor/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ var customTagSet _cbor.TagSet
func init() {
// Build custom tagset
customTagSet = _cbor.NewTagSet()
tagOpts := _cbor.TagOptions{EncTag: _cbor.EncTagRequired, DecTag: _cbor.DecTagRequired}
tagOpts := _cbor.TagOptions{
EncTag: _cbor.EncTagRequired,
DecTag: _cbor.DecTagRequired,
}
// Wrapped CBOR
if err := customTagSet.Add(
tagOpts,
Expand Down
3 changes: 2 additions & 1 deletion cbor/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ func (c *Constructor) UnmarshalCBOR(data []byte) error {
if _, err := Decode(tmpTag.Content, &tmpValue); err != nil {
return err
}
if tmpTag.Number >= CborTagAlternative1Min && tmpTag.Number <= CborTagAlternative1Max {
if tmpTag.Number >= CborTagAlternative1Min &&
tmpTag.Number <= CborTagAlternative1Max {
// Alternatives 0-6
c.constructor = uint(tmpTag.Number - CborTagAlternative1Min)
c.value = &tmpValue
Expand Down
5 changes: 4 additions & 1 deletion cbor/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,10 @@ func TestConstructorDecode(t *testing.T) {
testDef.expectedObj.Constructor(),
)
}
if !reflect.DeepEqual(tmpConstr.Fields(), testDef.expectedObj.Fields()) {
if !reflect.DeepEqual(
tmpConstr.Fields(),
testDef.expectedObj.Fields(),
) {
t.Fatalf(
"did not decode to expected fields\n got: %#v\n wanted: %#v",
tmpConstr.Fields(),
Expand Down
11 changes: 9 additions & 2 deletions cmd/gouroboros/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ func testChainSync(f *globalFlags) {
select {}
}

func chainSyncRollBackwardHandler(ctx chainsync.CallbackContext, point common.Point, tip chainsync.Tip) error {
func chainSyncRollBackwardHandler(
ctx chainsync.CallbackContext,
point common.Point,
tip chainsync.Tip,
) error {
fmt.Printf("roll backward: point = %#v, tip = %#v\n", point, tip)
return nil
}
Expand Down Expand Up @@ -318,7 +322,10 @@ func chainSyncRollForwardHandler(
return nil
}

func blockFetchBlockHandler(ctx blockfetch.CallbackContext, blockData ledger.Block) error {
func blockFetchBlockHandler(
ctx blockfetch.CallbackContext,
blockData ledger.Block,
) error {
switch block := blockData.(type) {
case *ledger.ByronEpochBoundaryBlock:
fmt.Printf("era = Byron (EBB), epoch = %d, slot = %d, id = %s\n", block.Header.ConsensusData.Epoch, block.SlotNumber(), block.Hash())
Expand Down
4 changes: 3 additions & 1 deletion cmd/gouroboros/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ func testQuery(f *globalFlags) {
}
tmpPools = append(tmpPools, tmpPoolId)
}
poolParams, err := o.LocalStateQuery().Client.GetStakePoolParams(tmpPools)
poolParams, err := o.LocalStateQuery().Client.GetStakePoolParams(
tmpPools,
)
if err != nil {
fmt.Printf("ERROR: failure querying stake pool params: %s\n", err)
os.Exit(1)
Expand Down
5 changes: 4 additions & 1 deletion cmd/tx-submission/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ func main() {
// convert to tx
txType, err := ledger.DetermineTransactionType(txBytes)
if err != nil {
fmt.Printf("ERROR: could not parse transaction to determine type: %s", err)
fmt.Printf(
"ERROR: could not parse transaction to determine type: %s",
err,
)
os.Exit(1)
}
tx, err := ledger.NewTransactionFromCbor(txType, txBytes)
Expand Down
28 changes: 17 additions & 11 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ func (c *Connection) Dial(proto string, address string) error {
// passed to the [net.DialTimeout] func. The handshake will be started when a connection is established.
// An error will be returned if the connection fails, a connection was already established, or the
// handshake fails
func (c *Connection) DialTimeout(proto string, address string, timeout time.Duration) error {
func (c *Connection) DialTimeout(
proto string,
address string,
timeout time.Duration,
) error {
if c.conn != nil {
return fmt.Errorf("a connection was already established")
}
Expand Down Expand Up @@ -310,17 +314,19 @@ func (c *Connection) setupConnection() error {
var handshakeFullDuplex bool
handshakeConfig := handshake.NewConfig(
handshake.WithProtocolVersionMap(protoVersions),
handshake.WithFinishedFunc(func(ctx handshake.CallbackContext, version uint16, versionData protocol.VersionData) error {
c.handshakeVersion = version
c.handshakeVersionData = versionData
if c.useNodeToNodeProto {
if versionData.DiffusionMode() == protocol.DiffusionModeInitiatorAndResponder {
handshakeFullDuplex = true
handshake.WithFinishedFunc(
func(ctx handshake.CallbackContext, version uint16, versionData protocol.VersionData) error {
c.handshakeVersion = version
c.handshakeVersionData = versionData
if c.useNodeToNodeProto {
if versionData.DiffusionMode() == protocol.DiffusionModeInitiatorAndResponder {
handshakeFullDuplex = true
}
}
}
close(c.handshakeFinishedChan)
return nil
}),
close(c.handshakeFinishedChan)
return nil
},
),
)
c.handshake = handshake.New(protoOptions, &handshakeConfig)
if c.server {
Expand Down
26 changes: 21 additions & 5 deletions connection_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ func NewConnectionManager(cfg ConnectionManagerConfig) *ConnectionManager {
}
}

func (c *ConnectionManager) AddHost(address string, port uint, tags ...ConnectionManagerTag) {
func (c *ConnectionManager) AddHost(
address string,
port uint,
tags ...ConnectionManagerTag,
) {
tmpTags := map[ConnectionManagerTag]bool{}
for _, tag := range tags {
tmpTags[tag] = true
Expand All @@ -99,12 +103,20 @@ func (c *ConnectionManager) AddHostsFromTopology(topology *TopologyConfig) {
}
for _, localRoot := range topology.LocalRoots {
for _, host := range localRoot.AccessPoints {
c.AddHost(host.Address, host.Port, ConnectionManagerTagHostLocalRoot)
c.AddHost(
host.Address,
host.Port,
ConnectionManagerTagHostLocalRoot,
)
}
}
for _, publicRoot := range topology.PublicRoots {
for _, host := range publicRoot.AccessPoints {
c.AddHost(host.Address, host.Port, ConnectionManagerTagHostPublicRoot)
c.AddHost(
host.Address,
host.Port,
ConnectionManagerTagHostPublicRoot,
)
}
}
}
Expand All @@ -129,13 +141,17 @@ func (c *ConnectionManager) RemoveConnection(connId ConnectionId) {
c.connectionsMutex.Unlock()
}

func (c *ConnectionManager) GetConnectionById(connId ConnectionId) *ConnectionManagerConnection {
func (c *ConnectionManager) GetConnectionById(
connId ConnectionId,
) *ConnectionManagerConnection {
c.connectionsMutex.Lock()
defer c.connectionsMutex.Unlock()
return c.connections[connId]
}

func (c *ConnectionManager) GetConnectionsByTags(tags ...ConnectionManagerTag) []*ConnectionManagerConnection {
func (c *ConnectionManager) GetConnectionsByTags(
tags ...ConnectionManagerTag,
) []*ConnectionManagerConnection {
var ret []*ConnectionManagerConnection
c.connectionsMutex.Lock()
for _, conn := range c.connections {
Expand Down
18 changes: 15 additions & 3 deletions connection_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,18 @@ func TestConnectionManagerConnError(t *testing.T) {
ConnClosedFunc: func(connId ouroboros.ConnectionId, err error) {
if err != nil {
if connId != expectedConnId {
t.Fatalf("did not receive error from expected connection: got %d, wanted %d", connId, expectedConnId)
t.Fatalf(
"did not receive error from expected connection: got %d, wanted %d",
connId,
expectedConnId,
)
}
if err != expectedErr {
t.Fatalf("did not receive expected error: got: %s, expected: %s", err, expectedErr)
t.Fatalf(
"did not receive expected error: got: %s, expected: %s",
err,
expectedErr,
)
}
close(doneChan)
}
Expand Down Expand Up @@ -121,7 +129,11 @@ func TestConnectionManagerConnClosed(t *testing.T) {
ouroboros.ConnectionManagerConfig{
ConnClosedFunc: func(connId ouroboros.ConnectionId, err error) {
if connId != expectedConnId {
t.Fatalf("did not receive closed signal from expected connection: got %d, wanted %d", connId, expectedConnId)
t.Fatalf(
"did not receive closed signal from expected connection: got %d, wanted %d",
connId,
expectedConnId,
)
}
if err != nil {
t.Fatalf("received unexpected error: %s", err)
Expand Down
9 changes: 7 additions & 2 deletions ledger/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,15 @@ func NewAlonzoTransactionFromCbor(data []byte) (*AlonzoTransaction, error) {
return &alonzoTx, nil
}

func NewAlonzoTransactionOutputFromCbor(data []byte) (*AlonzoTransactionOutput, error) {
func NewAlonzoTransactionOutputFromCbor(
data []byte,
) (*AlonzoTransactionOutput, error) {
var alonzoTxOutput AlonzoTransactionOutput
if _, err := cbor.Decode(data, &alonzoTxOutput); err != nil {
return nil, fmt.Errorf("Alonzo transaction output decode error: %s", err)
return nil, fmt.Errorf(
"Alonzo transaction output decode error: %s",
err,
)
}
return &alonzoTxOutput, nil
}
9 changes: 7 additions & 2 deletions ledger/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,15 @@ func NewBabbageTransactionFromCbor(data []byte) (*BabbageTransaction, error) {
return &babbageTx, nil
}

func NewBabbageTransactionOutputFromCbor(data []byte) (*BabbageTransactionOutput, error) {
func NewBabbageTransactionOutputFromCbor(
data []byte,
) (*BabbageTransactionOutput, error) {
var babbageTxOutput BabbageTransactionOutput
if _, err := cbor.Decode(data, &babbageTxOutput); err != nil {
return nil, fmt.Errorf("Babbage transaction output decode error: %s", err)
return nil, fmt.Errorf(
"Babbage transaction output decode error: %s",
err,
)
}
return &babbageTxOutput, nil
}
31 changes: 26 additions & 5 deletions ledger/babbage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ func TestBabbageBlockTransactions(t *testing.T) {

t.Run("empty", func(t *testing.T) {
if lenTxs := len(b.Transactions()); lenTxs != 0 {
t.Fatalf("expected number of transactions is 0 but it was %d", lenTxs)
t.Fatalf(
"expected number of transactions is 0 but it was %d",
lenTxs,
)
}
})

Expand All @@ -36,12 +39,21 @@ func TestBabbageBlockTransactions(t *testing.T) {
txs := b.Transactions()

if lenTxs := len(txs); lenTxs != txsCount {
t.Fatalf("expected number of transactions is %d but it was %d", txsCount, lenTxs)
t.Fatalf(
"expected number of transactions is %d but it was %d",
txsCount,
lenTxs,
)
}

for i, tx := range txs {
if btx := tx.(*BabbageTransaction); !btx.IsValid() {
t.Fatalf("expected transaction number %d IsValid is %v but is was %v", i, true, btx.IsValid())
t.Fatalf(
"expected transaction number %d IsValid is %v but is was %v",
i,
true,
btx.IsValid(),
)
}
}
})
Expand All @@ -51,13 +63,22 @@ func TestBabbageBlockTransactions(t *testing.T) {
txs := b.Transactions()

if lenTxs := len(txs); lenTxs != txsCount {
t.Fatalf("expected number of transactions is %d but it was %d", txsCount, lenTxs)
t.Fatalf(
"expected number of transactions is %d but it was %d",
txsCount,
lenTxs,
)
}

for i, tx := range txs {
expected := i != 2 && i != 4 && i != 5
if btx := tx.(*BabbageTransaction); btx.IsValid() != expected {
t.Fatalf("expected transaction number %d IsValid is %v but is was %v", i, expected, btx.IsValid())
t.Fatalf(
"expected transaction number %d IsValid is %v but is was %v",
i,
expected,
btx.IsValid(),
)
}
}
})
Expand Down
5 changes: 4 additions & 1 deletion ledger/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ func generateBlockHeaderHash(data []byte, prefix []byte) string {
tmpHash, err := blake2b.New256(nil)
if err != nil {
panic(
fmt.Sprintf("unexpected error generating empty blake2b hash: %s", err),
fmt.Sprintf(
"unexpected error generating empty blake2b hash: %s",
err,
),
)
}
if prefix != nil {
Expand Down
8 changes: 6 additions & 2 deletions ledger/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,9 @@ type MoveInstantaneousRewardsCertificateReward struct {
OtherPot uint64
}

func (r *MoveInstantaneousRewardsCertificateReward) UnmarshalCBOR(data []byte) error {
func (r *MoveInstantaneousRewardsCertificateReward) UnmarshalCBOR(
data []byte,
) error {
// Try to parse as map
tmpMapData := struct {
cbor.StructAsArray
Expand Down Expand Up @@ -424,7 +426,9 @@ type MoveInstantaneousRewardsCertificate struct {

func (c MoveInstantaneousRewardsCertificate) isCertificate() {}

func (c *MoveInstantaneousRewardsCertificate) UnmarshalCBOR(cborData []byte) error {
func (c *MoveInstantaneousRewardsCertificate) UnmarshalCBOR(
cborData []byte,
) error {
return c.UnmarshalCbor(cborData, c)
}

Expand Down
Loading

0 comments on commit c635297

Please sign in to comment.