From 6fd9aea6c8989000210b15034cdde91bf1837917 Mon Sep 17 00:00:00 2001 From: p4u Date: Fri, 11 Jan 2019 17:59:38 +0100 Subject: [PATCH] Add getRoot method --- service/processHttp.go | 15 +++++++++++---- tree/tree.go | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/service/processHttp.go b/service/processHttp.go index 4c5f460..df19a7b 100644 --- a/service/processHttp.go +++ b/service/processHttp.go @@ -79,6 +79,10 @@ func claimHandler(w http.ResponseWriter, req *http.Request, op string) { resp.Response, err = T.GenProof([]byte(c.ClaimData)) } + if op == "root" { + resp.Response = T.GetRoot() + } + if op == "check" { if len(c.ProofData) < 1 { resp.Error = true @@ -109,18 +113,21 @@ func claimHandler(w http.ResponseWriter, req *http.Request, op string) { func Listen(port int, proto string) { srv := &http.Server{ Addr: fmt.Sprintf(":%d", port), - ReadHeaderTimeout: 4 * time.Second, + ReadHeaderTimeout: 4 * time.Second, ReadTimeout: 4 * time.Second, WriteTimeout: 4 * time.Second, IdleTimeout: 3 * time.Second, } http.HandleFunc("/addClaim", func(w http.ResponseWriter, r *http.Request) { - claimHandler(w, r, "add")}) + claimHandler(w, r, "add")}) http.HandleFunc("/genProof", func(w http.ResponseWriter, r *http.Request) { - claimHandler(w, r, "gen")}) + claimHandler(w, r, "gen")}) http.HandleFunc("/checkProof", func(w http.ResponseWriter, r *http.Request) { - claimHandler(w, r, "check")}) + claimHandler(w, r, "check")}) + http.HandleFunc("/getRoot", func(w http.ResponseWriter, r *http.Request) { + claimHandler(w, r, "root")}) + if proto == "https" { log.Print("Starting server in https mode") diff --git a/tree/tree.go b/tree/tree.go index 390af5b..74263a3 100644 --- a/tree/tree.go +++ b/tree/tree.go @@ -60,3 +60,7 @@ func (t *Tree) CheckProof(data []byte, mpHex string) (bool, error) { claim := mkcore.NewGenericClaim(t.Namespace, "default", data, nil) return merkletree.CheckProof(t.Tree.Root(), mp, claim.Hi(), claim.Ht(), t.Tree.NumLevels()), nil } + +func (t *Tree) GetRoot() (string) { + return t.Tree.Root().Hex() +}