Skip to content

Commit

Permalink
style: enabling nlreturn linter (#938)
Browse files Browse the repository at this point in the history
  • Loading branch information
izikdepth authored Jan 11, 2024
1 parent 3f36b3e commit f29d3f0
Show file tree
Hide file tree
Showing 161 changed files with 657 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ linters:
# - nestif
- nilerr
- nilnil
# - nlreturn
- nlreturn
- noctx
- nolintlint
- nosprintfhostport
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ Please read the [CONTRIBUTING](./CONTRIBUTING.md) guidelines before submitting a
## License

The Pactus blockchain is under MIT [license](./LICENSE).

5 changes: 5 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
// line editing features.
func terminalSupported() bool {
bad := map[string]bool{"": true, "dumb": true, "cons25": true}

return !bad[strings.ToLower(os.Getenv("TERM"))]
}

Expand All @@ -52,6 +53,7 @@ func PromptPassword(label string, confirmation bool) string {
if input != password {
return errors.New("passwords do not match")
}

return nil
}

Expand Down Expand Up @@ -89,6 +91,7 @@ func PromptConfirm(label string) bool {
if len(result) > 0 && strings.ToUpper(result[:1]) == "Y" {
return true
}

return false
}

Expand Down Expand Up @@ -219,6 +222,7 @@ func PactusDefaultHomeDir() string {
} else {
home = filepath.Join(usr.HomeDir, "pactus")
}

return home
}

Expand Down Expand Up @@ -458,6 +462,7 @@ func makeLocalGenesis(w wallet.Wallet) *genesis.Genesis {
params := param.DefaultParams()
params.BlockVersion = 0
gen := genesis.MakeGenesis(util.RoundNow(60), accs, vals, params)

return gen
}

Expand Down
1 change: 1 addition & 0 deletions cmd/daemon/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func buildInitCmd(parentCmd *cobra.Command) {
workingDir, _ := filepath.Abs(*workingDirOpt)
if !util.IsDirNotExistsOrEmpty(workingDir) {
cmd.PrintErrorMsgf("The working directory is not empty: %s", workingDir)

return
}
var mnemonic string
Expand Down
2 changes: 2 additions & 0 deletions cmd/daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func buildStartCmd(parentCmd *cobra.Command) {

if !locked {
cmd.PrintWarnMsgf("Could not lock '%s', another instance is running?", lockFilePath)

return
}

Expand All @@ -73,6 +74,7 @@ func buildStartCmd(parentCmd *cobra.Command) {
} else {
password = cmd.PromptPassword("Wallet password", false)
}

return password, true
}
node, _, err := cmd.StartNode(
Expand Down
1 change: 1 addition & 0 deletions cmd/gtk/dialog_address_change_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func changePassword(wlt *wallet.Wallet) {

if newPassword != repeatPassword {
showWarningDialog(dlg, "Passwords do not match")

return
}

Expand Down
1 change: 1 addition & 0 deletions cmd/gtk/dialog_addresss_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func showAddressDetails(wlt *wallet.Wallet, addr string) {
info := wlt.AddressInfo(addr)
if info == nil {
showErrorDialog(nil, "address not found")

return
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/gtk/dialog_transaction_bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ func broadcastTransactionBond(wlt *wallet.Wallet) {
amount, err := util.StringToChange(amountStr)
if err != nil {
errorCheck(err)

return
}

trx, err := wlt.MakeBondTx(sender, receiver, publicKey, amount)
if err != nil {
errorCheck(err)

return
}
msg := fmt.Sprintf(`
Expand Down
2 changes: 2 additions & 0 deletions cmd/gtk/dialog_transaction_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ func broadcastTransactionTransfer(wlt *wallet.Wallet) {
amount, err := util.StringToChange(amountStr)
if err != nil {
errorCheck(err)

return
}

trx, err := wlt.MakeTransferTx(sender, receiver, amount)
if err != nil {
errorCheck(err)

return
}
msg := fmt.Sprintf(`
Expand Down
1 change: 1 addition & 0 deletions cmd/gtk/dialog_transaction_unbond.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func broadcastTransactionUnbond(wlt *wallet.Wallet) {
trx, err := wlt.MakeUnbondTx(validator)
if err != nil {
errorCheck(err)

return
}
msg := fmt.Sprintf(`
Expand Down
2 changes: 2 additions & 0 deletions cmd/gtk/dialog_transaction_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ func broadcastTransactionWithdraw(wlt *wallet.Wallet) {
amount, err := util.StringToChange(amountStr)
if err != nil {
errorCheck(err)

return
}

trx, err := wlt.MakeWithdrawTx(sender, receiver, amount)
if err != nil {
errorCheck(err)

return
}
msg := fmt.Sprintf(`
Expand Down
7 changes: 7 additions & 0 deletions cmd/gtk/icons.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,42 @@ func pixbufToIcon16(pixbuf *gdk.Pixbuf) *gtk.Image {

func AddIcon() *gtk.Image {
pixbuf, _ := gdk.PixbufNewFromDataOnly(iconAdd)

return pixbufToIcon16(pixbuf)
}

func OkIcon() *gtk.Image {
pixbuf, _ := gdk.PixbufNewFromDataOnly(iconOK)

return pixbufToIcon16(pixbuf)
}

func CancelIcon() *gtk.Image {
pixbuf, _ := gdk.PixbufNewFromDataOnly(iconCancel)

return pixbufToIcon16(pixbuf)
}

func CloseIcon() *gtk.Image {
pixbuf, _ := gdk.PixbufNewFromDataOnly(iconClose)

return pixbufToIcon16(pixbuf)
}

func PasswordIcon() *gtk.Image {
pixbuf, _ := gdk.PixbufNewFromDataOnly(iconPassword)

return pixbufToIcon16(pixbuf)
}

func SeedIcon() *gtk.Image {
pixbuf, _ := gdk.PixbufNewFromDataOnly(iconSeed)

return pixbufToIcon16(pixbuf)
}

func SendIcon() *gtk.Image {
pixbuf, _ := gdk.PixbufNewFromDataOnly(iconSend)

return pixbufToIcon16(pixbuf)
}
3 changes: 3 additions & 0 deletions cmd/gtk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func main() {
workingDir, err := filepath.Abs(*workingDirOpt)
if err != nil {
cmd.PrintErrorMsgf("Aborted! %v", err)

return
}

Expand Down Expand Up @@ -110,13 +111,15 @@ func start(workingDir string, app *gtk.Application) {
// change working directory
if err := os.Chdir(workingDir); err != nil {
log.Println("Aborted! Unable to changes working directory. " + err.Error())

return
}

passwordFetcher := func(wlt *wallet.Wallet) (string, bool) {
if *passwordOpt != "" {
return *passwordOpt, true
}

return getWalletPassword(wlt)
}
node, wlt, err := cmd.StartNode(workingDir, passwordFetcher)
Expand Down
8 changes: 8 additions & 0 deletions cmd/gtk/startup_assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func startupAssistant(workingDir string, chain genesis.ChainType) bool {
assistant.ShowAll()

gtk.Main()

return successful
}

Expand Down Expand Up @@ -272,6 +273,7 @@ func pageMode(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget,
pageModeTitle,
pageModeSubject,
pageModeDesc)

return mode, restoreWalletRadio, pageModeName
}

Expand Down Expand Up @@ -303,6 +305,7 @@ This seed will allow you to recover your wallet in case of computer failure.
pageSeedTitle,
pageSeedSubject,
pageSeedDesc)

return pageWidget, textViewSeed, pageSeedName
}

Expand All @@ -329,6 +332,7 @@ func pageSeedRestore(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.W
pageSeedTitle,
pageSeedSubject,
pageSeedDesc)

return pageWidget, textViewRestoreSeed, pageSeedName
}

Expand Down Expand Up @@ -379,6 +383,7 @@ To make sure that you have properly saved your seed, please retype it here.`
pageSeedConfirmTitle,
pageSeedConfirmSubject,
pageSeedConfirmDesc)

return pageWidget, pageSeedConfirmName
}

Expand Down Expand Up @@ -447,6 +452,7 @@ func pagePassword(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widg
pagePasswordTitle,
pagePasswordSubject,
pagePsswrdDesc)

return pageWidget, entryPassword, pagePasswordName
}

Expand Down Expand Up @@ -501,6 +507,7 @@ For more information, look <a href="https://pactus.org/user-guides/run-pactus-gu
pageNumValidatorsTitle,
pageNumValidatorsSubject,
pageNumValidatorsDesc)

return pageWidget, lsNumValidators, comboNumValidators, pageNumValidatorsName
}

Expand Down Expand Up @@ -533,6 +540,7 @@ Now you are ready to start the node!`
pageFinalTitle,
pageFinalSubject,
pageFinalDesc)

return pageWidget, textViewNodeInfo, pageFinalName
}

Expand Down
8 changes: 8 additions & 0 deletions cmd/gtk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func showQuestionDialog(parent gtk.IWindow, msg string) bool {
gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, msg)
res := dlg.Run()
dlg.Destroy()

return res == gtk.RESPONSE_YES
}

Expand Down Expand Up @@ -65,6 +66,7 @@ func fatalErrorCheck(err error) {
func getObj(builder *gtk.Builder, name string) glib.IObject {
obj, err := builder.GetObject(name)
fatalErrorCheck(err)

return obj
}

Expand Down Expand Up @@ -136,6 +138,7 @@ func getTextViewContent(tv *gtk.TextView) string {
// TODO: Log error
return ""
}

return content
}

Expand Down Expand Up @@ -186,6 +189,7 @@ func updateFeeHint(lbl *gtk.Label, amtStr string, w *wallet.Wallet, payloadType
fee, err := w.CalculateFee(amount, payloadType)
if err != nil {
errorCheck(err)

return
}
hint := fmt.Sprintf("payable: %v, fee: %v",
Expand All @@ -208,17 +212,20 @@ func signAndBroadcastTransaction(parent *gtk.Dialog, msg string, w *wallet.Walle
err := w.SignTransaction(password, trx)
if err != nil {
errorCheck(err)

return
}
_, err = w.BroadcastTransaction(trx)
if err != nil {
errorCheck(err)

return
}

err = w.Save()
if err != nil {
errorCheck(err)

return
}
}
Expand Down Expand Up @@ -250,6 +257,7 @@ func openURLInBrowser(address string) error {
cmd = "xdg-open"
}
args = append(args, address)

return exec.Command(cmd, args...).Start()
}

Expand Down
1 change: 1 addition & 0 deletions cmd/gtk/widget_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func buildWidgetNode(model *nodeModel) (*widgetNode, error) {
// Update widget for the first time
w.timeout1()
w.timeout10()

return w, nil
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/gtk/widget_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func buildWidgetWallet(model *walletModel) (*widgetWallet, error) {
item.Show()
item.Connect("activate", func(item *gtk.MenuItem) bool {
w.onUpdateLabel()

return false
})
menu.Append(item)
Expand All @@ -108,6 +109,7 @@ func buildWidgetWallet(model *walletModel) (*widgetWallet, error) {
item.Show()
item.Connect("activate", func(item *gtk.MenuItem) bool {
w.onShowDetails()

return false
})
menu.Append(item)
Expand All @@ -120,6 +122,7 @@ func buildWidgetWallet(model *walletModel) (*widgetWallet, error) {
item.Show()
item.Connect("activate", func(item *gtk.MenuItem) bool {
w.onShowPrivateKey()

return false
})
menu.Append(item)
Expand Down Expand Up @@ -220,5 +223,6 @@ func (ww *widgetWallet) getSelectedAddress() string {
return addr
}
}

return ""
}
1 change: 1 addition & 0 deletions cmd/wallet/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func buildPublicKeyCmd(parentCmd *cobra.Command) {
info := wlt.AddressInfo(addr)
if info == nil {
cmd.PrintErrorMsgf("Address not found")

return
}

Expand Down
Loading

0 comments on commit f29d3f0

Please sign in to comment.