Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate with frontend #4

Merged
merged 37 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
bd421bc
ui and signer
Aug 6, 2021
88c2703
一些逻辑补完
Aug 12, 2021
7ba6e4d
build windows
Aug 13, 2021
01a8d3b
logic in frontend
Aug 14, 2021
9856477
inline static files
Aug 14, 2021
50bfa34
improve documents
Aug 16, 2021
2638bc3
逻辑完善
Aug 16, 2021
7b53014
Merge remote-tracking branch 'origin/feature_singer' into feature_singer
Aug 17, 2021
51b83f9
删除index.html
Aug 18, 2021
edafd40
save file
Aug 18, 2021
537bfa3
disable auto update
Aug 18, 2021
fb96fa5
mac make
stechu Aug 18, 2021
1c1d659
mac make update
stechu Aug 18, 2021
b7ffd64
Merge remote-tracking branch 'origin/feature_singer' into feature_singer
Aug 20, 2021
f8053c9
集成代码
Aug 21, 2021
849b7b1
m1 mac build
stechu Aug 23, 2021
0dd9cee
translate
stechu Aug 24, 2021
795dd96
Update README.md
stechu Aug 24, 2021
c2184ae
translate
Aug 25, 2021
6953f91
i18n
Aug 25, 2021
b942e0c
Merge pull request #3 from Manta-Network/translate
summerback Aug 25, 2021
daf220b
create app without signing
stechu Aug 25, 2021
81fe73d
can build
Kevingislason Sep 3, 2021
f70241f
simplify frontend
Kevingislason Sep 4, 2021
1b19415
wip
Kevingislason Sep 13, 2021
e644487
wip
Kevingislason Sep 14, 2021
babe965
wip
Kevingislason Sep 14, 2021
415b1a2
in memory keys works
Kevingislason Sep 15, 2021
221c73e
cleanup
Kevingislason Sep 17, 2021
eed09e3
cleanup
Kevingislason Sep 17, 2021
4abfada
merge master
Kevingislason Sep 18, 2021
d10217d
translation
stechu Sep 18, 2021
1871f8e
code review
Kevingislason Sep 20, 2021
abcefc5
merge
Kevingislason Sep 20, 2021
0d709af
merge
Kevingislason Sep 20, 2021
b2082a0
testnet coin type id
Kevingislason Sep 20, 2021
8d606c7
use manta branch of manta api
Kevingislason Sep 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,22 @@ fabric.properties
debug/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

.idea
build/bin
.version
lib/darwin
lib/linux
lib/windows
/prover_key_gen/*.bin
*.aes
wails_dev.sh
/lib/zkp/keys
dist/*
manta-daemon.app
resources/manta-daemon
transfer_pk.bin
reclaim_pk.bin
lib/libzkp.a
26 changes: 12 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
build-mac-arm:
cd lib/zkp && cargo build --release --target=aarch64-apple-darwin
cp lib/zkp/target/aarch64-apple-darwin/release/libzkp.a lib/
cd prover_key_gen && cargo run --release
mkdir lib/zkp/keys && mv prover_key_gen/*.bin lib/zkp/keys
GOOS=darwin GOARCH=arm64 go build -o dist/darwin/manta-daemon lstaticdarwin.go main.go
go build -o dist/darwin/bundler mac/bundler.go
cp lib/zkp/target/aarch64-apple-darwin/release/libzkp.a lib/darwin
GOOS=darwin GOARCH=arm64 go build -o lstaticdarwin.go main.go app.go server.go service.go incoming_urls.go

build-mac-x86:
cd lib/zkp && cargo build --release --target=x86_64-apple-darwin
cp lib/zkp/target/x86_64-apple-darwin/release/libzkp.a lib/
cd prover_key_gen && cargo run --release
mkdir lib/zkp/keys && mv prover_key_gen/*.bin lib/zkp/keys
GOOS=darwin GOARCH=amd64 go build -o dist/darwin/manta-daemon lstaticdarwin.go main.go
go build -o dist/darwin/bundler mac/bundler.go
cp lib/zkp/target/x86_64-apple-darwin/release/libzkp.a lib
GOOS=darwin GOARCH=amd64 ~/go/bin/wails build -o dist/darwin/manta-signer lstaticdarwin.go main.go app.go server.go service.go incoming_urls.go

build-linux:
mkdir -p lib/linux
cd lib/zkp && cargo build --release --target=x86_64-unknown-linux-musl
cp lib/zkp/target/x86_64-unknown-linux-gnu/release/libzkp.a lib/
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++ go build -o dist/linux/manta-daemon main.go
cp lib/zkp/target/x86_64-unknown-linux-gnu/release/libzkp.a lib/linux
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++ go build -o dist/linux/manta-signer main.go app.go server.go service.go incoming_urls.go


build-windows:
source ~/.bash_profile
mkdir -p lib/windows
cd lib/zkp && cargo build --release --target=x86_64-pc-windows-gnu
cp lib/zkp/target/x86_64-pc-windows-gnu/release/libzkp.a lib/
#GOOS=windows GOARCH=amd64 go build -ldflags=$(LD_FLAGS) -o dist/windows/manta-daemon.exe main.go
cp lib/zkp/target/x86_64-pc-windows-gnu/release/libzkp.a lib/windows/
#GOOS=windows GOARCH=amd64 go build -ldflags=$(LD_FLAGS) -o dist/windows/manta-signer.exe main.go
GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ \
CGO_ENABLED=1 go build -o dist/windows/manta-daemon.exe lstaticwindows.go main.go

Expand Down
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
Manta Signer
=========================
# Manta Signer

## Singer Spec

https://hackmd.io/0ZnJMf9jRwug2_ZBE0F4fA?both

## Compile

# 执行`build/bin`下面相关平台的二进制文件

### MacOS Arm

### MacOS x86-64

### Ubuntu 20.04 LTS (x86_64)

### Ubuntu 20.04 LTS (x86_64)
need `brew install FiloSottile/musl-cross/musl-cross`
(To be fix: Compilation issues)

### Windows (x86_64)

1. Install toolchain

```bash
rustup toolchain install stable-x86_64-pc-windows-gnu
```

2. Install x86_64-w64-mingw32-gcc linker:

```bash
brew install mingw-w64
```

(To be fixed: compilation issue)

## Running

### MacOS

```bash
dist/darwin/manta-daemon
```
Expand All @@ -41,8 +46,8 @@ dist/darwin/manta-daemon
via RESTful API on `localhost:9988`.
A customized port could be specified at `--addr=0.0.0.0:<port number>`:

There are 3 RESTful APIs:
---
## There are 3 RESTful APIs:

1. /heartbeat

Method: GET
Expand All @@ -65,10 +70,10 @@ Params:
app_version: the current App version

Body:

ZKP payload (in binary).

Response:
Response:

{
"transfer_zkp": "0x22023891",
Expand All @@ -77,8 +82,9 @@ Response:
}

Example:

```
$ curl --request POST --data-binary "@dist/darwin/manta-daemon" http://localhost:9988/generateTransferZKP
$ curl --request POST --data-binary "@dist/darwin/manta-signer" http://localhost:9988/generateTransferZKP
```

3. /generateReclaimZKP
Expand All @@ -103,9 +109,11 @@ Response:
}

Example:

```
$ curl --request POST --data-binary "@dist/darwin/manta-daemon" http://localhost:9988/generateReclaimZKP
$ curl --request POST --data-binary "@dist/darwin/manta-signer" http://localhost:9988/generateReclaimZKP
```

### Generating MacOS `.dmg`

(TBD)
221 changes: 221 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
package main

import (
"fmt"
"log"
"os"
"sync"
"time"

"github.com/labstack/echo/v4"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/menu"
"github.com/wailsapp/wails/v2/pkg/menu/keys"
"github.com/wailsapp/wails/v2/pkg/options/dialog"
)

const (
ConcurrentIncomeURL = 1
)

// app struct
type app struct {
rootSeed *[64]byte
userIsSignedIn *bool
addr string
svr *echo.Echo
runtime *wails.Runtime

appMenu *menu.Menu
defaultTrayMenu *menu.TrayMenu

Service *Service
lock sync.Mutex
Verbose bool
isDarkMode bool

defaultTrayMenuActive bool

// incomingURLSemaphore use channel that ensure only one event will be processed
incomingURLSemaphore chan struct{}
}

// newApp creates a new app application struct
func newApp(addr string) (*app, error) {
var rootSeed [64]byte
userIsSignedIn := false
app := &app{
addr: addr,
incomingURLSemaphore: make(chan struct{}, ConcurrentIncomeURL),
rootSeed: &rootSeed,
userIsSignedIn: &userIsSignedIn,
}
app.appMenu = menu.NewMenuFromItems(
menu.AppMenu(),
menu.EditMenu(),
menu.WindowMenu(),
)

// initialize service,
// we put logic that interact with frontend into service
app.Service = NewService(app.rootSeed, app.userIsSignedIn)

// automated updates
//app.appUpdatesMenu = &menu.MenuItem{
// Type: menu.TextType,
// Label: "Check for updates...",
//}

// automated update when start
//app.autoUpdateMenu = &menu.MenuItem{
// Type: menu.CheckboxType,
// Label: "Update automatically",
//}

// start at login or not
//app.startsAtLoginMenu = &menu.MenuItem{
// Type: menu.CheckboxType,
// Label: "Start at Login",
// Checked: false,
//}
//startsAtLogin, err := mac.StartsAtLogin()
//if err != nil {
// if app.Verbose {
// log.Println("start at login:", err)
// }
// app.startsAtLoginMenu.Label = "Start at Login"
// app.startsAtLoginMenu.Checked = true
//} else {
// app.startsAtLoginMenu.Checked = startsAtLogin
//}

app.defaultTrayMenu = &menu.TrayMenu{
Label: DaemonName,
Menu: app.newTrayMenu(),
}

return app, nil
}

func (b *app) startupServer(runtime *wails.Runtime) {
svr := NewSvr(b.rootSeed, b.userIsSignedIn)
svr.RegisterRoutes()
err := svr.Start(runtime, b.addr)
if err != nil {
println(err.Error())
os.Exit(1)
return
}
}

// startup is called at application startup
func (b *app) startup(runtime *wails.Runtime) {
b.setDarkMode(runtime.System.IsDarkMode())
// change to dark mode
runtime.Events.OnThemeChange(func(darkMode bool) {
// keep track of dark mode changing, and refresh all
// plugins if it does.
b.setDarkMode(darkMode)
b.refreshAll()
})
b.runtime = runtime
b.Service.runtime = runtime
b.refreshAll()
// export web service
go b.startupServer(runtime)
// prepare for automated update
go func() {
// wait for checking automated update
time.Sleep(10 * time.Second)
for {
// todo app.checkForUpdates(true)
// wait 12 hour for checking automated update again
time.Sleep(12 * time.Hour)
}
}()
}

func (b *app) refreshAll() {
b.lock.Lock()
defer b.lock.Unlock()
if b.defaultTrayMenuActive {
// only default menu - remove it
b.runtime.Menu.DeleteTrayMenu(b.defaultTrayMenu)
b.defaultTrayMenuActive = false
}
b.runtime.Menu.SetTrayMenu(b.defaultTrayMenu)
b.defaultTrayMenuActive = true
return
}

// shutdown is called at application termination
func (b *app) shutdown() {
// Perform your teardown here
}

func (b *app) newTrayMenu() *menu.Menu {
var items []*menu.MenuItem
items = append(items, &menu.MenuItem{
Type: menu.TextType,
Label: fmt.Sprintf("manta-singer (%s)", version),
Disabled: true,
})
items = append(items, &menu.MenuItem{
Type: menu.TextType,
Label: "Open signer",
Click: func(_ *menu.CallbackData) {
b.runtime.Window.Show()
},
})
//items = append(items, b.appUpdatesMenu)
//items = append(items, b.autoUpdateMenu)
//items = append(items, b.startsAtLoginMenu)
items = append(items, menu.Separator())
items = append(items, &menu.MenuItem{
Type: menu.TextType,
Label: "Quit",
Accelerator: keys.CmdOrCtrl("q"),
Click: b.onQuitMenuClicked,
})
m := &menu.Menu{Items: items}
return m
}

func (b *app) onQuitMenuClicked(_ *menu.CallbackData) {
b.runtime.Quit()
}

func (b *app) setDarkMode(darkMode bool) {
b.lock.Lock()
defer b.lock.Unlock()
b.isDarkMode = darkMode
}

func (b *app) handleIncomeURL(url string) {
b.incomingURLSemaphore <- struct{}{}
defer func() {
<-b.incomingURLSemaphore
}()
log.Println("incoming URL: handleIncomingURL", url)
incomingURL, err := parseIncomingURL(url)
if err != nil {
_, err2 := b.runtime.Dialog.Message(&dialog.MessageDialog{
Type: dialog.ErrorDialog,
Title: "Invalid URL",
Message: err.Error(),
Buttons: []string{"OK"},
CancelButton: "OK",
})
if err2 != nil {
log.Println(err2)
return
}
return
}
switch incomingURL.Action {
case "show":
b.runtime.Window.Show()
default:
log.Printf("incoming URL: skipping, unknown action %q\n", incomingURL.Action)
}
}
Loading