From 29e4db3a1dd0fedb67731c9df5ca1edb4b5869b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20L=C3=A1zaro?= Date: Thu, 4 Jul 2024 20:23:48 -0300 Subject: [PATCH 1/2] Correction of the getBlockByHash function - QueryQSCC Handler: hashBytes, err := hex.DecodeString(hash), passed as a parameter to the chaincode.QueryGateway function, assigned to result. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matheus Lázaro --- ccapi/handlers/qscc.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ccapi/handlers/qscc.go b/ccapi/handlers/qscc.go index 22a486d..d999d39 100644 --- a/ccapi/handlers/qscc.go +++ b/ccapi/handlers/qscc.go @@ -4,7 +4,7 @@ import ( "encoding/hex" "fmt" "net/http" - + "github.com/gin-gonic/gin" "github.com/hyperledger-labs/ccapi/chaincode" "github.com/hyperledger-labs/ccapi/common" @@ -24,8 +24,8 @@ func QueryQSCC(c *gin.Context) { switch txname { case "getBlockByNumber": getBlockByNumber(c, channelName) - // case "getBlockByHash": - // getBlockByHash(c, channelName) + case "getBlockByHash": + getBlockByHash(c, channelName) case "getTransactionByID": getTransactionByID(c, channelName) case "getChainInfo": @@ -139,7 +139,15 @@ func getBlockByHash(c *gin.Context, channelName string) { return } - result, err := chaincode.QueryGateway(channelName, "qscc", "GetBlockByHash", user, []string{channelName, hash}) + hashBytes, err := hex.DecodeString(hash) + + if err != nil { + common.Abort(c, http.StatusBadRequest, fmt.Errorf("invalid hash format: %s", hash)) + return + } + + result, err := chaincode.QueryGateway(channelName, "qscc", "GetBlockByHash", user, []string{channelName, string(hashBytes)}) + if err != nil { err, status := common.ParseError(err) common.Abort(c, status, err) @@ -440,4 +448,4 @@ func decodeProcessedTransaction(t []byte) (map[string]interface{}, error) { } return processedTransactionMap, nil -} +} \ No newline at end of file From dc740e5a7d1866b44ba8ce971b9447e97436d014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20L=C3=A1zaro?= Date: Sun, 7 Jul 2024 18:57:58 -0300 Subject: [PATCH 2/2] Correction in the Swagger documentation for the getBlockByHash function - QueryQSCC Handler: hashBytes, err := hex.DecodeString(hash), passed as a parameter to the chaincode.QueryGateway function, assigned to the result. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matheus Lázaro --- ccapi/docs/swagger.yaml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/ccapi/docs/swagger.yaml b/ccapi/docs/swagger.yaml index 074cb7b..ca2113b 100644 --- a/ccapi/docs/swagger.yaml +++ b/ccapi/docs/swagger.yaml @@ -947,6 +947,42 @@ paths: - application/json produces: - application/json + /{channelName}/qscc/getBlockByHash: + get: + summary: Get block by hash + description: Retrieves a block by its hash from the specified channel. + tags: + - Blockchain + security: + - basicAuth: [] + parameters: + - name: channelName + in: path + required: true + schema: + type: string + example: mainchannel + description: Name of the channel. + - name: hash + in: query + required: true + schema: + type: string + example: dbd2b14fb3d61b7aeac3add76f99cd9b47850c7c95ca5e489696a6b543fc6b2d + description: The hash of the block to be retrieved. + responses: + "200": + description: Successful response + content: + application/json: + schema: + type: object + "400": + description: Bad request + "404": + description: Block not found + "500": + description: Internal server error /{channelName}/qscc/getChainInfo: get: summary: Get chain info