2024-11-23 01:28:58 -05:00
|
|
|
//go:build js && wasm
|
|
|
|
|
// +build js,wasm
|
|
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2024-12-02 14:27:18 -05:00
|
|
|
"encoding/json"
|
|
|
|
|
"syscall/js"
|
|
|
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
|
"github.com/onsonr/sonr/cmd/motr/internal"
|
2024-12-05 20:36:58 -05:00
|
|
|
"github.com/onsonr/sonr/pkg/common/controller"
|
2024-12-02 14:27:18 -05:00
|
|
|
"github.com/onsonr/sonr/pkg/vault"
|
|
|
|
|
"github.com/onsonr/sonr/pkg/vault/types"
|
2024-11-23 01:28:58 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
2024-12-02 14:27:18 -05:00
|
|
|
env *types.Environment
|
|
|
|
|
config *types.Config
|
2024-11-23 01:28:58 -05:00
|
|
|
err error
|
|
|
|
|
)
|
|
|
|
|
|
2024-12-02 14:27:18 -05:00
|
|
|
func broadcastTx(this js.Value, args []js.Value) interface{} {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func simulateTx(this js.Value, args []js.Value) interface{} {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func processConfig(this js.Value, args []js.Value) interface{} {
|
|
|
|
|
if len(args) < 1 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configString := args[0].String()
|
|
|
|
|
if err := json.Unmarshal([]byte(configString), &config); err != nil {
|
|
|
|
|
println("Error parsing config:", err.Error())
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-23 01:28:58 -05:00
|
|
|
func main() {
|
|
|
|
|
// Load dwn config
|
2024-12-02 14:27:18 -05:00
|
|
|
js.Global().Set("broadcastTx", js.FuncOf(broadcastTx))
|
|
|
|
|
js.Global().Set("simulateTx", js.FuncOf(simulateTx))
|
|
|
|
|
js.Global().Set("processConfig", js.FuncOf(processConfig))
|
|
|
|
|
|
|
|
|
|
e := echo.New()
|
|
|
|
|
e.Use(internal.WasmContextMiddleware)
|
2024-12-05 20:36:58 -05:00
|
|
|
e.Use(controller.Middleware(nil))
|
|
|
|
|
vault.RegisterRoutes(e, config)
|
2024-12-02 14:27:18 -05:00
|
|
|
internal.ServeFetch(e)
|
2024-11-23 01:28:58 -05:00
|
|
|
}
|