forked from tez-capital/tezpay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwasm.go
More file actions
57 lines (47 loc) · 1.32 KB
/
wasm.go
File metadata and controls
57 lines (47 loc) · 1.32 KB
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
//go:build js && wasm
package main
import (
"encoding/json"
"errors"
"log/slog"
"syscall/js"
"github.com/mavryk-network/mavpay/common"
"github.com/mavryk-network/mavpay/configuration"
"github.com/mavryk-network/mavpay/constants"
"github.com/mavryk-network/mavpay/core"
"github.com/mavryk-network/gomavryk/mavryk"
)
func main() {
slog.Info("mavpay wasm loaded", "version", constants.VERSION)
}
//export generate_payouts
func generate_payouts(key js.Value, cycle int64, configurationJs js.Value) (js.Value, error) {
configurationBytes := []byte(configurationJs.String())
config, err := configuration.LoadFromString(configurationBytes)
if err != nil {
return js.Null(), err
}
bakerKey, err := mavryk.ParseKey(key.String())
if err != nil {
return js.Null(), err
}
payoutBlueprint, err := core.GeneratePayoutsWithPayoutAddress(bakerKey, config, common.GeneratePayoutsOptions{
Cycle: cycle,
SkipBalanceCheck: true,
Engines: common.GeneratePayoutsEngines{
//FIXME possible JSCollector/JSSigner interfaced from JS
Collector: nil,
},
})
if err != nil {
return js.Null(), err
}
result, err := json.Marshal(payoutBlueprint)
return js.ValueOf(string(result)), err
}
//export test
func test(data js.Value) (js.Value, error) {
x := data.String()
slog.Info(x)
return js.ValueOf(x), errors.New("test")
}