From b00b62a128e8fcc815453308482624abf044b92b Mon Sep 17 00:00:00 2001 From: Konst Date: Mon, 9 Dec 2024 19:18:18 +0300 Subject: [PATCH] Added BlobProof response type --- cmd/api/handler/namespace.go | 2 +- cmd/api/handler/responses/blobProof.go | 33 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 cmd/api/handler/responses/blobProof.go diff --git a/cmd/api/handler/namespace.go b/cmd/api/handler/namespace.go index d5752f09..529ad284 100644 --- a/cmd/api/handler/namespace.go +++ b/cmd/api/handler/namespace.go @@ -804,5 +804,5 @@ func (handler *NamespaceHandler) BlobProofs(c echo.Context) error { return handleError(c, err, handler.namespace) } - return c.JSON(http.StatusOK, proofs.ShareProofs) + return c.JSON(http.StatusOK, responses.NewProofs(proofs.ShareProofs)) } diff --git a/cmd/api/handler/responses/blobProof.go b/cmd/api/handler/responses/blobProof.go new file mode 100644 index 00000000..9becf993 --- /dev/null +++ b/cmd/api/handler/responses/blobProof.go @@ -0,0 +1,33 @@ +// SPDX-FileCopyrightText: 2024 PK Lab AG +// SPDX-License-Identifier: MIT + +package responses + +import ( + "encoding/base64" + "github.com/celestiaorg/celestia-app/v3/pkg/proof" +) + +type BlobProof struct { + Start int32 `example:"0" format:"integer" json:"start" swaggertype:"integer"` + End int32 `example:"16" format:"integer" json:"end" swaggertype:"integer"` + Nodes []string `json:"nodes"` +} + +func NewProofs(proofs []*proof.NMTProof) []BlobProof { + result := make([]BlobProof, len(proofs)) + + for i := range proofs { + proofNodes := make([]string, len(proofs[i].Nodes)) + for j, node := range proofs[i].Nodes { + proofNodes[j] = base64.StdEncoding.EncodeToString(node) + } + + result[i] = BlobProof{ + Start: proofs[i].Start, + End: proofs[i].End, + Nodes: proofNodes, + } + } + return result +}