From 3ef96f1ca4902191ac6f9136c78e9fa33f3c4261 Mon Sep 17 00:00:00 2001 From: leovct Date: Fri, 16 Aug 2024 11:29:51 +0200 Subject: [PATCH 1/3] chore: use logger instead of `fmt.Print` --- cmd/ulxly/ulxly.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/cmd/ulxly/ulxly.go b/cmd/ulxly/ulxly.go index e91022af..9952c666 100644 --- a/cmd/ulxly/ulxly.go +++ b/cmd/ulxly/ulxly.go @@ -273,7 +273,7 @@ var depositNewCmd = &cobra.Command{ for { select { case <-txnMinedTimer.C: - fmt.Printf("Wait timer for transaction receipt exceeded!") + log.Info().Msg("Wait timer for transaction receipt exceeded!") return nil default: r, err := client.TransactionReceipt(ctx, bridgeTxn.Hash()) @@ -286,13 +286,11 @@ var depositNewCmd = &cobra.Command{ continue } if r.Status != 0 { - fmt.Printf("Deposit Transaction Successful: %s\n", r.TxHash) + log.Info().Interface("txHash", r.TxHash).Msg("Deposit transaction successful") return nil } else if r.Status == 0 { - fmt.Printf("Deposit Transaction Failed: %s\n", r.TxHash) - fmt.Printf("Perhaps try increasing the gas limit:\n") - fmt.Printf("Current gas limit: %d\n", gasLimit) - fmt.Printf("Cumulative gas used for transaction: %d\n", r.CumulativeGasUsed) + log.Error().Interface("txHash", r.TxHash).Msg("Deposit transaction failed") + log.Info().Uint64("currentGasLimit", gasLimit).Uint64("cumulativeGasUsedForTx", r.CumulativeGasUsed).Msg("Perhaps try increasing the gas limit") return nil } time.Sleep(1 * time.Second) @@ -371,7 +369,7 @@ var depositClaimCmd = &cobra.Command{ for { select { case <-txnMinedTimer.C: - fmt.Printf("Wait timer for transaction receipt exceeded!") + log.Info().Msg("Wait timer for transaction receipt exceeded!") return nil default: r, err := client.TransactionReceipt(ctx, claimTxn.Hash()) @@ -384,10 +382,10 @@ var depositClaimCmd = &cobra.Command{ continue } if r.Status != 0 { - fmt.Printf("Claim Transaction Successful: %s\n", r.TxHash) + log.Info().Interface("txHash", r.TxHash).Msg("Claim transaction successful") return nil } else if r.Status == 0 { - fmt.Printf("Claim Transaction Failed: %s\n", r.TxHash) + log.Info().Interface("txHash", r.TxHash).Msg("Claim transaction failed") return nil } time.Sleep(1 * time.Second) @@ -505,7 +503,6 @@ func readDeposits(rawDeposits []byte) error { } p := imt.GetProof(*ulxlyInputArgs.DepositNum) - fmt.Println(p.String()) return nil } @@ -833,7 +830,7 @@ func getDeposits(bridgeServiceDepositsEndpoint string) (globalIndex *big.Int, or log.Error().Msg("The claim transaction is not yet ready to be claimed. Try again in a few blocks.") return nil, common.HexToAddress("0x0"), nil, nil, errors.New("The claim transaction is not yet ready to be claimed. Try again in a few blocks.") } else if bridgeDeposit.Deposit[index].ClaimTxHash != "" { - fmt.Printf("The claim transaction has already been claimed at %s.", bridgeDeposit.Deposit[index].ClaimTxHash) + log.Info().Str("claimTxHash", bridgeDeposit.Deposit[index].ClaimTxHash).Msg("The claim transaction has already been claimed") return nil, common.HexToAddress("0x0"), nil, nil, errors.New("The claim transaction has already been claimed.") } originAddress = common.HexToAddress(bridgeDeposit.Deposit[index].OrigAddr) From 775ed74c601f6442d65d84f44bf9b0b850d7a74f Mon Sep 17 00:00:00 2001 From: leovct Date: Fri, 16 Aug 2024 11:30:07 +0200 Subject: [PATCH 2/3] fix: unused parameter --- cmd/ulxly/ulxly.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/ulxly/ulxly.go b/cmd/ulxly/ulxly.go index 9952c666..c0fdf31a 100644 --- a/cmd/ulxly/ulxly.go +++ b/cmd/ulxly/ulxly.go @@ -454,7 +454,7 @@ or if it's actually an intermediate hash.`, func checkProofArgs(cmd *cobra.Command, args []string) error { return nil } -func getInputData(cmd *cobra.Command, args []string) ([]byte, error) { +func getInputData(_ *cobra.Command, args []string) ([]byte, error) { if ulxlyInputArgs.InputFileName != nil && *ulxlyInputArgs.InputFileName != "" { return os.ReadFile(*ulxlyInputArgs.InputFileName) } From 78779d15668dcc4827fedab9c4d47322a5bf3be3 Mon Sep 17 00:00:00 2001 From: leovct Date: Fri, 16 Aug 2024 11:30:33 +0200 Subject: [PATCH 3/3] fix: error messages linter --- cmd/ulxly/ulxly.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/ulxly/ulxly.go b/cmd/ulxly/ulxly.go index c0fdf31a..40ed2c19 100644 --- a/cmd/ulxly/ulxly.go +++ b/cmd/ulxly/ulxly.go @@ -828,10 +828,10 @@ func getDeposits(bridgeServiceDepositsEndpoint string) (globalIndex *big.Int, or if intDepositCnt == intClaimIndex { // deposit_cnt must match the user's input value if !bridgeDeposit.Deposit[index].ReadyForClaim { log.Error().Msg("The claim transaction is not yet ready to be claimed. Try again in a few blocks.") - return nil, common.HexToAddress("0x0"), nil, nil, errors.New("The claim transaction is not yet ready to be claimed. Try again in a few blocks.") + return nil, common.HexToAddress("0x0"), nil, nil, errors.New("the claim transaction is not yet ready to be claimed, try again in a few blocks") } else if bridgeDeposit.Deposit[index].ClaimTxHash != "" { log.Info().Str("claimTxHash", bridgeDeposit.Deposit[index].ClaimTxHash).Msg("The claim transaction has already been claimed") - return nil, common.HexToAddress("0x0"), nil, nil, errors.New("The claim transaction has already been claimed.") + return nil, common.HexToAddress("0x0"), nil, nil, errors.New("the claim transaction has already been claimed") } originAddress = common.HexToAddress(bridgeDeposit.Deposit[index].OrigAddr) globalIndex.SetString(bridgeDeposit.Deposit[index].GlobalIndex, 10) @@ -842,7 +842,7 @@ func getDeposits(bridgeServiceDepositsEndpoint string) (globalIndex *big.Int, or } defer reqBridgeDeposits.Body.Close() - return nil, common.HexToAddress("0x0"), nil, nil, errors.New("Failed to correctly get deposits...") + return nil, common.HexToAddress("0x0"), nil, nil, errors.New("failed to correctly get deposits") } func checkGetDepositArgs(cmd *cobra.Command, args []string) error {