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

Sign mode support and BLE concurrent write fix #1492

Open
wants to merge 1 commit into
base: feature/wasm-sc-txn
Choose a base branch
from
Open
Changes from all commits
Commits
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
23 changes: 20 additions & 3 deletions wasmsdk/auth_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package main

import (
"fmt"
"sync"
"syscall/js"

"github.com/0chain/gosdk/core/sys"
Expand All @@ -13,12 +15,17 @@ type AuthCallbackFunc func(msg string) string

var authResponseC chan string
var authMsgResponseC chan string
var authMsgLockC chan struct{}
var authInitOnce sync.Once
var authMsgInitOnce sync.Once

// Register the callback function
func registerAuthorizer(this js.Value, args []js.Value) interface{} {
// Store the callback function
authCallback := parseAuthorizerCallback(args[0])
authResponseC = make(chan string, 1)
authInitOnce.Do(func() {
authResponseC = make(chan string, 1)
})

sys.Authorize = func(msg string) (string, error) {
authCallback(msg)
Expand All @@ -29,11 +36,21 @@ func registerAuthorizer(this js.Value, args []js.Value) interface{} {

func registerAuthCommon(this js.Value, args []js.Value) interface{} {
authMsgCallback := parseAuthorizerCallback(args[0])
authResponseC = make(chan string, 1)
authMsgInitOnce.Do(func() {
authMsgLockC = make(chan struct{}, 1)
authMsgResponseC = make(chan string, 1)
authMsgLockC <- struct{}{}
})

sys.AuthCommon = func(msg string) (string, error) {
fmt.Printf("try acquire lock: %p\n", &authMsgLockC)
<-authMsgLockC
fmt.Printf("acquired lock: %p\n", &authMsgLockC)
authMsgCallback(msg)
return <-authResponseC, nil
rsp := <-authMsgResponseC
fmt.Println("got auth common rsp:", rsp)
authMsgLockC <- struct{}{}
return rsp, nil
}
return nil
}
Expand Down
Loading