Skip to content

Commit 16c343c

Browse files
authored
Merge pull request #52 from KiraCore/feature/txExecuteScreen
Feature/tx execute screen
2 parents 9f8bb97 + 6b7c3fd commit 16c343c

File tree

9 files changed

+128
-31
lines changed

9 files changed

+128
-31
lines changed

gui/dialog_connect.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,19 @@ func (g *Gui) ShowConnect() {
234234
}
235235

236236
// / test ui block
237-
// testButton := widget.NewButton("connect to tested env", func() {
238-
// ipEntry.Text = "192.168.1.102"
239-
// userEntry.Text = "d"
240-
// passwordEntry.Text = "d"
241-
// passphraseCheck.SetChecked(false)
237+
testButton := widget.NewButton("connect to tested env", func() {
238+
ipEntry.Text = "192.168.1.101"
239+
userEntry.Text = "d"
240+
passwordEntry.Text = "d"
241+
passphraseCheck.SetChecked(false)
242242

243-
// submitFunc()
244-
// })
243+
submitFunc()
244+
})
245+
246+
if !g.DeveloperMode {
247+
testButton.Disable()
248+
testButton.Hide()
249+
}
245250

246251
///
247252

@@ -259,7 +264,7 @@ func (g *Gui) ShowConnect() {
259264
keyEntryBox,
260265
privKeyCheck,
261266
connectButton,
262-
// testButton,
267+
testButton,
263268
),
264269
nil, nil, nil,
265270
container.NewBorder(nil, nil, nil, nil, container.NewVScroll(errorLabel)),

gui/dialog_executeSekaid.go

+62-9
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,61 @@
11
package gui
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"log"
7+
"strings"
68

79
"fyne.io/fyne/v2"
810
"fyne.io/fyne/v2/container"
911
"fyne.io/fyne/v2/data/binding"
1012
"fyne.io/fyne/v2/widget"
1113
dialogWizard "github.com/KiraCore/kensho/gui/dialogs"
14+
"github.com/KiraCore/kensho/helper/httph"
15+
"github.com/KiraCore/kensho/types"
1216
)
1317

1418
func showSekaiExecuteDialog(g *Gui) {
1519
var wizard *dialogWizard.Wizard
1620

17-
cmdEntry := widget.NewEntry()
21+
sekaidCmdName := "/sekaid"
22+
cmdData := binding.NewString()
23+
cmdEntry := widget.NewEntryWithData(cmdData)
1824
cmdEntry.MultiLine = true
1925
cmdEntry.Wrapping = fyne.TextWrapWord
2026

2127
doneAction := binding.NewDataListener(func() {
2228
g.WaitDialog.ShowWaitDialog()
2329
log.Printf("Trying to execute: %v", cmdEntry.Text)
30+
cmd, _ := cmdData.Get()
31+
cmd = strings.ReplaceAll(cmd, "\n", " ")
32+
cmd = fmt.Sprintf("%v %v", sekaidCmdName, cmd)
2433

25-
// execute submit
34+
cmdArgs := strings.Split(cmd, " ")
35+
cmdArgs = RemoveEmptyAndWhitespaceStrings(cmdArgs)
36+
37+
cmdStruct := types.ExecSekaiCommands{Command: "sekaid", ExecArgs: types.ExecArgs{Exec: cmdArgs}}
38+
39+
payload, err := json.Marshal(cmdStruct)
40+
if err != nil {
41+
log.Printf("error when marshaling cmdStruct: %v", err.Error())
42+
g.WaitDialog.HideWaitDialog()
43+
g.showErrorDialog(err, binding.NewDataListener(func() {}))
44+
return
45+
}
46+
47+
o, err := httph.ExecHttpRequestBySSHTunnel(g.sshClient, types.SEKIN_EXECUTE_ENDPOINT, "POST", payload)
48+
if err != nil {
49+
log.Printf("error when executing cmdStruct: %v", err.Error())
50+
g.WaitDialog.HideWaitDialog()
51+
g.showErrorDialog(err, binding.NewDataListener(func() {}))
52+
return
53+
}
54+
55+
log.Printf("output of <%v>:\n%v", cmd, string(o))
2656
g.WaitDialog.HideWaitDialog()
27-
wizard.Hide()
57+
58+
showInfoDialog(g, "Out", string(o))
2859
})
2960

3061
submitButton := widget.NewButton("Submit", func() {
@@ -37,14 +68,36 @@ func showSekaiExecuteDialog(g *Gui) {
3768
wizard.Hide()
3869
})
3970
submitButton.Importance = widget.HighImportance
71+
72+
hintCmd := "'tx bank send <from_key_or_address> <to_address> 1000ukex --chain-id=chaosnet2 --home=/sekai --fees=100ukex \n--keyring-backend=test --yes --broadcast-mode=block --log_format=json --output=json' "
73+
hintText := &widget.TextSegment{Text: hintCmd, Style: widget.RichTextStyleBlockquote}
74+
welcomeText := &widget.TextSegment{Text: "Example:", Style: widget.RichTextStyle{TextStyle: fyne.TextStyle{Bold: true}}}
75+
76+
hintTextWidget := widget.NewRichText(welcomeText, hintText)
77+
// hintTextWidget.Wrapping = fyne.TextWrapWord // dont use word wrapping, richtext glitches with this one
78+
79+
entryItem := widget.NewFormItem(sekaidCmdName[1:]+":", container.NewVBox(cmdEntry))
80+
4081
content := container.NewBorder(
41-
widget.NewLabel("Enter sekai command below"),
82+
nil,
4283
container.NewVBox(submitButton, closeButton),
43-
nil, nil,
44-
cmdEntry,
84+
nil,
85+
nil,
86+
container.NewVBox(widget.NewForm(entryItem), hintTextWidget),
4587
)
46-
47-
wizard = dialogWizard.NewWizard("Sekai cmd executor", content)
88+
wizard = dialogWizard.NewWizard("Sekai executor", content)
4889
wizard.Show(g.Window)
49-
wizard.Resize(fyne.NewSize(900, 200))
90+
wizard.Resize(fyne.NewSize(800, 200))
91+
92+
}
93+
94+
func RemoveEmptyAndWhitespaceStrings(input []string) []string {
95+
var result []string
96+
for _, str := range input {
97+
trimmedStr := strings.TrimSpace(str)
98+
if trimmedStr != "" {
99+
result = append(result, trimmedStr)
100+
}
101+
}
102+
return result
50103
}

gui/dialogs.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
dialogWizard "github.com/KiraCore/kensho/gui/dialogs"
1717
"github.com/KiraCore/kensho/helper/gssh"
18+
"github.com/KiraCore/kensho/utils"
1819
"github.com/atotto/clipboard"
1920
)
2021

@@ -76,7 +77,8 @@ func showInfoDialog(g *Gui, infoTitle, infoString string) {
7677
closeButton := widget.NewButton("Close", func() { wizard.Hide() })
7778
infoLabel := widget.NewLabel(infoString)
7879
infoLabel.Wrapping = 2
79-
content := container.NewBorder(nil, closeButton, nil, nil,
80+
copyButton := widget.NewButton("Copy", func() { utils.CopyToClipboard(infoLabel.Text) })
81+
content := container.NewBorder(nil, container.NewVBox(copyButton, closeButton), nil, nil,
8082
container.NewHScroll(
8183
container.NewVScroll(
8284
infoLabel,

gui/gui.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ type Gui struct {
2929
NodeInfo nodeInfoScreen
3030
TxExec TxExecBinding
3131

32-
Version string
32+
DeveloperMode bool
33+
Version string
3334
}
3435

3536
type TxExecBinding struct {
@@ -42,6 +43,8 @@ type Host struct {
4243
}
4344

4445
func (g *Gui) MakeGui() fyne.CanvasObject {
46+
log.Printf("Developer mode: %v\n", g.DeveloperMode)
47+
4548
title := widget.NewLabel(appName)
4649
info := widget.NewLabel("Welcome to Kensho. Navigate trough panel on the left side")
4750
mainWindow := container.NewStack()

gui/screen_nodeInfo.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func makeNodeInfoTab(g *Gui) fyne.CanvasObject {
171171
widget.NewFormItem("Val.NodeID:", nodeIDLabel),
172172
widget.NewFormItem("Gen.SHA256:", genesisChecksumLabel),
173173
)
174-
execFunc := func(args types.ExecSekaiCmd) {
174+
execFunc := func(args types.ExecSekaiMaintenanceCommands) {
175175
g.TxExec.TxExecutionStatusBinding.Set(true)
176176

177177
request := types.RequestTXPayload{Command: "tx", Args: args}
@@ -195,7 +195,7 @@ func makeNodeInfoTab(g *Gui) fyne.CanvasObject {
195195
monikerEntryData := binding.NewString()
196196
claimDataListener := binding.NewDataListener(func() {
197197
moniker, _ := monikerEntryData.Get()
198-
execFunc(types.ExecSekaiCmd{TX: types.ClaimValidatorSeat, Moniker: moniker})
198+
execFunc(types.ExecSekaiMaintenanceCommands{TX: types.ClaimValidatorSeat, Moniker: moniker})
199199
})
200200

201201
claimValidatorSeatFunc := func() {
@@ -204,15 +204,15 @@ func makeNodeInfoTab(g *Gui) fyne.CanvasObject {
204204
}
205205
pauseValidatorFunc := func() {
206206
// pause
207-
execFunc(types.ExecSekaiCmd{TX: types.Pause})
207+
execFunc(types.ExecSekaiMaintenanceCommands{TX: types.Pause})
208208
}
209209
unpauseValidatorFunc := func() {
210210
// unpause tx
211-
execFunc(types.ExecSekaiCmd{TX: types.Unpause})
211+
execFunc(types.ExecSekaiMaintenanceCommands{TX: types.Unpause})
212212
}
213213
activateValidatorFunc := func() {
214214
// activate
215-
execFunc(types.ExecSekaiCmd{TX: types.Activate})
215+
execFunc(types.ExecSekaiMaintenanceCommands{TX: types.Activate})
216216
}
217217

218218
errBinding := binding.NewUntyped()
@@ -365,5 +365,8 @@ func makeNodeInfoTab(g *Gui) fyne.CanvasObject {
365365
validatorsTopPart := container.NewHBox(activeValidatorsBox, pausedValidatorsBox, inactiveValidatorsBox, jailedValidatorsBox, waitingValidatorsBox)
366366

367367
// return container.NewBorder(nil, refreshButton, nil, validatorsRightPart, mainInfo)
368-
return container.NewBorder(container.NewCenter(validatorsTopPart), validatorControlButton, nil, nil, mainInfo)
368+
executeSekaiCmdButton := widget.NewButton("Execute sekai command", func() {
369+
showSekaiExecuteDialog(g)
370+
})
371+
return container.NewBorder(container.NewCenter(validatorsTopPart), container.NewVBox(validatorControlButton, executeSekaiCmdButton), nil, nil, mainInfo)
369372
}

helper/httph/httph.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func ValidateIP(input string) bool {
147147
}
148148

149149
func ExecHttpRequestBySSHTunnel(sshClient *ssh.Client, address, method string, payload []byte) ([]byte, error) {
150-
log.Printf("requesting <%v>\nPayload: %+v", address, payload)
150+
log.Printf("requesting <%v>\nPayload: %+v", address, string(payload))
151151
dialer := func(network, addr string) (net.Conn, error) {
152152
conn, err := sshClient.Dial(network, addr)
153153
if err != nil {

main.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
package main
22

33
import (
4+
"flag"
5+
46
"fyne.io/fyne/v2"
57
"fyne.io/fyne/v2/app"
68
"github.com/KiraCore/kensho/gui"
79
)
810

911
func main() {
12+
devMode := flag.Bool("dev", false, "Enable developer mode")
13+
flag.Parse()
14+
1015
a := app.NewWithID("Kensho")
1116
w := a.NewWindow("Kensho")
1217
w.SetMaster()
1318
w.Resize(fyne.NewSize(1024, 768))
1419
g := gui.Gui{
15-
Window: w,
16-
Version: a.Metadata().Version,
20+
DeveloperMode: *devMode,
21+
Window: w,
22+
Version: a.Metadata().Version,
1723
}
1824
g.WaitDialog = gui.NewWaitDialog(&g)
1925
content := g.MakeGui()

types/types.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,19 @@ const (
3737
)
3838

3939
type RequestTXPayload struct {
40-
Command string `json:"command"`
41-
Args ExecSekaiCmd `json:"args"`
40+
Command string `json:"command"`
41+
Args ExecSekaiMaintenanceCommands `json:"args"`
4242
}
43-
type ExecSekaiCmd struct {
43+
type ExecSekaiMaintenanceCommands struct {
4444
TX Cmd `json:"tx"` //pause, unpause, activate,
4545
Moniker string `json:"moniker"`
4646
}
47+
48+
type ExecSekaiCommands struct {
49+
Command string `json:"command"`
50+
ExecArgs ExecArgs `json:"args"`
51+
}
52+
53+
type ExecArgs struct {
54+
Exec []string `json:"exec"`
55+
}

utils/utils.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package utils
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/atotto/clipboard"
7+
)
8+
9+
func CopyToClipboard(text string) error {
10+
// Copy the provided text to the clipboard
11+
err := clipboard.WriteAll(text)
12+
if err != nil {
13+
return fmt.Errorf("failed to copy text to clipboard: %w", err)
14+
}
15+
return nil
16+
}

0 commit comments

Comments
 (0)