mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
refactor reading of socket into a function
This commit is contained in:
parent
8cc8da8ea5
commit
bd83244bba
1 changed files with 66 additions and 65 deletions
|
|
@ -3,7 +3,6 @@ package main
|
|||
//@NOTE SHYFT main func for api, sets up router and spins up a server
|
||||
//to run server 'go run shyftRingWalletConn/*.go'
|
||||
import (
|
||||
//"bytes"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/ShyftNetwork/go-empyrean/common/hexutil"
|
||||
|
|
@ -53,7 +52,33 @@ func main() {
|
|||
// Handles incoming requests.
|
||||
func handleRequest(conn net.Conn) {
|
||||
|
||||
go func() {
|
||||
go readerConn(conn)
|
||||
|
||||
key, _ := crypto.HexToECDSA(testPrivHex)
|
||||
|
||||
f_msg := "Hello World"
|
||||
first_message := []byte(f_msg)
|
||||
new_msg2 := crypto.Keccak256(first_message)
|
||||
fmt.Println("HASH IS ::", hexutil.Encode(new_msg2))
|
||||
|
||||
//send_message := append(new_msg2, []byte{byte(10)}...)
|
||||
new_sig, err := crypto.Sign(new_msg2, key)
|
||||
if err != nil {
|
||||
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("\n"))
|
||||
conn.Write([]byte(f_msg))
|
||||
conn.Write([]byte("\n"))
|
||||
conn.Write(new_sig)
|
||||
conn.Write([]byte("\n"))
|
||||
|
||||
}
|
||||
|
||||
func readerConn(conn net.Conn) {
|
||||
var prevMsg []byte
|
||||
var addressOfClient []byte
|
||||
var signatureFromClient []byte
|
||||
|
|
@ -116,28 +141,4 @@ func handleRequest(conn net.Conn) {
|
|||
fmt.Println("ADDRESS IS ::", recoveredAddr.Hex())
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
key, _ := crypto.HexToECDSA(testPrivHex)
|
||||
|
||||
f_msg := "Hello World"
|
||||
first_message := []byte(f_msg)
|
||||
new_msg2 := crypto.Keccak256(first_message)
|
||||
fmt.Println("HASH IS ::", hexutil.Encode(new_msg2))
|
||||
|
||||
//send_message := append(new_msg2, []byte{byte(10)}...)
|
||||
new_sig, err := crypto.Sign(new_msg2, key)
|
||||
if err != nil {
|
||||
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("\n"))
|
||||
conn.Write([]byte(f_msg))
|
||||
conn.Write([]byte("\n"))
|
||||
conn.Write(new_sig)
|
||||
conn.Write([]byte("\n"))
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue