From 5cc2cfdf4c8d98c9092e2035e97a4f1a7f2dd286 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Mon, 9 Dec 2024 19:31:53 +0300 Subject: [PATCH] Added BlobProof response type (#313) * Added BlobProof response type * Linter fix * Changed BlobProof.Nodes field type to [][]byte --- cmd/api/handler/namespace.go | 2 +- cmd/api/handler/responses/blobProof.go | 26 ++++++++++++++++++++++++++ 2 files changed, 27 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..a8f0fc97 --- /dev/null +++ b/cmd/api/handler/responses/blobProof.go @@ -0,0 +1,26 @@ +// SPDX-FileCopyrightText: 2024 PK Lab AG +// SPDX-License-Identifier: MIT + +package responses + +import ( + "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 [][]byte `json:"nodes"` +} + +func NewProofs(proofs []*proof.NMTProof) []BlobProof { + result := make([]BlobProof, len(proofs)) + for i := range proofs { + result[i] = BlobProof{ + Start: proofs[i].Start, + End: proofs[i].End, + Nodes: proofs[i].Nodes, + } + } + return result +}