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

Improve JSON Output for Upload and Remove Commands #1389

Merged
merged 3 commits into from
Nov 24, 2023

Conversation

tareknaser
Copy link
Contributor

@tareknaser tareknaser commented Nov 1, 2023

Summary

This PR addresses an issue where the JSON output for both the upload and remove commands in cargo contract was in an invalid format.

  • [n] y/n | Does it introduce breaking changes?
  • [n] y/n | Is it dependent on the specific version of ink or pallet-contracts?

Description

This pull request enhances the JSON output for both the upload and remove commands in cargo contract.
Previously, the JSON output was in an invalid format, making it challenging to parse and extract information. The modified format now produces valid JSON objects for easier parsing.

Example: JSON Output Before:

// Invalid JSON Format (Before)
[
  {
    "pallet": "Balances",
    "name": "Withdraw",
    // ... Other fields
  },
  // ... Additional events
]
{
  "code_hash": "0xe62b681614e6b7dbe892796b..."
}

Example: JSON Output After:

// Valid JSON Format (After)
{
  "code_hash": "0xe62b681614e6b7dbe892796b...",
  "events": [
    {
      "name": "Withdraw",
      "pallet": "Balances",
      // ... Other fields
    },
    // ... Additional events
  ]
}

Checklist before requesting a review

  • My code follows the style guidelines of this project
  • I have added an entry to CHANGELOG.md
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

tareknaser added a commit to tareknaser/cargo-contract that referenced this pull request Nov 1, 2023
// Create a JSON object with the events and the removed code hash.
let json_object = serde_json::json!({
"events": serde_json::from_str::<serde_json::Value>(&output_events)?,
"removed_code_hash": remove_result,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we have removed_code_hash in JSON format, and in standard printing, we have Code hash. I think it makes sense to align it.

In the upload command, we have code hash in both cases; in JSON: code_hash, and in standard print: Code hash.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think I missed this one.
Which one do you prefer to be used in both cases?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be just code hash for me, but I am not owner of this repo.
@ascjones do you have any preferences?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now renamed it to code_hash for consistency.
Thanks for your input

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

This commit addresses an issue where the JSON output for both the upload and remove commands in cargo contract was in an invalid format.

This commit refactors the JSON structure for these commands, resulting in valid JSON objects.

Signed-off-by: Tarek <[email protected]>
This commit renames the field removed_code_hash to just code_hash in the remove command output to keep it consistent with between json output and human readable output

Signed-off-by: Tarek <[email protected]>
Copy link
Contributor

@xermicus xermicus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@xermicus xermicus merged commit 83b941d into use-ink:master Nov 24, 2023
10 checks passed
@tareknaser tareknaser deleted the upload-remove-json branch November 24, 2023 16:55
@smiasojed smiasojed mentioned this pull request Nov 30, 2023
@smiasojed smiasojed mentioned this pull request Mar 4, 2024
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

Successfully merging this pull request may close these issues.

3 participants