factor out more functions

This commit is contained in:
Tim Williams 2018-07-27 22:25:58 -04:00
parent aff5dbd48d
commit 142140a3ef

View file

@ -5,11 +5,11 @@ package main
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"github.com/ShyftNetwork/go-empyrean/common/hexutil"
"github.com/ShyftNetwork/go-empyrean/crypto" "github.com/ShyftNetwork/go-empyrean/crypto"
"io" "io"
"net" "net"
"os" "os"
"github.com/ShyftNetwork/go-empyrean/common/hexutil"
) )
const ( const (
@ -53,24 +53,24 @@ func main() {
func handleRequest(conn net.Conn) { func handleRequest(conn net.Conn) {
messages := make(chan []byte) messages := make(chan []byte)
checkBalanceChan := make(chan []byte)
go readerConn(conn, messages) go readerConn(conn, messages)
go handleMessages(messages) go handleMessages(messages, checkBalanceChan)
go checkBalance(checkBalanceChan)
key, _ := crypto.HexToECDSA(testPrivHex) key, _ := crypto.HexToECDSA(testPrivHex)
f_msg := "Hello World" f_msg := "Hello World"
first_message := []byte(f_msg) first_message := []byte(f_msg)
new_msg2 := crypto.Keccak256(first_message) new_msg2 := crypto.Keccak256(first_message)
fmt.Println("HASH IS ::", hexutil.Encode(new_msg2))
//send_message := append(new_msg2, []byte{byte(10)}...) //send_message := append(new_msg2, []byte{byte(10)}...)
new_sig, err := crypto.Sign(new_msg2, key) new_sig, err := crypto.Sign(new_msg2, key)
if err != nil { if err != nil {
fmt.Println("The crypto.Sign err is ", err) fmt.Println("The crypto.Sign err is ", err)
} }
hex_sig := hexutil.Encode(new_sig)
fmt.Println("HEX SIG ::", hex_sig)
conn.Write([]byte("Broadcasting Message")) conn.Write([]byte("Broadcasting Message"))
conn.Write([]byte("\n")) conn.Write([]byte("\n"))
@ -78,10 +78,9 @@ func handleRequest(conn net.Conn) {
conn.Write([]byte("\n")) conn.Write([]byte("\n"))
conn.Write(new_sig) conn.Write(new_sig)
conn.Write([]byte("\n")) conn.Write([]byte("\n"))
} }
func handleMessages(channel chan []byte) { func handleMessages(channel chan []byte, checkBalancesChan chan []byte) {
var prevMsg []byte var prevMsg []byte
var addressOfClient []byte var addressOfClient []byte
var signatureFromClient []byte var signatureFromClient []byte
@ -95,6 +94,7 @@ func handleMessages(channel chan []byte) {
s := string(prevMsg[:]) s := string(prevMsg[:])
if s == "-- ADDRESS --" { if s == "-- ADDRESS --" {
addressOfClient = msg addressOfClient = msg
checkBalancesChan <- addressOfClient
} }
if s == "-- SIGNATURE --" { if s == "-- SIGNATURE --" {
signatureFromClient = msg signatureFromClient = msg
@ -154,3 +154,8 @@ func readerConn(conn net.Conn, channel chan []byte) {
channel <- msg channel <- msg
} }
} }
func checkBalance(checkBalanceChan chan []byte) {
address := <-checkBalanceChan
fmt.Println("The address for balance check is ", address)
}