Add getRoot method

This commit is contained in:
p4u
2019-01-11 17:59:38 +01:00
parent a503c6555e
commit 6fd9aea6c8
2 changed files with 15 additions and 4 deletions

View File

@@ -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
@@ -121,6 +125,9 @@ func Listen(port int, proto string) {
claimHandler(w, r, "gen")})
http.HandleFunc("/checkProof", func(w http.ResponseWriter, r *http.Request) {
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")

View File

@@ -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()
}