mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-18 20:54:20 +01:00
* Add gRPC, REST, and gRPC-Web clients for server access This commit introduces clients for gRPC, REST, and gRPC-Web to access the server. - gRPC client: Includes additional argument opts ...grpc.CallOption in the interface for future extensibility. - REST client: Factory function accepts http.Client as an argument to allow user customization. - gRPC-Web client: Added a Log method for fast debugging in JavaScript. The decision to use different interfaces for each client type is to accommodate specific features and extensibility requirements for each protocol. * remove grpc web * generate rest * use grpc sdk in CLI * temp wasm * ark sdk * renaming * pr review refactor * pr review refactor * walletStore & configStore * ark sdk wasm wrapper * handle event stream with rest * wip on supporting rest * store init * simulate event stream with rest * fix rest sdk wip * Fix returning forfeit txs in round event * wasm first working e2e example * pr review refactor * pr review refactor * pr review refactor * Fixes --------- Co-authored-by: altafan <18440657+altafan@users.noreply.github.com>
96 lines
2.4 KiB
Go
96 lines
2.4 KiB
Go
package arksdkwasm
|
|
|
|
import (
|
|
"context"
|
|
"syscall/js"
|
|
|
|
arksdk "github.com/ark-network/ark-sdk"
|
|
)
|
|
|
|
func GetAspUrlWrapper() js.Func {
|
|
return js.FuncOf(func(this js.Value, p []js.Value) interface{} {
|
|
url, _ := inMemoryConfigStore.GetAspUrl(context.Background())
|
|
return js.ValueOf(url)
|
|
})
|
|
}
|
|
|
|
func GetAspPubKeyHexWrapper() js.Func {
|
|
return js.FuncOf(func(this js.Value, p []js.Value) interface{} {
|
|
key, _ := inMemoryConfigStore.GetAspPubKeyHex(context.Background())
|
|
return js.ValueOf(key)
|
|
})
|
|
}
|
|
|
|
func GetTransportProtocolWrapper() js.Func {
|
|
return js.FuncOf(func(this js.Value, p []js.Value) interface{} {
|
|
protocol, _ := inMemoryConfigStore.GetTransportProtocol(context.Background())
|
|
return js.ValueOf(int(protocol))
|
|
})
|
|
}
|
|
|
|
func GetExplorerUrlWrapper() js.Func {
|
|
return js.FuncOf(func(this js.Value, p []js.Value) interface{} {
|
|
url, _ := inMemoryConfigStore.GetExplorerUrl(context.Background())
|
|
return js.ValueOf(url)
|
|
})
|
|
}
|
|
|
|
func GetNetworkWrapper() js.Func {
|
|
return js.FuncOf(func(this js.Value, p []js.Value) interface{} {
|
|
network, _ := inMemoryConfigStore.GetNetwork(context.Background())
|
|
return js.ValueOf(network)
|
|
})
|
|
}
|
|
|
|
func SetAspUrlWrapper() js.Func {
|
|
return js.FuncOf(func(this js.Value, p []js.Value) interface{} {
|
|
aspUrl := p[0].String()
|
|
inMemoryConfigStore.SetAspUrl(aspUrl)
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func SetAspPubKeyHexWrapper() js.Func {
|
|
return js.FuncOf(func(this js.Value, p []js.Value) interface{} {
|
|
aspPubKeyHex := p[0].String()
|
|
inMemoryConfigStore.SetAspPubKeyHex(aspPubKeyHex)
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func SetTransportProtocolWrapper() js.Func {
|
|
return js.FuncOf(func(this js.Value, p []js.Value) interface{} {
|
|
protocol := arksdk.TransportProtocol(p[0].Int())
|
|
inMemoryConfigStore.SetTransportProtocol(protocol)
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func SetExplorerUrlWrapper() js.Func {
|
|
return js.FuncOf(func(this js.Value, p []js.Value) interface{} {
|
|
explorerUrl := p[0].String()
|
|
inMemoryConfigStore.SetExplorerUrl(explorerUrl)
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func SetNetworkWrapper() js.Func {
|
|
return js.FuncOf(func(this js.Value, p []js.Value) interface{} {
|
|
network := p[0].String()
|
|
inMemoryConfigStore.SetNetwork(network)
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func SaveWrapper() js.Func {
|
|
return js.FuncOf(func(this js.Value, p []js.Value) interface{} {
|
|
err := inMemoryConfigStore.Save(context.Background())
|
|
if err != nil {
|
|
return js.ValueOf(map[string]interface{}{
|
|
"error": err.Error(),
|
|
})
|
|
}
|
|
return nil
|
|
})
|
|
}
|