-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathsample.go
47 lines (40 loc) · 1.17 KB
/
sample.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"bufio"
"fmt"
"gopkg.in/zeromq/goczmq.v4"
"log"
"os"
"strings"
"time"
)
func main() {
ep := "tcp://34.71.52.251:40000"
sample := goczmq.NewReqChanneler(ep)
if sample == nil {
log.Fatal("Failed to subscribe to endpoint: ", ep)
}
defer sample.Destroy()
// Prompt the user for input
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter proof data (or press Enter to use default): ")
input, _ := reader.ReadString('\n')
input = strings.TrimSpace(input)
// Let the socket connect
time.Sleep(5 * time.Second)
// Prepare the proof data
var proof [][]byte
if input == "" {
// Use default value if no input is provided
proof = [][]byte{[]byte("proofblock"), []byte("timestamp :" + time.Now().String()), []byte("0x0000000000000000000")}
} else {
// Use user-provided input
proof = [][]byte{[]byte("proofblock"), []byte(input), []byte("!!!!!")}
}
// Send the proof
sample.SendChan <- proof
fmt.Printf("Proof sent: %s\n", proof)
// Receive the response
resp := <-sample.RecvChan
fmt.Printf("Response received: %s\n", resp)
}