pow/main.go

28 lines
750 B
Go
Raw Normal View History

2024-07-20 16:48:14 +01:00
package main
import (
2024-09-22 15:33:45 +01:00
"git.ailur.dev/ailur/pow-argon2/library"
2024-09-22 14:56:09 +01:00
2024-07-20 16:48:14 +01:00
"fmt"
"syscall/js"
)
func main() {
2024-09-22 14:56:09 +01:00
fmt.Println("Proof of work module online")
resource := js.Global().Get("resource").String()
difficulty := js.Global().Get("difficulty").Int()
fmt.Println("Beginning PoW with difficulty", difficulty, "and resource", resource)
result, err := library.PoW(uint64(difficulty), resource)
2024-07-20 16:48:14 +01:00
if err != nil {
2024-09-22 14:56:09 +01:00
fmt.Println("Error:", err)
js.Global().Set("return", js.ValueOf(err.Error()))
js.Global().Set("returnCode", js.ValueOf(1))
2024-07-20 16:48:14 +01:00
js.Global().Call("WASMComplete")
} else {
2024-09-22 14:56:09 +01:00
fmt.Println("Result:", result)
js.Global().Set("return", js.ValueOf(result))
2024-07-20 16:48:14 +01:00
js.Global().Set("returnCode", js.ValueOf(0))
js.Global().Call("WASMComplete")
}
}