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

QA: Delete a file #629

Open
Tracked by #591
SimiHunjan opened this issue Nov 28, 2023 · 5 comments
Open
Tracked by #591

QA: Delete a file #629

SimiHunjan opened this issue Nov 28, 2023 · 5 comments

Comments

@SimiHunjan
Copy link
Contributor

SimiHunjan commented Nov 28, 2023

Delete a file and its state from consensus nodes.

@SimiHunjan SimiHunjan mentioned this issue Nov 28, 2023
39 tasks
@SimiHunjan
Copy link
Contributor Author

Code Example

#include "Client.h"
#include "ED25519PrivateKey.h"
#include "FileCreateTransaction.h"
#include "FileDeleteTransaction.h"
#include "FileId.h"
#include "Status.h"
#include "TransactionReceipt.h"
#include "TransactionResponse.h"
#include "impl/Utilities.h"
#include "FileInfo.h"
#include "FileInfoQuery.h"
#include <iostream>

using namespace Hedera;


int main(int argc, char** argv)
{
  if (argc < 3)
  {
    std::cout << "Please input account ID and private key" << std::endl;
    return 1;
  }

  // Get a client for the Hedera testnet, and set the operator account ID and key such that all generated transactions
  // will be paid for by this account and be signed by this key.
  Client client = Client::forTestnet();
  client.setOperator(AccountId::fromString(argv[1]), ED25519PrivateKey::fromString(argv[2]));

  // Create a new file.
  const FileId fileId = FileCreateTransaction()
                          .setKeys({ client.getOperatorPublicKey() })
                          .setContents(internal::Utilities::stringToByteVector("Hedera Hashgraph is great!"))
                          .execute(client)
                          .getReceipt(client)
                          .mFileId.value();
  std::cout << "Created new file with ID " << fileId.toString() << std::endl;

  // Delete the newly-created file.
  const TransactionReceipt txReceipt = FileDeleteTransaction().setFileId(fileId).execute(client).getReceipt(client);
  std::cout << "Deleted file with response code: " << gStatusToString.at(txReceipt.mStatus) << std::endl;

  const FileInfo getFileInfo = FileInfoQuery()
          .setFileId(fileId)
          .execute(client);

  std::cout << "File is deleted: " << getFileInfo.mIsDeleted << std::endl;

  return 0;
}

Output

Created new file with ID 0.0.5996837
Deleted file with response code: SUCCESS
File is deleted: 1

@SimiHunjan
Copy link
Contributor Author

Hey @rwalworth !

I added the file info query at the end to validate the state of the file recorded it was deleted.

I am getting the response 1 (File is deleted: 1).

I believe this should be returning true.

@rwalworth
Copy link
Contributor

Hey @rwalworth !

I added the file info query at the end to validate the state of the file recorded it was deleted.

I am getting the response 1 (File is deleted: 1).

I believe this should be returning true.

C++ doesn't print booleans as strings unfortunately. Any value over 0 is considered true, while 0 is considered false.

@rwalworth
Copy link
Contributor

Hey @rwalworth !
I added the file info query at the end to validate the state of the file recorded it was deleted.
I am getting the response 1 (File is deleted: 1).
I believe this should be returning true.

C++ doesn't print booleans as strings unfortunately. Any value over 0 is considered true, while 0 is considered false.

@SimiHunjan just learned this, if you do
std::cout << "File is deleted: " << std::boolalpha << getFileInfo.mIsDeleted << std::endl;
it'll print the bool as a string

@SimiHunjan
Copy link
Contributor Author

ah thanks @rwalworth will try this out! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants