-
Notifications
You must be signed in to change notification settings - Fork 3
/
abi-form.go
168 lines (156 loc) · 3.91 KB
/
abi-form.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package cryptonym
import (
"encoding/json"
"fyne.io/fyne"
"fyne.io/fyne/layout"
"fyne.io/fyne/widget"
errs "github.com/blockpane/cryptonym/errLog"
"github.com/fioprotocol/fio-go"
"github.com/fioprotocol/fio-go/eos"
"gopkg.in/yaml.v3"
"math"
"regexp"
)
func GetAbiViewer(w int, h int, api *fio.API) (tab *widget.Box, ok bool) {
structs := widget.NewMultiLineEntry()
actions := widget.NewMultiLineEntry()
tables := widget.NewMultiLineEntry()
asJson := &widget.Check{}
scrollViews := &fyne.Container{}
layoutStructs := &widget.TabItem{}
layoutActions := &widget.TabItem{}
layoutTables := &widget.TabItem{}
r := regexp.MustCompile("(?m)^-")
getAbi := func(s string) {
if s == "" {
errs.ErrChan <- "queried for empty abi"
return
}
errs.ErrChan <- "getting abi for " + s
abiOut, err := api.GetABI(eos.AccountName(s))
if err != nil {
errs.ErrChan <- err.Error()
return
}
var yStruct []byte
if asJson.Checked {
yStruct, err = json.MarshalIndent(abiOut.ABI.Structs, "", " ")
} else {
yStruct, err = yaml.Marshal(abiOut.ABI.Structs)
}
if err != nil {
errs.ErrChan <- err.Error()
return
}
txt := r.ReplaceAllString(string(yStruct), "\n-")
func(s string) {
structs.SetText(s)
structs.OnChanged = func(string) {
structs.SetText(s)
}
}(txt) // deref
structs.SetText(txt)
var yActions []byte
if asJson.Checked {
yActions, err = json.MarshalIndent(abiOut.ABI.Actions, "", " ")
} else {
yActions, err = yaml.Marshal(abiOut.ABI.Actions)
}
if err != nil {
errs.ErrChan <- err.Error()
return
}
txt = r.ReplaceAllString(string(yActions), "\n-")
func(s string) {
actions.OnChanged = func(string) {
actions.SetText(s)
}
}(txt)
actions.SetText(txt)
var yTables []byte
if asJson.Checked {
yTables, err = json.MarshalIndent(abiOut.ABI.Tables, "", " ")
} else {
yTables, err = yaml.Marshal(abiOut.ABI.Tables)
}
if err != nil {
errs.ErrChan <- err.Error()
return
}
txt = r.ReplaceAllString(string(yTables), "\n-")
func(s string) {
tables.OnChanged = func(string) {
tables.SetText(s)
}
}(txt) // deref
tables.SetText(txt)
layoutActions.Content.Resize(actions.MinSize())
layoutStructs.Content.Resize(structs.MinSize())
layoutTables.Content.Resize(tables.MinSize())
layoutActions.Content.Refresh()
layoutStructs.Content.Refresh()
layoutTables.Content.Refresh()
scrollViews.Refresh()
tables.Refresh()
actions.Refresh()
structs.Refresh()
}
abis := &widget.Select{}
asJson = widget.NewCheck("Display Json", func(b bool) {
structs.SetText("")
actions.SetText("")
tables.SetText("")
getAbi(abis.Selected)
})
abis = widget.NewSelect(TableIndex.List(), func(s string) {
structs.SetText("")
actions.SetText("")
tables.SetText("")
getAbi(abis.Selected)
})
tabHeight := int(math.Round(float64(H) * .65))
layoutStructs = widget.NewTabItem("Structs",
fyne.NewContainerWithLayout(layout.NewFixedGridLayout(fyne.NewSize(RWidth(), tabHeight)),
fyne.NewContainerWithLayout(layout.NewMaxLayout(),
widget.NewScrollContainer(
structs,
),
),
),
)
layoutActions = widget.NewTabItem("Actions",
fyne.NewContainerWithLayout(layout.NewFixedGridLayout(fyne.NewSize(RWidth(), tabHeight)),
fyne.NewContainerWithLayout(layout.NewMaxLayout(),
widget.NewScrollContainer(
actions,
),
),
),
)
layoutTables = widget.NewTabItem("Tables",
fyne.NewContainerWithLayout(layout.NewFixedGridLayout(fyne.NewSize(RWidth(), tabHeight)),
fyne.NewContainerWithLayout(layout.NewMaxLayout(),
widget.NewScrollContainer(
tables,
),
),
),
)
scrollViews = fyne.NewContainer(
widget.NewTabContainer(
layoutStructs,
layoutActions,
layoutTables,
),
)
viewAbiLayout := widget.NewVBox(
fyne.NewContainerWithLayout(layout.NewFixedGridLayout(fyne.NewSize(200, 30)),
widget.NewHBox(
abis,
asJson,
),
),
scrollViews,
)
return viewAbiLayout, true
}