From 04dd103bb1040faaad92d2f9a16d2b0af67b9553 Mon Sep 17 00:00:00 2001 From: p4u Date: Fri, 25 Jan 2019 19:04:58 +0100 Subject: [PATCH] Add censushttp cmd. Rename processHttp to censusmanager Signed-off-by: p4u --- cmd/censushttp/README.md | 51 ++++++++++++++++++++ cmd/censushttp/censushttp.go | 30 ++++++++++++ service/{processHttp.go => censusmanager.go} | 2 +- 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 cmd/censushttp/README.md create mode 100644 cmd/censushttp/censushttp.go rename service/{processHttp.go => censusmanager.go} (99%) diff --git a/cmd/censushttp/README.md b/cmd/censushttp/README.md new file mode 100644 index 0000000..2a06617 --- /dev/null +++ b/cmd/censushttp/README.md @@ -0,0 +1,51 @@ +# censusService +Reference implementation of a voting census service running on the Vocdoni platform + +## Census HTTP service + +#### Compile + +``` +go get github.com/vocdoni/censusService +go build -o httpService http_census_service.go +``` + +#### Usage + +``` +./httpService 1500 +2018/12/17 09:54:20 Starting process HTTP service on port 1500 +2018/12/17 09:54:20 Starting server in http mode +``` + +##### add claims + +``` +curl -d '{"processID":"GoT_Favorite","claimData":"Jon Snow"}' http://localhost:1500/addClaim +{"error":false,"response":""} +``` + +``` +curl -d '{"processID":"GoT_Favorite","claimData":"Tyrion"}' http://localhost:1500/addClaim +{"error":false,"response":""} +``` + +##### generate proof + +``` +curl -d '{"processID":"GoT_Favorite","claimData":"Jon Snow"}' http://localhost:1500/genProof +{"error":false,"response":"0x000000000000000000000000000000000000000000000000000000000000000352f3ca2aaf635ec2ae4452f6a65be7bca72678287a8bb08ad4babfcccd76c2fef1aac7675261bf6d12c746fb7907beea6d1f1635af93ba931eec0c6a747ecc37"} +``` + +##### check proof + +``` +curl -d '{"processID":"GoT_Favorite","claimData":"Jon Snow", "proofData": "0x0000000000000000000000000000000000000000000000000000000000000000000123"}' http://localhost:1500/checkProof +{"error":false,"response":"invalid"} +``` + +``` +curl -d '{"processID":"GoT_Favorite","claimData":"Jon Snow", "proofData": "0x000000000000000000000000000000000000000000000000000000000000000352f3ca2aaf635ec2ae4452f6a65be7bca72678287a8bb08ad4babfcccd76c2fef1aac7675261bf6d12c746fb7907beea6d1f1635af93ba931eec0c6a747ecc37"}' http://localhost:1500/checkProof +{"error":false,"response":"valid"} +``` + diff --git a/cmd/censushttp/censushttp.go b/cmd/censushttp/censushttp.go new file mode 100644 index 0000000..68d545a --- /dev/null +++ b/cmd/censushttp/censushttp.go @@ -0,0 +1,30 @@ +package main + +import ( + "log" + "os" + "strconv" + + censusmanager "github.com/vocdoni/dvote-census/service" +) + +func main() { + if len(os.Args) < 2 { + log.Fatal("Usage: " + os.Args[0] + " [pubKey]") + os.Exit(2) + } + port, err := strconv.Atoi(os.Args[1]) + if err != nil { + log.Fatal(err) + os.Exit(2) + } + pubK := "" + if len(os.Args) > 2 { + log.Print("Public key authentication enabled") + pubK = os.Args[2] + } + log.Print("Starting process HTTP service on port " + os.Args[1]) + censusmanager.T.Init() + censusmanager.Listen(port, "http", pubK) + +} diff --git a/service/processHttp.go b/service/censusmanager.go similarity index 99% rename from service/processHttp.go rename to service/censusmanager.go index 2b19a8b..911dae4 100644 --- a/service/processHttp.go +++ b/service/censusmanager.go @@ -1,4 +1,4 @@ -package processHttp +package censusmanager import ( "encoding/json"