Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #21 from govm-net/lengzhao
Browse files Browse the repository at this point in the history
Lengzhao
  • Loading branch information
lengzhao authored Sep 13, 2020
2 parents 147deb2 + bdb5774 commit 494f7ac
Show file tree
Hide file tree
Showing 11 changed files with 367 additions and 45 deletions.
9 changes: 7 additions & 2 deletions bin/gui/assets/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
"View Private Key":"查看明文私钥",
"Register Miner":"注册矿工",
"Miner":"矿工",
"Number":"数量",
"":""
"Eth Address":"以太坊地址",
"Run APP":"执行App",
"Data":"数据",
"Data Type":"数据类型",
"wgovm_desc":"将govm兑换为以太坊的wGovm\n1.执行当前App锁定govm\n2.管理员签名\n3.你自己在以太坊上造币(http://govm.net:9090/wgovm.html)",
"":"",
"Number":"数量"
}
2 changes: 1 addition & 1 deletion bin/gui/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mkdir $folder
mv govm.exe $folder
cp assets $folder -rf
cp conf.json $folder -rf
zip -r govm_windows_wallet_$(date +'%Y%m%d_%H%M%S').tar.gz $folder
zip -r govm_windows_wallet_$(date +'%Y%m%d_%H%M%S').zip $folder
echo Enter to exit
read k
rm $folder -rf
2 changes: 1 addition & 1 deletion bin/gui/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// Vserion version of wallet
const Vserion = "v0.5.2"
const Vserion = "v0.5.3"

// Config config
type Config struct {
Expand Down
1 change: 1 addition & 0 deletions bin/gui/res/resoure.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var i18n = map[string]string{
"opCode.6": "Register Miner",
"setting.desc": "Restart after setting",
"vote_desc": "After voting, collect the income yourself (every month through 0 vote)",
"wgovm_desc": "govm exchange to eth.wGovm\n1. run this.Contract to lock coins.\n2. sign by admin(1 day)\n3. relayMint by yourself(http://govm.net:9090/wgovm.html)",
}

var readFile func(fn string) ([]byte, error)
Expand Down
221 changes: 221 additions & 0 deletions bin/gui/screens/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
package screens

import (
"encoding/hex"
"encoding/json"
"fmt"
"log"
"strconv"

"fyne.io/fyne"
"fyne.io/fyne/dialog"
"fyne.io/fyne/layout"
"fyne.io/fyne/widget"
"github.com/lengzhao/wallet/bin/gui/conf"
"github.com/lengzhao/wallet/bin/gui/event"
"github.com/lengzhao/wallet/bin/gui/res"
"github.com/lengzhao/wallet/trans"
)

func makeAppRunTab(w fyne.Window) fyne.Widget {
c := conf.Get()
chain := widget.NewSelect(c.Chains, nil)
chain.SetSelected(c.DefaultChain)
app := widget.NewEntry()
app.SetPlaceHolder("app name")
var dataType = "string"
dType := widget.NewSelect([]string{"string", "hex"}, func(nv string) {
dataType = nv
})
dType.SetSelected(dataType)
dEntry := widget.NewEntry()
amount := widget.NewEntry()
unit := widget.NewLabel(c.CoinUnit)
energy := widget.NewEntry()
energy.SetText("0.1")
unit2 := widget.NewLabel(c.CoinUnit)
result := widget.NewEntry()
result.Disable()

event.RegisterConsumer(event.EChangeUnit, func(e string, param ...interface{}) error {
unit.SetText(c.CoinUnit)
return nil
})

form := &widget.Form{
OnCancel: func() {
app.SetText("")
dEntry.SetText("")
amount.SetText("")
result.SetText("")
},
OnSubmit: func() {
result.SetText("")
costF, err := strconv.ParseFloat(amount.Text, 10)
if err != nil {
dialog.ShowError(fmt.Errorf("error amount"), w)
return
}
amount.SetPlaceHolder(amount.Text)
amount.SetText("")
cid, err := strconv.ParseUint(chain.Selected, 10, 64)
if err != nil {
dialog.ShowError(fmt.Errorf("error chain id"), w)
return
}
if app.Text == "" {
dialog.ShowError(fmt.Errorf("require app name"), w)
return
}
var param []byte
if dEntry.Text != "" {
switch dataType {
case "hex":
param, err = hex.DecodeString(dEntry.Text)
if err != nil {
dialog.ShowError(fmt.Errorf("error hex data.%s", err), w)
return
}
default:
param = []byte(dEntry.Text)
}
}

base := res.GetBaseOfUnit(c.CoinUnit)
cost := uint64(costF * float64(base))
myWlt := conf.GetWallet()
trans := trans.NewTransaction(cid, myWlt.Address, cost)
err = trans.RunApp(app.Text, param)
if err != nil {
dialog.ShowError(err, w)
return
}

td := trans.GetSignData()
sign := myWlt.Sign(td)
trans.SetTheSign(sign)
td = trans.Output()
key := trans.Key[:]

err = postTrans(cid, td)
if err != nil {
// result.SetText(fmt.Sprintf("%s", err))
dialog.ShowError(err, w)
return
}
log.Printf("new transfer:%x\n", key)
// dialog.ShowInformation("transaction", fmt.Sprintf("%x", key), w)
result.SetText(fmt.Sprintf("%x", key))
app.SetPlaceHolder(app.Text)
app.SetText("")
},
}
form.Append(res.GetLocalString("Chain"), chain)
form.Append(res.GetLocalString("App"), app)
form.Append(res.GetLocalString("Data Type"), dType)
form.Append(res.GetLocalString("Data"), dEntry)
borderLayout := layout.NewBorderLayout(nil, nil, nil, unit)
form.Append(res.GetLocalString("Amount"), fyne.NewContainerWithLayout(borderLayout, unit, amount))
borderLayout2 := layout.NewBorderLayout(nil, nil, nil, unit2)
form.Append(res.GetLocalString("Energy"), fyne.NewContainerWithLayout(borderLayout2, unit2, energy))

return widget.NewVBox(form, result)
}

type wGovmBody struct {
EthAddr string `json:"eth_addr,omitempty"`
}

func makeWGOVMTab(w fyne.Window) fyne.Widget {
c := conf.Get()
desc := widget.NewMultiLineEntry()
desc.Disable()
desc.SetText(res.GetLocalString("wgovm_desc"))
ethEntry := widget.NewEntry()
amount := widget.NewEntry()
unit := widget.NewLabel(c.CoinUnit)
energy := widget.NewEntry()
energy.SetText("0.1")
unit2 := widget.NewLabel(c.CoinUnit)
result := widget.NewEntry()
result.Disable()

event.RegisterConsumer(event.EChangeUnit, func(e string, param ...interface{}) error {
unit.SetText(c.CoinUnit)
return nil
})

form := &widget.Form{
OnCancel: func() {
ethEntry.SetText("")
amount.SetText("")
result.SetText("")
},
OnSubmit: func() {
result.SetText("")
costF, err := strconv.ParseFloat(amount.Text, 10)
if err != nil {
dialog.ShowError(fmt.Errorf("error amount"), w)
return
}
amount.SetPlaceHolder(amount.Text)
amount.SetText("")

if costF < 5000 {
dialog.ShowError(fmt.Errorf("require amount >= 5000govm"), w)
return
}

if ethEntry.Text == "" {
dialog.ShowError(fmt.Errorf("require eth address"), w)
return
}
param := []byte{0}
info := wGovmBody{ethEntry.Text}
d, _ := json.Marshal(info)
param = append(param, d...)
base := res.GetBaseOfUnit(c.CoinUnit)
cost := uint64(costF * float64(base))
myWlt := conf.GetWallet()
trans := trans.NewTransaction(1, myWlt.Address, cost)
err = trans.RunApp("a99b97a411b45c91779e1609386fa18484b8e50016379bd98c6822b491247b9b", param)
if err != nil {
dialog.ShowError(err, w)
return
}

td := trans.GetSignData()
sign := myWlt.Sign(td)
trans.SetTheSign(sign)
td = trans.Output()
key := trans.Key[:]

err = postTrans(1, td)
if err != nil {
// result.SetText(fmt.Sprintf("%s", err))
dialog.ShowError(err, w)
return
}
log.Printf("new transfer:%x\n", key)
// dialog.ShowInformation("transaction", fmt.Sprintf("%x", key), w)
result.SetText(fmt.Sprintf("%x", key))
},
}

form.Append(res.GetLocalString("Description"), desc)
form.Append(res.GetLocalString("Eth Address"), ethEntry)
borderLayout := layout.NewBorderLayout(nil, nil, nil, unit)
form.Append(res.GetLocalString("Amount"), fyne.NewContainerWithLayout(borderLayout, unit, amount))
borderLayout2 := layout.NewBorderLayout(nil, nil, nil, unit2)
form.Append(res.GetLocalString("Energy"), fyne.NewContainerWithLayout(borderLayout2, unit2, energy))

return widget.NewVBox(form, result)
}

// AppScreen shows a panel containing widget demos
func AppScreen(w fyne.Window) fyne.CanvasObject {
return widget.NewTabContainer(
widget.NewTabItem(res.GetLocalString("Run APP"), makeAppRunTab(w)),
widget.NewTabItem(res.GetLocalString("wGOVM"), makeWGOVMTab(w)),
)
}
1 change: 1 addition & 0 deletions bin/gui/screens/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func Master(a fyne.App) fyne.Window {
tabs := widget.NewTabContainer(
widget.NewTabItemWithIcon(res.GetLocalString("Home"), theme.HomeIcon(), AccountScreen(w)),
widget.NewTabItemWithIcon(res.GetLocalString("Transaction"), theme.MailSendIcon(), TransactionScreen(w)),
widget.NewTabItemWithIcon(res.GetLocalString("APP"), theme.MenuIcon(), AppScreen(w)),
widget.NewTabItemWithIcon(res.GetLocalString("Search"), theme.SearchIcon(), SearchScreen(w)),
widget.NewTabItemWithIcon(res.GetLocalString("History"), theme.ContentPasteIcon(), HistoryScreen(w)),
widget.NewTabItemWithIcon(res.GetLocalString("Setting"), theme.SettingsIcon(), SettingScreen(w)))
Expand Down
2 changes: 1 addition & 1 deletion bin/html/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mv html_wallet_linux $folder
mv html_wallet_mac $folder
cp static $folder -rf
#tar zcvf "$folder"_$(date +'%Y%m%d_%H%M%S').tar.gz $folder
zip -r "$folder"_$(date +'%Y%m%d_%H%M%S').tar.gz $folder
zip -r "$folder"_$(date +'%Y%m%d_%H%M%S').zip $folder
rm $folder -rf
echo Enter to exit
read k
3 changes: 3 additions & 0 deletions bin/html/static/js/encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ function dataEncode(input, type) {
case "bytes2int":
return dataEncode(dataEncode(input, "bytes2hex"), "hex2int")
case "hex2int":
if (input === undefined) {
return 0;
}
return parseInt(input, 16)
case "hex2bytes":
var myUint8Array = new Uint8Array(input.match(/[\da-f]{2}/gi).map(function (h) {
Expand Down
Loading

0 comments on commit 494f7ac

Please sign in to comment.