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