diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..27c9a1a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +vouchers/ +ceremony-client \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a6fa3c8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM golang:1.18 + +WORKDIR /app + +COPY go.mod go.sum ./ + +RUN go mod download + +# Add an entry to .bash_history so we can just run `make dev` and hit up to test the cli +RUN echo 'go run ./... test-voucher.hex' >> ~/.bash_history + +COPY . . + +RUN CGO_ENABLED=0 GOOS=linux go build -o ceremony-client + +CMD ./ceremony-client \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..036ec36 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +IMAGE_TAG := quilibrium-ceremony-client + +build-docker: + docker build -t $(IMAGE_TAG) . + +bash: + docker run --rm -it $(IMAGE_TAG) bash + +participate: build-docker + docker run --rm -it -v $(PWD)/vouchers:/vouchers $(IMAGE_TAG) ./ceremony-client "/vouchers/quil-voucher-$(shell date +'%m.%d.%y-%H:%M:%S').hex" + +dev: + docker run --rm -it -v $(PWD):$(PWD) --workdir $(PWD) $(IMAGE_TAG) bash \ No newline at end of file diff --git a/README.md b/README.md index 1c7288b..499eae4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ # ceremonyclient -KZG Ceremony client for Quilibrium. Run with `go run ./... ` or omit the filename to write to quil_voucher.hex. +KZG Ceremony client for Quilibrium. + +# Running + +Run with `go run ./... ` or omit the filename to write to quil_voucher.hex. + +If you have docker installed you can participate in the ceremony by simply running `make participate`. Your voucher will be written to `vouchers/`. \ No newline at end of file diff --git a/bootstrap.go b/bootstrap.go index 23ae6a9..d56ec53 100644 --- a/bootstrap.go +++ b/bootstrap.go @@ -78,7 +78,8 @@ func JoinLobby() { client := http.DefaultClient resp, err := client.Do(req) - fmt.Println("connected") + + fmt.Println("Connected to sequencer!") if err != nil { panic(err) diff --git a/main.go b/main.go index 3f2a4d6..2fe6dd8 100644 --- a/main.go +++ b/main.go @@ -11,13 +11,7 @@ func main() { PrintLogo() PrintVersion() - fmt.Println("Checking sequencer...") - state := GetSequencerState() - for state != SEQUENCER_ACCEPTING { - fmt.Println("Sequencer currently not accepting new contributions, waiting...") - time.Sleep(30 * time.Second) - state = GetSequencerState() - } + WaitForSequencerToBeReady() JoinLobby() Bootstrap() @@ -26,7 +20,33 @@ func main() { ContributeAndGetVoucher() } +func WaitForSequencerToBeReady() { + spinnerChars := []string{"⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"} + spinnerIndex := 0 + attempts := 0 + removeLine := "\u001B[A\u001B[2K" + state := GetSequencerState() + for state != SEQUENCER_ACCEPTING { + message := "Sequencer currently not accepting new contributions, waiting..." + status := fmt.Sprintf("[Attempt %d - Last Checked: %s]", attempts, time.Now().String()) + + fmt.Printf("\r%s", removeLine) + fmt.Printf("%s\n", message+spinnerChars[spinnerIndex]) + fmt.Printf(" |- %s", status) + + spinnerIndex = (spinnerIndex + 1) % len(spinnerChars) + attempts += 1 + + time.Sleep(5 * time.Second) + state = GetSequencerState() + } + + fmt.Println() + fmt.Println("Sequencer is ready for contributions!") +} + func PrintLogo() { + fmt.Println() fmt.Println(" %#########") fmt.Println(" #############################") fmt.Println(" ########################################&") @@ -64,4 +84,6 @@ func PrintLogo() { func PrintVersion() { fmt.Println(" ") fmt.Println(" Quilibrium Ceremony Client - CLI - v1.0.1") + fmt.Println() + fmt.Println() }