Skip to content
Snippets Groups Projects
Commit 3deaef1b authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

began process of integratign the xxDK

parent a06b3cb9
No related branches found
No related tags found
No related merge requests found
client.go 0 → 100644
package main
import (
"gitlab.com/elixxir/client/api"
"gitlab.com/elixxir/client/interfaces/params"
"io/ioutil"
"gitlab.com/elixxir/client/single"
"os"
jww "github.com/spf13/jwalterweatherman"
"time"
)
func initClient() (*api.Client, *single.Manager) {
createClient()
pass := password
storeDir := session
netParams := params.GetDefaultNetwork()
client, err := api.Login(storeDir, []byte(pass), netParams)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
_, err = client.StartNetworkFollower()
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
// Wait until connected or crash on timeout
connected := make(chan bool, 10)
client.GetHealth().AddChannel(connected)
waitUntilConnected(connected)
// Make single-use manager and start receiving process
singleMng := single.NewManager(client)
client.AddService(singleMng.StartProcesses)
return client, singleMng
}
func createClient() *api.Client {
pass := password
storeDir := session
//create a new client if none exist
if _, err := os.Stat(storeDir); os.IsNotExist(err) {
// Load NDF
ndfJSON, err := ioutil.ReadFile(ndfPath)
if err != nil {
jww.FATAL.Panicf(err.Error())
}
err = api.NewClient(string(ndfJSON), storeDir,
[]byte(pass), "")
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
}
netParams := params.GetDefaultNetwork()
client, err := api.OpenClient(storeDir, []byte(pass), netParams)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
return client
}
func waitUntilConnected(connected chan bool) {
timeoutTimer := time.NewTimer(90 * time.Second)
isConnected := false
//Wait until we connect or panic if we can't by a timeout
for !isConnected {
select {
case isConnected = <-connected:
jww.INFO.Printf("Network Status: %v\n",
isConnected)
break
case <-timeoutTimer.C:
jww.FATAL.Panic("timeout on connection")
}
}
// Now start a thread to empty this channel and update us
// on connection changes for debugging purposes.
go func() {
prev := true
for {
select {
case isConnected = <-connected:
if isConnected != prev {
prev = isConnected
jww.INFO.Printf(
"Network Status Changed: %v\n",
isConnected)
}
break
}
}
}()
}
\ No newline at end of file
...@@ -3,11 +3,10 @@ module gitlab.com/elixxir/xx-coin-game-ui ...@@ -3,11 +3,10 @@ module gitlab.com/elixxir/xx-coin-game-ui
go 1.13 go 1.13
require ( require (
github.com/davecgh/go-spew v1.1.1 // indirect github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 // indirect
github.com/dtylman/gowd v0.0.0-20190619113956-15e38debca22 github.com/dtylman/gowd v0.0.0-20190619113956-15e38debca22
github.com/kr/text v0.2.0 // indirect github.com/spf13/jwalterweatherman v1.1.0
github.com/stretchr/testify v1.6.1 // indirect github.com/ugorji/go v1.1.4 // indirect
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gitlab.com/elixxir/client v1.5.1-0.20210317220715-139e06c28b9b
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
) )
This diff is collapsed.
...@@ -2,16 +2,32 @@ package main ...@@ -2,16 +2,32 @@ package main
import ( import (
"github.com/dtylman/gowd" "github.com/dtylman/gowd"
"gitlab.com/elixxir/client/interfaces/contact"
"gitlab.com/elixxir/client/single"
"io/ioutil"
"os"
"fmt" "fmt"
"time" "time"
"github.com/dtylman/gowd/bootstrap" "github.com/dtylman/gowd/bootstrap"
"gitlab.com/elixxir/client/api"
"gitlab.com/elixxir/client/interfaces/params"
jww "github.com/spf13/jwalterweatherman"
) )
var password string
var session string
var ndfPath string
var singleMngr *single.Manager
var botContact contact.Contact
var body *gowd.Element var body *gowd.Element
func main() { func main() {
_, singleMngr = initClient()
//creates a new bootstrap fluid container //creates a new bootstrap fluid container
body = bootstrap.NewContainer(false) body = bootstrap.NewContainer(false)
...@@ -60,6 +76,20 @@ func btnClicked(sender *gowd.Element, event *gowd.EventElement) { ...@@ -60,6 +76,20 @@ func btnClicked(sender *gowd.Element, event *gowd.EventElement) {
// makes the body stop responding to user events // makes the body stop responding to user events
body.Disable() body.Disable()
ethAddr := body.Find("ethaddr").GetValue()
sendText := body.Find("message").GetValue()
//send the message
message := fmt.Sprintf("%s:%s",ethAddr,sendText)
replyFunc := func(payload []byte, err error){
}
err := singleMngr.TransmitSingleUse(botContact, []byte(message),
"xxCoinGame", 10, replyFunc, 30*time.Second)
// clean up - remove the added elements // clean up - remove the added elements
defer func() { defer func() {
sender.SetText("Start") sender.SetText("Start")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment