Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions pdp/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,31 @@ func (p *PDPService) handleDeleteDataSetPiece(w http.ResponseWriter, r *http.Req
http.Error(w, "Data set not found", http.StatusNotFound)
return
}
type DeletePiecePayload struct {
ExtraData *string `json:"extraData"`
}
var payload DeletePiecePayload
err = json.NewDecoder(r.Body).Decode(&payload)

// if the request body is empty, json.Decode will return io.EOF
if err != nil && !errors.Is(err, io.EOF) {
http.Error(w, "Invalid request body: "+err.Error(), http.StatusBadRequest)
return
}
defer func() {
_ = r.Body.Close()
}()

var extraDataBytes []byte
if payload.ExtraData != nil {
extraDataHexStr := *payload.ExtraData
extraDataBytes, err = hex.DecodeString(strings.TrimPrefix(extraDataHexStr, "0x"))
if err != nil {
log.Errorf("Failed to decode hex extraData: %v", err)
http.Error(w, "Invalid extraData format (must be hex encoded)", http.StatusBadRequest)
return
}
}

// Get the ABI and pack the transaction data
abiData, err := contract.PDPVerifierMetaData.GetAbi()
Expand All @@ -1312,7 +1337,7 @@ func (p *PDPService) handleDeleteDataSetPiece(w http.ResponseWriter, r *http.Req
data, err := abiData.Pack("schedulePieceDeletions",
big.NewInt(int64(dataSetId)),
[]*big.Int{big.NewInt(int64(pieceID))},
[]byte{},
[]byte(extraDataBytes),
)
if err != nil {
http.Error(w, "Failed to pack method call: "+err.Error(), http.StatusInternalServerError)
Expand Down Expand Up @@ -1364,8 +1389,17 @@ func (p *PDPService) handleDeleteDataSetPiece(w http.ResponseWriter, r *http.Req
return
}

// Return 204 No Content on successful deletion
w.WriteHeader(http.StatusNoContent)
response := struct {
TxHash string `json:"txHash"`
}{
TxHash: txHashLower,
}
// Send JSON response
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(response); err != nil {
http.Error(w, "Failed to encode response: "+err.Error(), http.StatusInternalServerError)
return
}
}

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