Skip to content

Commit 39cec7d

Browse files
cli: refactor neofs-sdk-go related operations in upload-bin
Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
1 parent 388ee25 commit 39cec7d

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

cli/util/upload_bin.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func uploadBin(ctx *cli.Context) error {
110110
return cli.Exit(fmt.Errorf("failed to find objects: %w", err), 1)
111111
}
112112

113-
err = uploadBlocksAndIndexFiles(ctx, pWrapper, rpc, signer, containerID, user.NewFromScriptHash(acc.ScriptHash()), attr, indexAttrKey, buf, i, indexFileSize, uint(currentBlockHeight), numWorkers, maxRetries, debug)
113+
err = uploadBlocksAndIndexFiles(ctx, pWrapper, rpc, signer, containerID, attr, indexAttrKey, buf, i, indexFileSize, uint(currentBlockHeight), numWorkers, maxRetries, debug)
114114
if err != nil {
115115
return cli.Exit(fmt.Errorf("failed to upload objects: %w", err), 1)
116116
}
@@ -138,7 +138,7 @@ func retry(action func() error, maxRetries uint, debug bool) error {
138138
}
139139

140140
// uploadBlocksAndIndexFiles uploads the blocks and index files to the container using the pool.
141-
func uploadBlocksAndIndexFiles(ctx *cli.Context, p poolWrapper, rpc *rpcclient.Client, signer user.Signer, containerID cid.ID, ownerID user.ID, attr, indexAttributeKey string, buf []byte, currentIndexFileID, indexFileSize, currentBlockHeight uint, numWorkers, maxRetries uint, debug bool) error {
141+
func uploadBlocksAndIndexFiles(ctx *cli.Context, p poolWrapper, rpc *rpcclient.Client, signer user.Signer, containerID cid.ID, attr, indexAttributeKey string, buf []byte, currentIndexFileID, indexFileSize, currentBlockHeight uint, numWorkers, maxRetries uint, debug bool) error {
142142
if currentIndexFileID*indexFileSize >= currentBlockHeight {
143143
fmt.Fprintf(ctx.App.Writer, "No new blocks to upload. Need to upload starting from %d, current height %d\n", currentIndexFileID*indexFileSize, currentBlockHeight)
144144
return nil
@@ -204,7 +204,7 @@ func uploadBlocksAndIndexFiles(ctx *cli.Context, p poolWrapper, rpc *rpcclient.C
204204
)
205205
errRetr := retry(func() error {
206206
var errUpload error
207-
resOid, errUpload = uploadObj(ctx.Context, p, signer, ownerID, containerID, objBytes, attrs)
207+
resOid, errUpload = uploadObj(ctx.Context, p, signer, containerID, objBytes, attrs)
208208
if errUpload != nil {
209209
return errUpload
210210
}
@@ -251,7 +251,7 @@ func uploadBlocksAndIndexFiles(ctx *cli.Context, p poolWrapper, rpc *rpcclient.C
251251
}
252252
err := retry(func() error {
253253
var errUpload error
254-
_, errUpload = uploadObj(ctx.Context, p, signer, ownerID, containerID, buf, attrs)
254+
_, errUpload = uploadObj(ctx.Context, p, signer, containerID, buf, attrs)
255255
return errUpload
256256
}, maxRetries, debug)
257257
if err != nil {
@@ -423,16 +423,15 @@ func searchObjects(ctx context.Context, p poolWrapper, containerID cid.ID, privK
423423
}
424424

425425
// uploadObj uploads object to the container using provided settings.
426-
func uploadObj(ctx context.Context, p poolWrapper, signer user.Signer, ownerID user.ID, containerID cid.ID, objData []byte, attrs []object.Attribute) (oid.ID, error) {
426+
func uploadObj(ctx context.Context, p poolWrapper, signer user.Signer, containerID cid.ID, objData []byte, attrs []object.Attribute) (oid.ID, error) {
427427
var (
428428
hdr object.Object
429429
prmObjectPutInit client.PrmObjectPutInit
430430
resOID = oid.ID{}
431431
)
432432

433-
hdr.SetPayload(objData)
434433
hdr.SetContainerID(containerID)
435-
hdr.SetOwner(ownerID)
434+
hdr.SetOwner(signer.UserID())
436435
hdr.SetAttributes(attrs...)
437436

438437
writer, err := p.ObjectPutInit(ctx, hdr, signer, prmObjectPutInit)
@@ -450,9 +449,6 @@ func uploadObj(ctx context.Context, p poolWrapper, signer user.Signer, ownerID u
450449
}
451450
res := writer.GetResult()
452451
resOID = res.StoredObjectID()
453-
if resOID.IsZero() {
454-
return resOID, fmt.Errorf("object ID is empty")
455-
}
456452
return resOID, nil
457453
}
458454

0 commit comments

Comments
 (0)