Skip to content

Commit f176f5f

Browse files
committed
feat(pdp): handle extraData in handleDeleteDataSetPiece
A valid extraData needs to be provided by the client for FWSS to allow PDP to delete the data. Signed-off-by: Jakub Sztandera <[email protected]>
1 parent 91aff56 commit f176f5f

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

pdp/handlers.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,31 @@ func (p *PDPService) handleDeleteDataSetPiece(w http.ResponseWriter, r *http.Req
13001300
http.Error(w, "Data set not found", http.StatusNotFound)
13011301
return
13021302
}
1303+
type DeletePiecePayload struct {
1304+
ExtraData *string `json:"extraData"`
1305+
}
1306+
var payload DeletePiecePayload
1307+
err = json.NewDecoder(r.Body).Decode(&payload)
1308+
1309+
// if the request body is empty, json.Decode will return io.EOF
1310+
if err != nil && !errors.Is(err, io.EOF) {
1311+
http.Error(w, "Invalid request body: "+err.Error(), http.StatusBadRequest)
1312+
return
1313+
}
1314+
defer func() {
1315+
_ = r.Body.Close()
1316+
}()
1317+
1318+
var extraDataBytes []byte
1319+
if payload.ExtraData != nil {
1320+
extraDataHexStr := *payload.ExtraData
1321+
extraDataBytes, err = hex.DecodeString(strings.TrimPrefix(extraDataHexStr, "0x"))
1322+
if err != nil {
1323+
log.Errorf("Failed to decode hex extraData: %v", err)
1324+
http.Error(w, "Invalid extraData format (must be hex encoded)", http.StatusBadRequest)
1325+
return
1326+
}
1327+
}
13031328

13041329
// Get the ABI and pack the transaction data
13051330
abiData, err := contract.PDPVerifierMetaData.GetAbi()
@@ -1312,7 +1337,7 @@ func (p *PDPService) handleDeleteDataSetPiece(w http.ResponseWriter, r *http.Req
13121337
data, err := abiData.Pack("schedulePieceDeletions",
13131338
big.NewInt(int64(dataSetId)),
13141339
[]*big.Int{big.NewInt(int64(pieceID))},
1315-
[]byte{},
1340+
[]byte(extraDataBytes),
13161341
)
13171342
if err != nil {
13181343
http.Error(w, "Failed to pack method call: "+err.Error(), http.StatusInternalServerError)
@@ -1364,8 +1389,17 @@ func (p *PDPService) handleDeleteDataSetPiece(w http.ResponseWriter, r *http.Req
13641389
return
13651390
}
13661391

1367-
// Return 204 No Content on successful deletion
1368-
w.WriteHeader(http.StatusNoContent)
1392+
response := struct {
1393+
TxHash string `json:"txHash"`
1394+
}{
1395+
TxHash: txHashLower,
1396+
}
1397+
// Send JSON response
1398+
w.Header().Set("Content-Type", "application/json")
1399+
if err := json.NewEncoder(w).Encode(response); err != nil {
1400+
http.Error(w, "Failed to encode response: "+err.Error(), http.StatusInternalServerError)
1401+
return
1402+
}
13691403
}
13701404

13711405
func (p *PDPService) handleGetDataSetPiece(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)