-
Notifications
You must be signed in to change notification settings - Fork 3
/
tx-result.go
809 lines (775 loc) · 21.3 KB
/
tx-result.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
package cryptonym
import (
"bufio"
"bytes"
"compress/zlib"
"encoding/json"
"fmt"
"fyne.io/fyne"
"fyne.io/fyne/layout"
"fyne.io/fyne/theme"
"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"
"io/ioutil"
"log"
"math"
"regexp"
"runtime"
"sort"
"strconv"
"strings"
"sync"
"time"
)
var (
Results = make([]TxResult, 0)
requestText = widget.NewMultiLineEntry()
responseText = widget.NewMultiLineEntry()
stopRequested = make(chan bool)
)
type TxResult struct {
FullResp []byte
FullReq []byte
Resp []byte
Req []byte
Success bool
Index int
Summary string
}
type TxSummary struct {
TransactionId string `json:"transaction_id" yaml:"Transaction Id"`
Processed struct {
BlockNum uint32 `json:"block_num" yaml:"Block Number"`
BlockTime string `json:"block_time" yaml:"Block Time"`
Receipt struct {
Status string `json:"status" yaml:"Status"`
} `json:"receipt" yaml:"Receipt,omitempty"`
} `json:"processed" yaml:"Processed,omitempty"`
ErrorCode interface{} `json:"error_code" yaml:"Error,omitempty"` // is this a string, int, varies on context?
TotalBytes int `json:"total_bytes,omitempty" yaml:"TX Size of All Actions,omitempty"` // this is field we calculate later
}
// to get the *real* size of what was transacted, we need to dig into the action traces and look at the length
// of the hex_data field, which is buried in the response.
type txTraces struct {
Processed struct {
ActionTraces []struct {
Act struct {
HexData string `json:"hex_data"`
} `json:"act"`
} `json:"action_traces"`
} `json:"processed"`
}
func (tt txTraces) size() int {
if len(tt.Processed.ActionTraces) == 0 {
return 0
}
var sz int
for _, t := range tt.Processed.ActionTraces {
sz = sz + (len(t.Act.HexData) / 2)
}
return sz
}
type txResultOpts struct {
repeat int
loop bool
threads string
hideFail bool
hideSucc bool
window fyne.Window
gone bool
msig bool
msigSigners string
msigAccount string
msigName func() string
wrap bool
wrapActor string
}
func TxResultsWindow(win *txResultOpts, api *fio.API, opts *fio.TxOptions, account *fio.Account) {
ResetTxResult()
// this is a workaround for fyne sometimes showing blank black windows, resizing fixes
// but when it happens the window still doesn't work correctly. It will show up, but does not
// refresh. Beats a black window, and at least the close button works.
resizeTrigger := make(chan interface{})
go func() {
for {
select {
case <-resizeTrigger:
if win.window == nil || !win.window.Content().Visible() {
continue
}
win.window.Resize(fyne.NewSize(txW, txH))
time.Sleep(100 * time.Millisecond)
win.window.Resize(win.window.Content().MinSize())
}
}
}()
workers, e := strconv.Atoi(win.threads)
if e != nil {
workers = 1
}
var (
grid *fyne.Container
b *widget.Button
stopButton *widget.Button
closeRow *widget.Group
running bool
exit bool
fullResponseIndex int
)
successLabel := widget.NewLabel("")
failedLabel := widget.NewLabel("")
successChan := make(chan bool)
failedChan := make(chan bool)
go func(s chan bool, f chan bool) {
time.Sleep(100 * time.Millisecond)
BalanceChan <- true
tick := time.NewTicker(time.Second)
update := false
updateBalance := false
successCount := 0
failedCount := 0
for {
select {
case <-tick.C:
if updateBalance {
BalanceChan <- true
updateBalance = false
}
if update {
successLabel.SetText(p.Sprintf("%d", successCount))
failedLabel.SetText(p.Sprintf("%d", failedCount))
successLabel.Refresh()
failedLabel.Refresh()
update = false
}
case <-f:
update = true
failedCount = failedCount + 1
case <-s:
update = true
updateBalance = true
successCount = successCount + 1
}
}
}(successChan, failedChan)
run := func() {}
mux := sync.Mutex{}
Results = make([]TxResult, 0)
summaryGroup := widget.NewGroupWithScroller("Transaction Result")
showFullResponseButton := widget.NewButtonWithIcon("Show Response Details", theme.VisibilityIcon(), func() {
// avoid nil pointer
if len(Results) <= fullResponseIndex {
errs.ErrChan <- "could not show full response: invalid result index - this shouldn't happen!"
return
}
if len(Results[fullResponseIndex].FullResp) == 0 {
errs.ErrChan <- "could not show full response: empty string"
return
}
ShowFullResponse(Results[fullResponseIndex].FullResp, win.window)
})
showFullRequestButton := widget.NewButtonWithIcon("Show Request JSON", theme.VisibilityIcon(), func() {
// avoid nil pointer
if len(Results) <= fullResponseIndex {
errs.ErrChan <- "could not show full request: invalid result index - this shouldn't happen!"
return
}
if len(Results[fullResponseIndex].FullReq) == 0 {
errs.ErrChan <- "could not show full request: empty string"
return
}
ShowFullRequest(Results[fullResponseIndex].FullReq, win.window)
})
textUpdateDone := make(chan interface{})
textUpdateReq := make(chan string)
textUpdateResp := make(chan string)
go func() {
for {
select {
case <-textUpdateDone:
return
case s := <-textUpdateReq:
requestText.OnChanged = func(string) {
requestText.SetText(s)
}
requestText.SetText(s)
case s := <-textUpdateResp:
responseText.OnChanged = func(string) {
responseText.SetText(s)
}
responseText.SetText(s)
}
}
}()
setGrid := func() {
grid = fyne.NewContainerWithLayout(layout.NewHBoxLayout(),
fyne.NewContainerWithLayout(layout.NewGridLayoutWithRows(1),
closeRow,
fyne.NewContainerWithLayout(layout.NewMaxLayout(),
summaryGroup,
),
),
widget.NewVBox(
fyne.NewContainerWithLayout(layout.NewFixedGridLayout(fyne.NewSize(txW, 30)),
fyne.NewContainerWithLayout(layout.NewGridLayout(2), showFullResponseButton, showFullRequestButton),
),
widget.NewLabel("Request:"),
requestText,
widget.NewLabel("Response Summary:"),
responseText,
),
)
win.window.SetContent(grid)
win.window.Resize(win.window.Content().MinSize())
}
clear := func() {
Results = make([]TxResult, 0)
summaryGroup = widget.NewGroupWithScroller("Transaction Result")
summaryGroup.Refresh()
textUpdateResp <- ""
textUpdateReq <- ""
setGrid()
}
closeButton := widget.NewButtonWithIcon(
"close",
theme.DeleteIcon(),
func() {
go func() {
if running {
stopRequested <- true
}
win.gone = true
win.window.Hide()
// this causes a segfault on linux, but on darwin if not closed it leaves a window hanging around.
if runtime.GOOS == "darwin" {
win.window.Close()
}
}()
},
)
resendButton := widget.NewButtonWithIcon("resend", theme.ViewRefreshIcon(), func() {
if running {
return
}
exit = false
go run()
})
stopButton = widget.NewButtonWithIcon("stop", theme.CancelIcon(), func() {
if running {
stopRequested <- true
}
})
clearButton := widget.NewButtonWithIcon("clear results", theme.ContentRemoveIcon(), func() {
clear()
})
closeRow = widget.NewGroup(" Control ",
stopButton,
resendButton,
clearButton,
closeButton,
layout.NewSpacer(),
BalanceLabel,
widget.NewLabel("Successful Requests:"),
successLabel,
widget.NewLabel("Failed Requests:"),
failedLabel,
)
closeRow.Show()
reqChan := make(chan string)
respChan := make(chan string)
fullRespChan := make(chan int)
trimDisplayed := func(s string) string {
re := regexp.MustCompile(`[[^:ascii:]]`)
var displayed string
s = s + "\n"
reader := strings.NewReader(s)
buf := bufio.NewReader(reader)
var lines int
for {
lines = lines + 1
line, err := buf.ReadString('\n')
if err != nil {
break
}
line, _ = strconv.Unquote(strconv.QuoteToASCII(line))
if len(line) > 128+21 {
line = fmt.Sprintf("%s ... trimmed %d chars ...\n", line[:128], len(line)-128)
}
displayed = displayed + line
if lines > 31 {
displayed = displayed + "\n ... too many lines to display ..."
break
}
}
return re.ReplaceAllString(displayed, "?")
}
go func(rq chan string, rs chan string, frs chan int) {
for {
select {
case q := <-rq:
textUpdateReq <- trimDisplayed(q)
case s := <-rs:
textUpdateResp <- trimDisplayed(s)
case fullResponseIndex = <-frs:
}
}
}(reqChan, respChan, fullRespChan)
reqChan <- ""
respChan <- ""
repaint := func() {
mux.Lock()
closeRow.Refresh()
summaryGroup.Refresh()
responseText.Refresh()
requestText.Refresh()
if grid != nil {
grid.Refresh()
}
mux.Unlock()
}
newButton := func(title string, index int, failed bool) {
if failed {
failedChan <- false
} else {
successChan <- true
}
if (!failed && win.hideSucc) || (failed && win.hideFail) {
return
}
// possible race while clearing the screen
if index > len(Results) {
return
}
deRef := &index
i := *deRef
if i-1 > len(Results) || len(Results) == 0 {
return
}
if len(Results) > 256 {
clear()
}
icon := theme.ConfirmIcon()
if failed {
icon = theme.CancelIcon()
}
b = widget.NewButtonWithIcon(title, icon, func() {
if i >= len(Results) {
return
}
reqChan <- string(Results[i].Req)
respChan <- string(Results[i].Resp)
fullRespChan <- i
})
summaryGroup.Append(b)
repaint()
}
run = func() {
defer func() {
if running {
stopRequested <- true
}
}()
// give each thread it's own http client pool:
workerApi, workerOpts, err := fio.NewConnection(account.KeyBag, api.BaseURL)
if err != nil {
errs.ErrChan <- err.Error()
errs.ErrChan <- "ERROR: could not get new client connection"
return
}
workerApi.Header.Set("User-Agent", "fio-cryptonym-wallet")
running = true
stopButton.Enable()
bombsAway.Disable()
resendButton.Disable()
closeButton.Disable()
defer func() {
running = false
stopButton.Disable()
bombsAway.Enable()
resendButton.Enable()
closeButton.Enable()
}()
var end int
switch {
case win.loop:
end = math.MaxInt32
case win.repeat > 1:
end = win.repeat
default:
end = 1
}
finished := make(chan bool)
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
defer func() {
running = false
finished <- true
wg.Done()
}()
for i := 0; i < end; i++ {
if exit {
return
}
output := TxResult{
Summary: fmt.Sprintf("%s", time.Now().Format("15:04:05.000")),
Index: i,
}
e := FormState.GeneratePayloads(account)
if e != nil {
errs.ErrChan <- e.Error()
errs.ErrChan <- "there was a problem generating dynamic payloads"
output.Resp = []byte(e.Error())
Results = append(Results, output)
newButton(output.Summary, len(Results)-1, true)
continue
}
if exit {
return
}
raw, tx, err := FormState.PackAndSign(workerApi, workerOpts, account, win.msig)
if tx == nil || tx.PackedTransaction == nil {
errs.ErrChan <- "sending a signed transaction with null action data"
empty := fio.NewAction(eos.AccountName(FormState.Contract), eos.ActionName(FormState.Action), account.Actor, nil)
_, tx, err = workerApi.SignTransaction(fio.NewTransaction([]*fio.Action{empty}, workerOpts), workerOpts.ChainID, fio.CompressionNone)
if err != nil {
errs.ErrChan <- err.Error()
continue
}
}
if win.msig && err == nil {
if tx == nil || tx.PackedTransaction == nil {
errs.ErrChan <- "did not build a valid transaction, refusing to continue."
output.Resp = []byte("could not build the transaction. Don't worry it's me, not you.")
Results = append(Results, output)
newButton(output.Summary, len(Results)-1, true)
continue
}
ntx, err := tx.Unpack()
if err != nil {
errs.ErrChan <- "Problem repacking transaction to embed in msig propose " + err.Error()
output.Resp = []byte(err.Error())
Results = append(Results, output)
newButton(output.Summary, len(Results)-1, true)
continue
}
// convert to transaction, without signature:
untx := eos.Transaction{}
if win.wrap {
untx = eos.Transaction{
TransactionHeader: ntx.TransactionHeader,
ContextFreeActions: ntx.ContextFreeActions,
Actions: ntx.Actions,
Extensions: ntx.Extensions,
}
untx.Expiration = eos.JSONTime{Time: time.Unix(0, 0)}
untx.RefBlockNum = 0
untx.RefBlockPrefix = 0
for i := range untx.Actions {
untx.Actions[i].Authorization = []eos.PermissionLevel{
{Actor: eos.AccountName(win.wrapActor), Permission: "active"},
}
}
} else {
for i := range ntx.Actions {
ntx.Actions[i].Authorization = []eos.PermissionLevel{{
Actor: eos.AccountName(win.msigAccount),
Permission: "active",
}}
}
}
requested := make([]*fio.PermissionLevel, 0)
signers := strings.Split(win.msigSigners, ",")
sort.Strings(signers)
for _, s := range signers {
requested = append(requested, &fio.PermissionLevel{
Actor: eos.AccountName(strings.ReplaceAll(s, " ", "")),
Permission: "active",
})
}
packed, _ := ntx.Pack(fio.CompressionNone)
//propose := fio.MsigPropose{}
//wrapPropose := fio.MsigWrappedPropose{}
var propose interface{}
if win.msig && !win.wrap {
ntx.Expiration = eos.JSONTime{Time: time.Now().Add(60 * time.Minute)}
propose = fio.MsigPropose{
Proposer: account.Actor,
ProposalName: eos.Name(win.msigName()),
Requested: requested,
MaxFee: fio.Tokens(fio.GetMaxFee(fio.FeeMsigPropose))*uint64(len(packed.PackedTransaction)/1000) + fio.Tokens(1.0),
Trx: ntx,
}
} else if win.wrap {
//wrap := fio.NewWrapExecute(account.Actor, eos.AccountName(win.msigAccount), ntx)
wrap := fio.NewWrapExecute("eosio.wrap", account.Actor, &untx)
wrap.Authorization = []eos.PermissionLevel{
//{Actor: account.Actor, Permission: "active"},
{Actor: "eosio.wrap", Permission: "active"},
}
wTx := fio.NewTransaction([]*fio.Action{wrap}, opts)
wTx.Expiration = eos.JSONTime{Time: time.Now().Add(60 * time.Minute)}
wTx.RefBlockNum = 0
wTx.RefBlockPrefix = 0
propose = fio.MsigWrappedPropose{
Proposer: account.Actor,
ProposalName: eos.Name(win.msigName()),
Requested: requested,
MaxFee: fio.Tokens(fio.GetMaxFee(fio.FeeMsigPropose))*uint64(len(packed.PackedTransaction)/1000) + fio.Tokens(1.0),
Trx: wTx,
}
}
_, tx, err = workerApi.SignTransaction(
fio.NewTransaction(
[]*fio.Action{
fio.NewAction(
"eosio.msig",
"propose",
account.Actor,
propose,
),
},
workerOpts),
workerOpts.ChainID, fio.CompressionNone,
)
if err != nil {
errs.ErrChan <- "Problem signing msig propose " + err.Error()
output.Resp = []byte(err.Error())
Results = append(Results, output)
newButton(output.Summary, len(Results)-1, true)
continue
}
raw, _ = json.Marshal(propose)
}
j, _ := json.MarshalIndent(raw, "", " ")
packed, _ := json.MarshalIndent(tx, "", " ")
output.Req = append(append(j, []byte("\n\nPacked Tx:\n\n")...), packed...)
if err != nil {
errs.ErrChan <- err.Error()
errs.ErrChan <- "could not marshall into a TX"
output.Resp = []byte(err.Error())
Results = append(Results, output)
newButton(output.Summary, len(Results)-1, true)
continue
}
if tx == nil || tx.PackedTransaction == nil {
errs.ErrChan <- "did not build a valid transaction, refusing to continue."
output.Resp = []byte("could not build the transaction. Don't worry it's me, not you.")
Results = append(Results, output)
newButton(output.Summary, len(Results)-1, true)
continue
}
output.Req = append(output.Req, []byte(p.Sprintf("\n\nSize of Packed TX (bytes): %d", len(tx.PackedTransaction)))...)
reqBuf := bytes.Buffer{}
reqZWriter, _ := zlib.NewWriterLevel(&reqBuf, zlib.BestCompression)
reqZWriter.Write(j)
reqZWriter.Close()
output.FullReq = reqBuf.Bytes()
if exit {
return
}
result, err := workerApi.PushEndpointRaw(actionEndPointActive, tx)
if err != nil {
errs.ErrChan <- err.Error()
if win.hideFail {
failedChan <- true
continue
}
output.Resp = []byte(err.Error())
output.Summary = fmt.Sprintf("%s", time.Now().Format("15:04:05.000"))
buf := bytes.Buffer{}
zWriter, _ := zlib.NewWriterLevel(&buf, zlib.BestCompression)
if len(result) > 0 {
zWriter.Write(result)
} else {
zWriter.Write([]byte(fmt.Sprintf(`{"error": "%s"}`, err.Error())))
}
zWriter.Close()
output.FullResp = buf.Bytes()
Results = append(Results, output)
newButton(output.Summary, len(Results)-1, true)
continue
}
if exit {
return
}
// store two responses, the summary -- displayed by default, and zlib compressed full response.
// the full response is huge, and will seriously screw up the display and consume a lot of memory!
summary := &TxSummary{}
err = json.Unmarshal(result, summary)
if err != nil {
errs.ErrChan <- err.Error()
output.Resp = []byte(err.Error())
output.Summary = fmt.Sprintf("%s", time.Now().Format("15:04:05.000"))
if win.hideFail {
failedChan <- true
continue
}
Results = append(Results, output)
newButton(output.Summary, len(Results)-1, true)
continue
}
// get the real tx size, since we got this far assume we have a valid tx result
sz := &txTraces{}
_ = json.Unmarshal(result, sz)
summary.TotalBytes = sz.size()
if win.hideSucc {
successChan <- true
continue
}
j, _ = yaml.Marshal(summary)
output.Resp = j
buf := bytes.Buffer{}
zWriter, _ := zlib.NewWriterLevel(&buf, zlib.BestCompression)
zWriter.Write(result)
zWriter.Close()
output.FullResp = buf.Bytes()
Results = append(Results, output)
newButton(output.Summary, len(Results)-1, false)
}
}()
for {
select {
case _ = <-stopRequested:
exit = true
case _ = <-finished:
wg.Wait()
return
}
}
}
for w := 0; w < workers; w++ {
go run()
}
time.Sleep(250 * time.Millisecond)
setGrid()
if len(Results) > 0 && !win.hideFail && !win.hideSucc {
textUpdateResp <- trimDisplayed(string(Results[0].Resp))
textUpdateReq <- trimDisplayed(string(Results[0].Req))
}
if !running {
stopButton.Disable()
}
repaint()
win.window.SetOnClosed(func() {
Win.RequestFocus()
win.gone = true
exit = true
close(textUpdateDone)
})
if win.gone && win != nil {
win.gone = false
win.window.Show()
resizeTrigger <- true
} else {
repaint()
}
}
func ShowFullResponse(b []byte, win fyne.Window) {
FullResponseText := widget.NewMultiLineEntry()
FullActionRespWin := App.NewWindow("Full Response")
FullActionRespWin.Hide()
FullActionRespWin.Resize(fyne.NewSize(W, H))
FullActionRespWin.SetContent(
fyne.NewContainerWithLayout(layout.NewMaxLayout(),
widget.NewScrollContainer(
FullResponseText,
),
),
)
FullActionRespWin.SetOnClosed(func() {
go func() {
// bug in fyne 1.3 where we need a very short wait to grab a child window
time.Sleep(100 * time.Millisecond)
for _, w := range fyne.CurrentApp().Driver().AllWindows() {
if w.Title() == "Tx Results" {
w.RequestFocus()
log.Println("found parent")
return
}
}
win.RequestFocus()
}()
})
set := func(s string) {
FullResponseText.OnChanged = func(string) {
FullResponseText.SetText(s)
}
FullResponseText.SetText(s)
FullResponseText.Refresh()
FullActionRespWin.Show()
}
reader := bufio.NewReader(bytes.NewReader(b))
zlReader, err := zlib.NewReader(reader)
if err != nil {
set(err.Error())
return
}
defer zlReader.Close()
j, err := ioutil.ReadAll(zlReader)
if err != nil {
set(err.Error())
return
}
full, err := json.MarshalIndent(json.RawMessage(j), "", " ")
if err != nil {
set(err.Error())
return
}
set(string(full))
}
func ShowFullRequest(b []byte, win fyne.Window) {
fullRequestText := widget.NewMultiLineEntry()
fullActionRespWin := App.NewWindow("Full Request")
fullActionRespWin.Hide()
fullActionRespWin.Resize(fyne.NewSize(W, H))
fullActionRespWin.SetContent(
fyne.NewContainerWithLayout(layout.NewMaxLayout(),
widget.NewScrollContainer(
fullRequestText,
),
),
)
fullActionRespWin.SetOnClosed(func() {
go func() {
time.Sleep(100 * time.Millisecond)
for _, w := range fyne.CurrentApp().Driver().AllWindows() {
if w.Title() == "Tx Results" {
w.RequestFocus()
log.Println("found parent")
return
}
}
win.RequestFocus()
}()
})
set := func(s string) {
fullRequestText.OnChanged = func(string) {
fullRequestText.SetText(s)
}
fullRequestText.SetText(s)
fullRequestText.Refresh()
fullActionRespWin.Show()
}
reader := bufio.NewReader(bytes.NewReader(b))
zlReader, err := zlib.NewReader(reader)
if err != nil {
set(err.Error())
return
}
defer zlReader.Close()
j, err := ioutil.ReadAll(zlReader)
if err != nil {
set(err.Error())
return
}
full, err := json.MarshalIndent(json.RawMessage(j), "", " ")
if err != nil {
set(err.Error())
return
}
set(string(full))
}