From caca215c9516e8dc236a8510a6a5467c267d2331 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Wed, 28 Oct 2020 14:56:11 +0100 Subject: added consistency-proof code path --- handler.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'handler.go') diff --git a/handler.go b/handler.go index ee1eae6..119f65c 100644 --- a/handler.go +++ b/handler.go @@ -174,6 +174,30 @@ func getProofByHash(ctx context.Context, i *Instance, w http.ResponseWriter, r * // getConsistencyProof provides a consistency proof between two STHs func getConsistencyProof(ctx context.Context, i *Instance, w http.ResponseWriter, r *http.Request) (int, error) { glog.Info("in getConsistencyProof") + request, err := NewGetConsistencyProofRequest(r) + if err != nil { + return http.StatusBadRequest, err + } // request can be decoded and is valid + + trillianRequest := trillian.GetConsistencyProofRequest{ + LogId: i.LogParameters.TreeId, + FirstTreeSize: int64(request.First), + SecondTreeSize: int64(request.Second), + } + trillianResponse, err := i.Client.GetConsistencyProof(ctx, &trillianRequest) + if err != nil { + return http.StatusInternalServerError, fmt.Errorf("failed fetching consistency proof from Trillian backend: %v", err) + } + // TODO: santity-checks? + + response, err := NewGetConsistencyProofResponse(i.LogParameters.LogId, request.First, request.Second, trillianResponse.Proof) + if err != nil { + return http.StatusInternalServerError, fmt.Errorf("failed creating get-consistency-proof response: %v", err) + } + if err := WriteJsonResponse(response, w); err != nil { + return http.StatusInternalServerError, err + } + return http.StatusOK, nil return http.StatusOK, nil // TODO } -- cgit v1.2.3