From 067af5b89f2c36c4f9de5643c7437196704ed779 Mon Sep 17 00:00:00 2001 From: Ekaterina Pavlova Date: Mon, 11 Nov 2024 17:22:53 +0300 Subject: [PATCH] cli: add logs for `upload-bin` Logs for testing purpose.Refs. https://github .com/nspcc-dev/neo-go/issues/3658#issuecomment-2468210667 Signed-off-by: Ekaterina Pavlova --- cli/util/upload_bin.go | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/cli/util/upload_bin.go b/cli/util/upload_bin.go index 4d5e387ce5..26a6060d19 100644 --- a/cli/util/upload_bin.go +++ b/cli/util/upload_bin.go @@ -295,7 +295,12 @@ func uploadBlocks(ctx *cli.Context, p *pool.Pool, rpc *rpcclient.Client, signer objBytes := bw.Bytes() errRetr := retry(func() error { - return uploadObj(ctx.Context, p, signer, acc.PrivateKey().GetScriptHash(), containerID, objBytes, attrs, homomorphicHashingDisabled) + resOid, errUpload := uploadObj(ctx.Context, p, signer, acc.PrivateKey().GetScriptHash(), containerID, objBytes, attrs, homomorphicHashingDisabled) + if errUpload != nil { + return errUpload + } + fmt.Fprintf(ctx.App.Writer, "Uploaded block %d with object ID: %s\n", blockIndex, resOid.String()) + return errUpload }, maxRetries) if errRetr != nil { select { @@ -460,7 +465,12 @@ func uploadIndexFiles(ctx *cli.Context, p *pool.Pool, containerID cid.ID, accoun *object.NewAttribute("IndexSize", strconv.Itoa(int(indexFileSize))), } err := retry(func() error { - return uploadObj(ctx.Context, p, signer, account.PrivateKey().GetScriptHash(), containerID, buffer, attrs, homomorphicHashingDisabled) + resOid, errUpload := uploadObj(ctx.Context, p, signer, account.PrivateKey().GetScriptHash(), containerID, buffer, attrs, homomorphicHashingDisabled) + if errUpload != nil { + return errUpload + } + fmt.Fprintf(ctx.App.Writer, "Uploaded index file %d with object ID: %s\n", i, resOid.String()) + return errUpload }, maxRetries) if err != nil { select { @@ -541,7 +551,7 @@ func searchObjects(ctx context.Context, p *pool.Pool, containerID cid.ID, accoun } // uploadObj uploads object to the container using provided settings. -func uploadObj(ctx context.Context, p *pool.Pool, signer user.Signer, owner util.Uint160, containerID cid.ID, objData []byte, attrs []object.Attribute, homomorphicHashingDisabled bool) error { +func uploadObj(ctx context.Context, p *pool.Pool, signer user.Signer, owner util.Uint160, containerID cid.ID, objData []byte, attrs []object.Attribute, homomorphicHashingDisabled bool) (oid.ID, error) { var ( ownerID user.ID hdr object.Object @@ -549,6 +559,7 @@ func uploadObj(ctx context.Context, p *pool.Pool, signer user.Signer, owner util chHomomorphic checksum.Checksum v = new(version.Version) prmObjectPutInit client.PrmObjectPutInit + resOID = oid.ID{} ) ownerID.SetScriptHash(owner) @@ -569,31 +580,32 @@ func uploadObj(ctx context.Context, p *pool.Pool, signer user.Signer, owner util err := hdr.SetIDWithSignature(signer) if err != nil { - return err + return resOID, err } err = hdr.CheckHeaderVerificationFields() if err != nil { - return err + return resOID, err } writer, err := p.ObjectPutInit(ctx, hdr, signer, prmObjectPutInit) if err != nil { - return fmt.Errorf("failed to initiate object upload: %w", err) + return resOID, fmt.Errorf("failed to initiate object upload: %w", err) } _, err = writer.Write(objData) if err != nil { _ = writer.Close() - return fmt.Errorf("failed to write object data: %w", err) + return resOID, fmt.Errorf("failed to write object data: %w", err) } err = writer.Close() if err != nil { - return fmt.Errorf("failed to close object writer: %w", err) + return resOID, fmt.Errorf("failed to close object writer: %w", err) } res := writer.GetResult() - if res.StoredObjectID().Equals(oid.ID{}) { - return fmt.Errorf("object ID is empty") + resOID = res.StoredObjectID() + if resOID.Equals(oid.ID{}) { + return resOID, fmt.Errorf("object ID is empty") } - return nil + return resOID, nil } func getBlockIndex(header object.Object, attribute string) (int, error) {