diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3520d3e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +ceremony-client +quil_voucher.hex \ 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..9081699 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +IMAGE_TAG := quillibrium-ceremony-client + +build-docker: + docker build -t $(IMAGE_TAG) . + +bash: + docker run --rm -it $(IMAGE_TAG) bash + +participate: + docker run --rm -it $(IMAGE_TAG) ./ceremony-client "quill-voucher-$(shell date +'%y.%m.%d-%H:%M:%S')" + +dev: + docker run --rm -it -v $(PWD):$(PWD) --workdir $(PWD) $(IMAGE_TAG) bash \ 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 26f23d4..ba835cb 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(1 * time.Second) - state = GetSequencerState() - } + WaitForSequencerToBeReady() JoinLobby() Bootstrap() @@ -26,6 +20,30 @@ 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(1 * time.Second) + state = GetSequencerState() + } + + fmt.Println("Sequencer is ready for contributions!") +} + func PrintLogo() { fmt.Println(" %#########") fmt.Println(" #############################") @@ -64,4 +82,6 @@ func PrintLogo() { func PrintVersion() { fmt.Println(" ") fmt.Println(" Quilibrium Ceremony Client - CLI - v1.0.1") + fmt.Println() + fmt.Println() } diff --git a/quil_voucher.hex b/quil_voucher.hex deleted file mode 100644 index 0ace8bd..0000000 --- a/quil_voucher.hex +++ /dev/null @@ -1 +0,0 @@ -654990bfacd0d2702f318089f73b838c64f79b0369840bdff6e1f6b8c3aa2698585c61a0e35794afb9365a4f5ed9c841a62eb9f35d29aa50486780552dd2293cb865905d120047905b98f55bb96a8e2b1e960807a3a0f5b236b7819799a64f7c0a52f8c754dc5086373bb0ce2702ebfba900 \ No newline at end of file