Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PSL-1228] fix burn-txid field for single file registration #905

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
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
20 changes: 17 additions & 3 deletions walletnode/api/services/cascade.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,15 @@ func (service *CascadeAPIHandler) StartProcessing(ctx context.Context, p *cascad
return nil, cascade.MakeInternalServerError(err)
}

if p.BurnTxid == nil {
return nil, cascade.MakeInternalServerError(errors.New("BurnTxId must not be null for single related file"))
burnTxID, err := validateBurnTxID(p.BurnTxid, p.BurnTxids)
if err != nil {
log.WithContext(ctx).WithError(err).Error("error validating burn-txid from the payload")
return nil, cascade.MakeInternalServerError(err)
}

addTaskPayload := &common.AddTaskPayload{
FileID: p.FileID,
BurnTxid: p.BurnTxid,
BurnTxid: &burnTxID,
AppPastelID: p.AppPastelID,
MakePubliclyAccessible: p.MakePubliclyAccessible,
Key: p.Key,
Expand Down Expand Up @@ -233,6 +235,18 @@ func isDuplicateExists(burnTxIDs []string) bool {
return false
}

func validateBurnTxID(burnTxID *string, burnTxIDs []string) (string, error) {
if burnTxID != nil {
return *burnTxID, nil
}

if len(burnTxIDs) > 0 {
return burnTxIDs[0], nil
}

return "", errors.New("burn txid should either passed in burn_txid field or as an item in burn_txids array")
}

// RegisterTaskState - Registers a task state
func (service *CascadeAPIHandler) RegisterTaskState(ctx context.Context, p *cascade.RegisterTaskStatePayload, stream cascade.RegisterTaskStateServerStream) (err error) {
defer stream.Close()
Expand Down
5 changes: 3 additions & 2 deletions walletnode/api/services/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
Expand Down Expand Up @@ -214,7 +213,6 @@ func handleUploadFile(ctx context.Context, reader *multipart.Reader, baseDir str
}

filename = part.FileName()
fmt.Printf("Upload image %q\n", filename)
outputFilePath = filepath.Join(dirPath, filename)
outputFile, err := os.Create(outputFilePath)
if err != nil {
Expand Down Expand Up @@ -246,6 +244,9 @@ func handleUploadFile(ctx context.Context, reader *multipart.Reader, baseDir str
// Use 7z to split the file
err := fs.SplitFile(outputFilePath)
if err != nil {
if strings.Contains(err.Error(), "no such file or directory") {
return "", "", 0, errors.New("seems like `p7zip-full` is not installed in your system, kindly proceed after installing the package")
}
return "", "", 0, err
}
// Remove the original file after splitting
Expand Down
11 changes: 6 additions & 5 deletions walletnode/services/cascaderegister/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ func (service *CascadeRegistrationService) RegisterVolumeTicket(ctx context.Cont
}

if len(relatedFiles) <= 1 {
return "", errors.New("related files must be greater than 1")
return "", errors.New("related volumes must be greater than 1 for creating multi-volume ticket")
}

concludedCount := 0
Expand Down Expand Up @@ -867,10 +867,11 @@ func (service *CascadeRegistrationService) RestoreFile(ctx context.Context, p *c
}
}

// only set base file txId return by pastel register all else remains nil
_, err = service.RegisterVolumeTicket(ctx, p.BaseFileID)
if err != nil {
return nil, err
if len(volumes) > 1 {
_, err = service.RegisterVolumeTicket(ctx, p.BaseFileID)
if err != nil {
return nil, err
}
}

return &cascade.RestoreFile{
Expand Down
Loading