Skip to content

Commit a893768

Browse files
authored
chore: golines and rename file to snake case (#281)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 83b4a7a commit a893768

File tree

8 files changed

+116
-38
lines changed

8 files changed

+116
-38
lines changed

cmd/adder/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ func main() {
123123
nil,
124124
)
125125
if err != nil {
126-
logger.Error(fmt.Sprintf("failed to start debug listener: %s", err))
126+
logger.Error(
127+
fmt.Sprintf("failed to start debug listener: %s", err),
128+
)
127129
os.Exit(1)
128130
}
129131
}()

input/chainsync/chainsync.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,12 @@ func (c *ChainSync) handleBlockFetchBlock(
368368
uint32(t),
369369
c.networkMagic,
370370
),
371-
NewTransactionEvent(block, transaction, c.includeCbor, resolvedInputs),
371+
NewTransactionEvent(
372+
block,
373+
transaction,
374+
c.includeCbor,
375+
resolvedInputs,
376+
),
372377
)
373378
c.eventChan <- txEvt
374379
}
@@ -456,7 +461,10 @@ func getKupoClient(c *ChainSync) (*kugo.Client, error) {
456461
defer resp.Body.Close()
457462

458463
if resp.StatusCode != http.StatusOK {
459-
return nil, fmt.Errorf("health check failed with status code: %d", resp.StatusCode)
464+
return nil, fmt.Errorf(
465+
"health check failed with status code: %d",
466+
resp.StatusCode,
467+
)
460468
}
461469

462470
c.kupoClient = k
@@ -466,7 +474,10 @@ func getKupoClient(c *ChainSync) (*kugo.Client, error) {
466474

467475
// resolveTransactionInputs resolves the transaction inputs by using the
468476
// Kupo client and fetching the corresponding transaction outputs.
469-
func resolveTransactionInputs(transaction ledger.Transaction, c *ChainSync) ([]ledger.TransactionOutput, error) {
477+
func resolveTransactionInputs(
478+
transaction ledger.Transaction,
479+
c *ChainSync,
480+
) ([]ledger.TransactionOutput, error) {
470481
var resolvedInputs []ledger.TransactionOutput
471482

472483
// Use Kupo client to resolve inputs if available
@@ -484,11 +495,20 @@ func resolveTransactionInputs(transaction ledger.Transaction, c *ChainSync) ([]l
484495
kugo.TxOut(chainsync.NewTxID(txId, txIndex)),
485496
)
486497
if err != nil {
487-
return nil, fmt.Errorf("Error fetching matches for input TxId: %s, Index: %d. Error: %w\n", txId, txIndex, err)
498+
return nil, fmt.Errorf(
499+
"Error fetching matches for input TxId: %s, Index: %d. Error: %w\n",
500+
txId,
501+
txIndex,
502+
err,
503+
)
488504
}
489505

490506
if len(matches) == 0 {
491-
slog.Info("No matches found for input TxId: %s, Index: %d, could be due to Kupo not in sync\n", txId, txIndex)
507+
slog.Info(
508+
"No matches found for input TxId: %s, Index: %d, could be due to Kupo not in sync\n",
509+
txId,
510+
txIndex,
511+
)
492512
} else {
493513
slog.Debug(fmt.Sprintf("Found matches %d for input TxId: %s, Index: %d\n", len(matches), txId, txIndex))
494514
for _, match := range matches {

input/chainsync/transactionOutput.go renamed to input/chainsync/transaction_output.go

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ type ResolvedTransactionOutput struct {
3333
AssetsField *common.MultiAsset[uint64] `json:"assets,omitempty"`
3434
}
3535

36-
func ExtractAssetDetailsFromMatch(match kugo.Match) (common.MultiAsset[uint64], uint64, error) {
36+
func ExtractAssetDetailsFromMatch(
37+
match kugo.Match,
38+
) (common.MultiAsset[uint64], uint64, error) {
3739
// Initialize the map that will store the assets
3840
assetsMap := map[common.Blake2b224]map[cbor.ByteString]uint64{}
3941
totalLovelace := uint64(0)
@@ -43,7 +45,12 @@ func ExtractAssetDetailsFromMatch(match kugo.Match) (common.MultiAsset[uint64],
4345
// Decode policyId if not ADA
4446
policyIdBytes, err := hex.DecodeString(policyId)
4547
if err != nil {
46-
slog.Debug(fmt.Sprintf("PolicyId %s is not a valid hex string\n", policyId))
48+
slog.Debug(
49+
fmt.Sprintf(
50+
"PolicyId %s is not a valid hex string\n",
51+
policyId,
52+
),
53+
)
4754
policyIdBytes = []byte(policyId)
4855
}
4956
policyBlake := common.NewBlake2b224(policyIdBytes)
@@ -56,15 +63,24 @@ func ExtractAssetDetailsFromMatch(match kugo.Match) (common.MultiAsset[uint64],
5663
// Check if this is the ADA (lovelace) asset
5764
if policyId == "ada" && assetName == "lovelace" {
5865
totalLovelace = amount.Uint64()
59-
slog.Debug(fmt.Sprintf("Found ADA (lovelace): %d\n", totalLovelace))
66+
slog.Debug(
67+
fmt.Sprintf("Found ADA (lovelace): %d\n", totalLovelace),
68+
)
6069
continue // Skip adding "lovelace" to assetsMap, as it is handled separately
6170
}
6271

6372
byteStringAssetName := cbor.NewByteString([]byte(assetName))
6473
assetAmount := amount.Uint64()
6574
policyAssets[byteStringAssetName] = assetAmount
6675
slog.Debug("Get policyId, assetName, assetAmount from match.Value")
67-
slog.Debug(fmt.Sprintf("policyId: %s, assetName: %s, amount: %d\n", policyId, assetName, assetAmount))
76+
slog.Debug(
77+
fmt.Sprintf(
78+
"policyId: %s, assetName: %s, amount: %d\n",
79+
policyId,
80+
assetName,
81+
assetAmount,
82+
),
83+
)
6884
}
6985

7086
// Only add non-empty policyAssets to the assetsMap
@@ -77,7 +93,9 @@ func ExtractAssetDetailsFromMatch(match kugo.Match) (common.MultiAsset[uint64],
7793
return assets, totalLovelace, nil
7894
}
7995

80-
func NewResolvedTransactionOutput(match kugo.Match) (ledger.TransactionOutput, error) {
96+
func NewResolvedTransactionOutput(
97+
match kugo.Match,
98+
) (ledger.TransactionOutput, error) {
8199
// Get common.Address from base58 or bech32 string
82100
addr, err := common.NewAddress(match.Address)
83101
if err != nil {
@@ -86,10 +104,20 @@ func NewResolvedTransactionOutput(match kugo.Match) (ledger.TransactionOutput, e
86104

87105
assets, amount, err := ExtractAssetDetailsFromMatch(match)
88106
if err != nil {
89-
return nil, fmt.Errorf("failed to extract asset details from match: %w", err)
107+
return nil, fmt.Errorf(
108+
"failed to extract asset details from match: %w",
109+
err,
110+
)
90111
}
91112

92-
slog.Debug(fmt.Sprintf("ResolvedTransactionOutput: address: %s, amount: %d, assets: %#v\n", addr, amount, assets))
113+
slog.Debug(
114+
fmt.Sprintf(
115+
"ResolvedTransactionOutput: address: %s, amount: %d, assets: %#v\n",
116+
addr,
117+
amount,
118+
assets,
119+
),
120+
)
93121
return &ResolvedTransactionOutput{
94122
AddressField: addr,
95123
AmountField: amount,

input/chainsync/transactionOutput_test.go renamed to input/chainsync/transaction_output_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ import (
2525

2626
func TestResolvedTransactionOutput_MarshalJSON(t *testing.T) {
2727
// Create the address, handle the error properly
28-
addr, err := common.NewAddress("addr_test1wq5yehcpw4e3r32rltrww40e6ezdckr9v9l0ehptsxeynlg630pts")
28+
addr, err := common.NewAddress(
29+
"addr_test1wq5yehcpw4e3r32rltrww40e6ezdckr9v9l0ehptsxeynlg630pts",
30+
)
2931
if err != nil {
3032
t.Fatalf("Failed to create address: %v", err)
3133
}
3234

3335
// Create assets for the resolved output
34-
assets := common.NewMultiAsset(map[common.Blake2b224]map[cbor.ByteString]uint64{
35-
common.NewBlake2b224([]byte("policy1")): {cbor.NewByteString([]byte("TokenA")): 100},
36-
})
36+
assets := common.NewMultiAsset(
37+
map[common.Blake2b224]map[cbor.ByteString]uint64{
38+
common.NewBlake2b224([]byte("policy1")): {
39+
cbor.NewByteString([]byte("TokenA")): 100,
40+
},
41+
},
42+
)
3743

3844
// Create the resolved transaction output
3945
resolvedOutput := ResolvedTransactionOutput{

internal/logging/logging.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ func Configure() {
4545
if a.Key == slog.TimeKey {
4646
// Format the time attribute to use RFC3339 or your custom format
4747
// Rename the time key to timestamp
48-
return slog.String("timestamp", a.Value.Time().Format(time.RFC3339))
48+
return slog.String(
49+
"timestamp",
50+
a.Value.Time().Format(time.RFC3339),
51+
)
4952
}
5053
return a
5154
},

output/push/fcm_repository.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ func storeFCMToken(c *gin.Context) {
7878

7979
store := getTokenStore()
8080
if store == nil {
81-
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed getting token store"})
81+
c.JSON(
82+
http.StatusInternalServerError,
83+
gin.H{"error": "failed getting token store"},
84+
)
8285
return
8386
}
8487
store.FCMTokens[req.FCMToken] = req.FCMToken
@@ -97,7 +100,10 @@ func readFCMToken(c *gin.Context) {
97100
token := c.Param("token")
98101
store := getTokenStore()
99102
if store == nil {
100-
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed getting token store"})
103+
c.JSON(
104+
http.StatusInternalServerError,
105+
gin.H{"error": "failed getting token store"},
106+
)
101107
return
102108
}
103109
storedToken, exists := store.FCMTokens[token]
@@ -120,7 +126,10 @@ func deleteFCMToken(c *gin.Context) {
120126
token := c.Param("token")
121127
store := getTokenStore()
122128
if store == nil {
123-
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed getting token store"})
129+
c.JSON(
130+
http.StatusInternalServerError,
131+
gin.H{"error": "failed getting token store"},
132+
)
124133
return
125134
}
126135
_, exists := store.FCMTokens[token]

output/push/push.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ func New(options ...PushOptionFunc) *PushOutput {
6060
}
6161

6262
if err := p.GetProjectId(); err != nil {
63-
logging.GetLogger().Error(fmt.Sprintf("Failed to get project ID: %v", err))
63+
logging.GetLogger().
64+
Error(fmt.Sprintf("Failed to get project ID: %v", err))
6465
os.Exit(1)
6566
}
6667
return p
@@ -122,10 +123,12 @@ func (p *PushOutput) Start() error {
122123

123124
re := payload.(chainsync.RollbackEvent)
124125
logger.Debug("Adder")
125-
logger.Debug(fmt.Sprintf("Rollback!\nSlotNumber: %d\nBlockHash: %s",
126-
re.SlotNumber,
127-
re.BlockHash,
128-
))
126+
logger.Debug(
127+
fmt.Sprintf("Rollback!\nSlotNumber: %d\nBlockHash: %s",
128+
re.SlotNumber,
129+
re.BlockHash,
130+
),
131+
)
129132
case "chainsync.transaction":
130133
payload := evt.Payload
131134
if payload == nil {
@@ -217,24 +220,28 @@ func (p *PushOutput) processFcmNotifications(title, body string) {
217220
)
218221

219222
if err := fcm.Send(p.accessToken, p.projectID, msg); err != nil {
220-
logging.GetLogger().Error(fmt.Sprintf("Failed to send message to token %s: %v", fcmToken, err))
223+
logging.GetLogger().
224+
Error(fmt.Sprintf("Failed to send message to token %s: %v", fcmToken, err))
221225
continue
222226
}
223-
logging.GetLogger().Info(fmt.Sprintf("Message sent successfully to token %s!", fcmToken))
227+
logging.GetLogger().
228+
Info(fmt.Sprintf("Message sent successfully to token %s!", fcmToken))
224229
}
225230
}
226231

227232
func (p *PushOutput) GetAccessToken() error {
228233
data, err := os.ReadFile(p.serviceAccountFilePath)
229234
if err != nil {
230-
logging.GetLogger().Error(fmt.Sprintf("Failed to read the credential file: %v", err))
235+
logging.GetLogger().
236+
Error(fmt.Sprintf("Failed to read the credential file: %v", err))
231237
os.Exit(1)
232238
return err
233239
}
234240

235241
conf, err := google.JWTConfigFromJSON(data, p.accessTokenUrl)
236242
if err != nil {
237-
logging.GetLogger().Error(fmt.Sprintf("Failed to parse the credential file: %v", err))
243+
logging.GetLogger().
244+
Error(fmt.Sprintf("Failed to parse the credential file: %v", err))
238245
os.Exit(1)
239246
return err
240247
}
@@ -264,7 +271,8 @@ func (p *PushOutput) GetProjectId() error {
264271
// Get project ID from file
265272
var v map[string]any
266273
if err := json.Unmarshal(data, &v); err != nil {
267-
logging.GetLogger().Error(fmt.Sprintf("Failed to parse the credential file: %v", err))
274+
logging.GetLogger().
275+
Error(fmt.Sprintf("Failed to parse the credential file: %v", err))
268276
os.Exit(1)
269277
return err
270278
}

output/webhook/webhook.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,15 @@ func (w *WebhookOutput) SendWebhook(e *event.Event) error {
287287
}
288288
defer resp.Body.Close()
289289

290-
logger.Info(fmt.Sprintf("sent: %s, payload: %s, body: %s, response: %s, status: %d",
291-
w.url,
292-
string(data),
293-
string(respBody),
294-
resp.Status,
295-
resp.StatusCode,
296-
))
290+
logger.Info(
291+
fmt.Sprintf("sent: %s, payload: %s, body: %s, response: %s, status: %d",
292+
w.url,
293+
string(data),
294+
string(respBody),
295+
resp.Status,
296+
resp.StatusCode,
297+
),
298+
)
297299
return nil
298300
}
299301

0 commit comments

Comments
 (0)